wCMF  3.6
 All Classes Namespaces Files Functions Variables Groups Pages
class.UserManagerRDB.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.UserManagerRDB.php 1462 2014-02-04 23:52:27Z iherwig $
18  */
19 require_once(BASE."wcmf/lib/security/class.UserManager.php");
20 require_once(BASE."wcmf/lib/security/class.User.php");
21 require_once(BASE."wcmf/lib/security/class.Role.php");
22 require_once(BASE."wcmf/lib/persistence/class.PersistenceFacade.php");
23 
24 /**
25  * @class UserManagerRDB
26  * @ingroup Security
27  * @brief UserManagerRDB is a UserManager that stores user and role information in a database
28  * using RDBMappers. The User and Role implementation classes are defined by the configuration
29  * keys 'User' and 'Role' in the [implementation] section.
30  *
31  * @author ingo herwig <ingo@wemove.com>
32  */
34 {
35  /**
36  * @see UserManager::initialize()
37  */
38  function initialize($params)
39  {
40  $userRepository = array();
41 
42  $userClass = UserManager::getUserClassName();
43  $roleClass = UserManager::getRoleClassName();
44 
45  // load the user/role instances
46  $query = &PersistenceFacade::createObjectQuery($userClass);
47  $users = $query->execute(BUILDDEPTH_SINGLE);
48  $query = &PersistenceFacade::createObjectQuery($roleClass);
49  $roles = $query->execute(BUILDDEPTH_SINGLE);
50 
51  // add the user/role instances to the repository
52  $userRepository['users'] = array();
53  for ($i=0, $count=sizeof($users); $i<$count; $i++) {
54  if ($users[$i] != null) {
55  $users[$i]->loadChildren($roleClass);
56  $userRepository['users'][sizeof($userRepository['users'])] = &$users[$i];
57  }
58  }
59  for ($i=0, $count=sizeof($roles); $i<$count; $i++) {
60  if ($roles[$i] != null) {
61  $roles[$i]->loadChildren($userClass);
62  $userRepository['roles'][sizeof($userRepository['roles'])] = &$roles[$i];
63  }
64  }
65  return $userRepository;
66  }
67 
68  /**
69  * @see UserManager::createUserImpl()
70  */
71  function &createUserImpl($name, $firstname, $login, $password)
72  {
73  $persistenceFacade = &PersistenceFacade::getInstance();
74  $user = &$persistenceFacade->create(UserManager::getUserClassName(), BUILDDEPTH_REQUIRED);
75  $user->setName($name);
76  $user->setFirstname($firstname);
77  $user->setLogin($login);
78  $user->setPassword($password);
79  $user->save();
80 
81  return $user;
82  }
83 
84  /**
85  * @see UserManager::removeUserImpl()
86  */
87  function removeUserImpl(&$user)
88  {
89  $user->delete();
90  }
91 
92  /**
93  * @see UserManager::setUserPropertyImpl()
94  */
95  function setUserPropertyImpl(&$user, $property, $value)
96  {
97  $user->setValue($property, $value, DATATYPE_ATTRIBUTE);
98  $user->save();
99  }
100 
101  /**
102  * @see UserManager::createRoleImpl()
103  */
104  function &createRoleImpl($name)
105  {
106  $persistenceFacade = &PersistenceFacade::getInstance();
107  $role = &$persistenceFacade->create($this->getRoleClassName(), BUILDDEPTH_REQUIRED);
108  $role->setName($name);
109  $role->save();
110 
111  return $role;
112  }
113 
114  /**
115  * @see UserManager::removeRoleImpl()
116  */
117  function removeRoleImpl(&$role)
118  {
119  $role->delete();
120  }
121 
122  /**
123  * @see UserManager::setRolePropertyImpl()
124  */
125  function setRolePropertyImpl(&$role, $property, $value)
126  {
127  $role->setValue($property, $value, DATATYPE_ATTRIBUTE);
128  $role->save();
129  }
130 
131  /**
132  * @see UserManager::addUserToRoleImpl()
133  */
134  function addUserToRoleImpl(&$role, &$user)
135  {
136  $user->addRole($role->getName(), true);
137  }
138 
139  /**
140  * @see UserManager::removeUserFromRoleImpl()
141  */
142  function removeUserFromRoleImpl(&$role, &$user)
143  {
144  $user->removeRole($role->getName(), true);
145  }
146 }
147 ?>
& createUserImpl($name, $firstname, $login, $password)
const DATATYPE_ATTRIBUTE
setRolePropertyImpl(&$role, $property, $value)
addUserToRoleImpl(&$role, &$user)
UserManager is used to edit users and roles. UserManager supports the following operations: ...
setUserPropertyImpl(&$user, $property, $value)
const BUILDDEPTH_REQUIRED
UserManagerRDB is a UserManager that stores user and role information in a database using RDBMappers...
const BUILDDEPTH_SINGLE
removeUserFromRoleImpl(&$role, &$user)