00001 <?php
00002
00015 import('lib.pkp.classes.controllers.grid.GridCellProvider');
00016
00017 class PluginGridCellProvider extends GridCellProvider {
00018
00022 function PluginGridCellProvider() {
00023 parent::GridCellProvider();
00024 }
00025
00033 function getTemplateVarsFromRowColumn(&$row, &$column) {
00034 $plugin =& $row->getData();
00035 $columnId = $column->getId();
00036 assert(is_a($plugin, 'Plugin') && !empty($columnId));
00037
00038 switch ($columnId) {
00039 case 'name':
00040 return array('label' => $plugin->getDisplayName());
00041 break;
00042 case 'category':
00043 return array('label' => $plugin->getCategory());
00044 break;
00045 case 'description':
00046 return array('label' => $plugin->getDescription());
00047 break;
00048 case 'enabled':
00049
00050 $enabled = true;
00051
00052 $hasVerbs = false;
00053
00054
00055 if (is_callable(array($plugin, 'getEnabled'))) {
00056
00057
00058 if (!$plugin->getEnabled()) {
00059 $enabled = false;
00060 }
00061
00062
00063
00064 $managementVerbs = $plugin->getManagementVerbs();
00065 if (!is_null($managementVerbs)) {
00066 foreach($managementVerbs as $verb) {
00067 list($verbName) = $verb;
00068 if ($verbName === 'enable' || $verbName === 'disable') {
00069 $hasVerbs = true;
00070 break;
00071 }
00072 }
00073 }
00074 } else {
00075
00076
00077 $hasVerbs = false;
00078 }
00079
00080
00081
00082 $selectDisabled = true;
00083 if ($hasVerbs) {
00084
00085
00086 $selectDisabled = false;
00087 }
00088
00089 return array('selected' => $enabled,
00090 'disabled' => $selectDisabled);
00091 default:
00092 break;
00093 }
00094
00095 return parent::getTemplateVarsFromRowColumn($row, $column);
00096 }
00097
00101 function getCellActions(&$request, &$row, &$column, $position = GRID_ACTION_POSITION_DEFAULT) {
00102 if ($column->getId() == 'enabled') {
00103 $plugin =& $row->getData();
00104
00105 $router =& $request->getRouter();
00106 $managementVerbs = $plugin->getManagementVerbs();
00107
00108 if (!is_null($managementVerbs)) {
00109 foreach ($managementVerbs as $verb) {
00110 list($verbName, $verbLocalizedName) = $verb;
00111
00112 $actionArgs = array_merge(array(
00113 'plugin' => $plugin->getName(),
00114 'verb' => $verbName),
00115 $row->getRequestArgs());
00116
00117 $actionRequest = null;
00118 $defaultUrl = $router->url($request, null, null, 'plugin', null, $actionArgs);
00119
00120 if ($verbName === 'enable') {
00121 import('lib.pkp.classes.linkAction.request.AjaxAction');
00122 $actionRequest = new AjaxAction($defaultUrl);
00123 } else if ($verbName === 'disable') {
00124 import('lib.pkp.classes.linkAction.request.RemoteActionConfirmationModal');
00125 $actionRequest = new RemoteActionConfirmationModal(__('grid.plugin.disable'),
00126 __('common.disable'), $defaultUrl);
00127 }
00128
00129 if ($actionRequest) {
00130 $linkAction = new LinkAction(
00131 $verbName,
00132 $actionRequest,
00133 $verbLocalizedName,
00134 null
00135 );
00136
00137 return array($linkAction);
00138 }
00139 }
00140 }
00141
00142
00143 return array();
00144 }
00145 return parent::getCellActions($request, $row, $column, $position);
00146 }
00147 }
00148
00149 ?>