00001 <?php
00002
00015
00016 import('lib.pkp.classes.controllers.grid.CategoryGridHandler');
00017 import('lib.pkp.classes.controllers.grid.DataObjectGridCellProvider');
00018
00019
00020 import('controllers.grid.settings.roles.UserGroupGridCategoryRow');
00021
00022
00023 import('lib.pkp.classes.linkAction.request.AjaxModal');
00024
00025 class UserGroupGridHandler extends CategoryGridHandler {
00026 var $_pressId;
00027
00031 function UserGroupGridHandler() {
00032 parent::CategoryGridHandler();
00033
00034 $this->addRoleAssignment(
00035 array(ROLE_ID_PRESS_MANAGER),
00036 array(
00037 'fetchGrid',
00038 'fetchCategory',
00039 'fetchRow',
00040 'addUserGroup',
00041 'editUserGroup',
00042 'updateUserGroup'
00043 )
00044 );
00045 }
00046
00047
00048
00049
00056 function authorize(&$request, $args, $roleAssignments) {
00057 import('classes.security.authorization.OmpPressAccessPolicy');
00058 $this->addPolicy(new OmpPressAccessPolicy($request, $roleAssignments));
00059 return parent::authorize($request, $args, $roleAssignments);
00060 }
00061
00067 function initialize(&$request) {
00068 parent::initialize($request);
00069
00070 $press =& $request->getPress();
00071 $this->_pressId =& $press->getId();
00072
00073
00074 AppLocale::requireComponents(
00075 LOCALE_COMPONENT_PKP_USER,
00076 LOCALE_COMPONENT_OMP_SUBMISSION,
00077 LOCALE_COMPONENT_OMP_MANAGER
00078 );
00079
00080
00081 $this->setTitle('grid.roles.currentRoles');
00082 $this->setInstructions('settings.roles.gridDescription');
00083
00084
00085 $router =& $request->getRouter();
00086 $this->addAction(
00087 new LinkAction(
00088 'addUserGroup',
00089 new AjaxModal(
00090 $router->url($request, null, null, 'addUserGroup'),
00091 __('grid.roles.add'),
00092 'modal_add_role'
00093 ),
00094 __('grid.roles.add'),
00095 'add_role'
00096 )
00097 );
00098
00099
00100 $cellProvider = new DataObjectGridCellProvider();
00101 $cellProvider->setLocale(AppLocale::getLocale());
00102
00103
00104 $this->addColumn(new GridColumn(
00105 'name',
00106 'settings.roles.roleName',
00107 null,
00108 'controllers/grid/gridCell.tpl',
00109 $cellProvider,
00110 array('alignment' => COLUMN_ALIGNMENT_LEFT)
00111 ));
00112 $this->addColumn(new GridColumn(
00113 'abbrev',
00114 'settings.roles.roleAbbrev',
00115 null,
00116 'controllers/grid/gridCell.tpl',
00117 $cellProvider
00118 ));
00119 }
00120
00124 function &loadData($request, $filter) {
00125 $pressId = $this->_getPressId();
00126 $userGroupDao =& DAORegistry::getDAO('UserGroupDAO');
00127
00128 if (is_array($filter) && isset($filter['selectedRoleId']) && $filter['selectedRoleId'] != 0) {
00129 $userGroups =& $userGroupDao->getByRoleId($pressId, $filter['selectedRoleId']);
00130 } else {
00131 $userGroups =& $userGroupDao->getByContextId($pressId);
00132 }
00133
00134 $stages = array();
00135 while ($userGroup =& $userGroups->next()) {
00136 $userGroupStages = $this->_getAssignedStages($pressId, $userGroup->getId());
00137 foreach ($userGroupStages as $stageId => $stage) {
00138 if ($stage != null) {
00139 $stages[$stageId] = array('id' => $stageId, 'name' => $stage);
00140 }
00141 }
00142 unset($userGroup);
00143 }
00144
00145 return $stages;
00146 }
00147
00152 function &getRowInstance() {
00153 import('controllers.grid.settings.roles.UserGroupGridRow');
00154 $row = new UserGroupGridRow();
00155 return $row;
00156 }
00157
00162 function &getCategoryRowInstance() {
00163 $row = new UserGroupGridCategoryRow();
00164 return $row;
00165 }
00166
00170 function getCategoryData(&$stage) {
00171
00172 $stageId = $stage['id'];
00173
00174 $userGroupDao =& DAORegistry::getDAO('UserGroupDAO');
00175
00176 $assignedGroups =& $userGroupDao->getUserGroupsByStage($this->_getPressId(), $stageId);
00177 $returner = $assignedGroups->toAssociativeArray();
00178
00179 return $returner;
00180 }
00181
00187 function addUserGroup($args, &$request) {
00188 return $this->editUserGroup($args, $request);
00189 }
00190
00196 function editUserGroup($args, &$request) {
00197 $userGroupForm = $this->_getUserGroupForm($request);
00198
00199 $userGroupForm->initData();
00200
00201 $json = new JSONMessage(true, $userGroupForm->fetch($request));
00202 return $json->getString();
00203 }
00204
00210 function updateUserGroup($args, &$request) {
00211 $userGroupForm = $this->_getUserGroupForm($request);
00212
00213 $userGroupForm->readInputData();
00214 if($userGroupForm->validate()) {
00215 $userGroupForm->execute($request);
00216 return DAO::getDataChangedEvent();
00217 } else {
00218 $json = new JSONMessage(true, $userGroupForm->fetch($request));
00219 return $json->getString();
00220 }
00221 }
00222
00223
00224
00225
00226
00232 function _getUserGroupForm(&$request) {
00233
00234 $userGroupId = (int) $request->getUserVar('userGroupId');
00235
00236
00237 import('controllers.grid.settings.roles.form.UserGroupForm');
00238 $pressId = $this->_getPressId();
00239 return new UserGroupForm($pressId, $userGroupId);
00240 }
00241
00248 function _getAssignedStages($pressId, $userGroupId) {
00249 $userGroupDao =& DAORegistry::getDAO('UserGroupDAO');
00250 $assignedStages =& $userGroupDao->getAssignedStagesByUserGroupId($pressId, $userGroupId);
00251
00252 $stages = $userGroupDao->getWorkflowStageTranslationKeys();
00253 foreach($stages as $stageId => $stageTranslationKey) {
00254 if (!array_key_exists($stageId, $assignedStages)) $stages[$stageId] = null;
00255 }
00256
00257 return $stages;
00258 }
00259
00264 function _getPressId() {
00265 return $this->_pressId;
00266 }
00267 }
00268
00269 ?>