smagEntityWorkflowPlugin
1.0.1stable
for sf 1.4sf 1.3 and Propel
MIT
smagEntityWorkflowPlugin
This Plugin handles a Workflow for Entities. If you need to bring an Object through several steps before it reaches a Final state, an Article for example, this is what you need.
Flexible Configuration
The configuration is flexible and gives you the freedom(Fries) to build loops and straightforward logic.
Developers
License
Copyright (c) 2010 spot-media AG
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
smagEntityWorkflowPlugin
Author: Sören Rohweder rohweder@spot-media.de
This Plugin is for handling entity based workflows. By defining workflownodes
in the configuration the entity can determine which possible steps could be used
next.
Example:
an Object is in state A and the next possible steps are B or C. But C only if a
condition is met.
workflow:
A:
title: 'Some useful Title'
next:
-
next: B
-
condition:
param: paramName
value: paramValue
next: C
B:
title: 'The Title for the B State'
C:
title: 'The Title for the C State'
If the workflow is now asked which states it could reach the returning list
will contain B/C but C only if the parameter paramName == paramValue
If Plugin enabled there will be an Instance of the WorkflowManager in
sfContext::getInstance()->get('workflowmanager');
The WorkflowManager is able to check for a Workflow for an Object. There only
has to exist a <objectClass>-workflow.yml for each type of object.
If the actual Object has no WorkflowMapping entry there will be one created
with the first node found in the Configurationfile.
Normaly all you need to know the WorkflowManager is able to handle. Get the
possible Nodes, get the actual Node and set a new Node
Take a look into the workflow.sample.yml to get a more detailed description
Handle an Object
Get the actual node to handle the workflowchange
$actualWFNode = ifContext::getInstance()->get('workflowmanager')->getActualStepForObject($object);
Check for the right to change the workflow and
if($this->getUser()->hasCredential(Workflow::WF_PREFIX.'_owner_'.$actualWFNode->getName()))
{
sfContext::getInstance()->get('workflowmanager')->setNewWorkflowStep($object,$statusName);
}
Prepare the Forms handled by the Workflow
The forms which should be handled by the workflow have to implement the Workflowable Interface
Forms implementing this interface are called by an event wich then calls the handleWorkflow
method to disable all formWidgets
class ObjectForm extends BaseForm implements Workflowable
/**
* handles the workflow stuff
*/
public function handleWorkflow()
{
if(!sfConfig::get('app_workflow_enabled',false))
{
return;
}
$object = $this->getObject();
if($object->isNew())
{
return;
}
$wfNode = sfContext::getInstance()->get('workflowmanager')->getActualStepForObject($object);
$credentialName = 'wf_'.$wfNode->getName().'_form_'.get_class($this);
if(!sfContext::getInstance()->getUser()->hasCredential($credentialName))
{
$this->reconfigureDisabled();
}
}
And the BaseForm has to read as follow
class BaseForm extends sfForm
/**
* disables the form widgets if neccesary for the workflow
*
* @param sfFormFieldSchema $schema
*/
public function reconfigureDisabled(sfFormFieldSchema $schema = null)
{
if (!$schema)
{
$schema = $this->getFormFieldSchema();
}
foreach ($schema as $key => $field)
{
if (!$field instanceof sfFormFieldSchema)
{
$field->getWidget()->setAttributes(array('disabled' => 'disabled', 'class' => 'disabled'));
}
else
{
$this->reconfigureDisabled($field);
}
}
}