@raoul at first after reading your comments I thought that perhaps I had over complicated things using the switch statement and I thought a bit about whether I could or should lose the switch statement.
It seems for me that it adds considerable flexibility. For my particular project I have a few requirements that I think I can only address this way.
[list=1]
[*]The users are not experienced so I want the super-user to be able to ‘fix’ things or do things that are essentially ‘illogical’
[*]different people are emailed depending on where in the process the status changes
[/list]
I have a down and dirty page up on my website to explain this project to you. You can access it here
Also a comment about the documentation. Possibly because I am a left to right reader I found the documentation confusing regarding the introduction of the constraints.
Example: one of my workflow arrays, it works fine.
$statusArray = array(
'initial' => 'draft',
'node' => array(
array('id'=>'draft','transition'=>'submitted,withdrawn'), // CONTRIBUTOR
array('id'=>'revise','constraint'=>'MyUtils::abstractReviewer($this->id)', 'transition'=>'submitted,withdrawn'),// CONTRIBUTOR
array('id'=>'withdrawn', 'constraint'=>'MyUtils::abstractOwner($this->id)', 'transition'=>'submitted'), // CONTRIBUTOR
array('id'=>'submitted','constraint'=>'MyUtils::abstractOwner($this->id)', 'transition'=>'accepted,revise,rejected'), // editor or contibuter
array('id'=>'rejected','constraint'=>'MyUtils::abstractReviewer($this->id)' ), // CONTRIBUTOR
array('id'=>'accepted','constraint'=>'MyUtils::abstractReviewer($this->id)' ), // publisher
array('id'=>'on-hold'), // publisher
array('id'=>'scheduled')
)
);
The same array in a slightly more understandable format (not necessarily more readable)
$statusArray = array(
'initial' => 'draft',
'node' => array(
array('id'=>'draft','transition'=>'submitted,withdrawn'), // CONTRIBUTOR
array('constraint'=>'MyUtils::abstractReviewer($this->id)', 'id'=>'revise', 'transition'=>'submitted,withdrawn'),// CONTRIBUTOR
array('constraint'=>'MyUtils::abstractOwner($this->id)','id'=>'withdrawn', 'transition'=>'submitted'), // CONTRIBUTOR
array('constraint'=>'MyUtils::abstractOwner($this->id)','id'=>'submitted', 'transition'=>'accepted,revise,rejected'), // editor or contibuter
array('constraint'=>'MyUtils::abstractReviewer($this->id)','id'=>'rejected', ), // CONTRIBUTOR
array('constraint'=>'MyUtils::abstractReviewer($this->id)','id'=>'accepted' ), // publisher
array('id'=>'on-hold'), // publisher
array('id'=>'scheduled')
)
);
So now all logic flows left to right
In order to make it to an ID you must pass THROUGH the constraint after reaching the ID the possible transitions are the next things to the right.
It helped me visualize what was happening.
Now the only issue I am facing is that notification is sent out before the save, this means that when a reviewer makes a note I don’t know how to access the most recent changes.
FWIW here is a chunk of the method that sends the mail
public function autoMail($subject,$docID,$userID=null,$fromID=null )
{
$doc = EventAbstract::model()->findByPk($docID);
if(!isset(Yii::app()->params->sendAdminMail)) // don't even try to mail if this setting is null
return;
/*
* If there is no FROM id assume that it is from the admin
* if it is a number it is a user id otherwise it must be an email address
*/
if(!$fromID){
$from=Yii::app()->params->masterEditorEmail;
} else {
$from = (is_numeric($fromID) ? User::model()->findByPk($fromID)->email : $userID);
}
/*
* If there is no TO id assume that it is to the admin
* if it is a number it is a user id otherwise it is an email address
*/
if($userID){
$to = (is_numeric($userID) ? User::model()->findByPk($userID)->email : $userID);
} else {
$to=Yii::app()->params->masterEditorEmail;
}
$headers = "MIME-Version: 1.0\r\nFrom: $from\r\nReply-To: $to\r\nContent-Type: text/html; charset=utf-8";
$body = '<em><strong>'.$subject.'</strong></em>';.....
As you can see it pulls the data from the existing record based on an ID.
Here is an example of an action that is triggered by a status change.
case User::CONTRIBUTOR_USER:
$statusArray = array(
'initial' => 'draft',
'node' => array(
array('id'=>'draft', 'transition'=>array(
'submitted'=>'MyUtils::contributorMail($this->id,0)'
)
),.....
@raoul I think I could learn a lot by examining your extension, thanks for sharing.
doodle