Open Monograph Press  1.1
 All Classes Namespaces Functions Variables Groups Pages
UserForm.inc.php
1 <?php
2 
16 import('lib.pkp.classes.form.Form');
17 
18 class UserForm extends Form {
19 
21  var $userId;
22 
29  function UserForm($template, $userId = null) {
30  parent::Form($template);
31 
32  $this->userId = isset($userId) ? (int) $userId : null;
33 
34  if (!is_null($userId)) {
35  $this->addCheck(new FormValidatorListBuilder($this, 'roles', 'manager.users.roleRequired'));
36  }
37  }
38 
42  function readInputData() {
43  $this->readUserVars(array('roles'));
44  }
45 
49  function execute($request) {
50  ListbuilderHandler::unpack($request, $this->getData('roles'));
51  }
52 
56  function insertEntry($request, $newRowId) {
57  $context = $request->getContext();
58  $userGroupDao = DAORegistry::getDAO('UserGroupDAO');
59 
60  $userGroupId = (int) $newRowId['name'];
61  $userId = (int) $this->userId;
62 
63  // Ensure that:
64  // $userGroupId is not empty
65  // $userGroupId is valid for this context.
66  // user group assignment does not already exist
67  if (
68  empty($userGroupId) ||
69  !$userGroupDao->contextHasGroup($context->getId(), $userGroupId) ||
70  $userGroupDao->userInGroup($userId, $userGroupId)
71  ) {
72  return false;
73  } else {
74  // Add the assignment
75  $userGroupDao->assignUserToGroup($userId, $userGroupId);
76  }
77 
78  return true;
79  }
80 
84  function deleteEntry($request, $rowId) {
85  $userGroupId = (int) $rowId;
86  $userId = (int) $this->userId;
87 
88  $userGroupDao = DAORegistry::getDAO('UserGroupDAO');
89  $context = $request->getContext();
90 
91  $userGroupDao->removeUserFromGroup(
92  $userId,
93  (int) $userGroupId,
94  $context->getId()
95  );
96 
97  return true;
98  }
99 
100 }
101 
102 ?>
static & getDAO($name, $dbconn=null)
addCheck($formValidator)
Definition: Form.inc.php:396
Base class for user forms.
readUserVars($vars)
Definition: Form.inc.php:364
Class defining basic operations for handling HTML forms.
Definition: Form.inc.php:47
deleteEntry($request, $rowId)
execute($request)
getData($key)
Definition: Form.inc.php:210
UserForm($template, $userId=null)
insertEntry($request, $newRowId)
unpack($request, $data, $deletionCallback=null, $insertionCallback=null, $updateCallback=null)