Exemple #1
0
 /**
  * Handle GET requests.
  *
  * @param Alpha\Util\Http\Request $request
  *
  * @return Alpha\Util\Http\Response
  *
  * @since 1.0
  *
  * @throws Alpha\Exception\IllegalArguementException
  */
 public function doGET($request)
 {
     self::$logger->debug('>>doGET($request=[' . var_export($request, true) . '])');
     $params = $request->getParams();
     if (isset($params['start']) ? $this->startPoint = $params['start'] : ($this->startPoint = 0)) {
     }
     $config = ConfigProvider::getInstance();
     $KPI = new KPI('search');
     $body = '';
     if (isset($params['query'])) {
         $this->query = $params['query'];
         // replace any %20 on the URL with spaces
         $params['query'] = str_replace('%20', ' ', $params['query']);
         $this->setTitle('Search results - ' . $params['query']);
         $body .= View::displayPageHead($this);
         // log the user's search query in a log file
         $log = new LogProviderFile();
         $log->setPath($config->get('app.file.store.dir') . 'logs/search.log');
         $log->writeLine(array($params['query'], date('Y-m-d H:i:s'), $request->getUserAgent(), $request->getIP()));
         $KPI->logStep('log search query');
         $provider = SearchProviderFactory::getInstance('Alpha\\Util\\Search\\SearchProviderTags');
         // if a BO name is provided, only search tags on that class, otherwise search all BOs
         if (isset($params['ActiveRecordType'])) {
             $results = $provider->search($params['query'], $params['bo'], $this->startPoint);
         } else {
             $results = $provider->search($params['query'], 'all', $this->startPoint);
         }
         $this->resultCount = $provider->getNumberFound();
         $KPI->logStep('search completed using SearchProviderTags provider');
         $body .= $this->renderResultList($results, $params['query']);
     } else {
         $this->setTitle('Search results');
         $body .= View::displayPageHead($this);
         self::$logger->debug('No search query provided!');
     }
     $body .= View::displayPageFoot($this);
     $KPI->log();
     self::$logger->debug('<<doGET');
     return new Response(200, $body, array('Content-Type' => 'text/html'));
 }
 /**
  * Testing the method for getting related objects.
  *
  * @since 1.2.3
  */
 public function testGetRelated()
 {
     $this->article->save();
     $article2 = $this->createArticle('unitTestArticle 2');
     $article2->save();
     $article3 = $this->createArticle('unitTestArticle 3');
     $article3->save();
     $provider = SearchProviderFactory::getInstance('Alpha\\Util\\Search\\SearchProviderTags');
     $results = $provider->getRelated($this->article);
     $this->assertTrue(count($results) == 2, 'Testing the method for getting related objects');
     $results = $provider->getRelated($this->article, 'all', 0, 1);
     $this->assertTrue(count($results) == 1, 'Testing the method for getting related objects honours limit param');
     $results = $provider->getRelated($this->article, 'PersonObject');
     $this->assertTrue(count($results) == 0, 'Testing the get related objects method honours returnType filtering');
 }