Subversion-Projekte lars-tiefland.ci

Revision

Revision 625 | Blame | Vergleich mit vorheriger | Letzte Änderung | Log anzeigen | RSS feed

<?php

/**
 * @author Lars Tiefland
 * @copyright 2016
 */

/**
 * Herstellerkatalog_model
 * 
 * @package WebanOS CI
 * @author Lars Tiefland
 * @copyright 2016
 * @version $Id: Herstellerkatalog_model.php 625 2016-09-20 19:39:35Z lars $
 * @access public
 */
class Herstellerkatalog_model extends CI_Model
{
        /**
         * Herstellerkatalog_model::__construct()
         * 
         * @return
         */
        public function __construct()
        {
                parent::__construct();
                $this->load->model('artikel_model', 'artikel');
                $this->load->model('alias_model', 'alias');
                $this->load->model('preise_model', 'preise');
        }

        /**
         * Herstellerkatalog_model::get_info()
         * 
         * Infos zu einem Hersteller
         * 
         * @param mixed $hId
         * @return
         */
        public function get_info($hId)
        {
                $res = $this->db->get_where('Herstellerkatalog', array('id' => $hId));
                $row = $res->row_array();
                return $row;
        }
        /**
         * Herstellerkatalog_model::list_hersteller()
         * 
         * Herstellerübersicht
         * 
         * @param string $begin
         * @param mixed $limit
         * @param integer $Eigenschaft_1
         * @param integer $Eigenschaft_2
         * @return
         */
        public function list_hersteller($begin = '', $limit = null, $Eigenschaft_1 = 0,
                $Eigenschaft_2 = 0)
        {
                $where = " EXISTS (SELECT 1 FROM artikel a WHERE a.hersteller=h.id AND a.father > 0 AND a.status=0)";
                if ($begin)
                {
                        $where .= " AND name LIKE '".$begin."%'";
                }
                if ($Eigenschaft_1)
                {
                        $where .= " AND Eigenschaft_1=1";
                }
                if ($Eigenschaft_2)
                {
                        $where .= " AND Eigenschaft_2=1";
                }
                $this->db->distinct();
                $this->db->order_by('name', 'ASC');
                $res = $this->db->get_where('Herstellerkatalog h', $where);
                $rows = $res->result_array();
                return $rows;
        }

        /**
         * Herstellerkatalog_model::list_items()
         * 
         * Übersicht über die Artikel eines Herstellers
         * 
         * @param mixed $hersteller
         * @return
         */
        public function list_items($hersteller = Null, $start = 0, $limit = 40)
        {
                $sql = 'SELECT
                                SQL_CALC_FOUND_ROWS
                                ID
                        FROM
                                artikel
                        WHERE
                                language="DE"
                        AND
                                status=0
                ';
                if (!is_null($hersteller))
                {
                        $sql .= '
                                AND
                                        hersteller='.$hersteller.'
                        ';
                }
                if (isset($_GET['kat']) && $_GET{'kat'})
                {
                        list($kat_id, $kat_name) = explode("-", $_GET['kat'], 2);
                        $this->smarty->assign('kat_name', $kat_name);
                        $sql .= '
                                AND
                                        father='.$kat_id.'
                        ';
                }
                if (!is_null($limit))
                {
                        $sql .= '
                                LIMIT
                                        '.$start.','.$limit.'
                        ';
                }
                $query = $this->db->query($sql);
                $sql = "SELECT FOUND_ROWS() AS total";
                $ret = $this->db->query($sql);
                $erg = $ret->row_array();
                $count = $erg['total'];
                $config{'base_url'} = $this->config->item('base_url').'/'.$this->get_link($hersteller);
                $config['total_rows'] = $count;
                $config['per_page'] = $limit;
                $config['page_query_string'] = true;
                //$config['use_page_numbers'] = true;
                $config['cur_tag_open'] = '&nbsp;[&nbsp;<b>';
                $config['cur_tag_close'] = '</b>&nbsp;]';
                $config['num_tag_open'] = '&nbsp;[&nbsp;';
                $config['num_tag_close'] = '&nbsp;]';
                $config['first_tag_open'] = '&nbsp;[&nbsp;';
                $config['first_tag_close'] = '&nbsp;]';
                $config['last_tag_open'] = '&nbsp;[&nbsp;';
                $config['last_tag_close'] = '&nbsp;]';
                $config['next_tag_open'] = '&nbsp;[&nbsp;';
                $config['next_tag_close'] = '&nbsp;]';
                $config['prev_tag_open'] = '&nbsp;[&nbsp;';
                $config['prev_tag_close'] = '&nbsp;]';
                $this->pagination->initialize($config);
                $this->smarty->assign('pagination', $this->pagination->create_links());
                while ($row = $query->unbuffered_row('array'))
                {
                        $a_id = $row['ID'];
                        $item = $this->artikel->get_artikel($a_id, true);
                        $items[] = $item;
                }
                return $items;
        }

        /**
         * Herstellerkatalog_model::get_serien()
         * 
         * Serien eines Herstellers
         * 
         * @param mixed $herstellerId
         * @return
         */
        public function get_serien($herstellerId)
        {
                $herstellerSerie = array();
                $sql = "SELECT DISTINCT
                    a.ID as aID,
                    s.id as sID,
                    s.name as sName,
                    h.Name as herstellerName
                FROM
                    artikel a,
                    Herstellerkatalog h,
                    directory d,
                    serien s
                JOIN
                    shop_link_table slt
                ON
                    s.id = slt.Father
                WHERE
                    a.hersteller = ".$herstellerId."
                AND
                    h.ID = ".$herstellerId."
                AND
                    (
                        (slt.Verwendung = 'a2s' AND a.ID = slt.ID)
                        OR
                        (slt.Verwendung = 'd2s' AND d.ID = slt.ID AND a.Father = d.ID)
                    )
                ORDER BY sName
        ";

                $q = $this->db->query($sql);
                if ($q)
                {
                        while ($r = $q->unbuffered_row('array'))
                        {
                                if ($r['sName'])
                                {
                                        $herstellerSerie[$r['sID']]['serieName'] = $r['sName'];
                                        $herstellerSerie[$r['sID']]['serieLink'] = "/serie/view/".$r['sID']."-".
                                                strtolower(str2url($r['sName'])).".html";
                                }
                        }
                }
                return $herstellerSerie;
        }

        private function get_link($hersteller)
        {
                $sql = 'SELECT
                                id,
                                name
                        FROM
                                Herstellerkatalog
                        WHERE
                                id='.$hersteller.'
                ';
                $res = $this->db->query($sql);
                $row = $res->row_array();
                $link = '/hersteller/view/'.$row['id'].'-'.str2url($row['name']).'.html';
                return $link;
        }
}

?>