Open Monograph Press  1.1
 All Classes Namespaces Functions Variables Groups Pages
UserUserGroupListbuilderHandler.inc.php
1 <?php
2 
16 import('lib.pkp.classes.controllers.listbuilder.ListbuilderHandler');
17 
20  var $_userId;
21 
23  var $_context;
24 
25 
30  parent::ListbuilderHandler();
31  $this->addRoleAssignment(
32  ROLE_ID_MANAGER,
33  array('fetch', 'fetchRow', 'fetchOptions', 'save')
34  );
35  }
36 
37 
38  //
39  // Setters and Getters
40  //
45  function setUserId($userId) {
46  $this->_userId = $userId;
47  }
48 
49 
54  function getUserId() {
55  return $this->_userId;
56  }
57 
58 
63  function setContext(&$context) {
64  $this->_context =& $context;
65  }
66 
67 
72  function &getContext() {
73  return $this->_context;
74  }
75 
76 
77  //
78  // Overridden parent class functions
79  //
83  function getRequestArgs() {
84  return array(
85  'userId' => $this->getUserId()
86  );
87  }
88 
92  function getAddItemLinkAction($actionRequest) {
93  AppLocale::requireComponents(LOCALE_COMPONENT_PKP_GRID);
94  return new LinkAction(
95  'addItem',
96  $actionRequest,
97  __('grid.user.addRole'),
98  'add_item'
99  );
100  }
101 
102 
107  function getOptions($includeDesignations = false) {
108  // Initialize the object to return
109  $items = array(
110  array(), // Names
111  array() // Designations
112  );
114  // Fetch the user groups
115  $context = $this->getContext();
116  $userGroupDao = DAORegistry::getDAO('UserGroupDAO');
117  $userGroups = $userGroupDao->getByContextId($context->getId());
118  $roleDao = DAORegistry::getDAO('RoleDAO');
119  $roleNames = $roleDao->getRoleNames(true);
120 
121  // Assemble the array to return
122  while ($userGroup = $userGroups->next()) {
123  $userGroupId = $userGroup->getId();
124  $roleId = $userGroup->getRoleId();
125  $roleName = __($roleNames[$roleId]);
126 
127  $items[0][$roleId][$userGroupId] = $userGroup->getLocalizedName();
128  if ($includeDesignations) {
129  $items[1][$userGroupId] = $userGroup->getLocalizedAbbrev();
130  }
131 
132  // Add the optgroup label.
133  $items[0][LISTBUILDER_OPTGROUP_LABEL][$roleId] = $roleName;
134  }
135 
136  return $items;
137  }
138 
139 
143  function loadData() {
144  $context = $this->getContext();
145  $userGroupDao = DAORegistry::getDAO('UserGroupDAO');
146  return $userGroupDao->getByUserId($this->getUserId(), $context->getId());
147  }
148 
150  //
151  // Implement template methods from PKPHandler
152  //
156  function authorize($request, &$args, $roleAssignments) {
157  import('lib.pkp.classes.security.authorization.PkpContextAccessPolicy');
158  $this->addPolicy(new PkpContextAccessPolicy($request, $roleAssignments));
159  return parent::authorize($request, $args, $roleAssignments);
160  }
161 
166  function initialize($request) {
167  // FIXME Validate user ID?
168 
169  // Load user-related translations.
170  AppLocale::requireComponents(LOCALE_COMPONENT_PKP_USER);
171 
172  $this->setUserId((int) $request->getUserVar('userId'));
173 
174  $this->setContext($request->getContext());
175  parent::initialize($request);
176 
177  // Basic configuration
178  $this->setTitle($request->getUserVar('title'));
179  $this->setSourceType(LISTBUILDER_SOURCE_TYPE_SELECT);
180  $this->setSaveType(LISTBUILDER_SAVE_TYPE_EXTERNAL);
181  $this->setSaveFieldName('roles');
182 
183  import('lib.pkp.controllers.listbuilder.users.UserGroupListbuilderGridCellProvider');
184  $cellProvider = new UserGroupListbuilderGridCellProvider();
185 
186  // Name column
187  $nameColumn = new ListbuilderGridColumn($this, 'name', 'common.name');
188  $nameColumn->setCellProvider($cellProvider);
189  $this->addColumn($nameColumn);
190 
191  // Designation column
192  $designationColumn = new ListbuilderGridColumn($this,
193  'designation',
194  'common.designation',
195  null,
196  'controllers/listbuilder/listbuilderNonEditGridCell.tpl'
197  );
198  $designationColumn->setCellProvider($cellProvider);
199  $this->addColumn($designationColumn);
200  }
201 
205  function getRowDataElement($request, $rowId) {
206  // fallback on the parent if a rowId is found
207  if ( !empty($rowId) ) {
208  return parent::getRowDataElement($request, $rowId);
209  }
210 
211  // Otherwise return from the $newRowId
212  $newRowId = $this->getNewRowId($request);
213  $userGroupId = $newRowId['name'];
214  $userGroupDao = DAORegistry::getDAO('UserGroupDAO');
215  $context = $this->getContext();
216  return $userGroupDao->getById($userGroupId, $context->getId());
217  }
218 }
219 
220 ?>
static & getDAO($name, $dbconn=null)
addPolicy($authorizationPolicy, $addToTop=false)
Class assign/remove mappings of user user groups.
Base class for a cell provider that can retrieve labels from arrays.
static requireComponents()
addColumn($column)
Class defining basic operations for handling Listbuilder UI elements.
Class to control access to PKP applications&#39; setup components.
addRoleAssignment($roleIds, $operations)
Represents a column within a listbuilder.
authorize($request, &$args, $roleAssignments)
Base class defining an action that can be performed by the user in the user interface.