Author: pmacadden
Date: 2010-08-30 18:36:06 +0200 (Mon, 30 Aug 2010)
New Revision: 30787

Added:
   plugins/pmPropelWorkflowableBehaviorPlugin/trunk/lib/WorkflowableBehavior.php
Removed:
   
plugins/pmPropelWorkflowableBehaviorPlugin/trunk/lib/pmPropelWorkflowableBehavior.class.php
Modified:
   plugins/pmPropelWorkflowableBehaviorPlugin/trunk/config/config.php
Log:
behavior improved to work on sf 1.4

Modified: plugins/pmPropelWorkflowableBehaviorPlugin/trunk/config/config.php
===================================================================
--- plugins/pmPropelWorkflowableBehaviorPlugin/trunk/config/config.php  
2010-08-30 16:03:13 UTC (rev 30786)
+++ plugins/pmPropelWorkflowableBehaviorPlugin/trunk/config/config.php  
2010-08-30 16:36:06 UTC (rev 30787)
@@ -1,6 +1,6 @@
 <?php
 
 sfPropelBehavior::registerMethods('workflowable', array(
-  array('pmPropelWorkflowableBehavior', 'stepForward'),
-  array('pmPropelWorkflowableBehavior', 'stepBackward')
+  array('WorkflowableBehavior', 'stepForward'),
+  array('WorkflowableBehavior', 'stepBackward')
 ));

Copied: 
plugins/pmPropelWorkflowableBehaviorPlugin/trunk/lib/WorkflowableBehavior.php 
(from rev 30764, 
plugins/pmPropelWorkflowableBehaviorPlugin/trunk/lib/pmPropelWorkflowableBehavior.class.php)
===================================================================
--- 
plugins/pmPropelWorkflowableBehaviorPlugin/trunk/lib/WorkflowableBehavior.php   
                            (rev 0)
+++ 
plugins/pmPropelWorkflowableBehaviorPlugin/trunk/lib/WorkflowableBehavior.php   
    2010-08-30 16:36:06 UTC (rev 30787)
@@ -0,0 +1,112 @@
+<?php
+
+class WorkflowableBehavior extends Behavior
+{
+  protected $parameters = array(
+    "status_column_name" => "status",
+    "possible_status_values" => array()
+  );
+
+  public function objectMethods()
+  {
+    $script = "";
+    $script .= $this->addCanStepForwardMethod();
+    $script .= $this->addStepForwardMethod();
+    $script .= $this->addCanStepBackwardMethod();
+    $script .= $this->addStepBackwardMethod();
+
+    return $script;
+  }
+
+  protected function getStatusAccessors()
+  {
+    $status_column_setter = 
"set".sfInflector::camelize($this->getParameter("status_column_name"));
+    $status_column_getter = 
"get".sfInflector::camelize($this->getParameter("status_column_name"));
+
+    return array($status_column_setter, $status_column_getter);
+  }
+
+  public function addCanStepForwardMethod()
+  {
+    list($status_column_setter, $status_column_getter) = 
$this->getStatusAccessors();
+    $possible_status_values = $this->getParameter("possible_status_values");
+
+    return "
+/**
+ * Returns true if the object can step forward.
+ */
+public function canStepForward()
+{
+  return in_array(\$this->$status_column_getter() + 1, 
array($possible_status_values));
+}
+";
+  }
+
+  public function addStepForwardMethod()
+  {
+    list($status_column_setter, $status_column_getter) = 
$this->getStatusAccessors();
+    $possible_status_values = $this->getParameter("possible_status_values");
+
+    return "
+/**
+ * Steps forward to the next status.
+ */
+public function stepForward()
+{
+  if (count(array($possible_status_values)))
+  {
+    if (\$this->canStepForward())
+    {
+      \$this->$status_column_setter(\$this->$status_column_getter() + 1);
+    }
+    else
+    {
+      throw new Exception(\"Object of class \".get_class(\$this).\" cannot 
step forward.\");
+    }
+  }
+}
+";
+  }
+
+  public function addCanStepBackwardMethod()
+  {
+    list($status_column_setter, $status_column_getter) = 
$this->getStatusAccessors();
+    $possible_status_values = $this->getParameter("possible_status_values");
+
+    return "
+/**
+ * Returns true if the object can step backward.
+ */
+public function canStepBackward()
+{
+  return in_array(\$this->$status_column_getter() - 1, 
array($possible_status_values));
+}
+";
+  }
+
+  public function addStepBackwardMethod()
+  {
+    list($status_column_setter, $status_column_getter) = 
$this->getStatusAccessors();
+    $possible_status_values = $this->getParameter("possible_status_values");
+    
+    return "
+/**
+ * Steps backward to the next status.
+ */
+public function stepBackward()
+{
+  if (count(array($possible_status_values)))
+  {
+    if (\$this->canStepBackward())
+    {
+      \$this->$status_column_setter(\$this->$status_column_getter() - 1);
+    }
+    else
+    {
+      throw new Exception(\"Object of class \".get_class(\$this).\" cannot 
step backward.\");
+    }
+  }
+}
+";
+  }
+}
\ No newline at end of file

Deleted: 
plugins/pmPropelWorkflowableBehaviorPlugin/trunk/lib/pmPropelWorkflowableBehavior.class.php
===================================================================
--- 
plugins/pmPropelWorkflowableBehaviorPlugin/trunk/lib/pmPropelWorkflowableBehavior.class.php
 2010-08-30 16:03:13 UTC (rev 30786)
+++ 
plugins/pmPropelWorkflowableBehaviorPlugin/trunk/lib/pmPropelWorkflowableBehavior.class.php
 2010-08-30 16:36:06 UTC (rev 30787)
@@ -1,85 +0,0 @@
-<?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