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:      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:     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(cApiStrCleanURLCharacters(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 = parent::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:         return ($item);
 83:     }
 84: 
 85: }
 86: 
 87:  88:  89:  90:  91:  92: 
 93: class cApiLayout extends Item {
 94: 
 95:      96:  97:  98:  99: 
100:     protected $_aUsedTemplates = array();
101: 
102:     103: 104: 105: 106: 
107:     public function __construct($mId = false) {
108:         global $cfg;
109:         parent::__construct($cfg['tab']['lay'], 'idlay');
110:         $this->setFilters(array(), array());
111:         if ($mId !== false) {
112:             $this->loadByPrimaryKey($mId);
113:         }
114:     }
115: 
116:     117: 118: 119: 120: 121: 122: 
123:     public function isInUse($setData = false) {
124:         if (!$this->isLoaded()) {
125:             throw new cException('Layout item not loaded!');
126:         }
127: 
128:         $oTplColl = new cApiTemplateCollection();
129:         $templates = $oTplColl->fetchByIdLay($this->get('idlay'));
130:         if (0 === count($templates)) {
131:             return false;
132:         }
133: 
134:         if ($setData === true) {
135:             $this->_aUsedTemplates = array();
136:             foreach ($templates as $i => $template) {
137:                 $this->_aUsedTemplates[$i] = array(
138:                     'tpl_id' => $template->get('idtpl'),
139:                     'tpl_name' => $template->get('name')
140:                 );
141:             }
142:         }
143: 
144:         return true;
145:     }
146: 
147:     148: 149: 150: 151: 
152:     public function getUsedTemplates() {
153:         return $this->_aUsedTemplates;
154:     }
155: 
156:     157: 158: 159: 160: 161: 162: 163: 
164:     public function setField($name, $value, $bSafe = true) {
165:         switch ($name) {
166:             case 'deletable':
167:                 $value = ($value == 1) ? 1 : 0;
168:                 break;
169:             case 'idclient':
170:                 $value = (int) $value;
171:                 break;
172:         }
173: 
174:         parent::setField($name, $value, $bSafe);
175:     }
176: 
177: }
178: