/** * function for making some trivial checks over input params * * @param object $p input params * @return boolean | varchar true on checks pass or error message */ private function trivialChecks(&$p) { /* dummy check if not pasting an object over itself But maybe in this case we can make a copy of the object with prefix 'Copy of ...' */ if (!\CB\Config::get('allow_duplicates', false)) { $res = DB\dbQuery('SELECT id FROM tree WHERE pid = $1 AND id IN (' . implode(',', $p['sourceIds']) . ')', $p['targetId']); if ($r = $res->fetch_assoc()) { return L\get('CannotCopyObjectToItself'); } $res->close(); } /* end of dummy check if not pasting an object over itself */ /* dummy check if not copying inside a child of sourceIds */ if (in_array($p['targetId'], $p['sourceIds'])) { return L\get('CannotCopyObjectInsideItself'); } $r = DM\TreeInfo::read($p['targetId']); if (!empty($r['pids'])) { $pids = Util\toNumericArray($r['pids']); foreach ($p['sourceIds'] as $sourceId) { if (in_array($sourceId, $pids)) { return L\get('CannotCopyObjectInsideItself'); } } } /* end of dummy check if not copying inside a child of sourceIds */ return true; }
/** * get pids of a given object id * @param int $objectId * @return array */ public static function getPids($objectId, $excludeItself = true) { $rez = array(); if (!is_numeric($objectId)) { return $rez; } $r = DM\TreeInfo::read($objectId); if (!empty($r)) { $rez = Util\toNumericArray($r['pids']); if ($excludeItself) { array_pop($rez); } } return $rez; }
/** * load object data into $this->data * @param int $id * @return array loaded data */ public function load($id = null) { if (!is_numeric($id)) { if (!is_numeric($this->id)) { throw new \Exception("No object id specified for load", 1); } $id = $this->id; } else { $this->id = $id; } $this->data = array(); $this->template = null; unset($this->linearData); $r = DM\Tree::read($id); if (!empty($r)) { $this->data = $r; $r = DM\TreeInfo::read($id); if (!empty($r)) { unset($r['updated']); $this->data = array_merge($this->data, $r); } if (!empty($this->data['template_id']) && $this->loadTemplate) { $this->template = \CB\Templates\SingletonCollection::getInstance()->getTemplate($this->data['template_id']); } } $this->loadCustomData(); $this->loaded = true; return $this->data; }