-
Notifications
You must be signed in to change notification settings - Fork 439
/
UserGroupGridCellProvider.inc.php
110 lines (93 loc) · 3.55 KB
/
UserGroupGridCellProvider.inc.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<?php
/**
* @file controllers/grid/settings/roles/UserGroupGridCellProvider.inc.php
*
* Copyright (c) 2014 Simon Fraser University Library
* Copyright (c) 2003-2014 John Willinsky
* Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
*
* @class UserGroupGridCellProvider
* @ingroup controllers_grid_settings_roles
*
* @brief Cell provider for columns in a user group grid.
*/
import('lib.pkp.classes.controllers.grid.GridCellProvider');
class UserGroupGridCellProvider extends GridCellProvider {
/**
* Constructor
*/
function UserGroupGridCellProvider() {
parent::GridCellProvider();
}
/**
* Extracts variables for a given column from a data element
* so that they may be assigned to template before rendering.
* @param $row GridRow
* @param $column GridColumn
* @return array
*/
function getTemplateVarsFromRowColumn($row, $column) {
$userGroup = $row->getData(); /* @var $userGroup UserGroup */
$columnId = $column->getId();
$workflowStages = Application::getApplicationStages();
$roleDao = DAORegistry::getDAO('RoleDAO'); /* @var $roleDao RoleDAO */
$userGroupDao = DAORegistry::getDAO('UserGroupDAO'); /* @var $userGroupDao UserGroupDAO */
$assignedStages = $userGroupDao->getAssignedStagesByUserGroupId($userGroup->getContextId(), $userGroup->getId());
switch ($columnId) {
case 'name':
return array('label' => $userGroup->getLocalizedName());
case 'abbrev':
return array('label' => $userGroup->getLocalizedAbbrev());
case in_array($columnId, $workflowStages):
// Set the state of the select element that will
// be used to assign the stage to the user group.
$selectDisabled = false;
if (in_array($columnId, $roleDao->getForbiddenStages($userGroup->getRoleId()))) {
// This stage should not be assigned to the user group.
$selectDisabled = true;
}
return array('selected' => in_array($columnId, array_keys($assignedStages)),
'disabled' => $selectDisabled);
default:
break;
}
return parent::getTemplateVarsFromRowColumn($row, $column);
}
/**
* @copydoc GridCellProvider::getCellActions()
*/
function getCellActions($request, $row, $column, $position = GRID_ACTION_POSITION_DEFAULT) {
$workflowStages = Application::getApplicationStages();
$columnId = $column->getId();
if (in_array($columnId, $workflowStages)) {
$userGroup = $row->getData(); /* @var $userGroup UserGroup */
$userGroupDao = DAORegistry::getDAO('UserGroupDAO'); /* @var $userGroupDao UserGroupDAO */
$assignedStages = $userGroupDao->getAssignedStagesByUserGroupId($userGroup->getContextId(), $userGroup->getId());
$router = $request->getRouter();
$roleDao = DAORegistry::getDAO('RoleDAO'); /* @var $roleDao RoleDAO */
if (!in_array($columnId, $roleDao->getForbiddenStages($userGroup->getRoleId()))) {
if (in_array($columnId, array_keys($assignedStages))) {
$operation = 'unassignStage';
$actionTitleKey = 'grid.userGroup.unassignStage';
} else {
$operation = 'assignStage';
$actionTitleKey = 'grid.userGroup.assignStage';
}
$actionArgs = array_merge(array('stageId' => $columnId),
$row->getRequestArgs());
$actionUrl = $router->url($request, null, null, $operation, null, $actionArgs);
import('lib.pkp.classes.linkAction.request.AjaxAction');
$actionRequest = new AjaxAction($actionUrl);
$linkAction = new LinkAction(
$operation,
$actionRequest,
__($actionTitleKey),
null
);
return array($linkAction);
}
}
return parent::getCellActions($request, $row, $column, $position);
}
}
?>