/**
  * Tries to replace the owner by the new owner.
  * 
  * If the logged in user can not perform the operation a new RequestChangeOwnership object is created.
  * 
  * 
  * @throws \MapasCulturais\Exceptions\PermissionDenied
  * @throws \MapasCulturais\Exceptions\WorkflowRequestTransport
  * 
  * @workflow RequestChangeOwnership
  */
 protected function _saveOwnerAgent()
 {
     if (!$this->owner && $this->_newOwner || $this->_newOwner && !$this->_newOwner->equals($this->owner)) {
         try {
             $this->checkPermission('changeOwner');
             $this->_newOwner->checkPermission('modify');
             $this->owner = $this->_newOwner;
         } catch (\MapasCulturais\Exceptions\PermissionDenied $e) {
             $app = App::i();
             if (!$app->isWorkflowEnabled()) {
                 throw $e;
             }
             $ar = new \MapasCulturais\Entities\RequestChangeOwnership();
             $ar->origin = $this;
             $ar->destination = $this->_newOwner;
             throw new \MapasCulturais\Exceptions\WorkflowRequestTransport($ar);
         }
     }
 }
Пример #2
0
 function setParent(Agent $parent = null)
 {
     if ($parent != $this->parent) {
         $this->checkPermission('changeOwner');
         $parent->checkPermission('modify');
         $this->parent = $parent;
         if (!is_null($parent)) {
             if ($parent->id == $this->id) {
                 $this->parent = null;
             }
             $this->setUser($parent->user);
         }
     }
 }