wCMF  3.6
 All Classes Namespaces Files Functions Variables Groups Pages
class.ChildrenListController.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.ChildrenListController.php 1462 2014-02-04 23:52:27Z iherwig $
18  */
19 require_once(BASE."wcmf/application/controller/class.NodeListController.php");
20 require_once(BASE."wcmf/lib/persistence/class.PersistenceFacade.php");
21 require_once(BASE."wcmf/lib/model/class.NodeUtil.php");
22 require_once(BASE."wcmf/lib/presentation/ListboxFunctions.php");
23 
24 /**
25  * @class ChildrenListController
26  * @ingroup Controller
27  * @brief ChildrenListController is a controller that loads chilren of a given node
28  * and displays the result in a list.
29  *
30  * <b>Input actions:</b>
31  * - unspecified: List nodes
32  *
33  * <b>Output actions:</b>
34  * - see NodeListController
35  *
36  * @param[in,out] poid The object id of the parent node to list the children for
37  * @param[in] type The entity type the type to list
38  * @param[in,out] canCreate True/False wether children of that type may be created or not
39  * @param[in,out] aggregation True/False wether children of that type are added as aggregation or not
40  * @param[in,out] composition True/False wether children of that type are added as composition or not
41 
42  * For additional parameters see NodeListController
43  *
44  * @author ingo herwig <ingo@wemove.com>
45  */
47 {
48  /**
49  * @see Controller::validate()
50  */
51  function validate()
52  {
53  if(!PersistenceFacade::isValidOID($this->_request->getValue('poid')))
54  {
55  $this->setErrorMsg("No valid 'poid' given in data.");
56  return false;
57  }
58  return parent::validate();
59  }
60  /**
61  * @see PagingController::getOIDs()
62  */
63  function getOIDs()
64  {
65  $oids = array();
66 
67  $persistenceFacade = &PersistenceFacade::getInstance();
68  $parent = &$persistenceFacade->load($this->_request->getValue('poid'), BUILDDEPTH_SINGLE);
69  $type = $this->_request->getValue('type');
70 
71  $parent->loadChildren($type);
72  $children = $parent->getChildrenEx(null, $type, null, null);
73  for ($i=0; $i<sizeof($children); $i++)
74  array_push($oids, $children[$i]->getOID());
75 
76  return $oids;
77  }
78  /**
79  * @see PagingController::modifyModel()
80  */
81  function modifyModel(&$nodes)
82  {
83  parent::modifyModel(&$nodes);
84 
85  // as manyToMany objects act as a proxy, we set a property 'realSubject',
86  // which holds to the real subject.
87  $persistenceFacade = &PersistenceFacade::getInstance();
88  for ($i=0; $i<sizeof($nodes); $i++)
89  {
90  $curNode = &$nodes[$i];
91  if (in_array('manyToMany', $curNode->getPropertyNames()))
92  {
93  $realSubjectType = $this->getRealSubjectType(&$curNode);
94 
95  // get the real subject from the parentoids property
96  $realSubject = null;
97  foreach($curNode->getProperty('parentoids') as $curParentOID)
98  {
99  if (PersistenceFacade::getOIDParameter($curParentOID, 'type') == $realSubjectType)
100  {
101  $realSubject = &$persistenceFacade->load($curParentOID, BUILDDEPTH_SINGLE);
102  break;
103  }
104  }
105 
106  $curNode->setProperty('realSubject', $realSubject);
107  }
108  }
109  }
110  /**
111  * @see Controller::executeKernel()
112  */
113  function executeKernel()
114  {
115  // as manyToMany objects act as a proxy, we set a property 'subjectType',
116  // which holds the type of the real subject and will be used instead of 'type'.
117  $persistenceFacade = &PersistenceFacade::getInstance();
118  $typeInstance = &$persistenceFacade->create($this->_request->getValue('type'), BUILDDEPTH_SINGLE);
119  if (in_array('manyToMany', $typeInstance->getPropertyNames()))
120  $this->_view->assign('subjectType', $this->getRealSubjectType(&$typeInstance));
121 
122  $this->_response->setValue('poid', $this->_request->getValue('poid'));
123  $this->_response->setValue('canCreate', $this->_request->getValue('canCreate'));
124  $this->_response->setValue('aggregation', $this->_request->getValue('aggregation'));
125  $this->_response->setValue('composition', $this->_request->getValue('composition'));
126 
127  return parent::executeKernel();
128  }
129  /**
130  * Get the sesson varname prefix depending on parent and child type.
131  * @return The prefix
132  */
133  function getSessionPrefix()
134  {
135  return 'ChildrenListController.'.PersistenceFacade::getOIDParameter(
136  $this->_request->getValue('poid'), 'type').'.'.$this->_request->getValue('type').'.';
137  }
138  /**
139  * Get the real subject type for a proxy node.
140  * @param node The proxy node
141  * @return The type
142  */
143  function getRealSubjectType(&$node)
144  {
145  $parentType = PersistenceFacade::getOIDParameter($this->_request->getValue('poid'), 'type');
146 
147  // get the type of the real subject from the manyToMany property
148  foreach($node->getProperty('manyToMany') as $curParentType)
149  {
150  if ($curParentType != $parentType)
151  return $curParentType;
152  }
153  return null;
154  }
155 }
156 ?>
ChildrenListController is a controller that loads chilren of a given node and displays the result in ...
NodeListController is a controller that loads nodes of a given type and displays the result in a list...
getOIDParameter($oid, $param, $validate=true)
const BUILDDEPTH_SINGLE