Пример #1
0
 public function grantActivity(Activity $activity, $action = 'view')
 {
     $grant = false;
     if ($this->authorizationChecker->isGranted('ROLE_RS')) {
         $grant = true;
     } elseif ($this->authorizationChecker->isGranted('ROLE_RCA') || $this->authorizationChecker->isGranted('ROLE_CA')) {
         $agency = $this->userManager->getCurrent()->getAgency();
         foreach ($activity->getUser()->getAgencies() as $histoAgence) {
             if ($agency == $histoAgence->getAgency()) {
                 if ($histoAgence->getDateCreated() <= $activity->getDateCreated()) {
                     if ($histoAgence->getEnd()) {
                         if ($histoAgence->getEnd()->getDateEnd() > $activity->getDateCreated()) {
                             $grant = true;
                         }
                     } else {
                         $grant = true;
                     }
                 }
             }
         }
     }
     if ($this->authorizationChecker->isGranted('ROLE_CA') && !$this->authorizationChecker->isGranted('ROLE_RCA')) {
         if ($grant) {
             $grant = false;
             if ($action == 'view') {
                 foreach ($activity->getAccount()->getOwners() as $account_owner) {
                     if ($account_owner->getUser() == $this->userManager->getCurrent() && !$account_owner->getEnd()) {
                         $grant = true;
                         break;
                     }
                 }
             } else {
                 if ($activity->getUser() == $this->userManager->getCurrent()) {
                     $grant = true;
                 }
             }
         }
     }
     return $grant;
 }