Example #1
0
 public function mkTreeDir($pid, $dir)
 {
     if (empty($dir) || $dir == '.') {
         return $pid;
     }
     $path = str_replace('\\', '/', $dir);
     $path = explode('/', $path);
     $userId = User::getId();
     foreach ($path as $dir) {
         if (empty($dir)) {
             continue;
         }
         $r = DM\Tree::getChildByName($pid, $dir);
         if (!empty($r)) {
             $pid = $r['id'];
         } else {
             $pid = DM\Tree::create(array('pid' => $pid, 'name' => $dir, 'type' => 1, 'cid' => $userId, 'uid' => $userId, 'template_id' => Config::get('default_folder_template')));
         }
     }
     return $pid;
 }
Example #2
0
 /**
  * create an object with specified params
  * @param  array $p object properties
  * @return int   created id
  */
 public function create($p = false)
 {
     if ($p !== false) {
         if (array_key_exists('id', $p)) {
             if (is_numeric($p['id'])) {
                 $this->id = $p['id'];
             } else {
                 $this->id = null;
                 unset($p['id']);
             }
         }
         $this->data = $p;
         unset($this->linearData);
         $this->template = null;
         if (!empty($this->data['template_id']) && $this->loadTemplate) {
             $this->template = \CB\Templates\SingletonCollection::getInstance()->getTemplate($this->data['template_id']);
         }
     }
     //check if there is defaultPid specified in template config
     if (!empty($this->template)) {
         $templateData = $this->template->getData();
         if (!empty($templateData['cfg']['defaultPid'])) {
             $this->data['pid'] = $templateData['cfg']['defaultPid'];
         }
     }
     \CB\fireEvent('beforeNodeDbCreate', $this);
     $p =& $this->data;
     if (!Security::canCreateActions($p['pid'])) {
         throw new \Exception(L\get('Access_denied'));
     }
     // check input params
     if (!isset($p['pid'])) {
         throw new \Exception("No pid specified for object creation", 1);
     }
     if (empty($p['name'])) {
         throw new \Exception("No name specified for object creation", 1);
     }
     // we admit object creation without template id
     // if (empty($p['template_id']) || !is_numeric($p['template_id'])) {
     //     throw new \Exception("No template_id specified for object creation", 1);
     // }
     $this->id = DM\Tree::create($this->collectModelData());
     if (!isset($this->id) || !(intval($this->id) > 0)) {
         trigger_error('Error on create object : ' . \CB\Cache::get('lastSql'), E_USER_ERROR);
     }
     $p['id'] = $this->id;
     $this->createCustomData();
     $this->checkDraftChilds();
     //load the object from db to have all its created data
     $this->load();
     //fire create event
     \CB\fireEvent('nodeDbCreate', $this);
     $this->logAction('create', array('mentioned' => $this->lastMentionedUserIds));
     return $this->id;
 }