/** * 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); } }
/** * get param for this node * * @param varchar $param for now using to get 'facets' or 'DC' * @return array */ public function getNodeParam($param = 'facets') { $rez = false; $from = $this->getId(); //check if cached $cacheParam = 'nodeParam_' . $param . '_' . $from; if (Cache::exist($cacheParam)) { return Cache::get($cacheParam); } $cfg = array(); $templateId = null; $tplCfg = array(); if (!empty($this->id) && is_numeric($this->id)) { $r = DM\Tree::read($this->id); } if (!empty($r)) { $cfg = $r['cfg']; $templateId = $r['template_id']; } if (!empty($this->config['template_id'])) { $templateId = $this->config['template_id']; } if (!empty($templateId)) { $r = DM\Templates::read($templateId); if (!empty($r)) { $tplCfg = $r['cfg']; } } if (isset($cfg[$param])) { $rez = $cfg[$param]; } elseif (isset($tplCfg[$param])) { $cfg = $tplCfg; $rez = $cfg[$param]; $from = 'template_' . $templateId; } //add grouping param for DC if ($param == 'DC' && $rez !== false) { if (!empty($cfg['view']['group'])) { $rez['group'] = $cfg['view']['group']; } elseif (!empty($cfg['group'])) { $rez['group'] = $cfg['group']; } } if ($rez === false) { $rez = parent::getNodeParam($param); } else { $rez = array('from' => $from, 'data' => $rez); } Cache::set($cacheParam, $rez); return $rez; }
/** * get template type by its id * @param int $id * @return varchar */ public function getType($id) { if (!is_numeric($id)) { return null; } // check if template has been loaded if (!empty($this->templates[$id])) { return $this->templates[$id]->getData()['type']; } $var_name = 'template_type' . $id; if (!\CB\Cache::exist($var_name)) { $r = DM\Templates::read($id); if (!empty($r)) { \CB\Cache::set($var_name, $r['type']); } } return \CB\Cache::get($var_name); }