SearchController.php
1 <?php
2 /**
3  * wCMF - wemove Content Management Framework
4  * Copyright (C) 2005-2015 wemove digital solutions GmbH
5  *
6  * Licensed under the terms of the MIT License.
7  *
8  * See the LICENSE file distributed with this work for
9  * additional information.
10  */
12 
24 
25 /**
26  * SearchController executes a search and returns matching objects in a paged list.
27  * Internally it uses Zend Lucene indexed search.
28  *
29  * The controller supports the following actions:
30  *
31  * <div class="controller-action">
32  * <div> __Action__ _default_ </div>
33  * <div>
34  * Search.
35  * | Parameter | Description
36  * |------------------------|-------------------------
37  * | _in_ / _out_ `query` | The query string
38  * | __Response Actions__ | |
39  * | `ok` | In all cases
40  * </div>
41  * </div>
42  *
43  * For additional actions and parameters see [ListController actions](@ref ListController).
44  *
45  * @author ingo herwig <ingo@wemove.com>
46  */
48 
49  private $_hits = array();
50  private $_search = null;
51 
52  /**
53  * Constructor
54  * @param $session
55  * @param $persistenceFacade
56  * @param $permissionManager
57  * @param $actionMapper
58  * @param $localization
59  * @param $message
60  * @param $configuration
61  * @param $search
62  */
63  public function __construct(Session $session,
64  PersistenceFacade $persistenceFacade,
65  PermissionManager $permissionManager,
66  ActionMapper $actionMapper,
67  Localization $localization,
68  Message $message,
69  Configuration $configuration,
70  Search $search) {
71  parent::__construct($session, $persistenceFacade, $permissionManager,
72  $actionMapper, $localization, $message, $configuration);
73  $this->_search = $search;
74  }
75 
76  /**
77  * @see ListController::getObjects()
78  */
79  protected function getObjects($type, $queryCondition, $sortArray, $pagingInfo) {
80  $permissionManager = $this->getPermissionManager();
81 
82  // search with searchterm (even if empty) if no query is given
83  $this->_hits = $this->_search->find($queryCondition, $pagingInfo);
84 
85  $oids = array();
86  foreach ($this->_hits as $hit) {
87  $oids[] = ObjectId::parse($hit['oid']);
88  }
89 
90  // load the objects
91  $persistenceFacade = $this->getPersistenceFacade();
92  $objects = array();
93  foreach($oids as $oid) {
94  if ($permissionManager->authorize($oid, '', PersistenceAction::READ)) {
95  $obj = $persistenceFacade->load($oid);
96  $objects[] = $obj;
97  }
98  }
99  return $objects;
100  }
101 
102  /**
103  * @see ListController::modifyModel()
104  */
105  protected function modifyModel($nodes) {
106  parent::modifyModel($nodes);
107 
108  $persistenceFacade = $this->getPersistenceFacade();
109  for ($i=0, $count=sizeof($nodes); $i<$count; $i++) {
110  $curNode = &$nodes[$i];
111  $hit = $this->_hits[$curNode->getOID()->__toString()];
112  $curNode->setValue('_displayValue', $curNode->getDisplayValue(), true);
113  $curNode->setValue('_summary', "... ".$hit['summary']." ...", true);
114  $curNode->setValue('_type', $persistenceFacade->getSimpleType($curNode->getType()), true);
115  }
116  }
117 }
118 ?>
__construct(Session $session, PersistenceFacade $persistenceFacade, PermissionManager $permissionManager, ActionMapper $actionMapper, Localization $localization, Message $message, Configuration $configuration, Search $search)
Constructor.
Localization defines the interface for storing localized entity instances and retrieving them back...
getObjects($type, $queryCondition, $sortArray, $pagingInfo)
getPermissionManager()
Get the PermissionManager instance.
Definition: Controller.php:230
ListController is used to load Node lists.
Message is used to get localized messages to be used in the user interface.
Definition: Message.php:23
Session is the interface for session implementations and defines access to session variables...
Definition: Session.php:21
static parse($oid)
Parse a serialized object id string into an ObjectId instance.
Definition: ObjectId.php:144
PermissionManager implementations are used to handle all authorization requests.
Implementations of Configuration give access to the application configuration.
Application controllers.
Definition: namespaces.php:3
ActionMapper implementations are responsible for instantiating and executing Controllers based on the...
PersistenceFacade defines the interface for PersistenceFacade implementations.
Search implementations are used to search entity objects.
Definition: Search.php:21
SearchController executes a search and returns matching objects in a paged list.
getPersistenceFacade()
Get the PersistenceFacade instance.
Definition: Controller.php:222