Skip to content

Commit

Permalink
*8637* Fix user groups stage assignment interface
Browse files Browse the repository at this point in the history
  • Loading branch information
beghelli committed Mar 20, 2014
1 parent edc2929 commit 9495c3a
Show file tree
Hide file tree
Showing 9 changed files with 441 additions and 130 deletions.
62 changes: 46 additions & 16 deletions classes/security/UserGroupDAO.inc.php
Expand Up @@ -221,22 +221,44 @@ function getDefaultByRoleId($contextId, $roleId) {
return $allDefaults->next();
}

/**
* Check whether the passed user group
* id is default or not.
* @param $userGroupId Integer
* @return boolean
*/
function isDefault($userGroupId) {
$result = $this->retrieve(
'SELECT is_default FROM user_groups
WHERE user_group_id = ?', array((int)$userGroupId)
);

$result = $result->GetArray();
if (isset($result[0]['is_default'])) {
return $result[0]['is_default'];
} else {
return false;
}
}

/**
* Get all user groups belonging to a role
* @param $contextId
* @param $roleId
* @param $default
* @param Integer $contextId
* @param Integer $roleId
* @param boolean $default (optional)
* @param DBResultRange $dbResultRange (optional)
* @return DAOResultFactory
*/
function getByRoleId($contextId, $roleId, $default = false) {
function getByRoleId($contextId, $roleId, $default = false, $dbResultRange = null) {
$params = array((int) $contextId, (int) $roleId);
if ($default) $params[] = 1; // true
$result = $this->retrieve(
$result = $this->retrieveRange(
'SELECT *
FROM user_groups
WHERE context_id = ? AND
role_id = ?' . ($default?' AND is_default = ?':''),
$params
$params,
$dbResultRange
);

return new DAOResultFactory($result, $this, '_returnFromRow');
Expand Down Expand Up @@ -365,16 +387,19 @@ function contextHasGroup($contextId, $userGroupId) {

/**
* Retrieve user groups for a given context (all contexts if null)
* @param $contextId
* @param Integer $contextId (optional)
* @param DBResultRange $dbResultRange (optional)
* @return DAOResultFactory
*/
function getByContextId($contextId = null) {
function getByContextId($contextId = null, $dbResultRange = null) {
$params = array();
if ($contextId) $params[] = (int) $contextId;
$result = $this->retrieve(
$result = $this->retrieveRange(
'SELECT ug.*
FROM user_groups ug' .
($contextId?' WHERE ug.context_id = ?':''),
$params);
$params,
$dbResultRange);

return new DAOResultFactory($result, $this, '_returnFromRow');
}
Expand All @@ -399,7 +424,7 @@ function getContextUsersCount($contextId, $userGroupId = null, $roleId = null) {
$returner = $result->fields[0];

$result->Close();
return $returner;
return (int) $returner;
}

/**
Expand Down Expand Up @@ -903,16 +928,20 @@ function getWorkflowStageKeysAndPaths() {
/**
* Get the user groups assigned to each stage. Provide the ability to omit authors and reviewers
* Since these are typically stored differently and displayed in different circumstances
* @param $contextId
* @param $stageId
* @param Integer $contextId
* @param Integer $stageId
* @param boolean (optional) $omitAuthors
* @param boolean (optional) $omitReviewers
* @param Integer (optional) $roleId
* @param DBResultRange (optional) $dbResultRange
* @return DAOResultFactory
*/
function getUserGroupsByStage($contextId, $stageId, $omitAuthors = false, $omitReviewers = false, $roleId = null) {
function getUserGroupsByStage($contextId, $stageId, $omitAuthors = false, $omitReviewers = false, $roleId = null, $dbResultRange = null) {
$params = array((int) $contextId, (int) $stageId);
if ($omitAuthors) $params[] = ROLE_ID_AUTHOR;
if ($omitReviewers) $params[] = ROLE_ID_REVIEWER;
if ($roleId) $params[] = $roleId;
$result = $this->retrieve(
$result = $this->retrieveRange(
'SELECT ug.*
FROM user_groups ug
JOIN user_group_stage ugs ON (ug.user_group_id = ugs.user_group_id AND ug.context_id = ugs.context_id)
Expand All @@ -922,7 +951,8 @@ function getUserGroupsByStage($contextId, $stageId, $omitAuthors = false, $omitR
($omitReviewers?' AND ug.role_id <> ?':'') .
($roleId?' AND ug.role_id = ?':'') .
' ORDER BY role_id ASC',
$params
$params,
$dbResultRange
);

return new DAOResultFactory($result, $this, '_returnFromRow');
Expand Down
40 changes: 0 additions & 40 deletions controllers/grid/settings/roles/UserGroupGridCategoryRow.inc.php

This file was deleted.

110 changes: 110 additions & 0 deletions controllers/grid/settings/roles/UserGroupGridCellProvider.inc.php
@@ -0,0 +1,110 @@
<?php

/**
* @file controllers/grid/settings/roles/UserGroupGridCellProvider.inc.php
*
* Copyright (c) 2014 Simon Fraser University Library
* Copyright (c) 2003-2014 John Willinsky
* Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
*
* @class UserGroupGridCellProvider
* @ingroup controllers_grid_settings_roles
*
* @brief Cell provider for columns in a user group grid.
*/

import('lib.pkp.classes.controllers.grid.GridCellProvider');

class UserGroupGridCellProvider extends GridCellProvider {

/**
* Constructor
*/
function UserGroupGridCellProvider() {
parent::GridCellProvider();
}

/**
* Extracts variables for a given column from a data element
* so that they may be assigned to template before rendering.
* @param $row GridRow
* @param $column GridColumn
* @return array
*/
function getTemplateVarsFromRowColumn($row, $column) {
$userGroup = $row->getData(); /* @var $userGroup UserGroup */
$columnId = $column->getId();
$workflowStages = Application::getApplicationStages();
$roleDao = DAORegistry::getDAO('RoleDAO'); /* @var $roleDao RoleDAO */
$userGroupDao = DAORegistry::getDAO('UserGroupDAO'); /* @var $userGroupDao UserGroupDAO */
$assignedStages = $userGroupDao->getAssignedStagesByUserGroupId($userGroup->getContextId(), $userGroup->getId());

switch ($columnId) {
case 'name':
return array('label' => $userGroup->getLocalizedName());
case 'abbrev':
return array('label' => $userGroup->getLocalizedAbbrev());
case in_array($columnId, $workflowStages):
// Set the state of the select element that will
// be used to assign the stage to the user group.
$selectDisabled = false;
if (in_array($columnId, $roleDao->getForbiddenStages($userGroup->getRoleId()))) {
// This stage should not be assigned to the user group.
$selectDisabled = true;
}

return array('selected' => in_array($columnId, array_keys($assignedStages)),
'disabled' => $selectDisabled);
default:
break;
}

return parent::getTemplateVarsFromRowColumn($row, $column);
}

/**
* @copydoc GridCellProvider::getCellActions()
*/
function getCellActions($request, $row, $column, $position = GRID_ACTION_POSITION_DEFAULT) {
$workflowStages = Application::getApplicationStages();
$columnId = $column->getId();

if (in_array($columnId, $workflowStages)) {
$userGroup = $row->getData(); /* @var $userGroup UserGroup */
$userGroupDao = DAORegistry::getDAO('UserGroupDAO'); /* @var $userGroupDao UserGroupDAO */
$assignedStages = $userGroupDao->getAssignedStagesByUserGroupId($userGroup->getContextId(), $userGroup->getId());

$router = $request->getRouter();
$roleDao = DAORegistry::getDAO('RoleDAO'); /* @var $roleDao RoleDAO */

if (!in_array($columnId, $roleDao->getForbiddenStages($userGroup->getRoleId()))) {
if (in_array($columnId, array_keys($assignedStages))) {
$operation = 'unassignStage';
$actionTitleKey = 'grid.userGroup.unassignStage';
} else {
$operation = 'assignStage';
$actionTitleKey = 'grid.userGroup.assignStage';
}
$actionArgs = array_merge(array('stageId' => $columnId),
$row->getRequestArgs());

$actionUrl = $router->url($request, null, null, $operation, null, $actionArgs);
import('lib.pkp.classes.linkAction.request.AjaxAction');
$actionRequest = new AjaxAction($actionUrl);

$linkAction = new LinkAction(
$operation,
$actionRequest,
__($actionTitleKey),
null
);

return array($linkAction);
}
}

return parent::getCellActions($request, $row, $column, $position);
}
}

?>

0 comments on commit 9495c3a

Please sign in to comment.