Exemple #1
0
 /**
  * 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;
 }
Exemple #2
0
 /**
  * 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;
 }
Exemple #3
0
 /**
  * return set ids for a user that have access on specified bit
  * @param  boolean         $user_id
  * @param  integer         $access_bit_index default static::$CAN_READ
  * @param  integer | array $pids
  * @return array           security set ids
  */
 public static function getSecuritySets($user_id = false, $access_bit_index = null, $pids = null)
 {
     $rez = array();
     $sets = array();
     if (empty($access_bit_index)) {
         $access_bit_index = static::$CAN_READ;
     }
     if (empty($user_id)) {
         $user_id = User::getId();
     }
     $everyoneGroupId = static::getSystemGroupId('everyone');
     $res = DB\dbQuery('SELECT security_set_id, user_id, bit' . $access_bit_index . ' `access`
         FROM `tree_acl_security_sets_result`
         WHERE user_id IN ($1, $2)', array($user_id, $everyoneGroupId));
     while ($r = $res->fetch_assoc()) {
         $sets[$r['security_set_id']][$r['user_id']] = $r['access'];
     }
     $res->close();
     $rez = array();
     foreach ($sets as $set_id => $set) {
         if (!empty($set[$user_id]) || !isset($set[$user_id]) && !empty($set[$everyoneGroupId])) {
             $rez[] = $set_id;
         }
     }
     //filter sets if pids specified
     if (!empty($pids)) {
         $pids = Util\toNumericArray($pids);
     }
     if (!empty($rez) && !empty($pids)) {
         //select all pids of given pid ids
         $res = DB\dbQuery('SELECT pids
             FROM tree_info
             WHERE id in (' . implode(',', $pids) . ')', array());
         while ($r = $res->fetch_assoc()) {
             $ids = explode(',', $r['pids']);
             foreach ($ids as $id) {
                 if (!in_array($id, $pids)) {
                     $pids[] = $id;
                 }
             }
         }
         $res->close();
         //select distinct set nodes
         $nodes = array();
         $res = DB\dbQuery('SELECT id, `set`
             FROM tree_acl_security_sets
             WHERE id in (' . implode(',', $rez) . ')');
         while ($r = $res->fetch_assoc()) {
             $ids = explode(',', $r['set']);
             foreach ($ids as $id) {
                 $nodes[$id][] = $r['id'];
             }
         }
         $res->close();
         $rez = array();
         //now select pids of collected nodes and filter only sets
         //that are for child nodes of the pids
         $recs = DM\TreeInfo::readByIds(array_keys($nodes));
         foreach ($recs as $r) {
             $ids = explode(',', $r['pids']);
             $intersection = array_intersect($pids, $ids);
             if (!empty($intersection)) {
                 foreach ($nodes[$r['id']] as $setId) {
                     $rez[$setId] = 1;
                 }
             }
         }
         $rez = array_keys($rez);
     }
     return $rez;
 }
Exemple #4
0
 /**
  * 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;
 }