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