1: <?php
2:
3: /**
4: * This file contains the category tree collection and item class.
5: *
6: * @package Core
7: * @subpackage GenericDB_Model
8: * @author Timo Hummel
9: * @copyright four for business AG <www.4fb.de>
10: * @license http://www.contenido.org/license/LIZENZ.txt
11: * @link http://www.4fb.de
12: * @link http://www.contenido.org
13: */
14:
15: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
16:
17: /**
18: * Category tree collection
19: *
20: * @package Core
21: * @subpackage GenericDB_Model
22: */
23: class cApiCategoryTreeCollection extends ItemCollection {
24:
25: /**
26: * Constructor to create an instance of this class.
27: *
28: * @param string $select [optional]
29: * where clause to use for selection (see ItemCollection::select())
30: */
31: public function __construct($select = false) {
32: global $cfg;
33: parent::__construct($cfg['tab']['cat_tree'], 'idtree');
34:
35: // set the join partners so that joins can be used via link() method
36: $this->_setJoinPartner('cApiCategoryCollection');
37:
38: $this->_setItemClass('cApiCategoryTree');
39: if ($select !== false) {
40: $this->select($select);
41: }
42: }
43:
44: /**
45: * Returns category tree structure by selecting the data from several tables
46: * ().
47: *
48: * @param int $client
49: * Client id
50: * @param int $lang
51: * Language id
52: * @return array
53: * Category tree structure as follows:
54: * <pre>
55: * $arr[n] (int) idtree value
56: * $arr[n]['idcat'] (int)
57: * $arr[n]['level'] (int)
58: * $arr[n]['idtplcfg'] (int)
59: * $arr[n]['visible'] (int)
60: * $arr[n]['name'] (string)
61: * $arr[n]['public'] (int)
62: * $arr[n]['urlname'] (string)
63: * $arr[n]['is_start'] (int)
64: * </pre>
65: */
66: function getCategoryTreeStructureByClientIdAndLanguageId($client, $lang) {
67: global $cfg;
68:
69: $aCatTree = array();
70:
71: $sql = 'SELECT * FROM `:cat_tree` AS A, `:cat` AS B, `:cat_lang` AS C ' . 'WHERE A.idcat = B.idcat AND B.idcat = C.idcat AND C.idlang = :idlang AND idclient = :idclient ' . 'ORDER BY idtree';
72:
73: $sql = $this->db->prepare($sql, array(
74: 'cat_tree' => $this->table,
75: 'cat' => $cfg['tab']['cat'],
76: 'cat_lang' => $cfg['tab']['cat_lang'],
77: 'idlang' => (int) $lang,
78: 'idclient' => (int) $client
79: ));
80: $this->db->query($sql);
81:
82: while ($this->db->nextRecord()) {
83: $aCatTree[$this->db->f('idtree')] = array(
84: 'idcat' => $this->db->f('idcat'),
85: 'level' => $this->db->f('level'),
86: 'idtplcfg' => $this->db->f('idtplcfg'),
87: 'visible' => $this->db->f('visible'),
88: 'name' => $this->db->f('name'),
89: 'public' => $this->db->f('public'),
90: 'urlname' => $this->db->f('urlname'),
91: 'is_start' => $this->db->f('is_start')
92: );
93: }
94:
95: return $aCatTree;
96: }
97: }
98:
99: /**
100: * Category tree item
101: *
102: * @package Core
103: * @subpackage GenericDB_Model
104: */
105: class cApiCategoryTree extends Item {
106:
107: /**
108: * Constructor to create an instance of this class.
109: *
110: * @param mixed $mId [optional]
111: * Specifies the ID of item to load
112: */
113: public function __construct($mId = false) {
114: global $cfg;
115: parent::__construct($cfg['tab']['cat_tree'], 'idtree');
116: $this->setFilters(array(), array());
117: if ($mId !== false) {
118: $this->loadByPrimaryKey($mId);
119: }
120: }
121: }
122: