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