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;
 }
示例#2
0
 /**
  * get the center
  * 
  * center is extracted from person
  * 
  * @return \Chill\MainBundle\Entity\Center
  */
 public function getCenter()
 {
     return $this->person->getCenter();
 }