Author: pmacadden
Date: 2010-04-30 17:04:46 +0200 (Fri, 30 Apr 2010)
New Revision: 29328

Added:
   plugins/pmPropelWorkflowableBehaviorPlugin/trunk/README
   plugins/pmPropelWorkflowableBehaviorPlugin/trunk/config/
   plugins/pmPropelWorkflowableBehaviorPlugin/trunk/config/config.php
   plugins/pmPropelWorkflowableBehaviorPlugin/trunk/lib/
   
plugins/pmPropelWorkflowableBehaviorPlugin/trunk/lib/pmPropelWorkflowableBehavior.class.php
Log:
initial import.


Added: plugins/pmPropelWorkflowableBehaviorPlugin/trunk/config/config.php
===================================================================
--- plugins/pmPropelWorkflowableBehaviorPlugin/trunk/config/config.php          
                (rev 0)
+++ plugins/pmPropelWorkflowableBehaviorPlugin/trunk/config/config.php  
2010-04-30 15:04:46 UTC (rev 29328)
@@ -0,0 +1,6 @@
+<?php
+
+sfPropelBehavior::registerMethods('workflowable', array(
+  array('pmPropelWorkflowableBehavior', 'stepForward'),
+  array('pmPropelWorkflowableBehavior', 'stepBackward')
+));

Added: 
plugins/pmPropelWorkflowableBehaviorPlugin/trunk/lib/pmPropelWorkflowableBehavior.class.php
===================================================================
--- 
plugins/pmPropelWorkflowableBehaviorPlugin/trunk/lib/pmPropelWorkflowableBehavior.class.php
                         (rev 0)
+++ 
plugins/pmPropelWorkflowableBehaviorPlugin/trunk/lib/pmPropelWorkflowableBehavior.class.php
 2010-04-30 15:04:46 UTC (rev 29328)
@@ -0,0 +1,85 @@
+<?php
+
+class pmPropelWorkflowableBehavior
+{
+  protected static function getStatusAccessors($object)
+  {
+    $class = get_class($object);
+    $status_column_name = 
sfConfig::get('propel_behavior_workflowable_'.$class.'_status_column_name', 
'status');
+    $status_column_setter = 'set'.sfInflector::camelize($status_column_name);
+    $status_column_getter = 'get'.sfInflector::camelize($status_column_name);
+    return array($status_column_setter, $status_column_getter);
+  }
+
+  protected static function getPossibleStatusValues($object)
+  {
+    $class = get_class($object);
+    return 
sfConfig::get('propel_behavior_workflowable_'.$class.'_possible_status_values', 
array());
+  }
+
+  public static function canStepForward($object)
+  {
+    list($status_column_setter, $status_column_getter) = 
self::getStatusAccessors($object);
+    $possible_status_values = self::getPossibleStatusValues($object);
+
+    if (method_exists($object, 'canStepForward'))
+    {
+      return $object->canStepForward();
+    }
+    else
+    {
+      return in_array($object->$status_column_getter() + 1, 
$possible_status_values);
+    }
+  }
+
+  public static function stepForward($object)
+  {
+    list($status_column_setter, $status_column_getter) = 
self::getStatusAccessors($object);
+    $possible_status_values = self::getPossibleStatusValues($object);
+
+    if (count($possible_status_values))
+    {
+      if (self::canStepForward($object))
+      {
+        $object->$status_column_setter($object->$status_column_getter() + 1);
+      }
+      else
+      {
+        throw new Exception('Object of class '.get_class($object).' cannot 
step forward.');
+      }
+    }
+  }
+
+  public static function canStepBackward($object)
+  {
+    list($status_column_setter, $status_column_getter) = 
self::getStatusAccessors($object);
+    $possible_status_values = self::getPossibleStatusValues($object);
+
+    if (method_exists($object, 'canStepBackward'))
+    {
+      return $object->canStepBackward();
+    }
+    else
+    {
+      return in_array($object->$status_column_getter() - 1, 
$possible_status_values);
+    }
+  }
+
+  public static function stepBackward($object)
+  {
+    list($status_column_setter, $status_column_getter) = 
self::getStatusAccessors($object);
+    $possible_status_values = self::getPossibleStatusValues($object);
+
+    if (count($possible_status_values))
+    {
+      if (self::canStepBackward($object))
+      {
+        $object->$status_column_setter($object->$status_column_getter() - 1);
+      }
+      else
+      {
+        throw new Exception('Object of class '.get_class($object).' cannot 
step backward.');
+      }
+    }
+  }
+}

-- 
You received this message because you are subscribed to the Google Groups 
"symfony SVN" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/symfony-svn?hl=en.

Reply via email to