Subversion-Projekte lars-tiefland.ci

Revision

Revision 369 | Revision 371 | Zur aktuellen Revision | Blame | Vergleich mit vorheriger | Letzte Änderung | Log anzeigen | RSS feed

<?php

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

class Artikel_model extends CI_Model
{
        public function __construct()
        {
                parent::__construct();
                $this->load->model('alias_model', 'alias');
                $this->load->model('preise_model', 'preise');
                $this->load->model('medien_model', 'medien');
                $this->load->model('shop_position_model', 'shop_position');

        }
        public function list_artikel($father, $return_zero_price = false)
        {
                $artikel = array();
                $this->db->select('ID');
                //$this->db->order_by('Lieferstatus', 'ASC');
                //$this->db->order_by('Rang', 'DESC');
                $query = $this->db->get_where('artikel', array(
                        "father" => $father,
                        "language" => "DE",
                        "status" => 0,
                        ));
                echo $this->db->last_query();
                while ($row = $query->unbuffered_row('array'))
                {
                        $item = $this->get_item_info($row["ID"], $return_zero_price);
                        if (is_array($item))
                        {
                                $artikel[] = $item;
                        }
                }
                return $artikel;
        }
        public function get_artikel($id, $return = false)
        {
                if (is_numeric($id))
                {
                        if ($return === false)
                        {
                                $link = $this->get_link($id, 1);
                                header("Location: ".$link);
                        }
                        else
                        {
                                $row = $this->get_item_info($id);
                                return $row;
                        }
                }
                else
                {
                        $query = $this->db->get_where('alias', array(
                                "alias" => $id.'.html',
                                "type_id" => 1,
                                ));
                        $row = $query->row_array();
                        $id = $row["id"];
                        $row = $this->get_item_info($id);
                        return $row;
                }
        }

        private function get_link($id)
        {
                $link = $this->alias->get_link($id, 1);
                return "/artikel/view/".$link;
        }

        private function get_item_info($id, $return_zero_price = false)
        {
                $query = $this->db->get_where('artikel', array(
                        'id' => $id,
                        "language" => "DE",
                        ));
                $row = $query->row_array();
                $row['itemLink'] = $this->get_link($row["ID"]);
                $preise = $this->preise->get_prices($row["ID"]);
                if (count($preise))
                {
                        if ((float)$preise["preis1"] > 0 || $return_zero_price === true)
                        {
                                $row = array_merge($row, $preise);
                                $row["shopPosition"] = $this->shop_position->get_position($row['Father']);
                                $row["shopPosition"][] = array(
                                        'Name' => $row['kurzbezeichnung'],
                                        'link' => $row['itemLink'],
                                        );
                                $medien = $this->medien->get_artikel_medien($row["ID"]);
                                $row["medien"] = $medien;
                                $row["preis"] = $row["preis1"];
                                return $row;
                        }
                }
        }
}

?>