Source of file WorkflowActionInstance.php
Size: 8,142 Bytes - Last Modified: 2021-12-23T10:27:27+00:00
/var/www/docs.ssmods.com/process/src/src/DataObjects/WorkflowActionInstance.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288 | <?php namespace Symbiote\AdvancedWorkflow\DataObjects; use SilverStripe\Control\HTTPRequest; use SilverStripe\Forms\Form; use SilverStripe\Forms\ReadonlyField; use SilverStripe\Forms\TextareaField; use SilverStripe\ORM\ArrayList; use SilverStripe\ORM\DataObject; use SilverStripe\ORM\FieldType\DBField; use SilverStripe\Security\Member; /** * A workflow action attached to a {@link WorkflowInstance} that has been run, * and is either currently running, or has finished. * * Each step of the workflow has one of these created for it - it refers back * to the original action definition, but is unique for each step of the * workflow to ensure re-entrant behaviour. * * @license BSD License (http://silverstripe.org/bsd-license/) * @package advancedworkflow */ class WorkflowActionInstance extends DataObject { private static $db = array( 'Comment' => 'Text', 'Finished' => 'Boolean' ); private static $has_one = array( 'Workflow' => WorkflowInstance::class, 'BaseAction' => WorkflowAction::class, 'Member' => Member::class, ); private static $summary_fields = array( 'BaseAction.Title', 'Comment', 'Created', 'Member.Name', ); private static $table_name = 'WorkflowActionInstance'; public function fieldLabels($includerelations = true) { $labels = parent::fieldLabels($includerelations); $labels['BaseAction.Title'] = _t('WorkflowActionInstance.Title', 'Title'); $labels['Comment'] = _t('WorkflowAction.CommentLabel', 'Comment'); $labels['Member.Name'] = _t('WorkflowAction.Author', 'Author'); $labels['Finished'] = _t('WorkflowAction.FinishedLabel', 'Finished'); $labels['BaseAction.Title'] = _t('WorkflowAction.TITLE', 'Title'); return $labels; } /** * Gets fields for when this is part of an active workflow */ public function updateWorkflowFields($fields) { $fieldDiff = $this->Workflow()->getTargetDiff(); foreach ($fieldDiff as $field) { $display = ReadonlyField::create( 'workflow-' . $field->Name, $field->Title, DBField::create_field('HTMLText', $field->Diff) ) ->addExtraClass('workflow-field-diff') ->setTemplate(__CLASS__ . '/ReadonlyField'); $fields->push($display); } if ($this->BaseAction()->AllowCommenting) { $fields->push(new TextareaField('Comment', _t('WorkflowAction.COMMENT', 'Comment'))); } } public function updateFrontendWorkflowFields($fields) { if ($this->BaseAction()->AllowCommenting) { $fields->push(new TextareaField( 'WorkflowActionInstanceComment', _t('WorkflowAction.FRONTENDCOMMENT', 'Comment') )); } $ba = $this->BaseAction(); $fields = $ba->updateFrontendWorkflowFields($fields, $this->Workflow()); } /** * Gets Front-End DataObject * * Use the DataObject as defined in the WorkflowAction, otherwise fall back to the * context object. * * Useful for situations where front end workflow deals with multiple data objects * * @return DataObject */ public function getFrontEndDataObject() { $obj = null; $ba = $this->BaseAction(); if ($ba->hasMethod('getFrontEndDataObject')) { $obj = $ba->getFrontEndDataObject(); } else { $obj = $this->Workflow()->getTarget(); } return $obj; } public function updateFrontEndWorkflowActions($actions) { $ba = $this->BaseAction(); if ($ba->hasMethod('updateFrontEndWorkflowActions')) { $ba->updateFrontEndWorkflowActions($actions); } } public function getRequiredFields() { $validator = null; $ba = $this->BaseAction(); if ($ba->hasMethod('getRequiredFields')) { $validator = $ba->getRequiredFields(); } return $validator; } public function setFrontendFormRequirements() { $ba = $this->BaseAction(); if ($ba->hasMethod('setFrontendFormRequirements')) { $ba->setFrontendFormRequirements(); } } public function doFrontEndAction(array $data, Form $form, HTTPRequest $request) { //Save Front End Workflow notes, then hand over to Workflow Action if (isset($data["WorkflowActionInstanceComment"])) { $this->Comment = $data["WorkflowActionInstanceComment"]; $this->write(); } $ba = $this->BaseAction(); if ($ba->hasMethod('doFrontEndAction')) { $ba->doFrontEndAction($data, $form, $request); } } /** * Gets the title of this active action instance * * @return string */ public function getTitle() { return $this->BaseAction()->Title; } /** * Returns all the valid transitions that lead out from this action. * * This is called if this action has finished, and the workflow engine wants * to run the next action. * * If this action returns only one valid transition it will be immediately * followed; otherwise the user will decide which transition to follow. * * @return ArrayList */ public function getValidTransitions() { $available = $this->BaseAction()->Transitions(); $valid = new ArrayList(); // iterate through the transitions and see if they're valid for the current state of the item being // workflowed if ($available) { foreach ($available as $transition) { if ($transition->isValid($this->Workflow())) { $valid->push($transition); } } } $this->extend('updateValidTransitions', $valid); return $valid; } /** * Called when this instance is started within the workflow */ public function actionStart(WorkflowTransition $transition) { $this->extend('onActionStart', $transition); } /** * Called when this action has been completed within the workflow */ public function actionComplete(WorkflowTransition $transition) { $this->MemberID = Member::currentUserID(); $this->write(); $this->extend('onActionComplete', $transition); } /** * Can documents in the current workflow state be edited? * * @param DataObject $target * @return bool */ public function canEditTarget(DataObject $target) { $absolute = $this->BaseAction()->canEditTarget($target); if (!is_null($absolute)) { return $absolute; } switch ($this->BaseAction()->AllowEditing) { case 'By Assignees': return $this->Workflow()->canEdit(); case 'No': return false; case 'Content Settings': default: return null; } } /** * Does this action restrict viewing of the document? * * @param DataObject $target * @return bool */ public function canViewTarget(DataObject $target) { return $this->BaseAction()->canViewTarget($target); } /** * Does this action restrict the publishing of a document? * * @param DataObject $target * @return bool */ public function canPublishTarget(DataObject $target) { $absolute = $this->BaseAction()->canPublishTarget($target); if (!is_null($absolute)) { return $absolute; } return false; } public function canView($member = null) { return $this->Workflow()->canView($member); } public function canEdit($member = null) { return $this->Workflow()->canEdit($member); } public function canDelete($member = null) { return $this->Workflow()->canDelete($member); } } |