Example #1
0
 /**
  * Gets/Generates the resource id.
  *
  * @param string|UserInterface|PermissionsResourceInterface $resource
  *
  * @return string
  */
 protected function getResourceId($resource)
 {
     if ($resource instanceof PermissionsResourceInterface) {
         return $resource->getPermissionsResourceId();
     }
     if ($resource instanceof UserInterface) {
         return 'user:'******'user:' . $resource;
 }
Example #2
0
 /**
  * @see \Auth\Dependency\ListInterface::getEntities()
  */
 public function getEntities(User $user)
 {
     return $this->repository->getUserOrganizations($user->getId());
 }
Example #3
0
 /**
  * @param string $query
  * @param UserInterface    $user
  * @return array
  */
 public function getTypeAheadResults($query, $user)
 {
     $organizationNames = array();
     $organizationNameQb = $this->getDocumentManager()->createQueryBuilder('Organizations\\Entity\\OrganizationName');
     $organizationNameQb->hydrate(false)->select(array('id', 'name'))->field('name')->equals(new \MongoRegex('/' . $query . '/i'))->sort('name')->limit(5);
     $organizationNameResults = $organizationNameQb->getQuery()->execute();
     foreach ($organizationNameResults as $id => $item) {
         $organizationNames[$id] = $item;
     }
     $organizations = array();
     $userOrg = $user->getOrganization();
     $qb = $this->createQueryBuilder();
     $qb->hydrate(false)->select(array('contact.city', 'contact.street', 'contact.houseNumber', 'organizationName'))->limit(5)->addAnd($qb->expr()->field('permissions.view')->equals($user->getId())->field('organizationName')->in(array_keys($organizationNames)));
     if ($userOrg->hasAssociation()) {
         $qb->addAnd($qb->expr()->addOr($qb->expr()->field('parent')->equals($userOrg->getId()))->addOr($qb->expr()->field('_id')->equals($userOrg->getId())));
     }
     $result = $qb->getQuery()->execute();
     foreach ($result as $id => $item) {
         $organizations[$id] = $item;
         $organizationNameId = (string) $organizations[$id]['organizationName'];
         $organizations[$id]['organizationName'] = $organizationNames[$organizationNameId];
     }
     return $organizations;
 }
Example #4
0
 /**
  * Returns true, if a User is an employee of the organization
  *
  * @param UserInterface $user
  *
  * @return bool
  */
 public function isEmployee(UserInterface $user)
 {
     return $this->refs && in_array($user->getId(), $this->refs->getEmployeeIds());
 }
Example #5
0
 /**
  * Gets an employee by User or ID.
  *
  * @param UserInterface|string $userOrId
  *
  * @return mixed|null
  */
 public function getEmployee($userOrId)
 {
     $employees = $this->getEmployees();
     $userId = $userOrId instanceof \Auth\Entity\UserInterface ? $userOrId->getId() : $userOrId;
     foreach ($employees as $employee) {
         if ($employee->getUser()->getId() == $userId) {
             return $employee;
         }
     }
     return null;
 }
Example #6
0
 /**
  * @param UserInterface $user
  * @param array $options
  * @throws UserDeactivatedException
  * @return null | UserInterface
  */
 protected function assertEntity(UserInterface $user = null, array $options)
 {
     if (isset($user) && (!isset($options['allowDeactivated']) || !$options['allowDeactivated']) && !$user->isActive()) {
         throw new UserDeactivatedException(sprintf('User with ID %s is not active', $user->getId()));
     }
     return $user;
 }