wCMF  3.6
 All Classes Namespaces Files Functions Variables Groups Pages
class.SearchController.php
Go to the documentation of this file.
1 <?php
2 /**
3  * wCMF - wemove Content Management Framework
4  * Copyright (C) 2005-2014 wemove digital solutions GmbH
5  *
6  * Licensed under the terms of any of the following licenses
7  * at your choice:
8  *
9  * - GNU Lesser General Public License (LGPL)
10  * http://www.gnu.org/licenses/lgpl.html
11  * - Eclipse Public License (EPL)
12  * http://www.eclipse.org/org/documents/epl-v10.php
13  *
14  * See the license.txt file distributed with this work for
15  * additional information.
16  *
17  * $Id: class.SearchController.php 1462 2014-02-04 23:52:27Z iherwig $
18  */
19 require_once(BASE."wcmf/application/controller/class.AsyncPagingController.php");
20 require_once(BASE."wcmf/lib/persistence/class.PersistenceFacade.php");
21 require_once(BASE."wcmf/lib/persistence/class.ObjectQuery.php");
22 require_once(BASE."wcmf/lib/presentation/ListboxFunctions.php");
23 require_once(BASE."wcmf/lib/util/class.SearchUtil.php");
24 
25 /**
26  * @class SearchController
27  * @ingroup Controller
28  * @brief SearchController is a controller that executes a search for oids and
29  * displays them in a paged list. Internally it uses Zend Lucene indexed search.
30  *
31  * <b>Input actions:</b>
32  * - @em list Actually do the search
33  *
34  * <b>Output actions:</b>
35  * - see AsyncPagingController in case of list action
36  * - @em ok If any other case
37  *
38  * @param [in,out] searchterm The term to search for (The actual searchterm in simple search, empty in advanced search)
39  * see AsyncPagingController for additional parameters
40  *
41  * @author ingo herwig <ingo@wemove.com>
42  */
44 {
45  // session name constants
46  var $FILTER_VARNAME = 'SearchController.filter';
47  var $HITS_VARNAME = 'SearchController.hits';
48 
49  /**
50  * @see Controller::initialize()
51  */
52  function initialize(&$request, &$response)
53  {
54  // check if this is a new call and the stored oids should be deleted
55  if ($request->getAction() != 'list')
56  {
57  $session = &SessionData::getInstance();
58  $session->remove($this->HITS_VARNAME);
59  }
60  parent::initialize($request, $response);
61  }
62  /**
63  * @see Controller::hasView()
64  */
65  function hasView()
66  {
67  if ($this->_request->getAction() == 'list') {
68  return false;
69  }
70  else {
71  return true;
72  }
73  }
74  /**
75  * @see Controller::executeKernel()
76  */
77  function executeKernel()
78  {
79  // execute the search if requested
80  if ($this->_request->getAction() == 'list')
81  {
82  return parent::executeKernel();
83  }
84 
85  $this->_response->setValue('searchdef', $this->_request->getValue('searchterm'));
86  $this->_response->setValue('searchterm', $this->_request->getValue('searchterm'));
87  $this->_response->setAction('ok');
88  return false;
89  }
90  /**
91  * @see AsyncPagingController::getObjects()
92  */
93  function getObjects($type, $filter, $sortArray, &$pagingInfo)
94  {
95  $rightsManager = RightsManager::getInstance();
96  $session = &SessionData::getInstance();
97 
98  if (!$session->exist($this->HITS_VARNAME))
99  {
100  // search with searchterm (even if empty) if no query is given
101  $hits = SearchUtil::find($filter);
102 
103  // store the hits in the session for later use
104  $session->set($this->HITS_VARNAME, $hits);
105  $session->set($this->FILTER_VARNAME, $filter);
106  }
107 
108  $allOIDs = array();
109  $hits = $session->get($this->HITS_VARNAME);
110  foreach ($hits as $hit) {
111  $allOIDs[] = $hit['oid'];
112  }
113  $allOIDs = array_unique($allOIDs);
114 
115  // update pagingInfo
116  $pagingInfo->setTotalCount(sizeof($allOIDs));
117 
118  // select the requested slice
119  if ($pagingInfo->getPageSize() == -1) {
120  $size = $pagingInfo->getTotalCount();
121  }
122  else {
123  $size = $pagingInfo->getPageSize();
124  }
125  $oids = array_slice($allOIDs, ($pagingInfo->getPage()-1)*$size, $size);
126 
127  // load the objects
128  $persistenceFacade = &PersistenceFacade::getInstance();
129  $objects = array();
130  foreach($oids as $oid)
131  {
132  if ($rightsManager->authorize($oid, '', ACTION_READ))
133  {
134  $obj = &$persistenceFacade->load($oid, BUILDEPTH_SINGLE);
135  $objects[] = &$obj;
136  }
137  }
138  return $objects;
139  }
140  /**
141  * Modify the model passed to the view.
142  * @param nodes A reference to the array of node references passed to the view
143  */
144  function modifyModel(&$nodes)
145  {
146  $session = &SessionData::getInstance();
147  $hits = $session->get($this->HITS_VARNAME);
148 
149  // remove all attributes except for display_values
150  if ($this->_request->getBooleanValue('completeObjects', false) == false) {
151  for($i=0; $i<sizeof($nodes); $i++) {
153  }
154  }
155  // render values
156  if ($this->_request->getBooleanValue('renderValues', false) == true) {
157  NodeUtil::renderValues($nodes);
158  }
159  for ($i=0, $count=sizeof($nodes); $i<$count; $i++)
160  {
161  $curNode = &$nodes[$i];
162  $hit = $hits[$curNode->getOID()];
163  $curNode->setValue('summary', $curNode->getDisplayValue()."<hr>... ".$hit['summary']." ...", DATATYPE_ATTRIBUTE);
164 
165  $curNode->setValue('type', $curNode->getType(), DATATYPE_ATTRIBUTE);
166  $curNode->setValue('displayValue', $curNode->getDisplayValue(), DATATYPE_ATTRIBUTE);
167  }
168  }
169 }
170 ?>
initialize(&$request, &$response)
static find($searchTerm, &$pagingInfo)
const DATATYPE_ATTRIBUTE
SearchController is a controller that executes a search for oids and displays them in a paged list...
renderValues(&$nodes, $language=null)
AsyncPagingController is a controller that allows to navigate lists.
removeNonDisplayValues(&$node)
const ACTION_READ
getObjects($type, $filter, $sortArray, &$pagingInfo)