arter/amos-workflow

There is no license information available for the latest version (1.1.0) of this package.

Sistema AMOS per il workflow

1.1.0 2022-05-04 16:00 UTC

This package is auto-updated.

Last update: 2024-03-21 08:49:53 UTC


README

The module Workflow is used in order to manage workflow status transitions on records useing a workflow. Amos Workflow is based on:

  • raoul2000/yii2-workflow
  • cornernote/yii2-workflow-manager

Installation

  1. The preferred way to install this extension is through composer.

Either run

composer require arter/amos-workflow

or add this row

"arter/amos-workflow": "dev-master"

to the require section of your composer.json file.

  1. Add module to your modules config in backend:

        
     'modules' => [
         'workflow' => [
            'class' => 'arter\amos\workflow\AmosWorkflow',
         ],
     ],
    
  2. Apply migrations

    a. amos-workflow migrations

     php yii migrate/up --migrationPath=@vendor/arter/amos-workflow/src/migrations
    

    or add this row to your migrations config in console:

     return [
         .
         .
         .
         '@vendor/arter/amos-workflow/src/migrations',
         .
         .
         .
     ];
    

Configuration

//TODO translate-fix this section

Ogni cambio di stato del workflow viene intercettato come evento e viene scritta un record di log nella tabella workflow_transition_log (vedere WorkflowLogFunctionsBehavior).

Define model workflow
Il workflow classico in amos4 comprende gli stati:

  • bozza /draft
  • da validare/richiesta pubblicazione
  • validato/pubblicato

Per automatizzare/standardizzare alcune operazioni è stata creata in amos-core l'interfaccia WorkflowModelInterface che è bene implementare, insieme ad estendere NotifyRecord per beneficiare ad esempio delle mail automatiche alla richiesta di validazione del modello.

Il workflow del model viene definito tramite il popolamento delle tabelle:

  • sw_workflow: definizione id del workflow, per convenzione in amos 4 è il nome del model seguito da 'Workflow' es. 'NewsWorkflow'. Definizione dello stato iniziale di default, eventualmente modificabile da interfaccia o tramite migration. Es initial_status_id = 'DRAFT'

  • sw_status: Definizione degli stati del workflow. Lo stato verrà salvato (come convenzione) nel campo status del model concatendo Workflow_id / status_id ad esempio 'NewsWorkflow/BOZZA'

  • sw_transition: definizione delle transizioni, ossia di tutti i possibili passaggi di stato. IMPORTANTE: l'errore non esiste la transizione tra stato A e stato B che potreste riscontrare, se avete definito la transizione è in realtà dovuto alla mancanza del permesso dell'utente salvare il modello in quello stato.

  • sw_metadata: per ogni stato del workflow definisce label sui bottoni di cambio stato, testi dei popup, classi css, ecc. E' possibile anche commentare il passaggio di stato e salvare tale nota/commento nei log di passaggio di stato.

To enable workflow event behavior, insert in your model behavior array eg.

 public function behaviors()
{
    return ArrayHelper::merge(parent::behaviors(), [
        .
        .
        .
        'workflow' => [
            'class' => SimpleWorkflowBehavior::className(),
            'defaultWorkflowId' => self::NEWS_WORKFLOW,
            'propagateErrorsToModel' => true
        ]
    ];
}

Widgets

Amos Workflow provides three Widgets:

  • WorkflowTransitionButtonsWidget
  • WorkflowTransitionStateDescriptorWidget

//TODO explain/example of use for new widgets above

  • WorkflowTransitionWidget arter\amos\workflow\widgets\WorkflowTransitionWidget
    Draws a section containing model current status and the buttons with possible status to change starting from the current one (reading from sw_metadata).
    Comment / notes on status change
    If needed, it is possible to show a popup to insert comment/notes on status change; to enable the functionality add in sw_metadata for the transition final status the metadata: key ='comment', value = 1

It is possible to use a global parameter to hide all transition widgets, if the model workflows are bypassed. Insert between your application backend params array:

    return [
        .
        .
        .
        'hideWorkflowTransitionWidget' => true
        .
        .
        .
    ];
    ```



example of use in a form:
<?= WorkflowTransitionWidget::widget([
    'form' => $form,
    'model' => $model,
    'workflowId' => ShowcaseProject::SHOWCASEPROJECT_WORKFLOW,
    'classDivIcon' => 'pull-left',
    'classDivMessage' => 'pull-left message',
    'viewWidgetOnNewRecord' => true,
    'translationCategory' => 'amosshowcaseprojects'
]); ?>