Example #1
0
 /**
  * List jobs
  */
 public function indexAction()
 {
     $service = $this->getServiceLocator();
     $request = $this->getRequest();
     $params = $request->getQuery();
     $jsonFormat = 'json' == $request->getQuery()->get('format');
     $event = $this->getEvent();
     $routeMatch = $event->getRouteMatch();
     $matchedRouteName = $routeMatch->getMatchedRouteName();
     $url = $this->url()->fromRoute($matchedRouteName, array(), array('force_canonical' => true));
     $action = $routeMatch->getParam('action');
     if (!$jsonFormat && !$this->getRequest()->isXmlHttpRequest()) {
         $session = new Session('Jobs\\Index');
         $sessionKey = $this->auth()->isLoggedIn() ? 'userParams' : 'guestParams';
         $sessionParams = $session[$sessionKey];
         if ($sessionParams) {
             foreach ($sessionParams as $key => $value) {
                 $params->set($key, $params->get($key, $value));
             }
         }
         $session[$sessionKey] = $params->toArray();
         $this->searchForm->bind($params);
     }
     $params = $params->get('params', []);
     if (isset($params['l']['data'])) {
         $geoText = $this->searchForm->get('params')->get('l');
         $geoText->setValue($params['l']);
         $params['location'] = $geoText->getValue('entity');
     }
     if (!isset($params['sort'])) {
         $params['sort'] = '-date';
     }
     $this->searchForm->setAttribute('action', $url);
     $params['by'] = "guest";
     $paginator = $this->paginatorService('Jobs/Board', $params);
     $options = $this->searchForm->getOptions();
     $options['showButtons'] = false;
     $this->searchForm->setOptions($options);
     $return = array('by' => $params['by'], 'jobs' => $paginator, 'filterForm' => $this->searchForm);
     $model = new ViewModel($return);
     return $model;
 }