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