[EXTENSION] simpleWorkflow

Yes, I’ll try to explain it.

I have an application for a client, where guest users can send request (via a form), with a category type (art, music, special, etc…)

The request goes into the workflow process from (1)new, (2)in process, (3)accepted, (4)closed.

But my client wants now to have an extra step, if the category is ‘special’.

So for this special category, the workflow will be: (1)new, (2)in process, (3)accepted, (4)director accepted, (5)closed.

Hi,

Thanks…it’s may helpful…

Any idea?

Hi,

sorry for the late reply (I was on holidays ;) )

I understand better now.

One simple solution would be to implement the logic not in the workflow itself, but in your php code (e.g. test the value of the ‘category’ attribute and if it is equal to “special”, set the status to “director accepted”, otheriwse “closed”.

Another option that would require minimal workflow change (one additional status “director accepted” and 2 transitions) would be to use the simpleWorkflow Validator. This requires you to validate the model prior to saving. Moreover you should first assume that ‘director accepted’ status can be reached and if it’s not the case (validation fails) set the status to ‘closed’.

Take a look to this schema. Validation rule 1 will allow an ‘accepted’ model to go to ‘closed’ only if ‘category’ != ‘special’. In this case the only transition possible would then be to the ‘diraccepted’ status.

In the same way validation rule 2 would allow a ‘diraccepted’ model to be sent into the ‘closed’ status only if ‘category’ == ‘special’ … but note that this second validation rule is optional as if the first validation rules was correctly tested, the model in "diraccepted’ is garanteed to have ‘category’ == ‘special’.

(read more about workflow driven validation)

I could not test it any further but you can give it a try and let me know if it works as expected

At last, and as you wrote, another option would be to create a brand new workflow and insert the model into it, only if it has the ‘category’ attribute equals to ‘special’. Note that in this case you can’t use the ‘autoInsert’ = true option.

hope it helps

ciao

B)

Hi all,

just a short update to inform that the simpleWorkflow Extension has a new home !! … so you’re all invited to visite the

[center][size="4"] New simpleWorkflow Home Page [/size]

[/center]

(of course it is made with Yii 1.1.14, and some cool extensions like YiiStrap, YiiWheels)

ciao

8)

Thank you Raoul, you saved my weeks of coding…

:) good to hear … you’re welcome

B)

Dear Raoul!

First of all I would like to thank you this extension.

For my current work I got an existing database, what I can’t modify :(

In every table has a statusID attribute (INT) and these tables has a relation:


'status' => array(self::BELONGS_TO, 'Status', 'statusID'),

The status table:

status(id, name, description)

My question: Is it possible to use statusID (INT) instead of using varchar(45), OR to use the status->name attribute inside the workflow definition and swNextStatus() method?

Thanks in advanced.

Tom

Hi Tom,

sorry for the late reply but I did not received any forum notification that a new messages had been posted in this thread …

Anyway, the reply to your first question is “no” : the status must have the following format : workflowId/statusName (e.g. ‘post/published’) so it can’t be stored as in integer.

Unfortunatly, it is not possible to use a relation to retrieve the status name from another table. When the simpleWorkflow behavior is attached to a model, it first test if the ‘status’ attribute (default name) belongs to the model. The "status’ attribute is then used to read/write status value … so using a relation will not work.

Sorry to say that in the current version I see no way to solve this.

ciao

8)

Hi Roul …

I am glad this extensions really help me at work and easy to use;

but, i had seen in vimeo video that i can include a function in transition ?

how do i define this function ? correct me if am wrong

will you explain ? . or i must define it by myself on my update controller ??

thank

hi Kay,

glad to know that the simpleWorkflow Extension helped you.

Regarding the function that you can call in a transition, yes you’re right, this is a feature of the simpleWorkflow extension. Such function is called a “transition task” and it is executed when a model is going through a transition.

To define a transition task, you have to simple add it in your workflow definition.

Take a look to this example and you’ll get a better idea. Note that if your transition task refers to $this, then it is assumed to be related to the model if your workflow is defined as a PHP array. If it is defined as a PHP class, $this is the workflow instance itself (just like inthis example).

hope its helped.

ciao

B)

Hello Roul :) i`m glad that this extension exist and helped me much

but, what if user didn`t chose the task. application provide for them automatically look like a static task.

i had made two helpers. to provide what next and what before. so user didn`t have to chose what next.

what if someday the task growing so i had to edit the helpers again. i hope you understand what i mean for the next

simpleworkflow update

sorry for terrible english

Hi Kay,

Sorry but I’m not sur to understand your concern about tasks.

The task is a way to run some code when the model goeas from one status to another … the user doesn’t really “choose” a task but choose to do some action that will end up in a transition being performed (e.g. model goes from status "draft’ to ‘published’) and if a task is defined to this transition, then it is executed.

What do you mean by "what if someday the task growing" ?

Maybe you could provide an example and explain me again …

ciao

B)