wCMF  3.6
 All Classes Namespaces Files Functions Variables Groups Pages
class.ListboxController.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.ListboxController.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/util/class.Obfuscator.php");
21 
22 /**
23  * @class ListboxController
24  * @ingroup Controller
25  * @brief ListboxController is a controller that uses g_getOIDs to retrieve listbox data.
26  *
27  * <b>Input actions:</b>
28  * - unspecified: List Nodes of given type
29  *
30  * <b>Output actions:</b>
31  * - @em ok In any case
32  *
33  * @param[in] type The entity type to list
34  * @param[in] filter A query passed to g_getOIDs
35  * @param[in] displayFilter A regular expression that the returned 'val' values should match
36  * @param[out] totalCount The total number of all entities that match the criteria
37  * @param[out] objects An associative array with keys 'key' and 'val'
38  *
39  * @author ingo herwig <ingo@wemove.com>
40  */
42 {
43  /**
44  * @see Controller::hasView()
45  */
46  function hasView()
47  {
48  return false;
49  }
50  /**
51  * Do processing and assign Node data to View.
52  * @return False in every case.
53  * @see Controller::executeKernel()
54  */
55  function executeKernel()
56  {
57  // unveil the filter value if it is ofuscated
58  $filter = $this->_request->getValue('filter');
59  $unveiled = Obfuscator::unveil($filter);
60  if (strlen($filter) > 0)
61  {
62  if (strlen($unveiled) > 0) {
63  $filter = $unveiled;
64  }
65  else {
66  $filter = stripslashes($filter);
67  }
68  }
69 
70  $objects = g_getOIDs($this->_request->getValue('type'), $filter);
71  if ($this->isLocalizedRequest()) {
72  $objects = g_getOIDs($this->_request->getValue('type'), $filter, null, false,
73  $this->_request->getValue('language'));
74  }
75  else {
76  $objects = g_getOIDs($this->_request->getValue('type'), $filter);
77  }
78 
79  // translate all nodes to the requested language if requested
80  if ($this->isLocalizedRequest())
81  {
82  $localization = Localization::getInstance();
83  for ($i=0; $i<sizeof($objects); $i++) {
84  $localization->loadTranslation($objects[$i], $this->_request->getValue('language'), true, true);
85  }
86  }
87 
88  // apply displayFilter, if given
89  $regexp = $this->_request->getValue('displayFilter');
90  if (strlen($regexp) > 0)
91  {
92  $regexp = '/'.$regexp.'/i';
93  $tmp = array();
94  foreach ($objects as $key => $val)
95  {
96  if (preg_match($regexp, $val)) {
97  $tmp[$key] = $val;
98  }
99  }
100  $objects = $tmp;
101  }
102 
103  $this->_response->setValue('totalCount', sizeof($objects));
104  $responseObjects = array();
105  foreach($objects as $key => $val)
106  array_push($responseObjects, array('key' => $key, 'val' => $val));
107  $this->_response->setValue('objects', $responseObjects);
108 
109  // success
110  $this->_response->setAction('ok');
111  return false;
112  }
113 }
114 ?>
Controller is the base class of all controllers. If a Controller has a view it is expected to reside ...
g_getOIDs($type, $queryStr=null, $orderbyStr=null, $realOIDs=false, $language=null)
ListboxController is a controller that uses g_getOIDs to retrieve listbox data.