Open Journal Systems  3.3.0
QueriesAccessHelper.inc.php
1 <?php
2 
29 
31  var $_user;
32 
38  function __construct($authorizedContext, $user) {
39  $this->_authorizedContext = $authorizedContext;
40  $this->_user = $user;
41  }
42 
48  function getAuthorizedContextObject($assocType) {
49  return isset($this->_authorizedContext[$assocType])?$this->_authorizedContext[$assocType]:null;
50  }
51 
57  function getCanOpenClose($query) {
58  // Managers and sub editors are always allowed
59  if ($this->hasStageRole($query->getStageId(), array(ROLE_ID_MANAGER, ROLE_ID_SUB_EDITOR))) return true;
60 
61  // Assigned assistants are allowed
62  if ($this->hasStageRole($query->getStageId(), array(ROLE_ID_ASSISTANT)) && $this->isAssigned($this->_user->getId(), $query->getId())) return true;
63 
64  // Otherwise, not allowed.
65  return false;
66  }
67 
73  function getCanOrder($stageId) {
74  return $this->hasStageRole($stageId, array(ROLE_ID_MANAGER, ROLE_ID_SUB_EDITOR));
75  }
76 
82  function getCanCreate($stageId) {
83  return $this->hasStageRole($stageId, array(ROLE_ID_MANAGER, ROLE_ID_SUB_EDITOR, ROLE_ID_ASSISTANT, ROLE_ID_AUTHOR, ROLE_ID_REVIEWER));
84  }
85 
91  function getCanEdit($queryId) {
92  $queryDao = DAORegistry::getDAO('QueryDAO'); /* @var $queryDao QueryDAO */
93  $query = $queryDao->getById($queryId);
94  if (!$query) return false;
95 
96  // Assistants, authors and reviewers are allowed, if they created the query
97  if ($this->hasStageRole($query->getStageId(), array(ROLE_ID_ASSISTANT, ROLE_ID_AUTHOR, ROLE_ID_REVIEWER))) {
98  if ($query->getHeadNote()->getUserId() == $this->_user->getId()) return true;
99  }
100 
101  // Managers are always allowed
102  if ($this->hasStageRole($query->getStageId(), array(ROLE_ID_MANAGER, ROLE_ID_SUB_EDITOR))) return true;
103 
104  // Otherwise, not allowed.
105  return false;
106  }
107 
113  function getCanDelete($queryId) {
114  // Users can always delete their own placeholder queries.
115  $queryDao = DAORegistry::getDAO('QueryDAO'); /* @var $queryDao QueryDAO */
116  $query = $queryDao->getById($queryId);
117  if ($query) {
118  $headNote = $query->getHeadNote();
119  if ($headNote->getUserId() == $this->_user->getId() && $headNote->getTitle()=='') return true;
120  }
121 
122  // Managers are always allowed
123  if ($this->hasStageRole($query->getStageId(), array(ROLE_ID_MANAGER))) return true;
124 
125  // Otherwise, not allowed.
126  return false;
127  }
128 
129 
135  function getCanListAll($stageId) {
136  return $this->hasStageRole($stageId, array(ROLE_ID_MANAGER));
137  }
138 
145  protected function isAssigned($userId, $queryId) {
146  $queryDao = DAORegistry::getDAO('QueryDAO'); /* @var $queryDao QueryDAO */
147  return (boolean) $queryDao->getParticipantIds($queryId, $userId);
148  }
149 
157  protected function hasStageRole($stageId, $roles) {
158  $stageRoles = $this->getAuthorizedContextObject(ASSOC_TYPE_ACCESSIBLE_WORKFLOW_STAGES);
159  return !empty(array_intersect($stageRoles[$stageId], $roles));
160  }
161 }
162 
163 
QueriesAccessHelper\getCanOpenClose
getCanOpenClose($query)
Definition: QueriesAccessHelper.inc.php:63
QueriesAccessHelper\isAssigned
isAssigned($userId, $queryId)
Definition: QueriesAccessHelper.inc.php:151
QueriesAccessHelper\getCanOrder
getCanOrder($stageId)
Definition: QueriesAccessHelper.inc.php:79
DAORegistry\getDAO
static & getDAO($name, $dbconn=null)
Definition: DAORegistry.inc.php:57
QueriesAccessHelper\getCanEdit
getCanEdit($queryId)
Definition: QueriesAccessHelper.inc.php:97
QueriesAccessHelper
Implements access rules for queries. Permissions are intended as follows (per UI/UX group,...
Definition: QueriesAccessHelper.inc.php:26
QueriesAccessHelper\getCanDelete
getCanDelete($queryId)
Definition: QueriesAccessHelper.inc.php:119
QueriesAccessHelper\getCanListAll
getCanListAll($stageId)
Definition: QueriesAccessHelper.inc.php:141
QueriesAccessHelper\$_authorizedContext
$_authorizedContext
Definition: QueriesAccessHelper.inc.php:31
QueriesAccessHelper\getAuthorizedContextObject
getAuthorizedContextObject($assocType)
Definition: QueriesAccessHelper.inc.php:54
QueriesAccessHelper\hasStageRole
hasStageRole($stageId, $roles)
Definition: QueriesAccessHelper.inc.php:163
QueriesAccessHelper\$_user
$_user
Definition: QueriesAccessHelper.inc.php:37
QueriesAccessHelper\getCanCreate
getCanCreate($stageId)
Definition: QueriesAccessHelper.inc.php:88
QueriesAccessHelper\__construct
__construct($authorizedContext, $user)
Definition: QueriesAccessHelper.inc.php:44