/** * 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; }
/** * return templates list * @param array $p * @return json response */ public function readAll($p) { $rez = DM\Templates::readAllWithData(); foreach ($rez as &$r) { $r['title'] = Util\detectTitle($r['data']); unset($r['data']); unset($r['cfg']['source']['fn']); } return $rez; }