/**
  * Add parent to ancestor
  *
  * @param Registered $parent parent instance
  * @return void
  */
 public function addParent(Registered $parent)
 {
     if ($this->isParent($parent) === true) {
         $this->parent = $parent;
     } elseif ($this->parent !== null) {
         $this->parent->addParent($parent);
     }
 }
Example #2
0
 /**
  * Move entity hierarchy to new parent or root
  *
  * @param Registered  $registered registered object
  * @param string|null $to         to registered prefix
  *
  * @return void
  * @throws InvalidArgumentException
  */
 public function move(Registered $registered, $to = null)
 {
     $toParent = $to !== null ? $this->repo->findByTypeAndName($registered->siteKey, $registered->type, $to) : null;
     if ($to !== null && $toParent === null || $toParent !== null && $registered->type != $toParent->type) {
         throw new InvalidArgumentException();
     }
     $parent = $registered->getParent();
     if ($parent === null) {
         if ($registered->getDepth() !== 1) {
             throw new InvalidArgumentException();
         }
         $this->repo->affiliate($registered, $to);
     } else {
         $this->repo->foster($registered, $to);
     }
 }
 /**
  * Update register information
  *
  * @param Registered $item registered instance
  *
  * @return Registered
  */
 public function update(Registered $item)
 {
     $diff = $item->diff();
     $dates = [];
     if (count($diff) > 0) {
         $dates = ['updatedAt' => date('Y-m-d H:i:s')];
         $this->conn->table($this->table)->where('id', $item->id)->update(array_merge($diff, $dates));
     }
     return $this->createItem(array_merge($item->getOriginal(), $diff, $dates));
 }