Commit 116bce9152e2ec3e54974eb36e24ebaf49647a86
1 parent
b784f8bf
Add getWorkflowForDocument and getWorkflowStateForDocument, which do
what they say they do. Add getTransitionsForDocumentUser stub, which should eventually list the transitions available for a document (taking its current state into account) for a specific user (taking groups/roles into account). git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@3823 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
1 changed file
with
51 additions
and
1 deletions
lib/workflow/workflowutil.inc.php
| @@ -28,7 +28,7 @@ class KTWorkflowUtil { | @@ -28,7 +28,7 @@ class KTWorkflowUtil { | ||
| 28 | return; | 28 | return; |
| 29 | } | 29 | } |
| 30 | 30 | ||
| 31 | - function getTransitionsFrom($oState, $aOptions) { | 31 | + function getTransitionsFrom($oState, $aOptions = null) { |
| 32 | $bIds = KTUtil::arrayGet($aOptions, 'ids'); | 32 | $bIds = KTUtil::arrayGet($aOptions, 'ids'); |
| 33 | $sTable = KTUtil::getTableName('workflow_state_transitions'); | 33 | $sTable = KTUtil::getTableName('workflow_state_transitions'); |
| 34 | $aQuery = array( | 34 | $aQuery = array( |
| @@ -153,5 +153,55 @@ class KTWorkflowUtil { | @@ -153,5 +153,55 @@ class KTWorkflowUtil { | ||
| 153 | } | 153 | } |
| 154 | return true; | 154 | return true; |
| 155 | } | 155 | } |
| 156 | + | ||
| 157 | + function getWorkflowForDocument ($oDocument, $aOptions = null) { | ||
| 158 | + $ids = KTUtil::arrayGet($aOptions, 'ids', false); | ||
| 159 | + $iDocumentId = KTUtil::getId($oDocument); | ||
| 160 | + $sTable = KTUtil::getTableName('workflow_documents'); | ||
| 161 | + $aQuery = array( | ||
| 162 | + "SELECT workflow_id FROM $sTable WHERE document_id = ?", | ||
| 163 | + array($iDocumentId), | ||
| 164 | + ); | ||
| 165 | + $iWorkflowId = DBUtil::getOneResultKey($aQuery, 'workflow_id'); | ||
| 166 | + if (is_null($iWorkflowId)) { | ||
| 167 | + return $iWorkflowId; | ||
| 168 | + } | ||
| 169 | + if (PEAR::isError($iWorkflowId)) { | ||
| 170 | + return $iWorkflowId; | ||
| 171 | + } | ||
| 172 | + if ($ids) { | ||
| 173 | + return $iWorkflowId; | ||
| 174 | + } | ||
| 175 | + return KTWorkflow::get($iWorkflowId); | ||
| 176 | + } | ||
| 177 | + | ||
| 178 | + function getWorkflowStateForDocument ($oDocument, $aOptions = null) { | ||
| 179 | + $ids = KTUtil::arrayGet($aOptions, 'ids', false); | ||
| 180 | + $iDocumentId = KTUtil::getId($oDocument); | ||
| 181 | + $sTable = KTUtil::getTableName('workflow_documents'); | ||
| 182 | + $aQuery = array( | ||
| 183 | + "SELECT state_id FROM $sTable WHERE document_id = ?", | ||
| 184 | + array($iDocumentId), | ||
| 185 | + ); | ||
| 186 | + $iWorkflowStateId = DBUtil::getOneResultKey($aQuery, 'state_id'); | ||
| 187 | + if (is_null($iWorkflowStateId)) { | ||
| 188 | + return $iWorkflowStateId; | ||
| 189 | + } | ||
| 190 | + if (PEAR::isError($iWorkflowStateId)) { | ||
| 191 | + return $iWorkflowStateId; | ||
| 192 | + } | ||
| 193 | + if ($ids) { | ||
| 194 | + return $iWorkflowStateId; | ||
| 195 | + } | ||
| 196 | + return KTWorkflowState::get($iWorkflowStateId); | ||
| 197 | + } | ||
| 198 | + | ||
| 199 | + function getTransitionsForDocumentUser($oDocument, $oUser) { | ||
| 200 | + $oState = KTWorkflowUtil::getWorkflowStateForDocument($oDocument); | ||
| 201 | + if (is_null($oState) || PEAR::isError($oState)) { | ||
| 202 | + return $oState; | ||
| 203 | + } | ||
| 204 | + return KTWorkflowUtil::getTransitionsFrom($oState); | ||
| 205 | + } | ||
| 156 | } | 206 | } |
| 157 | 207 |