Open Journal Systems  3.3.0
PluginGridCellProvider.inc.php
1 <?php
2 
16 import('lib.pkp.classes.controllers.grid.GridCellProvider');
17 
19 
27  function getTemplateVarsFromRowColumn($row, $column) {
28  $plugin =& $row->getData();
29  $columnId = $column->getId();
30  assert(is_a($plugin, 'Plugin') && !empty($columnId));
31 
32  switch ($columnId) {
33  case 'name':
34  return array('label' => $plugin->getDisplayName());
35  break;
36  case 'category':
37  return array('label' => $plugin->getCategory());
38  break;
39  case 'description':
40  return array('label' => $plugin->getDescription());
41  break;
42  case 'enabled':
43  $isEnabled = $plugin->getEnabled();
44  return array(
45  'selected' => $isEnabled,
46  'disabled' => $isEnabled?!$plugin->getCanDisable():!$plugin->getCanEnable(),
47  );
48  default:
49  break;
50  }
51 
52  return parent::getTemplateVarsFromRowColumn($row, $column);
53  }
54 
58  function getCellActions($request, $row, $column, $position = GRID_ACTION_POSITION_DEFAULT) {
59  switch ($column->getId()) {
60  case 'enabled':
61  $plugin = $row->getData(); /* @var $plugin Plugin */
62  $requestArgs = array_merge(
63  array('plugin' => $plugin->getName()),
64  $row->getRequestArgs()
65  );
66  switch (true) {
67  case $plugin->getEnabled() && $plugin->getCanDisable():
68  // Create an action to disable the plugin
69  import('lib.pkp.classes.linkAction.request.RemoteActionConfirmationModal');
70  return array(new LinkAction(
71  'disable',
73  $request->getSession(),
74  __('grid.plugin.disable'),
75  __('common.disable'),
76  $request->url(null, null, 'disable', null, $requestArgs)
77  ),
78  __('manager.plugins.disable'),
79  null
80  ));
81  break;
82  case !$plugin->getEnabled() && $plugin->getCanEnable():
83  // Create an action to enable the plugin
84  import('lib.pkp.classes.linkAction.request.AjaxAction');
85  return array(new LinkAction(
86  'enable',
87  new AjaxAction(
88  $request->url(null, null, 'enable', null, array_merge(
89  ['csrfToken' => $request->getSession()->getCSRFToken()],
90  $requestArgs
91  ))
92  ),
93  __('manager.plugins.enable'),
94  null
95  ));
96  break;
97  }
98  }
99  return parent::getCellActions($request, $row, $column, $position);
100  }
101 }
PluginGridCellProvider
Cell provider for columns in a plugin grid.
Definition: PluginGridCellProvider.inc.php:18
RemoteActionConfirmationModal
Class defining a simple confirmation modal with a remote action and ok/cancel buttons.
Definition: RemoteActionConfirmationModal.inc.php:18
AjaxAction
Class defining an AJAX action.
Definition: AjaxAction.inc.php:21
LinkAction
Base class defining an action that can be performed by the user in the user interface.
Definition: LinkAction.inc.php:22
GridCellProvider
Base class for a grid column's cell provider.
Definition: GridCellProvider.inc.php:20
PluginGridCellProvider\getTemplateVarsFromRowColumn
getTemplateVarsFromRowColumn($row, $column)
Definition: PluginGridCellProvider.inc.php:27
PluginGridCellProvider\getCellActions
getCellActions($request, $row, $column, $position=GRID_ACTION_POSITION_DEFAULT)
Definition: PluginGridCellProvider.inc.php:58