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:
159: public function loadByArticleOrCategory($idart, $idcat, $lang, $client) {
160:
161:
162:
163: $idtplcfg = conGetTemplateConfigurationIdForArticle($idart, $idcat, $lang, $client);
164: if (!is_numeric($idtplcfg) || $idtplcfg == 0) {
165: $idtplcfg = conGetTemplateConfigurationIdForCategory($idcat, $lang, $client);
166: }
167: if (is_null($idtplcfg)) {
168: return false;
169: }
170:
171:
172: $templateConfiguration = new cApiTemplateConfiguration($idtplcfg);
173: if (!$templateConfiguration->isLoaded()) {
174: return;
175: }
176:
177:
178: $idtpl = $templateConfiguration->get('idtpl');
179: $this->loadByPrimaryKey($idtpl);
180: }
181:
182: 183: 184: 185: 186: 187: 188: 189: 190:
191: public function setField($name, $value, $bSafe = true) {
192: switch ($name) {
193: case 'deletable':
194: case 'status':
195: case 'defaulttemplate':
196: $value = ($value == 1) ? 1 : 0;
197: break;
198: case 'idclient':
199: case 'idlay':
200: $value = (int) $value;
201: break;
202: case 'idtplcfg':
203: if (!is_numeric($value)) {
204: $value = '';
205: }
206: break;
207: }
208:
209: parent::setField($name, $value, $bSafe);
210: }
211:
212: }
213: