Beispiel #1
0
 /**
  * load all templates from database
  * @param  boolean $reload reload even if already all loaded
  * @return void
  */
 public function loadAll($reload = false)
 {
     //skip loading if already loaded and reload not true
     if ($this->loadedAll && !$reload) {
         return;
     }
     $this->reset();
     /* collecting template_fields */
     $fields = array();
     $fieldsByIndex = array();
     $recs = DM\TemplatesStructure::getFields();
     foreach ($recs as $r) {
         $templateId = $r['template_id'];
         unset($r['template_id']);
         $fields[$templateId][$r['id']] =& $r;
         $fieldsByIndex[$templateId][] =& $r;
         unset($r);
     }
     /* loading templates */
     $recs = DM\Templates::readAllWithData();
     foreach ($recs as $r) {
         $r['fields'] = empty($fields[$r['id']]) ? array() : $fields[$r['id']];
         $r['fieldsByIndex'] = empty($fieldsByIndex[$r['id']]) ? array() : $fieldsByIndex[$r['id']];
         /* store template in collection */
         $this->templates[$r['id']] = new \CB\Objects\Template($r['id'], false);
         $this->templates[$r['id']]->setData($r);
     }
     $this->loadedAll = true;
 }
Beispiel #2
0
 /**
  * load template custom data
  */
 protected function loadCustomData()
 {
     parent::loadCustomData();
     $r = DM\Templates::read($this->id);
     if (!empty($r)) {
         //dont override name from tree with name from templates table
         unset($r['name']);
         $this->data = array_merge($this->data, $r);
     } else {
         throw new \Exception("Template load error: no template found with id = " . $this->id);
     }
     /* loading template fields */
     $this->data['fields'] = array();
     $this->data['fieldsByIndex'] = array();
     $this->fieldsOrder = array();
     $recs = DM\TemplatesStructure::getFields($this->id);
     foreach ($recs as &$r) {
         $this->data['fields'][$r['id']] =& $r;
         $this->data['fieldsByIndex'][] =& $r;
         $this->fieldsOrder[$r['name']] = intval($r['order']);
         unset($r);
     }
 }