Subversion-Projekte lars-tiefland.ci

Revision

Revision 527 | Revision 613 | Zur aktuellen Revision | 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 528 2016-09-15 11:20:18Z 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)
        {
                $this->db->select('ID');
                if (is_null($hersteller))
                {
                        $arr = array(
                                'language' => 'DE',
                                'status' => 0,
                                );
                }
                else
                {
                        $arr = array(
                                "hersteller" => $hersteller,
                                'language' => 'DE',
                                'status' => 0,
                                );
                }
                if (isset($_GET['kat']) && $_GET{'kat'})
                {
                        list($kat_id, $kat_name) = explode("-", $_GET['kat'], 2);
                        $this->smarty->assign('kat_name', $kat_name);
                        $arr['father'] = $kat_id;
                }
                $res = $this->db->get_where('artikel', $arr);
                while ($row = $res->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;
    }
}

?>