Open Journal Systems  3.3.0
UserGridRow.inc.php
1 <?php
2 
16 import('lib.pkp.classes.controllers.grid.GridRow');
17 import('lib.pkp.classes.linkAction.request.RemoteActionConfirmationModal');
18 import('lib.pkp.classes.linkAction.request.RedirectConfirmationModal');
19 import('lib.pkp.classes.linkAction.request.JsEventConfirmationModal');
20 
21 class UserGridRow extends GridRow {
24 
28  function __construct($oldUserId = null) {
29  $this->_oldUserId = $oldUserId;
30  parent::__construct();
31  }
32 
33 
34  //
35  // Overridden methods from GridRow
36  //
40  function initialize($request, $template = null) {
41  parent::initialize($request, $template);
42 
43  // Is this a new row or an existing row?
44  $element =& $this->getData();
45  assert(is_a($element, 'User'));
46 
47  $rowId = $this->getId();
48 
49  if (!empty($rowId) && is_numeric($rowId)) {
50  // Only add row actions if this is an existing row
51  $router = $request->getRouter();
52  $actionArgs = array(
53  'gridId' => $this->getGridId(),
54  'rowId' => $rowId
55  );
56 
57  $actionArgs = array_merge($actionArgs, $this->getRequestArgs());
58 
59  // If this is the grid for merging a user, only show the merge
60  // linkaction
61  if ($this->getOldUserId()) {
62  $actionArgs['oldUserId'] = $this->getOldUserId();
63  $actionArgs['newUserId'] = $rowId;
64 
65  // Verify that the old user exists
66  $userDao = DAORegistry::getDAO('UserDAO'); /* @var $userDao UserDAO */
67  $oldUser = $userDao->getById($this->getOldUserId());
68 
69  // Don't merge a user in itself
70  if ($oldUser && $actionArgs['oldUserId'] != $actionArgs['newUserId']) {
71  $this->addAction(
72  new LinkAction(
73  'mergeUser',
75  $request->getSession(),
76  __('grid.user.mergeUsers.confirm', array('oldUsername' => $oldUser->getUsername(), 'newUsername' => $element->getUsername())),
77  null,
78  $router->url($request, null, null, 'mergeUsers', null, $actionArgs),
79  'modal_merge_users'
80  ),
81  __('grid.user.mergeUsers.mergeIntoUser'),
82  'merge_users')
83  );
84  }
85 
86  // Otherwise display all the default link actions
87  } else {
88 
89  $this->addAction(
90  new LinkAction(
91  'email',
92  new AjaxModal(
93  $router->url($request, null, null, 'editEmail', null, $actionArgs),
94  __('grid.user.email'),
95  'modal_email',
96  true
97  ),
98  __('grid.user.email'),
99  'notify')
100  );
101  $this->addAction(
102  new LinkAction(
103  'edit',
104  new AjaxModal(
105  $router->url($request, null, null, 'editUser', null, $actionArgs),
106  __('grid.user.edit'),
107  'modal_edit',
108  true
109  ),
110  __('grid.user.edit'),
111  'edit')
112  );
113  if ($element->getDisabled()) {
114  $actionArgs['enable'] = true;
115  $this->addAction(
116  new LinkAction(
117  'enable',
118  new AjaxModal(
119  $router->url($request, null, null, 'editDisableUser', null, $actionArgs),
120  __('common.enable'),
121  'enable',
122  true
123  ),
124  __('common.enable'),
125  'enable')
126  );
127  } else {
128  $actionArgs['enable'] = false;
129  $this->addAction(
130  new LinkAction(
131  'disable',
132  new AjaxModal(
133  $router->url($request, null, null, 'editDisableUser', null, $actionArgs),
134  __('grid.user.disable'),
135  'disable',
136  true
137  ),
138  __('grid.user.disable'),
139  'disable')
140  );
141  }
142  $this->addAction(
143  new LinkAction(
144  'remove',
146  $request->getSession(),
147  __('manager.people.confirmRemove'),
148  __('common.remove'),
149  $router->url($request, null, null, 'removeUser', null, $actionArgs),
150  'modal_delete'
151  ),
152  __('grid.action.remove'),
153  'delete')
154  );
155 
156  $canAdminister = Validation::canAdminister($this->getId(), $request->getUser()->getId());
157  if (
159  $request->getUser()->getId() != $this->getId() and
160  $canAdminister
161  ) {
162  $dispatcher = $router->getDispatcher();
163  $this->addAction(
164  new LinkAction(
165  'logInAs',
167  __('grid.user.confirmLogInAs'),
168  __('grid.action.logInAs'),
169  $dispatcher->url($request, ROUTE_PAGE, null, 'login', 'signInAsUser', $this->getId())
170  ),
171  __('grid.action.logInAs'),
172  'enroll_user'
173  )
174  );
175  }
176 
177  // do not allow the deletion of the admin account.
178  if ($rowId > 1 && $canAdminister) {
179  $this->addAction(
180  new LinkAction(
181  'mergeUser',
182  new AjaxModal(
183  $router->url($request, null, null, 'mergeUsers', null, array('oldUserId' => $rowId)),
184  __('grid.user.mergeUsers.mergeUser'),
185  'modal_merge_users',
186  true
187  ),
188  __('grid.user.mergeUsers.mergeUser'),
189  'merge_users')
190  );
191  }
192  }
193  }
194  }
195 
200  function getOldUserId() {
201  return $this->_oldUserId;
202  }
203 }
204 
205 
Validation\isLoggedInAs
static isLoggedInAs()
Definition: Validation.inc.php:388
RemoteActionConfirmationModal
Class defining a simple confirmation modal with a remote action and ok/cancel buttons.
Definition: RemoteActionConfirmationModal.inc.php:18
GridRow\addAction
addAction($action, $position=GRID_ACTION_POSITION_DEFAULT)
Definition: GridRow.inc.php:179
DAORegistry\getDAO
static & getDAO($name, $dbconn=null)
Definition: DAORegistry.inc.php:57
GridBodyElement\getId
getId()
Definition: GridBodyElement.inc.php:57
UserGridRow\initialize
initialize($request, $template=null)
Definition: UserGridRow.inc.php:40
GridRow\getGridId
getGridId()
Definition: GridRow.inc.php:97
GridRow
GridRow implements a row of a Grid. See GridHandler for general information about grids.
Definition: GridRow.inc.php:29
AjaxModal
A modal that retrieves its content from via AJAX.
Definition: AjaxModal.inc.php:18
LinkAction
Base class defining an action that can be performed by the user in the user interface.
Definition: LinkAction.inc.php:22
UserGridRow
User grid row definition.
Definition: UserGridRow.inc.php:21
GridRow\getRequestArgs
getRequestArgs()
Definition: GridRow.inc.php:115
RedirectConfirmationModal
Class defining a simple confirmation modal with a redirect url and ok/cancel buttons.
Definition: RedirectConfirmationModal.inc.php:18
UserGridRow\getOldUserId
getOldUserId()
Definition: UserGridRow.inc.php:200
UserGridRow\__construct
__construct($oldUserId=null)
Definition: UserGridRow.inc.php:28
Validation\canAdminister
static canAdminister($administeredUserId, $administratorUserId)
Definition: Validation.inc.php:410
GridRow\getData
& getData()
Definition: GridRow.inc.php:131
UserGridRow\$_oldUserId
$_oldUserId
Definition: UserGridRow.inc.php:23