Open Journal Systems  3.3.0
PluginGridRow.inc.php
1 <?php
2 
16 import('lib.pkp.classes.controllers.grid.GridRow');
17 
18 class PluginGridRow extends GridRow {
19 
21  var $_userRoles;
22 
27  function __construct($userRoles) {
28  parent::__construct();
29  $this->_userRoles = $userRoles;
30  }
31 
32 
33  //
34  // Overridden methods from GridRow
35  //
39  function initialize($request, $template = null) {
40  parent::initialize($request, $template);
41 
42  // Is this a new row or an existing row?
43  $plugin =& $this->getData(); /* @var $plugin Plugin */
44  assert(is_a($plugin, 'Plugin'));
45 
46  $rowId = $this->getId();
47 
48  // Only add row actions if this is an existing row
49  if (!is_null($rowId)) {
50  $router = $request->getRouter(); /* @var $router PKPRouter */
51 
52  $actionArgs = array_merge(
53  array('plugin' => $plugin->getName()),
54  $this->getRequestArgs()
55  );
56 
57  if ($this->_canEdit($plugin)) {
58  foreach ($plugin->getActions($request, $actionArgs) as $action) {
59  $this->addAction($action);
60  }
61  }
62 
63  // Administrative functions.
64  if (in_array(ROLE_ID_SITE_ADMIN, $this->_userRoles)) {
65  import('lib.pkp.classes.linkAction.request.RemoteActionConfirmationModal');
66  $this->addAction(new LinkAction(
67  'delete',
69  $request->getSession(),
70  __('manager.plugins.deleteConfirm'),
71  __('common.delete'),
72  $router->url($request, null, null, 'deletePlugin', null, $actionArgs), 'modal_delete'),
73  __('common.delete'),
74  'delete'
75  ));
76 
77  $this->addAction(new LinkAction(
78  'upgrade',
79  new AjaxModal(
80  $router->url($request, null, null, 'upgradePlugin', null, $actionArgs),
81  __('manager.plugins.upgrade'), 'modal_upgrade'),
82  __('grid.action.upgrade'),
83  'upgrade'
84  ));
85  }
86  }
87  }
88 
89 
90  //
91  // Protected helper methods
92  //
98  protected function _canEdit($plugin) {
99  if ($plugin->isSitePlugin()) {
100  if (in_array(ROLE_ID_SITE_ADMIN, $this->_userRoles)) return true;
101  } else {
102  if (in_array(ROLE_ID_MANAGER, $this->_userRoles)) return true;
103  }
104  return false;
105  }
106 }
107 
108 
PluginGridRow\$_userRoles
$_userRoles
Definition: PluginGridRow.inc.php:24
GridRow\__construct
__construct()
Definition: GridRow.inc.php:75
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
GridBodyElement\getId
getId()
Definition: GridBodyElement.inc.php:57
PluginGridRow\_canEdit
_canEdit($plugin)
Definition: PluginGridRow.inc.php:101
PluginGridRow
Plugin grid row definition.
Definition: PluginGridRow.inc.php:18
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
PluginGridRow\initialize
initialize($request, $template=null)
Definition: PluginGridRow.inc.php:42
PluginGridRow\__construct
__construct($userRoles)
Definition: PluginGridRow.inc.php:30
GridRow\getData
& getData()
Definition: GridRow.inc.php:131