Subversion-Projekte lars-tiefland.ci

Revision

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

Revision Autor Zeilennr. Zeile
322 lars 1
<?php
2
 
3
/**
4
 * @author Lars Tiefland
5
 * @copyright 2016
6
 */
7
 
519 lars 8
/**
9
 * Herstellerkatalog_model
10
 *
527 lars 11
 * @package WebanOS CI
12
 * @author Lars Tiefland
13
 * @copyright 2016
14
 * @version $Id: Herstellerkatalog_model.php 625 2016-09-20 19:39:35Z lars $
519 lars 15
 * @access public
16
 */
322 lars 17
class Herstellerkatalog_model extends CI_Model
18
{
519 lars 19
	/**
20
	 * Herstellerkatalog_model::__construct()
21
	 *
22
	 * @return
23
	 */
322 lars 24
	public function __construct()
25
	{
26
		parent::__construct();
27
		$this->load->model('artikel_model', 'artikel');
28
		$this->load->model('alias_model', 'alias');
29
		$this->load->model('preise_model', 'preise');
30
	}
31
 
519 lars 32
	/**
33
	 * Herstellerkatalog_model::get_info()
34
	 *
35
	 * Infos zu einem Hersteller
36
	 *
37
	 * @param mixed $hId
38
	 * @return
39
	 */
375 lars 40
	public function get_info($hId)
41
	{
388 lars 42
		$res = $this->db->get_where('Herstellerkatalog', array('id' => $hId));
375 lars 43
		$row = $res->row_array();
44
		return $row;
388 lars 45
	}
519 lars 46
	/**
47
	 * Herstellerkatalog_model::list_hersteller()
48
	 *
49
	 * Herstellerübersicht
50
	 *
51
	 * @param string $begin
52
	 * @param mixed $limit
53
	 * @param integer $Eigenschaft_1
54
	 * @param integer $Eigenschaft_2
55
	 * @return
56
	 */
486 lars 57
	public function list_hersteller($begin = '', $limit = null, $Eigenschaft_1 = 0,
58
		$Eigenschaft_2 = 0)
322 lars 59
	{
328 lars 60
		$where = " EXISTS (SELECT 1 FROM artikel a WHERE a.hersteller=h.id AND a.father > 0 AND a.status=0)";
322 lars 61
		if ($begin)
62
		{
330 lars 63
			$where .= " AND name LIKE '".$begin."%'";
322 lars 64
		}
486 lars 65
		if ($Eigenschaft_1)
66
		{
67
			$where .= " AND Eigenschaft_1=1";
68
		}
69
		if ($Eigenschaft_2)
70
		{
71
			$where .= " AND Eigenschaft_2=1";
72
		}
326 lars 73
		$this->db->distinct();
333 lars 74
		$this->db->order_by('name', 'ASC');
326 lars 75
		$res = $this->db->get_where('Herstellerkatalog h', $where);
322 lars 76
		$rows = $res->result_array();
77
		return $rows;
78
	}
333 lars 79
 
519 lars 80
	/**
81
	 * Herstellerkatalog_model::list_items()
82
	 *
83
	 * Übersicht über die Artikel eines Herstellers
84
	 *
85
	 * @param mixed $hersteller
86
	 * @return
87
	 */
614 lars 88
	public function list_items($hersteller = Null, $start = 0, $limit = 40)
333 lars 89
	{
613 lars 90
		$sql = 'SELECT
617 lars 91
				SQL_CALC_FOUND_ROWS
613 lars 92
				ID
93
			FROM
94
				artikel
95
			WHERE
96
				language="DE"
97
			AND
98
				status=0
99
		';
100
		if (!is_null($hersteller))
101
		{
102
			$sql .= '
103
				AND
104
					hersteller='.$hersteller.'
105
			';
106
		}
107
		if (isset($_GET['kat']) && $_GET{'kat'})
108
		{
389 lars 109
			list($kat_id, $kat_name) = explode("-", $_GET['kat'], 2);
486 lars 110
			$this->smarty->assign('kat_name', $kat_name);
613 lars 111
			$sql .= '
112
				AND
113
					father='.$kat_id.'
114
			';
388 lars 115
		}
613 lars 116
		if (!is_null($limit))
333 lars 117
		{
613 lars 118
			$sql .= '
119
				LIMIT
120
					'.$start.','.$limit.'
121
			';
122
		}
123
		$query = $this->db->query($sql);
124
		$sql = "SELECT FOUND_ROWS() AS total";
125
		$ret = $this->db->query($sql);
126
		$erg = $ret->row_array();
127
		$count = $erg['total'];
621 lars 128
		$config{'base_url'} = $this->config->item('base_url').'/'.$this->get_link($hersteller);
616 lars 129
		$config['total_rows'] = $count;
130
		$config['per_page'] = $limit;
131
		$config['page_query_string'] = true;
132
		//$config['use_page_numbers'] = true;
133
		$config['cur_tag_open'] = '&nbsp;[&nbsp;<b>';
134
		$config['cur_tag_close'] = '</b>&nbsp;]';
135
		$config['num_tag_open'] = '&nbsp;[&nbsp;';
136
		$config['num_tag_close'] = '&nbsp;]';
137
		$config['first_tag_open'] = '&nbsp;[&nbsp;';
138
		$config['first_tag_close'] = '&nbsp;]';
139
		$config['last_tag_open'] = '&nbsp;[&nbsp;';
140
		$config['last_tag_close'] = '&nbsp;]';
141
		$config['next_tag_open'] = '&nbsp;[&nbsp;';
142
		$config['next_tag_close'] = '&nbsp;]';
143
		$config['prev_tag_open'] = '&nbsp;[&nbsp;';
144
		$config['prev_tag_close'] = '&nbsp;]';
145
		$this->pagination->initialize($config);
146
		$this->smarty->assign('pagination', $this->pagination->create_links());
613 lars 147
		while ($row = $query->unbuffered_row('array'))
148
		{
333 lars 149
			$a_id = $row['ID'];
341 lars 150
			$item = $this->artikel->get_artikel($a_id, true);
151
			$items[] = $item;
333 lars 152
		}
153
		return $items;
154
	}
613 lars 155
 
519 lars 156
	/**
157
	 * Herstellerkatalog_model::get_serien()
158
	 *
159
	 * Serien eines Herstellers
160
	 *
161
	 * @param mixed $herstellerId
162
	 * @return
163
	 */
490 lars 164
	public function get_serien($herstellerId)
613 lars 165
	{
166
		$herstellerSerie = array();
167
		$sql = "SELECT DISTINCT
488 lars 168
                    a.ID as aID,
169
                    s.id as sID,
170
                    s.name as sName,
171
                    h.Name as herstellerName
172
                FROM
173
                    artikel a,
174
                    Herstellerkatalog h,
175
                    directory d,
176
                    serien s
177
                JOIN
178
                    shop_link_table slt
179
                ON
180
                    s.id = slt.Father
181
                WHERE
613 lars 182
                    a.hersteller = ".$herstellerId."
488 lars 183
                AND
613 lars 184
                    h.ID = ".$herstellerId."
488 lars 185
                AND
186
                    (
187
                        (slt.Verwendung = 'a2s' AND a.ID = slt.ID)
188
                        OR
189
                        (slt.Verwendung = 'd2s' AND d.ID = slt.ID AND a.Father = d.ID)
190
                    )
191
                ORDER BY sName
192
        ";
193
 
613 lars 194
		$q = $this->db->query($sql);
195
		if ($q)
196
		{
197
			while ($r = $q->unbuffered_row('array'))
198
			{
199
				if ($r['sName'])
200
				{
201
					$herstellerSerie[$r['sID']]['serieName'] = $r['sName'];
202
					$herstellerSerie[$r['sID']]['serieLink'] = "/serie/view/".$r['sID']."-".
203
						strtolower(str2url($r['sName'])).".html";
204
				}
205
			}
206
		}
207
		return $herstellerSerie;
208
	}
621 lars 209
 
210
	private function get_link($hersteller)
211
	{
212
		$sql = 'SELECT
213
				id,
214
				name
215
			FROM
216
				Herstellerkatalog
217
			WHERE
218
				id='.$hersteller.'
219
		';
220
		$res = $this->db->query($sql);
221
		$row = $res->row_array();
222
		$link = '/hersteller/view/'.$row['id'].'-'.str2url($row['name']).'.html';
223
		return $link;
224
	}
322 lars 225
}
226
 
227
?>