wCMF  3.6
 All Classes Namespaces Files Functions Variables Groups Pages
class.RoleRDBBase.php
Go to the documentation of this file.
1 <?php
2 /**
3  * This file was generated by wCMFGenerator 2.6.1.0033 from cookbook1.xmi on 23.02.09 21:34.
4  * Manual modifications should be placed inside the protected regions.
5  */
6 require_once(BASE."wcmf/lib/security/class.Role.php");
7 
8 /**
9  * @class RoleRDB
10  * RoleRDB description:
11  *
12  * @author <ingo@wemove.com>
13  * @version 1.0
14  */
15 class RoleRDBBase extends Role
16 {
17  function RoleRDBBase($oid=null, $type=null)
18  {
19  if ($type == null)
20  parent::Role($oid, 'RoleRDB');
21  else
22  parent::Role($oid, $type);
23  }
24  /**
25  * @see PersistentObject::getObjectDisplayName()
26  */
28  {
29  return Message::get("RoleRDB");
30  }
31  /**
32  * @see PersistentObject::getObjectDescription()
33  */
35  {
36  return Message::get("");
37  }
38  /**
39  * @see PersistentObject::getValueDisplayName()
40  */
41  function getValueDisplayName($name, $type=null)
42  {
43  $displayName = $name;
44  if ($name == 'id') $displayName = Message::get("id");
45  if ($name == 'name') $displayName = Message::get("name");
46  return Message::get($displayName);
47  }
48  /**
49  * @see PersistentObject::getValueDescription()
50  */
51  function getValueDescription($name, $type=null)
52  {
53  $description = $name;
54  if ($name == 'id') $description = Message::get("");
55  if ($name == 'name') $description = Message::get("");
56  return Message::get($description);
57  }
58  /**
59  * See if the node is an association object, that implements a many to many relation
60  */
61  function isManyToManyObject()
62  {
63  return false;
64  }
65  /**
66  * Getter/Setter
67  */
68  function getId($unconverted=false)
69  {
70  if ($unconverted)
71  return $this->getUnconvertedValue('id', DATATYPE_IGNORE);
72  else
73  return $this->getValue('id', DATATYPE_IGNORE);
74  }
75  function setId($id)
76  {
77  return $this->setValue('id', $id, DATATYPE_IGNORE);
78  }
79  function getName($unconverted=false)
80  {
81  if ($unconverted)
82  return $this->getUnconvertedValue('name', DATATYPE_ATTRIBUTE);
83  else
84  return $this->getValue('name', DATATYPE_ATTRIBUTE);
85  }
86  function setName($name)
87  {
88  return $this->setValue('name', $name, DATATYPE_ATTRIBUTE);
89  }
90  /**
91  * @deprecated use getNMUserRoleChildren() instead
92  */
93  function getNMUserRoleList()
94  {
95  Log::warn("use of deprecated method getNMUserRoleList. use getNMUserRoleChildren() instead.\n".WCMFException::getStackTrace(), __CLASS__);
96  return $this->getNMUserRoleChildren();
97  }
99  {
100  return $this->getChildrenEx(null, 'NMUserRole', array('fk_role_id' => $this->getDBID()), null);
101  }
102  /**
103  * @deprecated use getUserRDBChildren() instead
104  */
105  function getUserRDBList()
106  {
107  Log::warn("use of deprecated method getUserRDBList. use getUserRDBChildren() instead.\n".WCMFException::getStackTrace(), __CLASS__);
108  return $this->getUserRDBChildren();
109  }
111  {
112  // the foreign key column does not exist
113  return $this->getChildrenEx(null, 'UserRDB', null, null);
114  }
115 
116  /**
117  * Node class overrides
118  */
119 
120  /**
121  * @see Node::loadChildren()
122  * Override this to also load the children of many-to-many relations
123  */
124  function loadChildren($type, $buildDepth=BUILDDEPTH_SINGLE, $forceUpdate=false)
125  {
126  // handle NMUserRole as many-to-many type
127  if ($type == 'UserRDB')
128  {
129  // for every NMUserRole we have to load the UserRDB
130  $this->loadChildren('NMUserRole');
131  $children = parent::getChildrenEx(null, 'NMUserRole', array('fk_role_id' => $this->getDBID()), null);
132  $persistenceFacade = &PersistenceFacade::getInstance();
133  $grandChildren = array();
134  for($i=0; $i<sizeof($children); $i++)
135  {
136  if (PersistenceFacade::isValidOID($children[$i]->getUserRDBOID()))
137  {
138  $grandChild = &$persistenceFacade->load($children[$i]->getUserRDBOID(), BUILDDEPTH_SINGLE);
139  if ($grandChild != null)
140  {
141  // establish connetcion
142  $grandChild->addChild($children[$i]);
143  $grandChild->setState(STATE_CLEAN);
144  $children[$i]->setState(STATE_CLEAN);
145  }
146  }
147  }
148  return;
149  }
150  // do default
151  parent::loadChildren($type, $buildDepth, $forceUpdate);
152  }
153  /**
154  * @see Node::getChildrenEx()
155  * Override this to also get the children of many-to-many relations
156  */
157  function getChildrenEx($oid, $type, $values, $properties)
158  {
159  // handle NMUserRole as many-to-many type
160  if ($type == 'UserRDB' || PersistenceFacade::getOIDParameter($oid, 'type') == 'UserRDB')
161  {
162  // for every NMUserRole we have to get the UserRDB parents
163  $children = parent::getChildrenEx(null, 'NMUserRole', array('fk_role_id' => $this->getDBID()), null);
164  $grandChildren = array();
165  $persistenceFacade = &PersistenceFacade::getInstance();
166  for($i=0; $i<sizeof($children); $i++)
167  {
168  // load the parents
169  $grandChildrenParents = array();
170  foreach ($children[$i]->getProperty('parentoids') as $parentoid)
171  {
172  if (PersistenceFacade::getOIDParameter($parentoid, 'type') == 'UserRDB')
173  {
174  $tmpParents = $children[$i]->getParentsEx($parentoid, null, null, null);
175  if (sizeof($tmpParents) > 0)
176  $curChildParent = &$tmpParents[0];
177  else
178  $curChildParent = &$persistenceFacade->load($parentoid, BUILDDEPTH_SINGLE);
179  if ($curChildParent != null)
180  $grandChildrenParents[sizeof($grandChildrenParents)] = &$curChildParent;
181  }
182  }
183  for($j=0; $j<sizeof($grandChildrenParents); $j++)
184  $grandChildren[sizeof($grandChildren)] = &$grandChildrenParents[$j];
185  }
186  return Node::filter($grandChildren, $oid, $type, $values, $properties);
187  }
188  // do default
189  return parent::getChildrenEx($oid, $type, $values, $properties);
190  }
191  /**
192  * @see Node::addChild()
193  * Override this to insert association objects if necessary
194  */
195  function addChild(&$child, $addtype=ADDCHILD_BACK)
196  {
197  if ($child != null && $child->getType() == 'UserRDB')
198  {
199  // for every UserRDB we have to insert a NMUserRole
200  $persistenceFacade = &PersistenceFacade::getInstance();
201  // check if the relation already exists
202  $relOID = $persistenceFacade->getFirstOID('NMUserRole', array('fk_role_id' => $this->getDBID(), 'fk_user_id' => $child->getDBID()));
203  if ($relOID == null)
204  {
205  // add the child only if it is not added already
206  $associationNode = &$persistenceFacade->create('NMUserRole', BUILDTYPE_SINGLE);
207  $associationNode->setRoleRDB($this);
208  $associationNode->setUserRDB($child);
209  $child->addChild($associationNode);
210  }
211  else
212  $associationNode = &$persistenceFacade->load($relOID, BUILDTYPE_SINGLE);
213  // set child parameter to associationNode and prodeed with default behaviour
214  $child = &$associationNode;
215  }
216  // do default
217  parent::addChild($child, $addtype);
218  }
219  /**
220  * @see Node::deleteChild()
221  * Override this to delete association objects if necessary
222  */
223  function deleteChild($childOID, $reallyDelete=false)
224  {
225  if (PersistenceFacade::isValidOID($childOID) && PersistenceFacade::getOIDParameter($childOID, 'type') == 'UserRDB')
226  {
227  // for every UserRDB we have to delete the NMUserRole
228  // set childOID parameter to the NMUserRole's object id and prodeed with default behaviour
229  $ids = PersistenceFacade::getOIDParameter($childOID, 'id');
230  array_unshift($ids, $this->getDBID());
231  $childOID = PersistenceFacade::composeOID(array('type' => 'NMUserRole', 'id' => $ids));
232  }
233  // do default
234  parent::deleteChild($childOID, $reallyDelete);
235  }
236 }
237 ?>
getValueDisplayName($name, $type=null)
loadChildren($type, $buildDepth=BUILDDEPTH_SINGLE, $forceUpdate=false)
get($message, $parameters=null, $domain='', $lang='')
warn($message, $category)
Definition: class.Log.php:59
deleteChild($childOID, $reallyDelete=false)
const DATATYPE_ATTRIBUTE
Abstract base class for role classes that represent a user role.
Definition: class.Role.php:28
getValueDescription($name, $type=null)
getValue($name, $type=null)
const STATE_CLEAN
filter(&$nodeList, $oid, $type, $values, $properties, $useRegExp=true)
Definition: class.Node.php:401
const DATATYPE_IGNORE
const ADDCHILD_BACK
Definition: class.Node.php:31
getOIDParameter($oid, $param, $validate=true)
getChildrenEx($oid, $type, $values, $properties)
addChild(&$child, $addtype=ADDCHILD_BACK)
setValue($name, $value, $type=null, $forceSet=false)
getName($unconverted=false)
RoleRDBBase($oid=null, $type=null)
getId($unconverted=false)
const BUILDDEPTH_SINGLE
getUnconvertedValue($name, $type=null)