Commit 4c8a12648ca3759fd4e280ecdc6ad0584a859d73
1 parent
4ae5efd4
Implement getTransitionsForDocumentUser in terms of guard permissions.
Implement performTransitionOnDocument, which performs the transition, and which will later perform associated actions (such as adding something into the document transactions). git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@3832 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
1 changed file
with
28 additions
and
1 deletions
lib/workflow/workflowutil.inc.php
| ... | ... | @@ -201,7 +201,34 @@ class KTWorkflowUtil { |
| 201 | 201 | if (is_null($oState) || PEAR::isError($oState)) { |
| 202 | 202 | return $oState; |
| 203 | 203 | } |
| 204 | - return KTWorkflowUtil::getTransitionsFrom($oState); | |
| 204 | + $aTransitions = KTWorkflowUtil::getTransitionsFrom($oState); | |
| 205 | + $aEnabledTransitions = array(); | |
| 206 | + foreach ($aTransitions as $oTransition) { | |
| 207 | + $oPermission =& KTPermission::get($oTransition->getGuardPermissionId()); | |
| 208 | + if (!KTPermissionUtil::userHasPermissionOnItem($oUser, $oPermission, $oDocument)) { | |
| 209 | + continue; | |
| 210 | + } | |
| 211 | + $aEnabledTransitions[] = $oTransition; | |
| 212 | + } | |
| 213 | + return $aEnabledTransitions; | |
| 214 | + } | |
| 215 | + | |
| 216 | + function performTransitionOnDocument($oTransition, $oDocument, $oUser, $sComments) { | |
| 217 | + $oWorkflow =& KTWorkflow::getByDocument($oDocument); | |
| 218 | + if (empty($oWorkflow)) { | |
| 219 | + return PEAR::raiseError("Document has no workflow"); | |
| 220 | + } | |
| 221 | + if (PEAR::isError($oWorkflow)) { | |
| 222 | + return $oWorkflow; | |
| 223 | + } | |
| 224 | + $sTable = KTUtil::getTableName('workflow_documents'); | |
| 225 | + $iStateId = $oTransition->getTargetStateId(); | |
| 226 | + $iDocumentId = $oDocument->getId(); | |
| 227 | + $aQuery = array( | |
| 228 | + "UPDATE $sTable SET state_id = ? WHERE document_id = ?", | |
| 229 | + array($iStateId, $iDocumentId), | |
| 230 | + ); | |
| 231 | + return DBUtil::runQuery($aQuery); | |
| 205 | 232 | } |
| 206 | 233 | } |
| 207 | 234 | ... | ... |