コード例 #1
0
 /**
  * Delete children relation from current model.
  *
  * @param {?array|AbstractModel|int|string} $children Target children to delete, or all children of omitted.
  * @param {?string} $collection Collection identifier of the relation, defaults to the model's collection name.
  */
 protected function deleteDescendants($collection = '%', $children = null)
 {
     if ($collection === null) {
         $collection = $this->collectionName();
     }
     if ($children === null) {
         return Relation::deleteDescendants($this->identity(), $collection);
     } else {
         if (!is_array($children)) {
             $children = (array) $children;
         }
         return array_reduce($children, function ($result, $child) use($collection) {
             if ($child instanceof AbstractModel) {
                 $child = $child->identity();
             }
             return $result && Relation::delete($this->identity(), $child, $collection);
         }, true);
     }
 }
コード例 #2
0
ファイル: WorkInstance.php プロジェクト: Victopia/prefw
 /**
  * @protected
  *
  * Load task contents, remove task scripts.
  */
 function afterLoad()
 {
     // unpack uuid
     $this->uuid = util::unpackUuid($this->uuid);
     $this->nextTask = util::unpackUuid($this->nextTask);
     // note: Only users with access to nextTask has view permission.
     if (!$this->__isSuperUser) {
         // 1. Group:User
         $res = (array) @$this->__request->user->groups;
         // 2. Task:Group
         $res = Relation::getAncestors($res, Task::GROUP_RELATION);
         // 3. Task
         $res = Relation::getDescendants($res, 'Task');
         // 4. UUID comparison
         if (!in_array($this->nextTask, $res)) {
             return $this->data(array());
         }
     }
     // load task details, do not expose internal scripts
     $taskInstance = new TaskInstance();
     $this->tasks = array_map(removes('order'), $taskInstance->find(array('uuid' => $this->children($taskInstance::WORK_RELATION), '@sorter' => ['order'])));
     unset($taskInstance);
     $res = parent::afterLoad();
     // lock the item after load
     $this->_immutable = true;
     return $res;
 }