Gentics Portal.Node PHP API
 All Classes Namespaces Functions Variables Pages
SearchResultWidget.php
1 <?php
2  /**
3  * Gentics Portal.Node PHP
4  * Author & Copyright (c) by Gentics Software GmbH
5  * sales@gentics.com
6  * http://www.gentics.com
7  * Licenses can be found in the LICENSE.txt file in the root-folder of this installation
8  * You must not use this software without a valid license agreement.
9  *
10  * Comment controller class file.
11  *
12  * @author Vitalii Kovalchuk <vitaly.kovalchuk@oberig.com>
13  */
14 
16 {
17  /**
18  * search phrase
19  * @var string
20  */
21  public $phrase = '';
22 
23  /**
24  * Search result. Contains result of search that has to be displayed
25  * @var array
26  */
27  public $searchResult = '';
28 
29  /**
30  * How many results should be skipped. Used fot pagination
31  * @var string
32  */
33  public $offset = 0;
34 
35  /**
36  * status of search (ok|error)
37  * @var string
38  */
39  public $status = 'ok';
40 
41  /**
42  * total matches found, exlc. status
43  * @var int
44  */
45  public $totalQty = 0;
46 
47  /**
48  * how many results show per page
49  * @var int
50  */
51  public $perPage = 20;
52 
53  /**
54  * Base href for current page
55  * @var int
56  */
57  public $baseHref = '';
58 
59  /**
60  * @var bool $usePersonalisation defines if personalisation should be performed
61  */
62  public $usePersonalisation = true;
63 
64  public $pageNumber;
65 
66  public $existsMore = false;
67 
68  /**
69  * Overrided search url
70  *
71  * @public string
72  **/
73  public $searchUrl;
74 
75  /**
76  * Widget run method.
77  *
78  * @return void
79  */
80  public function run()
81  {
82  $this->phrase = Yii::app()->request->getQuery('searchTerm', '');
83  $this->offset = (int)Yii::app()->request->getQuery('offset', 0);
84  $this->pageNumber = (int)Yii::app()->request->getQuery('page', 1);
85 
86  if (trim($this->phrase)!='') {
87  $searchAdaptor = new SearchAdaptor(
88  $this->phrase,
89  isset($_GET['advanced']) ? $_GET : array(),
90  $this->usePersonalisation
91  );
92  if(!empty($this->searchUrl)) {
93  $searchAdaptor->searchApi->searchUrl = $this->searchUrl;
94  }
95  $searchAdaptor->pageNumber = $this->pageNumber;
96  $searchAdaptor->pageSize = Yii::app()->getModule('search')->perPage;
97  $this->searchResult = $searchAdaptor->fetchNext();
98  $this->existsMore = $searchAdaptor->existsMore();
99 
100 // if (isset($_GET['advanced'])) {
101 // $this->searchResult = $searchApi->advancedSearch($this->phrase, $_GET, $this->usePersonalisation);
102 // } else {
103 // $this->searchResult = $searchApi->simpleSearch($this->phrase, $this->usePersonalisation);
104 // }
105 
106 // $this->status = $this->searchResult['status'];
107 // unset($this->searchResult['status']);
108 
109 //
110 // $this->totalQty = count($this->searchResult);
111 // $this->perPage = Yii::app()->getModule('search')->perPage;
112 
113 
114  /* check if offet is in range of results quantity */
115 // if ($this->offset>=count($this->searchResult)V || $this->offset<0) {
116 // $this->offset = 0;
117 // }
118 
119  /* calculating pagination */
120 // $this->searchResult = array_slice($this->searchResult, $this->offset, $this->perPage);
121 
122  $this->render('SearchResultWidget');
123  }
124  }
125 
126 
127  /**
128  * Create pagination urls
129  *
130  * @return string
131  */
132  public function paginationUrl($pageNumber)
133  {
134  $url = AppHelper::removeParamsFromUrl(Yii::app()->request->requestUri, array('page'));
135  if($pageNumber > 1) {
136  $url = AppHelper::addParamsToUrl($url, array('page' => $pageNumber));
137  }
138  return $url;
139  }
140 }
141 
142 ?>