Esempio n. 1
0
 /**
  * for people
  * following parameter are relevant
  * by     => 'all', 'me', 'guest'
  * status => Status::CREATED, 'all'
  * user   => User::ROLE_RECRUITER, User::ROLE_ADMIN, User::ROLE_USER
  *
  * @param $params
  * @param $queryBuilder
  * @return mixed
  */
 public function createQuery($params, $queryBuilder)
 {
     $this->value = $params->toArray();
     $this->user = $this->auth->getUser();
     $isRecruiter = $this->user->getRole() == User::ROLE_RECRUITER || $this->acl->inheritsRole($this->user, User::ROLE_RECRUITER);
     if ($isRecruiter && (!isset($this->value['by']) || $this->value['by'] != 'guest')) {
         /*
          * a recruiter can see his jobs and jobs from users who gave permissions to do so
          */
         if (isset($this->value['params']['by']) && 'me' == $this->value['params']['by']) {
             $queryBuilder->field('user')->equals($this->user->id);
         } else {
             $queryBuilder->field('permissions.view')->equals($this->user->id);
         }
         if (isset($this->value['params']['status']) && !empty($this->value['params']['status']) && $this->value['params']['status'] != 'all') {
             $queryBuilder->field('status.name')->equals((string) $this->value['params']['status']);
         }
     } else {
         /*
          * an applicants or guests can see all active jobs
          */
         $queryBuilder->field('status.name')->equals(Status::ACTIVE);
     }
     /*
      * search jobs by keywords
      */
     if (isset($this->value['params']['search']) && !empty($this->value['params']['search'])) {
         $search = strtolower($this->value['params']['search']);
         $searchPatterns = array();
         foreach (explode(' ', $search) as $searchItem) {
             $searchPatterns[] = new \MongoRegex('/^' . $searchItem . '/');
         }
         $queryBuilder->field('keywords')->all($searchPatterns);
     }
     if (isset($this->value['location'])) {
         $loc = $this->value['location'];
         $queryBuilder->field('locations.coordinates')->near($loc->getCoordinates())->maxDistance($this->value['d'] * 1000);
     }
     if (isset($this->value['sort'])) {
         foreach (explode(",", $this->value['sort']) as $sort) {
             $queryBuilder->sort($this->filterSort($sort));
         }
     }
     return $queryBuilder;
 }
Esempio n. 2
0
 /**
  * for people
  * following parameter are relevant
  * by     => 'all', 'me', 'guest'
  * status => Status::CREATED, 'all'
  * user   => User::ROLE_RECRUITER, User::ROLE_ADMIN, User::ROLE_USER
  *
  * @param $params Parameters
  * @param $queryBuilder \Doctrine\ODM\MongoDB\Query\Builder
  * @return mixed
  */
 public function createQuery($params, $queryBuilder)
 {
     $this->value = $params;
     /*
      * search jobs by keywords
      */
     if (isset($params['search']) && !empty($params['search'])) {
         $search = strtolower($params['search']);
         $expression = $queryBuilder->expr()->operator('$text', ['$search' => $search]);
         $queryBuilder->field(null)->equals($expression->getQuery());
     }
     if (isset($this->value['location']->coordinates)) {
         $coordinates = $this->value['location']->coordinates->getCoordinates();
         $queryBuilder->field('locations.coordinates')->geoWithinCenter($coordinates[0], $coordinates[1], (double) $this->value['d'] / 100);
     }
     if (isset($params['channel']) && !empty($params['channel']) && $params['channel'] != "default") {
         $queryBuilder->field('portals')->equals($params['channel']);
     }
     $this->user = $this->auth->getUser();
     $isRecruiter = $this->user->getRole() == User::ROLE_RECRUITER || $this->acl->inheritsRole($this->user, User::ROLE_RECRUITER);
     if ($isRecruiter && (!isset($this->value['by']) || $this->value['by'] != 'guest')) {
         /*
          * a recruiter can see his jobs and jobs from users who gave permissions to do so
          */
         if (isset($params['by']) && 'me' == $params['by']) {
             $queryBuilder->field('user')->equals($this->user->id);
         } else {
             $queryBuilder->field('permissions.view')->equals($this->user->id);
         }
         if (isset($params['status']) && !empty($params['status']) && $params['status'] != 'all') {
             $queryBuilder->field('status.name')->equals((string) $params['status']);
         }
     } else {
         /*
          * an applicants or guests can see all active jobs
          */
         $queryBuilder->field('status.name')->equals(Status::ACTIVE);
     }
     if (isset($this->value['sort'])) {
         foreach (explode(",", $this->value['sort']) as $sort) {
             $queryBuilder->sort($this->filterSort($sort));
         }
     }
     return $queryBuilder;
 }