Open Monograph Press  1.1
 All Classes Namespaces Functions Variables Groups Pages
ExportableUsersGridHandler.inc.php
1 <?php
2 
16 import('lib.pkp.classes.controllers.grid.GridHandler');
17 import('lib.pkp.classes.controllers.grid.DataObjectGridCellProvider');
18 import('lib.pkp.classes.linkAction.request.RedirectConfirmationModal');
19 
21 
22  var $_pluginName;
23 
28  parent::GridHandler();
29  $this->addRoleAssignment(array(
30  ROLE_ID_MANAGER),
31  array('fetchGrid', 'fetchRow')
32  );
33  }
34 
35 
36  //
37  // Implement template methods from PKPHandler.
38  //
42  function authorize($request, &$args, $roleAssignments) {
43  import('lib.pkp.classes.security.authorization.PkpContextAccessPolicy');
44  $this->addPolicy(new PkpContextAccessPolicy($request, $roleAssignments));
45  return parent::authorize($request, $args, $roleAssignments);
46  }
47 
51  function initialize($request) {
52  parent::initialize($request);
53 
54  // Load user-related translations.
56  LOCALE_COMPONENT_PKP_USER,
57  LOCALE_COMPONENT_PKP_MANAGER,
58  LOCALE_COMPONENT_APP_MANAGER
59  );
60 
61  // Basic grid configuration.
62  $this->setTitle('grid.user.currentUsers');
63 
64  // Grid actions.
65  $router = $request->getRouter();
66  $pluginName = $request->getUserVar('pluginName');
67  assert(!empty($pluginName));
68  $this->_pluginName = $pluginName;
69 
70  $dispatcher = $request->getDispatcher();
71  $url = $dispatcher->url($request, ROUTE_PAGE, null, 'manager', 'importexport', array('plugin', $pluginName, 'exportAllUsers'));
72 
73  $this->addAction(
74  new LinkAction(
75  'exportAllUsers',
77  __('grid.users.confirmExportAllUsers'),
78  null,
79  $url
80  ),
81  __('grid.action.exportAllUsers'),
82  'export_users'
83  )
84  );
85 
86  //
87  // Grid columns.
88  //
89 
90  // First Name.
91  $cellProvider = new DataObjectGridCellProvider();
92  $this->addColumn(
93  new GridColumn(
94  'firstName',
95  'user.firstName',
96  null,
97  'controllers/grid/gridCell.tpl',
98  $cellProvider
99  )
100  );
101 
102  // Last Name.
103  $cellProvider = new DataObjectGridCellProvider();
104  $this->addColumn(
105  new GridColumn(
106  'lastName',
107  'user.lastName',
108  null,
109  'controllers/grid/gridCell.tpl',
110  $cellProvider
111  )
112  );
113 
114  // User name.
115  $cellProvider = new DataObjectGridCellProvider();
116  $this->addColumn(
117  new GridColumn(
118  'username',
119  'user.username',
120  null,
121  'controllers/grid/gridCell.tpl',
122  $cellProvider
123  )
124  );
125 
126  // Email.
127  $cellProvider = new DataObjectGridCellProvider();
128  $this->addColumn(
129  new GridColumn(
130  'email',
131  'user.email',
132  null,
133  'controllers/grid/gridCell.tpl',
134  $cellProvider
135  )
136  );
137  }
138 
139 
140  //
141  // Implement methods from GridHandler.
142  //
146  function initFeatures($request, $args) {
147  import('lib.pkp.classes.controllers.grid.feature.selectableItems.SelectableItemsFeature');
148  import('lib.pkp.classes.controllers.grid.feature.PagingFeature');
149  return array(new SelectableItemsFeature(), new PagingFeature());
150  }
151 
155  function getSelectName() {
156  return 'selectedUsers';
157  }
158 
159  //
160  // Implemented methods from GridHandler.
161  //
165  function isDataElementSelected($gridDataElement) {
166  return false; // Nothing is selected by default
167  }
168 
174  function loadData($request, $filter) {
175  // Get the context.
176  $context = $request->getContext();
177 
178  // Get all users for this context that match search criteria.
179  $userGroupDao = DAORegistry::getDAO('UserGroupDAO');
180  $rangeInfo = $this->getGridRangeInfo($request, $this->getId());
181 
182  return $users = $userGroupDao->getUsersById(
183  $filter['userGroup'],
184  $context->getId(),
185  $filter['searchField'],
186  $filter['search']?$filter['search']:null,
187  $filter['searchMatch'],
188  $rangeInfo
189  );
190  }
191 
195  function renderFilter($request) {
196  $context = $request->getContext();
197  $userGroupDao = DAORegistry::getDAO('UserGroupDAO');
198  $userGroups = $userGroupDao->getByContextId($context->getId());
199  $userGroupOptions = array('' => __('grid.user.allRoles'));
200  while ($userGroup = $userGroups->next()) {
201  $userGroupOptions[$userGroup->getId()] = $userGroup->getLocalizedName();
202  }
203 
204  // Import PKPUserDAO to define the USER_FIELD_* constants.
205  import('lib.pkp.classes.user.PKPUserDAO');
206  $fieldOptions = array(
207  USER_FIELD_FIRSTNAME => 'user.firstName',
208  USER_FIELD_LASTNAME => 'user.lastName',
209  USER_FIELD_USERNAME => 'user.username',
210  USER_FIELD_EMAIL => 'user.email'
211  );
212 
213  $matchOptions = array(
214  'contains' => 'form.contains',
215  'is' => 'form.is'
216  );
217 
218  $filterData = array(
219  'userGroupOptions' => $userGroupOptions,
220  'fieldOptions' => $fieldOptions,
221  'matchOptions' => $matchOptions
222  );
223 
224  return parent::renderFilter($request, $filterData);
225  }
226 
231  function getFilterSelectionData($request) {
232  // Get the search terms.
233  $userGroup = $request->getUserVar('userGroup') ? (int)$request->getUserVar('userGroup') : null;
234  $searchField = $request->getUserVar('searchField');
235  $searchMatch = $request->getUserVar('searchMatch');
236  $search = $request->getUserVar('search');
237 
238  return $filterSelectionData = array(
239  'userGroup' => $userGroup,
240  'searchField' => $searchField,
241  'searchMatch' => $searchMatch,
242  'search' => $search ? $search : ''
243  );
244  }
245 
250  function getFilterForm() {
251  return 'controllers/grid/users/exportableUsers/userGridFilter.tpl';
252  }
253 
257  function getRequestArgs() {
258  return array_merge(parent::getRequestArgs(), array('pluginName' => $this->_getPluginName()));
259  }
260 
265  function _getPluginName() {
266  return $this->_pluginName;
267  }
268 }
269 
270 ?>
authorize($request, &$args, $roleAssignments)
static & getDAO($name, $dbconn=null)
addPolicy($authorizationPolicy, $addToTop=false)
Implements grid widgets selectable items functionality.
static requireComponents()
Handle exportable user grid requests.
addAction($action, $position=GRID_ACTION_POSITION_ABOVE)
addColumn($column)
Class defining basic operations for handling HTML grids.
Class defining a simple confirmation modal with a redirect url and ok/cancel buttons.
Class to control access to PKP applications&#39; setup components.
addRoleAssignment($roleIds, $operations)
Add paging functionality to grids.
Base class for a cell provider that can retrieve simple labels from DataObjects. If you need more com...
getGridRangeInfo($request, $rangeName, $contextData=null)
Represents a column within a grid. It is used to configure the way cells within a column are displaye...
Base class defining an action that can be performed by the user in the user interface.