Пример #1
0
 /**
  *
  * @param \MapasCulturais\Entities\User $user
  * @param mixed $status = all all|sent|Entities\Registration::STATUS_*|[Entities\Registration::STATUS_*, Entities\Registration::STATUS_*]
  * @return \MapasCulturais\Entities\Registration[]
  */
 function findByUser($user, $status = 'all')
 {
     if ($user->is('guest')) {
         return [];
     }
     $status_where = "";
     if ($status === 'all') {
         $status = false;
     } else {
         if ($status === 'sent') {
             $status = false;
             $status_where = "r.status > 0 AND";
         } else {
             if (is_int($status)) {
                 $status_where = "r.status = :status AND";
             } else {
                 if (is_array($status)) {
                     $status_where = "r.status IN (:status) AND";
                 }
             }
         }
     }
     $dql = "\n            SELECT\n                r\n            FROM\n                MapasCulturais\\Entities\\Registration r\n                LEFT JOIN  MapasCulturais\\Entities\\RegistrationAgentRelation rar WITH rar.owner = r\n            WHERE\n                {$status_where}\n                (\n                    r.owner IN (:agents) OR\n                    rar.agent IN (:agents)\n                )";
     $q = $this->_em->createQuery($dql);
     $q->setParameter('agents', $user->agents ? $user->agents->toArray() : [-1]);
     if ($status !== false) {
         $q->setParameter('status', $status);
     }
     \MapasCulturais\App::i()->log->debug($dql);
     return $q->getResult();
 }
Пример #2
0
 /**
  * Checks if user can verify this entity
  * 
  * @param \MapasCulturais\Entities\User $user
  * @return boolean
  */
 protected function canUserVerify($user)
 {
     if ($user->is('guest')) {
         return false;
     }
     return $user->is('admin') || $this->canUser('modify') && $user->is('staff');
 }
 /**
  * Generic permission verification for entities that has owner agent.
  * 
  * @param \MapasCulturais\Entities\User $user
  * @param string $action
  * @return boolean
  */
 protected function _canUser($user, $action = '')
 {
     if ($user->is('guest')) {
         return false;
     }
     if ($user->is('admin')) {
         return true;
     }
     if ($this->getOwnerUser()->id == $user->id) {
         return true;
     }
     if ($this->owner->userHasControl($user)) {
         return true;
     }
     if ($this->usesAgentRelation() && $this->userHasControl($user) && $action !== 'remove') {
         return true;
     }
     return false;
 }
 public function canUser($action, $userOrAgent = null)
 {
     return $this->owner->canUser($action, $userOrAgent);
 }
Пример #5
0
 function setAsUserProfile()
 {
     $this->checkPermission('setAsUserProfile');
     $this->user->profile = $this;
     $this->user->save(true);
 }
Пример #6
0
 /**
  * Virifies if the user can view private metadata of this entity.
  * 
  * @param \MapasCulturais\Entities\User $user
  * 
  * @return boolean
  */
 protected function canUserViewPrivateData($user)
 {
     if ($user->is('guest')) {
         return false;
     }
     if ($user->is('admin') || $this->getOwnerUser()->equals($user)) {
         return true;
     }
     return false;
 }
Пример #7
0
 function setAsUserProfile()
 {
     $this->checkPermission('setAsUserProfile');
     $this->user->getProfile()->isUserProfile = false;
     $this->user->getProfile()->save();
     $this->isUserProfile = true;
     $this->save(true);
 }