Commit 553819a2f8a4cee6fe8190d31b531249add49d11

Authored by Neil Blakey-Milner
1 parent b5b04772

Implement the document workflow screen within the actions framework.


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@4073 c91229c3-7414-0410-bfa2-8a42b809f60b
plugins/ktcore/KTDocumentActions.php
... ... @@ -414,10 +414,63 @@ class KTDocumentPermissionsAction extends KTBuiltInDocumentAction {
414 414 }
415 415 $oKTActionRegistry->registerAction('documentaction', 'KTDocumentPermissionsAction', 'ktcore.actions.document.permissions');
416 416  
417   -class KTDocumentWorkflowAction extends KTBuiltInDocumentAction {
  417 +class KTDocumentWorkflowAction extends KTDocumentAction {
418 418 var $sBuiltInAction = 'documentWorkflow';
419 419 var $sDisplayName = 'Workflow';
420 420 var $sName = 'ktcore.actions.document.workflow';
  421 + var $_sShowPermission = "ktcore.permissions.write";
  422 +
  423 + function do_main() {
  424 + $this->oPage->setBreadcrumbDetails("workflow");
  425 + $oTemplate =& $this->oValidator->validateTemplate("ktcore/workflow/documentWorkflow");
  426 + $oDocument =& $this->oValidator->validateDocument($_REQUEST['fDocumentId']);
  427 +
  428 + $oWorkflow = KTWorkflowUtil::getWorkflowForDocument($oDocument);
  429 + $oWorkflowState = KTWorkflowUtil::getWorkflowStateForDocument($oDocument);
  430 +
  431 + $oUser =& User::get($_SESSION['userID']);
  432 + $aTransitions = KTWorkflowUtil::getTransitionsForDocumentUser($oDocument, $oUser);
  433 + $aWorkflows = KTWorkflow::getList();
  434 +
  435 + $fieldErrors = null;
  436 +
  437 + $aVocab = array();
  438 + foreach ($aTransitions as $oTransition) {
  439 + $aVocab[$oTransition->getId()] = $oTransition->showDescription();
  440 + }
  441 + $fieldOptions = array("vocab" => $aVocab);
  442 + $transition_fields = array();
  443 + $transition_fields[] = new KTLookupWidget('Transition to perform', 'FIXME', 'fTransitionId', null, $this->oPage, true, null, $fieldErrors, $fieldOptions);
  444 + $transition_fields[] = new KTStringWidget('Reason for transition', 'Describe the changes made to the document.', 'fComments', "", $this->oPage, true);
  445 + $aTemplateData = array(
  446 + 'oDocument' => $oDocument,
  447 + 'oWorkflow' => $oWorkflow,
  448 + 'oState' => $oWorkflowState,
  449 + 'aTransitions' => $aTransitions,
  450 + 'aWorkflows' => $aWorkflows,
  451 + 'transition_fields' => $transition_fields,
  452 + );
  453 + return $oTemplate->render($aTemplateData);
  454 + }
  455 +
  456 + function do_startWorkflow() {
  457 + $oDocument =& $this->oValidator->validateDocument($_REQUEST['fDocumentId']);
  458 + $oWorkflow =& $this->oValidator->validateWorkflow($_REQUEST['fWorkflowId']);
  459 + $res = KTWorkflowUtil::startWorkflowOnDocument($oWorkflow, $oDocument);
  460 + $this->successRedirectToMain('Workflow started',
  461 + array('fDocumentId' => $oDocument->getId()));
  462 + exit(0);
  463 + }
  464 +
  465 + function do_performTransition() {
  466 + $oDocument =& $this->oValidator->validateDocument($_REQUEST['fDocumentId']);
  467 + $oTransition =& $this->oValidator->validateWorkflowTransition($_REQUEST['fTransitionId']);
  468 + $sComments =& $this->oValidator->notEmpty($_REQUEST['fComments']);
  469 + $oUser =& User::get($_SESSION['userID']);
  470 + $res = KTWorkflowUtil::performTransitionOnDocument($oTransition, $oDocument, $oUser, $sComments);
  471 + $this->successRedirectToMain('Transition performed',
  472 + array('fDocumentId' => $oDocument->getId()));
  473 + }
421 474 }
422 475 $oKTActionRegistry->registerAction('documentaction', 'KTDocumentWorkflowAction', 'ktcore.actions.document.workflow');
423 476  
... ...