Commit f616258615c2e7b1a509ecbd1b4944a1af97c9c3
1 parent
2d9381fb
Workflow administration page
git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@3720 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
1 changed file
with
226 additions
and
0 deletions
presentation/lookAndFeel/knowledgeTree/administration/workflow/workflows.php
0 → 100644
| 1 | +<?php | |
| 2 | + | |
| 3 | +require_once('../../../../../config/dmsDefaults.php'); | |
| 4 | +require_once(KT_LIB_DIR . '/dispatcher.inc.php'); | |
| 5 | +require_once(KT_LIB_DIR . '/validation/dispatchervalidation.inc.php'); | |
| 6 | +require_once(KT_LIB_DIR . '/templating/templating.inc.php'); | |
| 7 | + | |
| 8 | +require_once(KT_LIB_DIR . '/workflow/workflow.inc.php'); | |
| 9 | +require_once(KT_LIB_DIR . '/workflow/workflowstate.inc.php'); | |
| 10 | +require_once(KT_LIB_DIR . '/workflow/workflowtransition.inc.php'); | |
| 11 | + | |
| 12 | +$sectionName = "Administration"; | |
| 13 | +require_once(KT_DIR . "/presentation/webpageTemplate.inc"); | |
| 14 | + | |
| 15 | +class KTWorkflowDispatcher extends KTStandardDispatcher { | |
| 16 | + var $bAutomaticTransaction = true; | |
| 17 | + | |
| 18 | + // {{{ WORKFLOW HANDLING | |
| 19 | + // {{{ do_main | |
| 20 | + function do_main () { | |
| 21 | + $oTemplating =& KTTemplating::getSingleton(); | |
| 22 | + $oTemplate =& $oTemplating->loadTemplate('ktcore/workflow/listWorkflows'); | |
| 23 | + $oTemplate->setData(array( | |
| 24 | + 'aWorkflow' => KTWorkflow::getList(), | |
| 25 | + )); | |
| 26 | + return $oTemplate; | |
| 27 | + } | |
| 28 | + // }}} | |
| 29 | + | |
| 30 | + // {{{ do_editWorkflow | |
| 31 | + function do_editWorkflow() { | |
| 32 | + // $oTemplating =& KTTemplating::getSingleton(); | |
| 33 | + // $oTemplate =& $oTemplating->loadTemplate('ktcore/workflow/editWorkflow'); | |
| 34 | + $oTemplate =& KTDispatcherValidation::validateTemplate($this, 'ktcore/workflow/editWorkflow'); | |
| 35 | + $oWorkflow =& KTDispatcherValidation::validateWorkflow($this, $_REQUEST['fWorkflowId']); | |
| 36 | + $oTemplate->setData(array( | |
| 37 | + 'oWorkflow' => $oWorkflow, | |
| 38 | + 'aStates' => KTWorkflowState::getByWorkflow($oWorkflow), | |
| 39 | + 'aTransitions' => KTWorkflowTransition::getByWorkflow($oWorkflow), | |
| 40 | + 'aPermissions' => KTPermission::getList(), | |
| 41 | + )); | |
| 42 | + return $oTemplate; | |
| 43 | + } | |
| 44 | + // }}} | |
| 45 | + | |
| 46 | + // {{{ do_saveWorkflow | |
| 47 | + function do_saveWorkflow() { | |
| 48 | + $oWorkflow =& KTDispatcherValidation::validateWorkflow($this, $_REQUEST['fWorkflowId']); | |
| 49 | + $oWorkflow->setName($_REQUEST['fName']); | |
| 50 | + $oWorkflow->setHumanName($_REQUEST['fName']); | |
| 51 | + $res = $oWorkflow->update(); | |
| 52 | + KTDispatcherValidation::notErrorFalse($this, $res, array( | |
| 53 | + 'redirect_to' => array('editWorkflow', 'fWorkflowId=' . $oWorkflow->getId()), | |
| 54 | + 'message' => 'Error saving workflow', | |
| 55 | + )); | |
| 56 | + $this->successRedirectTo('editWorkflow', 'Changes saved', 'fWorkflowId=' . $oWorkflow->getId()); | |
| 57 | + exit(0); | |
| 58 | + } | |
| 59 | + // }}} | |
| 60 | + | |
| 61 | + // {{{ do_newWorkflow | |
| 62 | + function do_newWorkflow() { | |
| 63 | + $res = KTWorkflow::createFromArray(array( | |
| 64 | + 'name' => $_REQUEST['fName'], | |
| 65 | + 'humanname' => $_REQUEST['fName'], | |
| 66 | + )); | |
| 67 | + KTDispatcherValidation::notError($this, $res, array( | |
| 68 | + 'redirect_to' => array('main'), | |
| 69 | + 'message' => 'Could not create workflow', | |
| 70 | + )); | |
| 71 | + $this->successRedirectTo('editWorkflow', 'Workflow created', 'fWorkflowId=' . $res->getId()); | |
| 72 | + exit(0); | |
| 73 | + } | |
| 74 | + // }}} | |
| 75 | + | |
| 76 | + // }}} | |
| 77 | + | |
| 78 | + // {{{ STATE HANDLING | |
| 79 | + // | |
| 80 | + // {{{ do_newState | |
| 81 | + function do_newState() { | |
| 82 | + $oWorkflow =& KTDispatcherValidation::validateWorkflow($this, $_REQUEST['fWorkflowId']); | |
| 83 | + $oState = KTWorkflowState::createFromArray(array( | |
| 84 | + 'workflowid' => $oWorkflow->getId(), | |
| 85 | + 'name' => $_REQUEST['fName'], | |
| 86 | + 'humanname' => $_REQUEST['fName'], | |
| 87 | + )); | |
| 88 | + KTDispatcherValidation::notError($this, $oState, array( | |
| 89 | + 'redirect_to' => array('editWorkflow', 'fWorkflowId=' . $oWorkflow->getId()), | |
| 90 | + 'message' => 'Could not create workflow state', | |
| 91 | + )); | |
| 92 | + $this->successRedirectTo('editState', 'Workflow state created', 'fWorkflowId=' . $oWorkflow->getId() . '&fStateId=' . $oState->getId()); | |
| 93 | + exit(0); | |
| 94 | + } | |
| 95 | + // }}} | |
| 96 | + | |
| 97 | + // {{{ do_editState | |
| 98 | + function do_editState() { | |
| 99 | + $oTemplate =& KTDispatcherValidation::validateTemplate($this, 'ktcore/workflow/editState'); | |
| 100 | + $oWorkflow =& KTDispatcherValidation::validateWorkflow($this, $_REQUEST['fWorkflowId']); | |
| 101 | + $oState =& KTDispatcherValidation::validateWorkflowState($this, $_REQUEST['fStateId']); | |
| 102 | + $aTransitionsTo =& KTWorkflowTransition::getByTargetState($oState); | |
| 103 | + $aTransitionIdsTo = array(); | |
| 104 | + foreach ($aTransitionsTo as $oTransition) { | |
| 105 | + $aTransitionIdsTo[] = $oTransition->getId(); | |
| 106 | + } | |
| 107 | + $aAllTransitions =& KTWorkflowTransition::getByWorkflow($oWorkflow); | |
| 108 | + $aTransitions = array(); | |
| 109 | + foreach ($aAllTransitions as $oTransition) { | |
| 110 | + if (!in_array($oTransition->getId(), $aTransitionIdsTo)) { | |
| 111 | + $aTransitions[] = $oTransition; | |
| 112 | + } | |
| 113 | + } | |
| 114 | + $aTransitionsSelected = KTWorkflowUtil::getTransitionsFrom($oState, array('ids' => true)); | |
| 115 | + $oTemplate->setData(array( | |
| 116 | + 'oWorkflow' => $oWorkflow, | |
| 117 | + 'oState' => $oState, | |
| 118 | + 'aTransitionsTo' => $aTransitionsTo, | |
| 119 | + 'aTransitions' => $aTransitions, | |
| 120 | + 'aTransitionsSelected' => $aTransitionsSelected, | |
| 121 | + )); | |
| 122 | + return $oTemplate; | |
| 123 | + } | |
| 124 | + // }}} | |
| 125 | + | |
| 126 | + // {{{ do_saveState | |
| 127 | + function do_saveState() { | |
| 128 | + $oWorkflow =& KTDispatcherValidation::validateWorkflow($this, $_REQUEST['fWorkflowId']); | |
| 129 | + $oState =& KTDispatcherValidation::validateWorkflowState($this, $_REQUEST['fStateId']); | |
| 130 | + $oState->setName($_REQUEST['fName']); | |
| 131 | + $oState->setHumanName($_REQUEST['fName']); | |
| 132 | + $res = $oState->update(); | |
| 133 | + KTDispatcherValidation::notErrorFalse($this, $res, array( | |
| 134 | + 'redirect_to' => array('editState', 'fWorkflowId=' . $oWorkflow->getId() . '&fStateId=' . $oState->getId()), | |
| 135 | + 'message' => 'Error saving state', | |
| 136 | + )); | |
| 137 | + $this->successRedirectTo('editState', 'Changes saved', 'fWorkflowId=' . $oWorkflow->getId() . '&fStateId=' . $oState->getId()); | |
| 138 | + exit(0); | |
| 139 | + } | |
| 140 | + // }}} | |
| 141 | + | |
| 142 | + // {{{ do_saveTransitions | |
| 143 | + function do_saveTransitions() { | |
| 144 | + $oWorkflow =& KTDispatcherValidation::validateWorkflow($this, $_REQUEST['fWorkflowId']); | |
| 145 | + $oState =& KTDispatcherValidation::validateWorkflowState($this, $_REQUEST['fStateId']); | |
| 146 | + $res = KTWorkflowUtil::saveTransitionsFrom($oState, $_REQUEST['fTransitionIds']); | |
| 147 | + KTDispatcherValidation::notErrorFalse($this, $res, array( | |
| 148 | + 'redirect_to' => array('editState', 'fWorkflowId=' . $oWorkflow->getId() . '&fStateId=' . $oState->getId()), | |
| 149 | + 'message' => 'Error saving transitions', | |
| 150 | + )); | |
| 151 | + $this->successRedirectTo('editState', 'Changes saved', 'fWorkflowId=' . $oWorkflow->getId() . '&fStateId=' . $oState->getId()); | |
| 152 | + exit(0); | |
| 153 | + } | |
| 154 | + // }}} | |
| 155 | + | |
| 156 | + // }}} | |
| 157 | + | |
| 158 | + // {{{ TRANSITION HANDLING | |
| 159 | + // | |
| 160 | + // {{{ do_newTransition | |
| 161 | + function do_newTransition() { | |
| 162 | + $oWorkflow =& KTDispatcherValidation::validateWorkflow($this, $_REQUEST['fWorkflowId']); | |
| 163 | + $oState =& KTDispatcherValidation::validateWorkflowState($this, $_REQUEST['fTargetStateId']); | |
| 164 | + $oPermission =& KTDispatcherValidation::validatePermission($this, $_REQUEST['fPermissionId']); | |
| 165 | + $res = KTWorkflowTransition::createFromArray(array( | |
| 166 | + 'workflowid' => $oWorkflow->getId(), | |
| 167 | + 'name' => $_REQUEST['fName'], | |
| 168 | + 'humanname' => $_REQUEST['fName'], | |
| 169 | + 'targetstateid' => $oState->getId(), | |
| 170 | + 'guardpermissionid' => $oPermission->getId(), | |
| 171 | + )); | |
| 172 | + KTDispatcherValidation::notError($this, $res, array( | |
| 173 | + 'redirect_to' => array('editWorkflow', 'fWorkflowId=' . $oWorkflow->getId()), | |
| 174 | + 'message' => 'Could not create workflow transition', | |
| 175 | + )); | |
| 176 | + $this->successRedirectTo('editWorkflow', 'Workflow transition created', 'fWorkflowId=' . $oWorkflow->getId()); | |
| 177 | + exit(0); | |
| 178 | + } | |
| 179 | + // }}} | |
| 180 | + | |
| 181 | + // {{{ do_editTransition | |
| 182 | + function do_editTransition() { | |
| 183 | + $oTemplate =& KTDispatcherValidation::validateTemplate($this, 'ktcore/workflow/editTransition'); | |
| 184 | + $oWorkflow =& KTDispatcherValidation::validateWorkflow($this, $_REQUEST['fWorkflowId']); | |
| 185 | + $oTransition =& KTDispatcherValidation::validateWorkflowTransition($this, $_REQUEST['fTransitionId']); | |
| 186 | + $oTemplate->setData(array( | |
| 187 | + 'oWorkflow' => $oWorkflow, | |
| 188 | + 'oTransition' => $oTransition, | |
| 189 | + 'aStates' => KTWorkflowState::getByWorkflow($oWorkflow), | |
| 190 | + 'aPermissions' => KTPermission::getList(), | |
| 191 | + )); | |
| 192 | + return $oTemplate; | |
| 193 | + } | |
| 194 | + // }}} | |
| 195 | + | |
| 196 | + // {{{ do_saveTransition | |
| 197 | + function do_saveTransition() { | |
| 198 | + $oWorkflow =& KTDispatcherValidation::validateWorkflow($this, $_REQUEST['fWorkflowId']); | |
| 199 | + $oTransition =& KTDispatcherValidation::validateWorkflowTransition($this, $_REQUEST['fTransitionId']); | |
| 200 | + $oState =& KTDispatcherValidation::validateWorkflowState($this, $_REQUEST['fTargetStateId']); | |
| 201 | + $oPermission =& KTDispatcherValidation::validatePermission($this, $_REQUEST['fPermissionId']); | |
| 202 | + $oTransition->updateFromArray(array( | |
| 203 | + 'workflowid' => $oWorkflow->getId(), | |
| 204 | + 'name' => $_REQUEST['fName'], | |
| 205 | + 'humanname' => $_REQUEST['fName'], | |
| 206 | + 'targetstateid' => $oState->getId(), | |
| 207 | + 'guardpermissionid' => $oPermission->getId(), | |
| 208 | + )); | |
| 209 | + $res = $oTransition->update(); | |
| 210 | + KTDispatcherValidation::notErrorFalse($this, $res, array( | |
| 211 | + 'redirect_to' => array('editTransition', 'fWorkflowId=' . $oWorkflow->getId() . '&fTransitionId=' . $oTransition->getId()), | |
| 212 | + 'message' => 'Error saving transition', | |
| 213 | + )); | |
| 214 | + $this->successRedirectTo('editTransition', 'Changes saved', 'fWorkflowId=' . $oWorkflow->getId() . '&fTransitionId=' . $oTransition->getId()); | |
| 215 | + exit(0); | |
| 216 | + } | |
| 217 | + // }}} | |
| 218 | + | |
| 219 | + // }}} | |
| 220 | + | |
| 221 | +} | |
| 222 | + | |
| 223 | +$d =& new KTWorkflowDispatcher; | |
| 224 | +$d->dispatch(); | |
| 225 | + | |
| 226 | +?> | ... | ... |