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 cApiTemplateCollection extends ItemCollection {
25:
26: 27: 28: 29: 30: 31:
32: public function __construct($select = false) {
33: global $cfg;
34: parent::__construct($cfg['tab']['tpl'], 'idtpl');
35: $this->_setItemClass('cApiTemplate');
36:
37:
38: $this->_setJoinPartner('cApiLayoutCollection');
39: $this->_setJoinPartner('cApiTemplateCollection');
40: $this->_setJoinPartner('cApiTemplateConfigurationCollection');
41:
42: if ($select !== false) {
43: $this->select($select);
44: }
45: }
46:
47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62:
63: public function create($idclient, $idlay, $idtplcfg, $name, $description, $deletable = 1, $status = 0, $defaulttemplate = 0, $author = '', $created = '', $lastmodified = '') {
64: if (empty($author)) {
65: $auth = cRegistry::getAuth();
66: $author = $auth->auth['uname'];
67: }
68: if (empty($created)) {
69: $created = date('Y-m-d H:i:s');
70: }
71: if (empty($lastmodified)) {
72: $lastmodified = date('Y-m-d H:i:s');
73: }
74:
75: $oItem = parent::createNewItem();
76:
77: $oItem->set('idclient', $idclient);
78: $oItem->set('idlay', $idlay);
79: $oItem->set('idtplcfg', $idtplcfg);
80: $oItem->set('name', $name);
81: $oItem->set('description', $description);
82: $oItem->set('deletable', $deletable);
83: $oItem->set('status', $status);
84: $oItem->set('defaulttemplate', $defaulttemplate);
85: $oItem->set('author', $author);
86: $oItem->set('created', $created);
87: $oItem->set('lastmodified', $lastmodified);
88: $oItem->store();
89:
90: return $oItem;
91: }
92:
93: 94: 95: 96: 97: 98:
99: public function selectDefaultTemplate($idclient) {
100: $this->select('defaulttemplate = 1 AND idclient = ' . (int) $idclient);
101: return $this->next();
102: }
103:
104: 105: 106: 107: 108: 109:
110: public function fetchByIdLay($idlay) {
111: $this->select('idlay = ' . (int) $idlay);
112: $entries = array();
113: while (($entry = $this->next()) !== false) {
114: $entries[] = clone $entry;
115: }
116: return $entries;
117: }
118: }
119:
120: 121: 122: 123: 124: 125:
126: class cApiTemplate extends Item {
127:
128: 129: 130: 131: 132:
133: public function __construct($mId = false) {
134: global $cfg;
135: parent::__construct($cfg['tab']['tpl'], 'idtpl');
136: $this->setFilters(array(), array());
137: if ($mId !== false) {
138: $this->loadByPrimaryKey($mId);
139: }
140: }
141:
142: 143: 144: 145: 146: 147: 148: 149:
150: public function setField($name, $value, $bSafe = true) {
151: switch ($name) {
152: case 'deletable':
153: case 'status':
154: case 'defaulttemplate':
155: $value = ($value == 1) ? 1 : 0;
156: break;
157: case 'idclient':
158: case 'idlay':
159: $value = (int) $value;
160: break;
161: case 'idtplcfg':
162: if (!is_numeric($value)) {
163: $value = '';
164: }
165: break;
166: }
167:
168: parent::setField($name, $value, $bSafe);
169: }
170:
171: }
172: