コード例 #1
0
 protected function isGranted($attribute, $report, $user = null)
 {
     if (!$user instanceof \Chill\MainBundle\Entity\User) {
         return false;
     }
     return $this->helper->userHasAccess($user, $report, $attribute);
 }
コード例 #2
0
 private function getWhereClause(ClassMetadata $metadataActivity, ClassMetadata $metadataPerson, Person $person)
 {
     $role = new Role('CHILL_ACTIVITY_SEE');
     $reachableCenters = $this->helper->getReachableCenters($this->user, $role);
     $associationMapping = $metadataActivity->getAssociationMapping('person');
     // we start with activities having the person_id linked to person
     // (currently only context "person" is supported)
     $whereClause = sprintf('%s = %d', $associationMapping['joinColumns'][0]['name'], $person->getId());
     // we add acl (reachable center and scopes)
     $centerAndScopeLines = array();
     foreach ($reachableCenters as $center) {
         $reachablesScopesId = array_map(function (Scope $scope) {
             return $scope->getId();
         }, $this->helper->getReachableScopes($this->user, $role, $person->getCenter()));
         $centerAndScopeLines[] = sprintf('(%s = %d AND %s IN (%s))', $metadataPerson->getTableName() . '.' . $metadataPerson->getAssociationMapping('center')['joinColumns'][0]['name'], $center->getId(), $metadataActivity->getTableName() . '.' . $metadataActivity->getAssociationMapping('scope')['joinColumns'][0]['name'], implode(',', $reachablesScopesId));
     }
     $whereClause .= ' AND (' . implode(' OR ', $centerAndScopeLines) . ')';
     return $whereClause;
 }