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 cApiTemplateCollection extends ItemCollection {
24:
25: 26: 27: 28: 29: 30:
31: public function __construct($select = false) {
32: global $cfg;
33: parent::__construct($cfg['tab']['tpl'], 'idtpl');
34: $this->_setItemClass('cApiTemplate');
35:
36:
37: $this->_setJoinPartner('cApiLayoutCollection');
38: $this->_setJoinPartner('cApiTemplateCollection');
39: $this->_setJoinPartner('cApiTemplateConfigurationCollection');
40:
41: if ($select !== false) {
42: $this->select($select);
43: }
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,
64: $deletable = 1, $status = 0, $defaulttemplate = 0, $author = '',
65: $created = '', $lastmodified = '') {
66: if (empty($author)) {
67: $auth = cRegistry::getAuth();
68: $author = $auth->auth['uname'];
69: }
70: if (empty($created)) {
71: $created = date('Y-m-d H:i:s');
72: }
73: if (empty($lastmodified)) {
74: $lastmodified = date('Y-m-d H:i:s');
75: }
76:
77: $oItem = $this->createNewItem();
78:
79: $oItem->set('idclient', $idclient);
80: $oItem->set('idlay', $idlay);
81: $oItem->set('idtplcfg', $idtplcfg);
82: $oItem->set('name', $name);
83: $oItem->set('description', $description);
84: $oItem->set('deletable', $deletable);
85: $oItem->set('status', $status);
86: $oItem->set('defaulttemplate', $defaulttemplate);
87: $oItem->set('author', $author);
88: $oItem->set('created', $created);
89: $oItem->set('lastmodified', $lastmodified);
90: $oItem->store();
91:
92: return $oItem;
93: }
94:
95: 96: 97: 98: 99: 100:
101: public function selectDefaultTemplate($idclient) {
102: $this->select('defaulttemplate = 1 AND idclient = ' . (int) $idclient);
103: return $this->next();
104: }
105:
106: 107: 108: 109: 110: 111:
112: public function fetchByIdLay($idlay) {
113: $this->select('idlay = ' . (int) $idlay);
114: $entries = array();
115: while (($entry = $this->next()) !== false) {
116: $entries[] = clone $entry;
117: }
118: return $entries;
119: }
120: }
121:
122: 123: 124: 125: 126: 127:
128: class cApiTemplate extends Item {
129:
130: 131: 132: 133: 134: 135:
136: public function __construct($mId = false) {
137: global $cfg;
138: parent::__construct($cfg['tab']['tpl'], 'idtpl');
139: $this->setFilters(array(), array());
140: if ($mId !== false) {
141: $this->loadByPrimaryKey($mId);
142: }
143: }
144:
145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157:
158: public function loadByArticleOrCategory($idart, $idcat, $lang, $client) {
159:
160:
161:
162: $idtplcfg = conGetTemplateConfigurationIdForArticle($idart, $idcat, $lang, $client);
163: if (!is_numeric($idtplcfg) || $idtplcfg == 0) {
164: $idtplcfg = conGetTemplateConfigurationIdForCategory($idcat, $lang, $client);
165: }
166: if (is_null($idtplcfg)) {
167: return false;
168: }
169:
170:
171: $templateConfiguration = new cApiTemplateConfiguration($idtplcfg);
172: if (!$templateConfiguration->isLoaded()) {
173: return false;
174: }
175:
176:
177: $idtpl = $templateConfiguration->get('idtpl');
178: $this->loadByPrimaryKey($idtpl);
179:
180: return true;
181: }
182:
183: 184: 185: 186: 187: 188: 189: 190: 191: 192:
193: public function setField($name, $value, $bSafe = true) {
194: switch ($name) {
195: case 'deletable':
196: case 'status':
197: case 'defaulttemplate':
198: $value = ($value == 1) ? 1 : 0;
199: break;
200: case 'idclient':
201: case 'idlay':
202: $value = (int) $value;
203: break;
204: case 'idtplcfg':
205: if (!is_numeric($value)) {
206: $value = '';
207: }
208: break;
209: }
210:
211: return parent::setField($name, $value, $bSafe);
212: }
213:
214: }
215: