Amiro.CMS API Reference [beta] (available from v5.10) Amiro.Ru / Manual

Source for file PlgAJAXResp_SearchHistory.php

Documentation is available at PlgAJAXResp_SearchHistory.php

  1. <?php
  2. /**
  3.  * @copyright  Amiro.CMS. All rights reserved.
  4.  * @category   Plugin
  5.  * @package    Plugin_AJAXResponder
  6.  * @since      5.10.0
  7.  * @filesource
  8.  */
  9.  
  10. /**
  11.  * AJAX Responder SearchHistory plugin JSON generation class.
  12.  *
  13.  * @package    Plugin_AJAXResponder
  14.  * @subpackage Controller
  15.  */
  16.  
  17.     protected $oModel;
  18.  
  19.     /**
  20.      * Maximum result number from search history table
  21.      *
  22.      * @var int 
  23.      */
  24.     private $iMaxHistoryResults 5;
  25.  
  26.     private function createFulltextFilter($fieldName$phrase){
  27.         $aWords preg_split('/a-zёа-я0-9.-/ui'$phrase);
  28.         $aParts array();
  29.         foreach($aWords as $word){
  30.             if(!empty($word)){
  31.                 $aParts['+' $word '*';
  32.             }
  33.         }
  34.         return DB_Query::getSnippet("AND MATCH(%s)  AGAINST(%s IN BOOLEAN MODE)")
  35.             ->plain($fieldName)
  36.             ->implode($aParts);
  37.     }
  38.  
  39.     /**
  40.      * Adds extra list model initializations
  41.      *
  42.      * @return AMI_ModTableList 
  43.      */
  44.     protected function initModel(){
  45.         $this->oModel = $oModelList parent::initModel();
  46.         $this->oModel->setInvalidColumnExclusion(false);
  47.  
  48.         $sPhrase $this->oRequest->get('phrase''');
  49.         if(!empty($sPhrase)){
  50.             if($this->modId == 'search_history'){
  51.                 $oModelList->addWhereDef($this->createFulltextFilter('query'$sPhrase));
  52.                 $oModelList->addWhereDef('AND count_pages>0');
  53.             }else if($this->modId == 'search'){
  54.                 $oModelList->addWhereDef($this->createFulltextFilter('words'$sPhrase));
  55.             }
  56.         }
  57.  
  58.         return $oModelList;
  59.     }
  60.  
  61.     /**
  62.      * Returns list data
  63.      *
  64.      * @return array 
  65.      * @see    PlgAJAXResp_ListView::get()
  66.      */
  67.     public function getResponse(){
  68.         $aSearchHistoryData $this->oView->get();
  69.  
  70.         $aHasPhrases array();
  71.         $aTmp $aSearchHistoryData;
  72.         $aSearchHistoryData array();
  73.         for($i 0$i sizeof($aTmp)$i++){
  74.             $phrase mb_strtolower($aTmp[$i]['query']);
  75.             if(!isset($aHasPhrases[$phrase])){
  76.                 $aSearchHistoryData[$aTmp[$i];
  77.                 $aHasPhrases[$phrasetrue;
  78.                 if(sizeof($aSearchHistoryData>= $this->iMaxHistoryResults){
  79.                     break;
  80.                 }
  81.             }
  82.         }
  83.  
  84.         $iLimit $this->oRequest->get('limit'sizeof($aSearchHistoryData);
  85.         if($iLimit 0){
  86.             $this->oRequest->set('limit'$iLimit);
  87.  
  88.             // Init search module
  89.             $this->modId = 'search';
  90.             $this->oRequest->set('order''id');
  91.             $this->initStateAndView();
  92.             $oModelList $this->initModel();
  93.             $this->oView->setModel($oModelList);
  94.  
  95.             $aSearchData $this->oView->get();
  96.         }else{
  97.             $aSearchData array();
  98.         }
  99.  
  100.         $aResult array(
  101.             'list' => array_merge($aSearchHistoryData$aSearchData)
  102.         );
  103.  
  104.         return $aResult;
  105.     }
  106. }
  107.  
  108. /**
  109.  * Plugin SearchHistory module model (server-side plugin context).
  110.  *
  111.  * @package    Plugin_AJAXResponder
  112.  * @subpackage Model
  113.  */
  114.     /**
  115.      * PlgAJAXResp_iState::getDateFieldName() implementation
  116.      *
  117.      * Returns item date field name or empty string
  118.      *
  119.      * @return string 
  120.      * @see    PlgAJAXResp::initModel()
  121.      */
  122.     public function getDateFieldName(){
  123.         return '';
  124.     }
  125. }
  126.  
  127. /**
  128.  * Plugin SearchHistory module list view (server-side plugin context).
  129.  *
  130.  * @package    Plugin_AJAXResponder
  131.  * @subpackage View
  132.  */
  133.     /**
  134.      * Return columns for list model
  135.      *
  136.      * @return array 
  137.      */
  138.     protected function getColumns(){
  139.         $aCols array(
  140.             'id''query'
  141.         );
  142.         return $aCols parent::getColumns();
  143.     }
  144. }

Documentation generated on Wed, 21 Dec 2011 10:42:27 +0600 by