Open Journal Systems  3.3.0
WorkflowStageDAO.inc.php
1 <?php
2 
17 class WorkflowStageDAO extends DAO {
18 
24  static function getPathFromId($stageId) {
25  static $stageMapping = array(
26  WORKFLOW_STAGE_ID_SUBMISSION => WORKFLOW_STAGE_PATH_SUBMISSION,
27  WORKFLOW_STAGE_ID_INTERNAL_REVIEW => WORKFLOW_STAGE_PATH_INTERNAL_REVIEW,
28  WORKFLOW_STAGE_ID_EXTERNAL_REVIEW => WORKFLOW_STAGE_PATH_EXTERNAL_REVIEW,
29  WORKFLOW_STAGE_ID_EDITING => WORKFLOW_STAGE_PATH_EDITING,
30  WORKFLOW_STAGE_ID_PRODUCTION => WORKFLOW_STAGE_PATH_PRODUCTION
31  );
32  if (isset($stageMapping[$stageId])) {
33  return $stageMapping[$stageId];
34  }
35  return null;
36  }
37 
43  static function getIdFromPath($stagePath) {
44  static $stageMapping = array(
45  WORKFLOW_STAGE_PATH_SUBMISSION => WORKFLOW_STAGE_ID_SUBMISSION,
46  WORKFLOW_STAGE_PATH_INTERNAL_REVIEW => WORKFLOW_STAGE_ID_INTERNAL_REVIEW,
47  WORKFLOW_STAGE_PATH_EXTERNAL_REVIEW => WORKFLOW_STAGE_ID_EXTERNAL_REVIEW,
48  WORKFLOW_STAGE_PATH_EDITING => WORKFLOW_STAGE_ID_EDITING,
49  WORKFLOW_STAGE_PATH_PRODUCTION => WORKFLOW_STAGE_ID_PRODUCTION
50  );
51  if (isset($stageMapping[$stagePath])) {
52  return $stageMapping[$stagePath];
53  }
54  return null;
55  }
56 
62  static function getTranslationKeyFromId($stageId) {
63  $stageMapping = self::getWorkflowStageTranslationKeys();
64 
65  assert(isset($stageMapping[$stageId]));
66  return $stageMapping[$stageId];
67  }
68 
73  static function getWorkflowStageTranslationKeys() {
74  $applicationStages = Application::get()->getApplicationStages();
75  AppLocale::requireComponents(LOCALE_COMPONENT_PKP_SUBMISSION, LOCALE_COMPONENT_APP_SUBMISSION);
76  static $stageMapping = array(
77  WORKFLOW_STAGE_ID_SUBMISSION => 'submission.submission',
78  WORKFLOW_STAGE_ID_INTERNAL_REVIEW => 'workflow.review.internalReview',
79  WORKFLOW_STAGE_ID_EXTERNAL_REVIEW => 'workflow.review.externalReview',
80  WORKFLOW_STAGE_ID_EDITING => 'submission.editorial',
81  WORKFLOW_STAGE_ID_PRODUCTION => 'submission.production'
82  );
83 
84  return array_intersect_key($stageMapping, array_flip($applicationStages));
85  }
86 
92  static function getWorkflowStageKeysAndPaths() {
93  $workflowStages = self::getWorkflowStageTranslationKeys();
94  $stageMapping = array();
95  foreach ($workflowStages as $stageId => $translationKey) {
96  $stageMapping[$stageId] = array(
97  'id' => $stageId,
98  'translationKey' => $translationKey,
99  'path' => self::getPathFromId($stageId)
100  );
101  }
102 
103  return $stageMapping;
104  }
105 
114  static function getStageStatusesBySubmission($submission, $stagesWithDecisions, $stageNotifications) {
115 
116  $currentStageId = $submission->getStageId();
117  $workflowStages = self::getWorkflowStageKeysAndPaths();
118 
119  foreach ($workflowStages as $stageId => $stageData) {
120 
121  $foundState = false;
122  // If we have not found a state, and the current stage being examined is below the current submission stage, and there have been
123  // decisions for this stage, but no notifications outstanding, mark it as complete.
124  if (!$foundState && $stageId <= $currentStageId && (in_array($stageId, $stagesWithDecisions) || $stageId == WORKFLOW_STAGE_ID_PRODUCTION) && !$stageNotifications[$stageId]) {
125  $workflowStages[$currentStageId]['statusKey'] = 'submission.complete';
126  }
127 
128  // If this is an old stage with no notifications, this was a skiped/not initiated stage.
129  if (!$foundState && $stageId < $currentStageId && !$stageNotifications[$stageId]) {
130  $foundState = true;
131  // Those are stages not initiated, that were skipped, like review stages.
132  }
133 
134  // Finally, if this stage has outstanding notifications, or has no decision yet, mark it as initiated.
135  if (!$foundState && $stageId <= $currentStageId && ( !in_array($stageId, $stagesWithDecisions) || $stageNotifications[$stageId])) {
136  $workflowStages[$currentStageId]['statusKey'] = 'submission.initiated';
137  $foundState = true;
138  }
139  }
140 
141  return $workflowStages;
142 
143  }
144 }
145 
AppLocale\requireComponents
static requireComponents()
Definition: env1/MockAppLocale.inc.php:56
WorkflowStageDAO\getWorkflowStageTranslationKeys
static getWorkflowStageTranslationKeys()
Definition: WorkflowStageDAO.inc.php:73
WorkflowStageDAO
class for operations involving the workflow stages.
Definition: WorkflowStageDAO.inc.php:17
WorkflowStageDAO\getIdFromPath
static getIdFromPath($stagePath)
Definition: WorkflowStageDAO.inc.php:43
WorkflowStageDAO\getWorkflowStageKeysAndPaths
static getWorkflowStageKeysAndPaths()
Definition: WorkflowStageDAO.inc.php:92
WorkflowStageDAO\getPathFromId
static getPathFromId($stageId)
Definition: WorkflowStageDAO.inc.php:24
PKPApplication\get
static get()
Definition: PKPApplication.inc.php:235
WorkflowStageDAO\getTranslationKeyFromId
static getTranslationKeyFromId($stageId)
Definition: WorkflowStageDAO.inc.php:62
WorkflowStageDAO\getStageStatusesBySubmission
static getStageStatusesBySubmission($submission, $stagesWithDecisions, $stageNotifications)
Definition: WorkflowStageDAO.inc.php:114
DAO
Operations for retrieving and modifying objects from a database.
Definition: DAO.inc.php:31