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