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 cApiLayoutCollection extends ItemCollection {
24: 25: 26: 27: 28:
29: public function __construct() {
30: global $cfg;
31: parent::__construct($cfg['tab']['lay'], 'idlay');
32: $this->_setItemClass('cApiLayout');
33:
34:
35: $this->_setJoinPartner('cApiClientCollection');
36: }
37:
38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55:
56: public function create($name, $idclient = NULL, $alias = '', $description = '', $deletable = 1, $author = '', $created = '', $lastmodified = '') {
57: global $client, $auth;
58:
59: if (NULL === $idclient) {
60: $idclient = $client;
61: }
62:
63: if (empty($alias)) {
64: $alias = cString::toLowerCase(cString::cleanURLCharacters(i18n("-- New layout --")));
65: }
66:
67: if (empty($author)) {
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: $item = $this->createNewItem();
78: $item->set('idclient', $idclient);
79: $item->set('name', $name);
80: $item->set('alias', $alias);
81: $item->set('description', $description);
82: $item->set('deletable', $deletable);
83: $item->set('author', $author);
84: $item->set('created', $created);
85: $item->set('lastmodified', $lastmodified);
86: $item->store();
87:
88: return $item;
89: }
90:
91: }
92:
93: 94: 95: 96: 97: 98:
99: class cApiLayout extends Item {
100:
101: 102: 103: 104: 105:
106: protected $_aUsedTemplates = array();
107:
108: 109: 110: 111: 112: 113: 114: 115: 116:
117: public function __construct($mId = false) {
118: global $cfg;
119: parent::__construct($cfg['tab']['lay'], 'idlay');
120: $this->setFilters(array(), array());
121: if ($mId !== false) {
122: $this->loadByPrimaryKey($mId);
123: }
124: }
125:
126: 127: 128: 129: 130: 131: 132: 133: 134:
135: public function isInUse($setData = false) {
136: if (!$this->isLoaded()) {
137: throw new cException('Layout item not loaded!');
138: }
139:
140: $oTplColl = new cApiTemplateCollection();
141: $templates = $oTplColl->fetchByIdLay($this->get('idlay'));
142: if (0 === count($templates)) {
143: return false;
144: }
145:
146: if ($setData === true) {
147: $this->_aUsedTemplates = array();
148: foreach ($templates as $i => $template) {
149: $this->_aUsedTemplates[$i] = array(
150: 'tpl_id' => $template->get('idtpl'),
151: 'tpl_name' => $template->get('name')
152: );
153: }
154: }
155:
156: return true;
157: }
158:
159: 160: 161: 162: 163: 164:
165: public function getUsedTemplates() {
166: return $this->_aUsedTemplates;
167: }
168:
169: 170: 171: 172: 173: 174: 175: 176: 177:
178: public function setField($name, $value, $bSafe = true) {
179: switch ($name) {
180: case 'deletable':
181: $value = ($value == 1) ? 1 : 0;
182: break;
183: case 'idclient':
184: $value = (int) $value;
185: break;
186: }
187:
188: return parent::setField($name, $value, $bSafe);
189: }
190:
191: }
192: