[EXTENSION] simpleWorkflow

Hi raoul,

I got this error "Non-static method SWHelper::_createListData() should not be called statically".

I used the latest simpleWorkflow-1.1.0.0 version. I have edited the method to static and its working now.

I just wonder if it is a bug or there is something wrong on how I used the workflow?

Thanks.

Hi Jan,

you are right, this is a bug I fixed but did not commit. Good job ! I will release a new version that includes the fix.

ciao

8)

Thanks Raoul.

I have this problem on auto update of the status on one of my table.

I have been reading your documentation and as well as the previous issues posted on this thread to find the solution but I was not able to got an answer or maybe I was not able to understand.

Maybe it is better to ask directly from the developer itself.

As what I have understand, the simpleworkflow extension it will handle the update of the status field of the model.

On my code, when a new record is created/inserted to the table, the status field is set automatically base on the initial status I set on the workflow files. That is without me doing anything to set the status.

However, when I update the record I expect it change the status to next status on my workflow. But it did not change.

What could be possible problem on this.

Below is the content of my swNotice.php on /protected/models/workflows:




return array(

		'initial' => 'Draft',

		'node' => array(

			array('id'=>'Draft', 'transition'=>'Published',),

			array('id'=>'Published')

		)

	);



Below is the code for my model update:




if(isset($_POST['Notice']))

		{

			$model->attributes=$_POST['Notice'];

			

			$model->swNextStatus('swNotice/Draft');

			

			if($model->save()){

				$this->redirect(array('view','id'=>$model->id));

			}

		}



I believe the line $model->swNextStatus(‘swNotice/Draft’); will trigger the change but it won’t.

Am I right with this assumption, or do I need add some code somewhere else.

I also tried $model->swNextStatus(‘Draft’);, still the same result.

Right now, I just manually change the status with $model->status = ‘swNotice/Published’;

But I would really want to make this to auto change the status. Since I will be using the workflow on another model that will have 5 statuses.

I would greatly appreciate if you could enlighten me this problem of mine.

Thanks.

Hi Jan,

in fact, the method swNextStatus("swNotice/Draft") will not send the model into the "next status" from "swNoticeDraft", but will set the status to "swNotice/Draft".

In other words, the model is sent into the status whose name is passed as argument to the swNextStatus() method (if of course, it can be reached from the current status).

Ok, maybe the name of the method is not correctly choosen ! ::)

On the other hand, it is not always possible to find a single “next status”. In your case it is obvious because ‘draft’ has only one next status (that is ‘published’), but most of the time, more than one status can be reached from a given status.

One "weakness" of the simpleWorkflow extension is it ability to automatically change status of the model … it has been designed to be driven by user.

Now, how to solve your issue ? one possible solution is to get the list of all status that can be reached from the current status, and if there is only one, then use it.

Below is a sample (not tested … away from computer).




$next = $model->swGetNextStatus();

if( count($next) == 1){

	$model->swNextStatus($next[0]);

}else {

	// well ... more than one status can be reached from the

	// current model status : do what you want here <img src='http://www.yiiframework.com/forum/public/style_emoticons/default/wink.gif' class='bbc_emoticon' alt=';)' />

}



[i](If it doesn’t work as expected, tell me)

[/i]Hope this helps[i]

B)

[/i]

Dear Raoul,

I’m newbie in Yii & PHP. Could you send me full source code of demo + DB. I downloaded your extension but I can’t run it.

Thank a lot!

Dear Raoul,

I followed your tutorial to modify YiiBlog. Everything is okie. But now I want use SimpleWorkflow with x-editable & yiiBootstrap.




	<div class="row">

		<?php echo $form->labelEx($model,'status'); ?>

        <?php echo $form->dropDownList($model,'status',SWHelper::nextStatuslistData($model)); ?>

		<?php echo $form->error($model,'status'); ?>

	</div>


        <?php echo $form->labelEx($model,'status'); ?>

        <?php

        $this->widget('editable.EditableField', array(

            'type'      => 'select',

            'model'     => $model,

            'attribute' => 'status',

            'url'       => $this->createUrl('post/updatePost'),

            'source'    => (SWHelper::allStatuslistData($model)),

//            'source'    => array('site/getStatusList'),

            'placement' => 'right',

        ));

        ?>

But the result is:

4228

incorrect.png

I want result is.

4226

correct.png

Please tell me how to do that.

Many many thanks!

Hi Hacmieu,

I’m not familiar with the x-editable extension but maybe that if your replace




'source'	=> (SWHelper::allStatuslistData($model)),



…by …




'source'	=> SWHelper::nextStatuslistData($model),



…the dropdown box should contain only possible next statuses).

Hope this helps

ciao

B)

It doesn’t work. But by the way, thank you very much :D I love this extension :D

humm … strange.

Could you please try to replace the call to SWHelper::nextStatuslistData() by an array like


'source' => array('id1'=>'value1','id2'=>'value2')

Just to check if the x-editable extension is all right

Then could you dump the value returned by SWHelper::nextStatuslistData() ? Normally it should return an array where each key is the status id and each value is the status label, ans that only for statuses that can be reached from the current model status.

I’ll be glad yo help you but I need more info ;)

ciao

B)

Here you are!

4229

5-13-2013 5-39-46 PM.png

ok, so the x-editable seems fine.

Now what about the value returned by SWHelper::nextStatuslistData() ? Could you print it somewhere so we have a look ?

B)

And here :D

I found that if I refresh page then x-editable reload SWHelper::nextStatuslistData is update ok.

4230

5-13-2013 7-56-28 PM.png

Thanks.

The value returned seems ok … I mean, I don’t know what are the actual next Statuses for the model you used for this test, but assuming that they are “ready” and “onLoan”, the dropdown bow should contain them.

I don’t know how x-editable works, but what you say is intresting : “when I refresh it’s ok” … but then when does it not work ? … on which circumstances ?

Please note that if there some ajax call made by the x-editable extension, what you wrote will initialize the dorpdown when the page is rendered by you controller … and no more. So, the list of next statuses you will always get, is the one corresponding to the model at the time the page is rendered ! … no dynamic update here.

Again, I suspect that the problem comes from how you want to use x-editable but as I’ve never used it, it’s quite difficult for me to help (sorry)

ciao

B)

Thank you very much!

I disable x-editable for Status. Everything ok now! :D

Hi,

A new version of the simpleWorkflow extension has been released.

[color="#0000FF"]VERSION 1.1.0.8[/color]

  • gii command : add SWyEdConverterDOM that uses DOM extension. If domxml extension is available, use it in priority otherwise use DOM.
  • add [i]swSetStatus/i to replace [i]swNextStatus/i which is still supported, but deprecated

This is a minor update so unless you want to use the Gii command to import workflow created with yEd and you don’t have domxml installed, no update is needed.

ciao

B)

Thank’s Raoul for your work!

;)

i did read in SWValidator:


const SW_SCENARIO_STATUS_SEPARATOR='-';

instead of


 const SW_SCENARIO_STATUS_SEPARATOR='_';

which are the effects/repercussions of that modify?

best regards!

This modification is only relevant if you’re using validation based on transition scenario. In this case, the scenario name to go from status “workflow1/statusA” to “workflow1/statusB” is should be :

"sw:workflow1/statusA-workflow1/statusB" instead of "sw:workflow1/statusA_workflow1/statusB"

(basically, the ‘-’ is replaced by ‘_’)

ciao

B)

ps: sorry for this late reply but the notification did not notified by of your message Salsero !!

ok raoul i suspected it and now i have the confirmation!

thank’s for your replay ;)

Hello,

I’m using your great extension for months now.

I’m looking for a way to achieve a specific behavior:

I have another field ‘category’. I is possible to insert an extra node, only if category is equal to a specific value?

Or maybe to use another workflow, for this specific category value?

Hi Ferlings,

I’m not sure to understand what you mean by “insert an extra node” but please note that the workflow definition has been designed to be static and consequently “inserting a node” based on some external condition, is something that you “should not” be able to do.

If you want your model to be able to reach an existing node only if this ‘categroy’ field is equal to a specific value, that could indeed be achieved using status constraints. In the example provided, the constraint is applied on the current user access rights, but it could also be applied to the model and so, you could write some condition on the ‘category’ field.

Could you please elaborate on the use case that would require such behavior ? … maybe that could help me understand how to solve your problem using the current implementation.

ciao

B)