Exemplo n.º 1
0
 /**
  * load template custom data
  */
 protected function loadCustomData()
 {
     parent::loadCustomData();
     $r = DM\Objects::read($this->id);
     if (!empty($r)) {
         $r = $r['data'];
     } else {
         //read from templates_structure if object not present in tree
         // for backward compatibility
         $r = DM\TemplatesStructure::read($this->id);
     }
     if (!empty($r)) {
         if (isset($r['cfg'])) {
             $r['cfg'] = Util\toJSONArray($r['cfg']);
         }
         $r['title'] = Util\detectTitle($r);
         $this->data = array_merge($this->data, $r);
     } else {
         \CB\debug("Template field load error: no field found with id = " . $this->id);
         // throw new \Exception("Template field load error: no field found with id = ".$this->id);
     }
 }
Exemplo n.º 2
0
 /**
  * get objects from cache or loads them and store in cache
  * @param  array $ids
  * @return array
  */
 public static function getCachedObjects($ids)
 {
     $ids = Util\toNumericArray($ids);
     $rez = array();
     $toLoad = array();
     foreach ($ids as $id) {
         //verify if already have cached result
         $var_name = 'Objects[' . $id . ']';
         if (\CB\Cache::exist($var_name)) {
             $rez[$id] = \CB\Cache::get($var_name);
         } else {
             $toLoad[] = $id;
         }
     }
     if (!empty($toLoad)) {
         $tc = Templates\SingletonCollection::getInstance();
         $data = DataModel\Objects::read($toLoad);
         foreach ($data as $objData) {
             $var_name = 'Objects[' . $objData['id'] . ']';
             $o = static::getCustomClassByType($tc->getType($objData['template_id']));
             if (!empty($o)) {
                 $o->setData($objData);
                 \CB\Cache::set($var_name, $o);
                 $rez[$objData['id']] = $o;
             }
         }
     }
     return $rez;
 }
Exemplo n.º 3
0
 /**
  * copy data from objects table
  * @param  int  $targetId
  * @return void
  */
 protected function copyCustomDataTo($targetId)
 {
     DM\Objects::copy($this->id, $targetId);
 }