wCMF  3.6
 All Classes Namespaces Files Functions Variables Groups Pages
class.DisplayController.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.DisplayController.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.InifileParser.php");
21 require_once(BASE."wcmf/lib/persistence/class.PersistenceFacade.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/lib/security/class.RightsManager.php");
25 require_once(BASE."wcmf/lib/util/class.StringUtil.php");
26 require_once(BASE."wcmf/lib/presentation/ListboxFunctions.php");
27 require_once(BASE."wcmf/lib/util/class.Log.php");
28 
29 /**
30  * @class DisplayController
31  * @ingroup Controller
32  * @brief DisplayController is a simple controller demonstrating how to display a Node
33  * using the displaynode.tpl template.
34  *
35  * <b>Input actions:</b>
36  * - unspecified: Display given Node if an oid is given
37  *
38  * <b>Output actions:</b>
39  * - @em failure If a fatal error occurs
40  * - @em ok In any other case
41  *
42  * @param[in,out] oid The oid of the Node to show
43  * @param[in] depth The BUILDDEPTH used when loading the Node
44  * @param[in] omitMetaData True/False. If true, only the parameters 'node' and 'lockMsg' will be returned. If not given,
45  * all parameters will be returned.
46  * @param[in] translateValues True/False. If true, list values will be translated using FormUtil::translateValue. If not given,
47  * all values will be returned as is.
48  * @param[out] node The Node object to display
49  * @param[out] lockMsg The lock message, if any
50  * @param[out] possibleparents An array with Node objects of possible parents (see NodeUtil::getPossibleParents()) [optional]
51  * @param[out] possiblechildren An array with Node objects of possible children (see NodeUtil::getPossibleChildren()) [optional]
52  * @param[out] rootType The root type of the Node (selects the navigation tab) [optional]
53  * @param[out] rootTemplateNode An instance of the root type [optional]
54  * @param[out] viewMode One of the values 'detail' (in case of an oid given) or 'overview' (else) [optional]
55  *
56  * @author ingo herwig <ingo@wemove.com>
57  */
59 {
60  /**
61  * @see Controller::initialize()
62  */
63  function initialize(&$request, &$response)
64  {
65  if (strlen($request->getContext()) == 0)
66  {
67  $request->setContext('cms');
68  $response->setContext('cms');
69  }
70 
71  // set rootType variable if a valid oid is given in data
72  $oid = $request->getValue('oid');
74  {
75  $parts = PersistenceFacade::decomposeOID($oid);
76  $request->setValue('rootType', $parts['type']);
77  $request->setContext($parts['type']);
78  }
79  // set rootType to context, if it corresponds to an entity type
80  else if (PersistenceFacade::isKnownType($request->getContext()))
81  {
82  $request->setValue('rootType', $request->getContext());
83  }
84 
85  parent::initialize($request, $response);
86  }
87  /**
88  * @see Controller::hasView()
89  */
90  function hasView()
91  {
92  return true;
93  }
94  /**
95  * Assign Node data to View.
96  * @return Array of given context and action 'failure' on failure.
97  * False on success (Stop action processing chain).
98  * In case of 'failure' a detailed description is provided by getErrorMsg().
99  * @see Controller::executeKernel()
100  */
101  function executeKernel()
102  {
103  $persistenceFacade = &PersistenceFacade::getInstance();
104  $rightsManager = &RightsManager::getInstance();
105 
106  // release all locks before edit
107  $lockManager = &LockManager::getInstance();
108  $lockManager->releaseAllLocks();
109  $lockMsg = '';
110 
111  // get root types from ini file
112  $parser = &InifileParser::getInstance();
113  if (!$this->isOmitMetaData())
114  {
115  $rootTypes = $parser->getValue('rootTypes', 'cms');
116  if ($rootTypes === false || !is_array($rootTypes) || $rootTypes[0] == '')
117  {
118  $this->setErrorMsg(Message::get("No root types defined."));
119  $this->_response->setAction('failure');
120  return true;
121  }
122  }
123 
124  // load model
125  $oid = $this->_request->getValue('oid');
126  if (PersistenceFacade::isValidOID($this->_request->getValue('oid')) && $rightsManager->authorize($oid, '', ACTION_READ))
127  {
128  // an object id is given. load the data for editing the object
129  $viewMode = 'detail';
130 
131  // determine the builddepth
132  $buildDepth = BUILDDEPTH_SINGLE;
133  if ($this->_request->hasValue('depth')) {
134  $buildDepth = $this->_request->getValue('depth');
135  }
136  $node = &$persistenceFacade->load($oid, $buildDepth);
137 
138  if ($node == null)
139  {
140  $this->setErrorMsg(Message::get("A Node with object id %1% does not exist.", array($oid)));
141  $this->_response->setAction('failure');
142  return true;
143  }
144 
145  // translate all nodes to the requested language if requested
146  if ($this->isLocalizedRequest())
147  {
148  $localization = Localization::getInstance();
149  $localization->loadTranslation($node, $this->_request->getValue('language'), true, true);
150  }
151 
152  if (Log::isDebugEnabled(__CLASS__)) {
153  Log::debug(nl2br($node->toString()), __CLASS__);
154  }
155  // handle locking
156  $lockMsg .= LockManager::handleLocking($node, $node->getOID());
157 
158  // assign meta data
159  if (!$this->isOmitMetaData())
160  {
161  // determine root type
162  $rootOID = $oid;
163  if (sizeof($pathData) > 0) {
164  $rootOID = $pathData[0]['oid'];
165  }
166  $rootType = PersistenceFacade::getOIDParameter($rootOID, 'type');
167 
168  $template = &$persistenceFacade->create($node->getType(), 1);
169 
170  // possible parents
171  $possibleParentsAll = NodeUtil::getPossibleParents($node, $template);
172  $possibleParents = array();
173  $possibleParentTypes = array_keys($possibleParentsAll);
174  for ($i=0; $i<sizeof($possibleParentTypes); $i++)
175  {
176  $curParentType = $possibleParentTypes[$i];
177  if ($rightsManager->authorize($curParentType, '', ACTION_READ)) {
178  $possibleParents[$curParentType] = &$possibleParentsAll[$curParentType];
179  }
180  }
181  $this->_response->setValue('possibleparents', $possibleParents);
182 
183  // possible children
184  // don't resolve many to many relations
185  $possibleChildrenAll = NodeUtil::getPossibleChildren($node, $template, false);
186  $possibleChildren = array();
187  $possibleChildTypes = array_keys($possibleChildrenAll);
188  for ($i=0; $i<sizeof($possibleChildTypes); $i++)
189  {
190  $curChildType = $possibleChildTypes[$i];
191  if ($rightsManager->authorize($curChildType, '', ACTION_READ)) {
192  $possibleChildren[$curChildType] = &$possibleChildrenAll[$curChildType];
193  }
194  }
195  $this->_response->setValue('possiblechildren', $possibleChildren);
196  }
197 
198  // translate values if requested
199  if ($this->_request->getBooleanValue('translateValues'))
200  {
201  $nodes = array($node);
202  if ($this->isLocalizedRequest()) {
203  NodeUtil::translateValues($nodes, $this->_request->getValue('language'));
204  }
205  else {
207  }
208  }
209 
210  // assign node data
211  $this->_response->setValue('node', $node);
212  $this->_response->setValue('lockMsg', $lockMsg);
213  }
214  else
215  {
216  // no object id is given. load the data for the overview
217  $viewMode = 'overview';
218 
219  if (!$this->isOmitMetaData())
220  {
221  // determine root type
222  $rootType = $this->_request->getValue('rootType');
223  if (strlen($rootType) == 0) {
224  $rootType = $rootTypes[0];
225  }
226  }
227  }
228 
229  // assign meta data
230  if (!$this->isOmitMetaData())
231  {
232  $this->_response->setValue('oid', $oid);
233  $this->_response->setValue('rootType', $rootType);
234  $this->_response->setValue('rootTemplateNode', $persistenceFacade->create($rootType, BUILDDEPTH_SINGLE));
235  $this->_response->setValue('viewMode', $viewMode);
236  }
237  // success
238  $this->_response->setAction('ok');
239  return false;
240  }
241 
242  /**
243  * Determine, if meta data is not requested
244  * @return True/False
245  */
246  function isOmitMetaData()
247  {
248  return $this->_request->getValue('omitMetaData');
249  }
250 }
251 ?>
debug($message, $category)
Definition: class.Log.php:39
get($message, $parameters=null, $domain='', $lang='')
getPossibleChildren(&$realNode, &$tplNode, $resolveManyToMany=true)
Controller is the base class of all controllers. If a Controller has a view it is expected to reside ...
DisplayController is a simple controller demonstrating how to display a Node using the displaynode...
translateValues(&$nodes, $language=null)
decomposeOID($oid, $validate=true)
isDebugEnabled($category)
Definition: class.Log.php:89
getOIDParameter($oid, $param, $validate=true)
getPossibleParents(&$realNode, &$tplNode)
handleLocking(&$object, $name)
initialize(&$request, &$response)
const BUILDDEPTH_SINGLE
const ACTION_READ