sinevia/php-library-workflow

PHP库工作流程

v1.3.0 2022-03-26 01:19 UTC

This package is auto-updated.

Last update: 2024-09-26 06:32:07 UTC


README

一个简单而实用的多步骤工作流程实现,具有最小要求。

工作流程步骤

步骤类非常基础,可以很容易地通过每个工作流程所需的内容进行扩展。这可以通过使用动态属性或扩展步骤类来实现。步骤名称应该是唯一的。

步骤不是顺序的,尽管可以是。然而,当你将步骤添加到工作流程中时,应该按照它们逻辑上的顺序添加。逻辑顺序用于计算工作流程的整体进度。

正如现实生活中可以跳过步骤一样。例如,如果你已经有了瓶子里的水,就不需要去河边取水。

工作流程进度

工作流程进度是一个很好的功能,它允许通过进度条或饼图来显示进度。它是通过将步骤添加到工作流程中的顺序来计算的。例如,如果一个工作流程有100个步骤,而你正处于第70个步骤,那么添加的所有步骤都被视为“完成”,工作流程的整体完成度为70%。

功能

  • 多步骤支持
  • 当前步骤支持
  • 导出状态到字符串
  • 从保存的状态导入
  • 可扩展
  • 简单
  • 步骤元数据

示例

这只是一个示例实现。它可能对更简单的工作流程来说有点过于复杂。

// Create application
$aplication = new Application;

// Create application workflow
$applicationWorkflow = new ApplicationWorkflow($application);

// Send email and update workflow
if(sendEmailToApplicant() == true){
    $applicationWorkflow->completeStepStartApplication();
}

// Check what is the current step
echo $applicationWorkflow->getCurrentStep()->title;

// Check what is the current step
echo $applicationWorkflow->getProgress();


class ApplicationWorkflow extends Workflow {

    protected $application = null;

    function __construct($application) {
        parent::__construct();

        $step = new Step("StartApplication");
        $step->type = "first";
        $step->title = "Start application process";
        $step->responsible = "Applicant";
        $this->addStep($step);
        
        $step = new Step("SignAgreement");
        $step->title = "Signing agreement";
        $step->responsible = "Applicant";
        $this->addStep($step);

        $step = new Step("SelectCourses");
        $step->title = "Select Courses";
        $step->responsible = "Applicant";
        $this->addStep($step);
        
        $step = new Step("UploadDiploma");
        $step->title = "Upload Diploma";
        $step->responsible = "Applicant";
        $this->addStep($step);

        $step = new Step("ConfirmFitsRequirements");
        $step->title = "Confirm if applicant fits the requirements. If not – advise other suitable programs.";
        $step->responsible = "Manager";
        $this->addStep($step);

        $step = new Step("SendApplicationForward");
        $step->title = "Send application forward";
        $step->responsible = "Manager";
        $this->addStep($step);
        
        $step = new Step("RecieveConfirmationLetter");
        $step->title = "Receive the letter of confirmation";
        $step->responsible = "Manager";
        $this->addStep($step);

        $step = new Step("NotifyApplicantOfAcceptance");
        $step->title = "Notify applicant has been accepted";
        $step->responsible = "Manager";
        $this->addStep($step);

        $step = new Step("RecieveLetterOfApprovalOfAcomodation");
        $step->title = "Receive official letter for approval of accommodation";
        $step->responsible = "Manager";
        $this->addStep($step);
        
        $step = new Step("NotifyApplicantHasBeenApprovedForAccomodation");
        $step->title = "Notify applicant is approved for accomodation";
        $step->responsible = "Manager";
        $this->addStep($step);

        $step = new Step("SendAccommodationApprovalLetterToApplicant");
        $step->title = "Send the accommodation approval letter to applicant - needed for visa application";
        $step->responsible = "Manager";
        $this->addStep($step);

        $step = new Step("PreparePapersForVisaApplication");
        $step->title = "Prepare papers needed for visa application";
        $step->responsible = "Manager";
        $this->addStep($step);

        $step = new Step("ApplyForVisa");
        $step->title = "Apply for Visa";
        $step->responsible = "Applicant";
        $this->addStep($step);

        $step = new Step("ReceiveDecisionForVisa");
        $step->title = "Receive decision for the visa";
        $step->responsible = "Manager";
        $this->addStep($step);
        
        $step = new Step("FindAccommodation");
        $step->title = "Find sutable accomodation";
        $step->responsible = "Applicant";
        $this->addStep($step);

        $step = new Step("PrepareFilesForResidenceCard");
        $step->title = "Prepare files for residence card.";
        $step->responsible = "Applicant";
        $this->addStep($step);

        $step = new Step("ApplyForResidenceCard");
        $step->title = "Apply for residence card";
        $step->responsible = "Applicant";
        $this->addStep($step);

        $this->application = $application;
        if ($application != null) {
            $this->fromString($application->State);
        }
    }
    
    function save() {
        if ($this->application != null) {
            $this->application->State = $this->toString();
            return $this->application->save();
        }
        return false;
    }
    
    function completeStepStartApplication() {
        $this->setCurrentStep("SignAgreement");
        return $this->save();
    }
    
    function completeStepSignAgreement() {
        $this->setCurrentStep("SelectCourses");
        return $this->save();
    }
}