wCMF  3.6
 All Classes Namespaces Files Functions Variables Groups Pages
class.SOAPController.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.SOAPController.php 1462 2014-02-04 23:52:27Z iherwig $
18  */
19 require_once(BASE."wcmf/lib/presentation/class.Controller.php");
20 require_once(BASE."wcmf/lib/persistence/class.PersistenceFacade.php");
21 require_once(BASE."wcmf/lib/persistence/class.LockManager.php");
22 require_once(BASE."wcmf/lib/model/class.Node.php");
23 require_once(BASE."wcmf/lib/model/class.NodeUtil.php");
24 require_once(BASE."wcmf/application/controller/class.SearchController.php");
25 
26 /**
27  * @class SOAPController
28  * @ingroup Controller
29  * @brief SOAPController is a controller that handles SOAPRequests.
30  *
31  * <b>Input actions:</b>
32  * - @em soapSearch Search for objects that match a searchterm in any attribute
33  * - @em soapAdvancedSearch Search for objects of a given type
34  *
35  * <b>Output actions:</b>
36  * - @em ok In any case
37  *
38  * @param [in] searchterm The search term to use (needed for the action soapSearch)
39  * @param [in] type The entity type to search for (needed for the action soapAdvancedSearch)
40  * @param [in] query The query string to use, see StringQuery (needed for the action soapAdvancedSearch)
41  * @param [out] soapResult The result of the processed action
42  *
43  * @author ingo herwig <ingo@wemove.com>
44  */
46 {
47  /**
48  * @see Controller::hasView()
49  */
50  function hasView()
51  {
52  return false;
53  }
54  /**
55  * Execute the requested soap action and add 'soapResult' to the data array
56  * @see Controller::executeKernel()
57  */
58  function executeKernel()
59  {
60  // process actions
61  $action = $this->_request->getAction();
62  if ($action == 'soapSearch')
63  $this->soapSearch($this->_request->getValue('searchterm'));
64 
65  else if ($action == 'soapAdvancedSearch')
66  $this->soapAdvancedSearch($this->_request->getValue('type'), $this->_request->getValue('query'));
67 
68  // release all locks
69  $lockManager = &LockManager::getInstance();
70  $lockManager->releaseAllLocks();
71 
72  $this->_response->setAction('ok');
73  return false;
74  }
75 
76  /**
77  * Search all searchable types for a given term.
78  * @param searchTerm The term to search for
79  */
80  function soapSearch($searchTerm)
81  {
82  // get all known types from configuration file
83  $parser = &InifileParser::getInstance();
84  $types = array_keys($parser->getSection('typemapping'));
85  $searchController = new SearchController();
86 
87  // query for each type
88  $objectList = array();
89  foreach ($types as $type)
90  {
91  $query = &PersistenceFacade::createObjectQuery($type);
92  $tpl = &$query->getObjectTemplate($type, QUERYOP_OR, QUERYOP_OR);
93 
94  // only search types with attributes and which are searchable
95  if ($searchController->isSearchable($tpl))
96  {
97  $processor = new NodeProcessor('setSearchTerm', array($searchTerm), $searchController);
98  $processor->run($tpl, false);
99 
100  $nodes = $query->execute(BUILDDEPTH_SINGLE);
101  foreach ($nodes as $node)
102  {
103  $object = array();
104  $object['type'] = $node->getType();
105  $object['oid'] = $node->getOID();
106  $object['displayName'] = strip_tags(preg_replace("/[\r\n']/", " ", NodeUtil::getDisplayValue($node)));
107  array_push($objectList, $object);
108  }
109  }
110  }
111  $this->_response->setValue('soapResult', $objectList);
112  }
113 
114  /**
115  * Search for instances of a given type, that satisfy the given query.
116  * @param type The type to search for
117  * @param queryStr The query string to satisfy
118  */
119  function soapAdvancedSearch($type, $queryStr)
120  {
122  $nodes = $query->execute($type, $queryStr, BUILDDEPTH_SINGLE);
123  $objectList = array();
124  foreach ($nodes as $node)
125  {
126  $object = array();
127  $object['type'] = $node->getType();
128  $object['oid'] = $node->getOID();
129  $object['displayName'] = strip_tags(preg_replace("/[\r\n']/", " ", NodeUtil::getDisplayValue($node)));
130  array_push($objectList, $object);
131  }
132  $this->_response->setValue('soapResult', $objectList);
133  }
134 }
135 ?>
SOAPController is a controller that handles SOAPRequests.
SearchController is a controller that executes a search for oids and displays them in a paged list...
NodeProcessor is used to iterate over all values of a Node and apply a given callback function...
const QUERYOP_OR
soapSearch($searchTerm)
Controller is the base class of all controllers. If a Controller has a view it is expected to reside ...
soapAdvancedSearch($type, $queryStr)
getDisplayValue(&$node, $useDisplayType=false, $language=null, $values=null)
const BUILDDEPTH_SINGLE