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: * Constructor to create an instance of this class.
26: *
27: * @param bool $select [optional]
28: * where clause to use for selection (see ItemCollection::select())
29: *
30: * @throws cDbException
31: * @throws cInvalidArgumentException
32: */
33: public function __construct($select = false) {
34: global $cfg;
35: parent::__construct($cfg['tab']['cat_tree'], 'idtree');
36:
37: // set the join partners so that joins can be used via link() method
38: $this->_setJoinPartner('cApiCategoryCollection');
39:
40: $this->_setItemClass('cApiCategoryTree');
41: if ($select !== false) {
42: $this->select($select);
43: }
44: }
45:
46: /**
47: * Returns category tree structure by selecting the data from several tables
48: * ().
49: *
50: * @param int $client
51: * Client id
52: * @param int $lang
53: * Language id
54: *
55: * @return array
56: * Category tree structure as follows:
57: * <pre>
58: * $arr[n] (int) idtree value
59: * $arr[n]['idcat'] (int)
60: * $arr[n]['level'] (int)
61: * $arr[n]['idtplcfg'] (int)
62: * $arr[n]['visible'] (int)
63: * $arr[n]['name'] (string)
64: * $arr[n]['public'] (int)
65: * $arr[n]['urlname'] (string)
66: * $arr[n]['is_start'] (int)
67: * </pre>
68: *
69: * @throws cDbException
70: */
71: function getCategoryTreeStructureByClientIdAndLanguageId($client, $lang) {
72: global $cfg;
73:
74: $aCatTree = array();
75:
76: $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';
77:
78: $sql = $this->db->prepare($sql, array(
79: 'cat_tree' => $this->table,
80: 'cat' => $cfg['tab']['cat'],
81: 'cat_lang' => $cfg['tab']['cat_lang'],
82: 'idlang' => (int) $lang,
83: 'idclient' => (int) $client
84: ));
85: $this->db->query($sql);
86:
87: while ($this->db->nextRecord()) {
88: $aCatTree[$this->db->f('idtree')] = array(
89: 'idcat' => $this->db->f('idcat'),
90: 'level' => $this->db->f('level'),
91: 'idtplcfg' => $this->db->f('idtplcfg'),
92: 'visible' => $this->db->f('visible'),
93: 'name' => $this->db->f('name'),
94: 'public' => $this->db->f('public'),
95: 'urlname' => $this->db->f('urlname'),
96: 'is_start' => $this->db->f('is_start')
97: );
98: }
99:
100: return $aCatTree;
101: }
102: }
103:
104: /**
105: * Category tree item
106: *
107: * @package Core
108: * @subpackage GenericDB_Model
109: */
110: class cApiCategoryTree extends Item {
111: /**
112: * Constructor to create an instance of this class.
113: *
114: * @param mixed $mId [optional]
115: * Specifies the ID of item to load
116: *
117: * @throws cDbException
118: * @throws cException
119: */
120: public function __construct($mId = false) {
121: global $cfg;
122: parent::__construct($cfg['tab']['cat_tree'], 'idtree');
123: $this->setFilters(array(), array());
124: if ($mId !== false) {
125: $this->loadByPrimaryKey($mId);
126: }
127: }
128: }
129: