1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
15:
16: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
17:
18: 19: 20: 21: 22: 23:
24: class cApiContainerCollection extends ItemCollection {
25:
26: 27: 28: 29: 30: 31:
32: public function __construct($select = false) {
33: global $cfg;
34: parent::__construct($cfg['tab']['container'], 'idcontainer');
35: $this->_setItemClass('cApiContainer');
36:
37:
38: $this->_setJoinPartner('cApiTemplateCollection');
39:
40: if ($select !== false) {
41: $this->select($select);
42: }
43: }
44:
45: 46: 47: 48: 49: 50: 51: 52:
53: public function create($idtpl, $number, $idmod) {
54: $item = parent::createNewItem();
55:
56: $item->set('idtpl', $idtpl);
57: $item->set('number', $number);
58: $item->set('idmod', $idmod);
59: $item->store();
60:
61: return $item;
62: }
63:
64: 65: 66: 67: 68: 69:
70: public function getNumbersByTemplate($idtpl) {
71: $list = array();
72: $sql = "SELECT number FROM `%s` WHERE idtpl = %d";
73: $this->db->query($sql, $this->table, $idtpl);
74: while ($this->db->nextRecord()) {
75: $list[] = $this->db->f('number');
76: }
77: return $list;
78: }
79:
80: 81: 82: 83:
84: public function clearAssignments($idtpl) {
85: $this->deleteBy('idtpl', (int) $idtpl);
86: }
87:
88: 89: 90: 91: 92: 93:
94: public function assignModule($idtpl, $number, $idmod) {
95: $this->select('idtpl = ' . (int) $idtpl . ' AND number = ' . (int) $number);
96: if (($item = $this->next()) !== false) {
97: $item->set('idmod', $idmod);
98: $item->store();
99: } else {
100: $this->create($idtpl, $number, $idmod);
101: }
102: }
103:
104: 105: 106:
107: public function assignModul($idtpl, $number, $idmod) {
108: cDeprecated("The method assignModul() is deprecated. Use assignModule() instead.");
109: $this->assignModule($idtpl, $number, $idmod);
110: }
111: }
112:
113: 114: 115: 116: 117: 118:
119: class cApiContainer extends Item {
120:
121: 122: 123: 124: 125:
126: public function __construct($mId = false) {
127: global $cfg;
128: parent::__construct($cfg['tab']['container'], 'idcontainer');
129: $this->setFilters(array(), array());
130: if ($mId !== false) {
131: $this->loadByPrimaryKey($mId);
132: }
133: }
134:
135: 136: 137: 138: 139: 140: 141: 142:
143: public function setField($name, $value, $bSafe = true) {
144: switch ($name) {
145: case 'idtpl':
146: case 'number':
147: case 'idmod':
148: $value = (int) $value;
149: break;
150: }
151:
152: parent::setField($name, $value, $bSafe);
153: }
154:
155: }
156: