public function ajaxgethitsAction()
 {
     // the remote fetch should only occur once, when a new pz2
     // session is created for a new query. Otherwise, the existing
     // result should be returned.
     $uo = new UserOptions($this->request);
     $sid = $uo->getSessionData('pz2session');
     $aid = $uo->getSessionData('aim25session');
     if ($aid != $sid) {
         $aid = null;
         // new pz2session, so new query, restart
     }
     $hits = array();
     if (is_null($sid)) {
         // if there's no session yet, just return nothing
         $hits['hits'] = 0;
     } else {
         $hits = $this->engine->getHitCount($aid, $sid, $this->query);
         $uo->setSessionData('aim25session', $sid);
     }
     $response = $this->getResponse();
     $response->headers()->addHeaderLine("Content-type", "application/json");
     $response->setContent(json_encode($hits));
     // returned to View\Listener
     return $response;
 }
Example #2
0
 public function __construct(Request $request = null, Config $config = null)
 {
     parent::__construct($request, $config);
     $uo = new UserOptions($request);
     $tids = $uo->getSessionData('targets');
     $type = $uo->getSessionData('source_type');
     $this->targets = new Targets($type, $tids);
 }
 /**
  * Called repeatedly by AJAX from results page until session is finished.
  *  Javascript then reloads results page, and resultsAction should
  *  populate it with search results.
  */
 public function ajaxstatusAction()
 {
     $uo = new UserOptions($this->request);
     $target_keys = $uo->getSessionData('targets');
     $type = $uo->getSessionData('source_type');
     $sid = $this->request->getParam("session");
     // fetch the target statuses
     $status = $this->engine->getSearchStatus($sid);
     $mystatus = array();
     $targets = new Targets($type, $target_keys);
     $mystatus['pz2status'] = $status->getTargetStatuses($targets);
     // tidy the array for the javascript to process
     $mystatus['pz2status']['global'] = array();
     $mystatus['pz2status']['global']['progress'] = $mystatus['pz2status']['progress'];
     $mystatus['pz2status']['global']['finished'] = $mystatus['pz2status']['finished'] == 0 ? false : true;
     // remove redundant fields
     unset($mystatus['pz2status']['xml']);
     unset($mystatus['pz2status']['finished']);
     unset($mystatus['pz2status']['progress']);
     // if finished add redirect address if needed
     if ($mystatus['pz2status']['global']['finished'] == true) {
         $params = $this->helper->searchRedirectParams();
         $params['action'] = 'results';
         $mystatus['pz2status']['global']['reload_url'] = $this->request->url_for($params);
     }
     // return results as json
     $response = $this->getResponse();
     $response->headers()->addHeaderLine("Content-type", "application/json");
     $response->setContent(json_encode($mystatus));
     //Debug::dump($response->getContent()); exit;
     return $response;
 }