Author: francois.b
Date: 2010-01-24 13:25:40 +0100 (Sun, 24 Jan 2010)
New Revision: 27119
Added:
plugins/sfUnobstrusiveWidgetPlugin/trunk/lib/widget/orm/propel/listing/
plugins/sfUnobstrusiveWidgetPlugin/trunk/lib/widget/orm/propel/listing/sfUoWidgetPropelList.class.php
plugins/sfUnobstrusiveWidgetPlugin/trunk/lib/widget/orm/propel/listing/sfUoWidgetPropelNestedList.class.php
Removed:
plugins/sfUnobstrusiveWidgetPlugin/trunk/lib/widget/orm/propel/sfUoWidgetPropelList.class.php
plugins/sfUnobstrusiveWidgetPlugin/trunk/lib/widget/orm/propel/sfUoWidgetPropelNestedList.class.php
Log:
[sfUnobstrusiveWidgetPlugin] moved propel listin widgets to the appropriate
folder
Copied:
plugins/sfUnobstrusiveWidgetPlugin/trunk/lib/widget/orm/propel/listing/sfUoWidgetPropelList.class.php
(from rev 27117,
plugins/sfUnobstrusiveWidgetPlugin/trunk/lib/widget/orm/propel/sfUoWidgetPropelList.class.php)
===================================================================
---
plugins/sfUnobstrusiveWidgetPlugin/trunk/lib/widget/orm/propel/listing/sfUoWidgetPropelList.class.php
(rev 0)
+++
plugins/sfUnobstrusiveWidgetPlugin/trunk/lib/widget/orm/propel/listing/sfUoWidgetPropelList.class.php
2010-01-24 12:25:40 UTC (rev 27119)
@@ -0,0 +1,141 @@
+<?php
+
+/*
+ * This file is part of the symfony package.
+ * (c) Fabien Potencier <[email protected]>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+/**
+ * sfUoWidgetPropelList
+ * Propel list widget rend a list from database using propel.
+ *
+ * @package symfony
+ * @subpackage sfUnobstrusiveWidgetPlugin
+ * @author François Béliveau <[email protected]>
+ */
+class sfUoWidgetPropelList extends sfUoWidgetList
+{
+ /**
+ * @see sfUoWidget
+ */
+ public function __construct($options = array(), $attributes = array())
+ {
+ $options['choices'] = new sfCallable(array($this, 'getChoices'));
+
+ parent::__construct($options, $attributes);
+ }
+
+ /**
+ * Configures the current widget.
+ *
+ * * model: The model class (required)
+ * * add_empty: Whether to add a first empty value or not (false by
default)
+ * If the option is not a Boolean, the value will be used
as the text value
+ * * method: The method to use to display object values
("__toString" by default)
+ * * peer_method: The method to use to get objects ("doSelect" by
default)
+ * * order_by: An array composed of two fields:
+ * * The column to order by the results (must be in the
PhpName format)
+ * * "asc" or "desc"
+ * * criteria: A criteria to use when retrieving objects
+ * * connection: The Propel connection to use (null by default)
+ *
+ * @param array $options An array of options
+ * @param array $attributes An array of default HTML attributes
+ *
+ * @see sfUoWidget
+ */
+ protected function configure($options = array(), $attributes = array())
+ {
+ parent::configure($options, $attributes);
+
+ $this->addRequiredOption('model');
+ $this->addOption('method', '__toString');
+ $this->addOption('attributes_method', null);
+ $this->addOption('peer_method', 'doSelect');
+ $this->addOption('order_by', null);
+ $this->addOption('criteria', null);
+ $this->addOption('connection', null);
+ }
+
+ /**
+ * Return list choices.
+ *
+ * @return string
+ */
+ public function getChoices()
+ {
+ try
+ {
+ $this->checkObjectMethods();
+ }
+ catch (Exception $e)
+ {
+ throw $e;
+ }
+
+ $method = $this->getOption('method');
+ $atributesMethod = $this->getOption('attributes_method');
+ $choices = array();
+ $objects = $this->getObjects();
+
+ foreach ($objects as $object)
+ {
+ $choices[$object->getPrimaryKey()]['label'] = $object->$method();
+ if (!empty($atributesMethod))
+ {
+ $choices[$object->getPrimaryKey()]['attributes'] =
$object->$atributesMethod();
+ }
+ }
+
+ return $choices;
+ }
+
+ /**
+ * Return objects list.
+ *
+ * @return array
+ */
+ protected function getObjects()
+ {
+ $class = $this->getOption('model').'Peer';
+
+ $criteria = is_null($this->getOption('criteria')) ? new Criteria() : clone
$this->getOption('criteria');
+ if ($order = $this->getOption('order_by'))
+ {
+ $method = sprintf('add%sOrderByColumn', 0 ===
strpos(strtoupper($order[1]), 'ASC') ? 'Ascending' : 'Descending');
+ $criteria->$method(call_user_func(array($class, 'translateFieldName'),
$order[0], BasePeer::TYPE_PHPNAME, BasePeer::TYPE_COLNAME));
+ }
+
+ return call_user_func(array($class, $this->getOption('peer_method')),
$criteria, $this->getOption('connection'));
+ }
+
+ /**
+ * Check object methods.
+ * Throw an exception if a method missed.
+ *
+ * @return boolean
+ */
+ protected function checkObjectMethods()
+ {
+ $methods = array('method');
+ $atributesMethod = $this->getOption('attributes_method');
+
+ if (!empty($atributesMethod))
+ {
+ $methods[] = 'attributes_method';
+ }
+
+ foreach ($methods as $method)
+ {
+ if (!method_exists($this->getOption('model'), $this->getOption($method)))
+ {
+ throw new RuntimeException(sprintf('Class "%s" must implement a "%s"
method to be rendered in a "%s" widget', $this->getOption('model'),
$this->getOption($method), __CLASS__));
+ }
+ }
+
+ return true;
+ }
+}
\ No newline at end of file
Copied:
plugins/sfUnobstrusiveWidgetPlugin/trunk/lib/widget/orm/propel/listing/sfUoWidgetPropelNestedList.class.php
(from rev 27117,
plugins/sfUnobstrusiveWidgetPlugin/trunk/lib/widget/orm/propel/sfUoWidgetPropelNestedList.class.php)
===================================================================
---
plugins/sfUnobstrusiveWidgetPlugin/trunk/lib/widget/orm/propel/listing/sfUoWidgetPropelNestedList.class.php
(rev 0)
+++
plugins/sfUnobstrusiveWidgetPlugin/trunk/lib/widget/orm/propel/listing/sfUoWidgetPropelNestedList.class.php
2010-01-24 12:25:40 UTC (rev 27119)
@@ -0,0 +1,156 @@
+<?php
+
+/*
+ * This file is part of the symfony package.
+ * (c) Fabien Potencier <[email protected]>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+/**
+ * sfUoWidgetPropelNestedList
+ * Propel nested list widget rend a nested list from database using propel.
+ *
+ * @package symfony
+ * @subpackage sfUnobstrusiveWidgetPlugin
+ * @author François Béliveau <[email protected]>
+ */
+class sfUoWidgetPropelNestedList extends sfUoWidgetPropelList
+{
+ /**
+ * Return list choices.
+ *
+ * @return string
+ */
+ public function getChoices()
+ {
+ try
+ {
+ $this->checkObjectMethods();
+ }
+ catch (Exception $e)
+ {
+ throw $e;
+ }
+
+ $objects = $this->getObjects();
+ $scopeMethod = $this->getOption('scope_method');
+ $choices = array();
+ foreach ($objects as $object)
+ {
+ $choices[$object->$scopeMethod()][] = $object;
+ }
+
+ $result = array();
+ foreach ($choices as $values)
+ {
+ $excludes = array();
+ $result += $this->recursiveChoicesParser($values, $excludes);
+ }
+ return $result;
+ }
+
+ /**
+ * Configures the current widget.
+ *
+ * * tree_left_method: The method to use to get tree left object values
("getTreeLeft" by default)
+ * * tree_right_method: The method to use to get tree right object
values ("getTreeRight" by default)
+ * * scope_method: The method to use to get scope object values
("getScope" by default)
+ *
+ * @param array $options An array of options
+ * @param array $attributes An array of default HTML attributes
+ *
+ * @see sfUoWidget
+ */
+ protected function configure($options = array(), $attributes = array())
+ {
+ parent::configure($options, $attributes);
+
+ $this->addOption('tree_left_method', 'getTreeLeft');
+ $this->addOption('tree_right_method', 'getTreeRight');
+ $this->addOption('scope_method', 'getScope');
+ }
+
+ /**
+ * Create recursive choices.
+ *
+ * @param array $objects An array of objects
+ * @param array $excludes An array of objects PK that allreay parsed
+ * @param integer $options Parent tree left value
+ * @param integer $options Parent tree right value
+ *
+ * @return boolean
+ */
+ protected function recursiveChoicesParser(Array $objects, &$excludes,
$parentTreeLeft = null, $parentTreeRight = null)
+ {
+ $result = array();
+
+ $method = $this->getOption('method');
+ $treeLeftMethod = $this->getOption('tree_left_method');
+ $treeRightMethod = $this->getOption('tree_right_method');
+ $atributesMethod = $this->getOption('attributes_method');
+
+ foreach ($objects as $object)
+ {
+ if (count($excludes) == count($objects))
+ {
+ break;
+ }
+
+ $id = $object->getPrimaryKey();
+ $label = $object->$method();
+ $treeLeft = $object->$treeLeftMethod();
+ $treeRight = $object->$treeRightMethod();
+ $attributes = empty($atributesMethod) ? array() :
$object->$atributesMethod();
+
+ if (
+ ((is_null($parentTreeLeft) && is_null($parentTreeRight))
+ || ($treeLeft>$parentTreeLeft && $treeRight<$parentTreeRight))
+ && !in_array($id, $excludes)
+ )
+ {
+ $result[$id]['label'] = $label;
+ $result[$id]['attributes'] = $attributes;
+
+ $excludes[] = $id;
+ $diff = $treeRight - $treeLeft;
+ if ($diff > 1)
+ {
+ $result[$id]['contents'] = $this->recursiveChoicesParser($objects,
$excludes, $treeLeft, $treeRight);
+ }
+ }
+ }
+
+ return $result;
+ }
+
+ /**
+ * Check object methods.
+ * Throw an exception if a method missed.
+ *
+ * @return boolean
+ */
+ protected function checkObjectMethods()
+ {
+ try
+ {
+ parent::checkObjectMethods();
+ }
+ catch (Exception $e)
+ {
+ throw $e;
+ }
+
+ $methods = array('tree_left_method', 'tree_right_method', 'scope_method');
+ foreach ($methods as $method)
+ {
+ if (!method_exists($this->getOption('model'), $this->getOption($method)))
+ {
+ throw new RuntimeException(sprintf('Class "%s" must implement a "%s"
method to be rendered in a "%s" widget', $this->getOption('model'),
$this->getOption($method), __CLASS__));
+ }
+ }
+
+ return true;
+ }
+}
\ No newline at end of file
Deleted:
plugins/sfUnobstrusiveWidgetPlugin/trunk/lib/widget/orm/propel/sfUoWidgetPropelList.class.php
===================================================================
---
plugins/sfUnobstrusiveWidgetPlugin/trunk/lib/widget/orm/propel/sfUoWidgetPropelList.class.php
2010-01-24 12:23:12 UTC (rev 27118)
+++
plugins/sfUnobstrusiveWidgetPlugin/trunk/lib/widget/orm/propel/sfUoWidgetPropelList.class.php
2010-01-24 12:25:40 UTC (rev 27119)
@@ -1,141 +0,0 @@
-<?php
-
-/*
- * This file is part of the symfony package.
- * (c) Fabien Potencier <[email protected]>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-/**
- * sfUoWidgetPropelList
- * Propel list widget rend a list from database using propel.
- *
- * @package symfony
- * @subpackage sfUnobstrusiveWidgetPlugin
- * @author François Béliveau <[email protected]>
- */
-class sfUoWidgetPropelList extends sfUoWidgetList
-{
- /**
- * @see sfUoWidget
- */
- public function __construct($options = array(), $attributes = array())
- {
- $options['choices'] = new sfCallable(array($this, 'getChoices'));
-
- parent::__construct($options, $attributes);
- }
-
- /**
- * Configures the current widget.
- *
- * * model: The model class (required)
- * * add_empty: Whether to add a first empty value or not (false by
default)
- * If the option is not a Boolean, the value will be used
as the text value
- * * method: The method to use to display object values
("__toString" by default)
- * * peer_method: The method to use to get objects ("doSelect" by
default)
- * * order_by: An array composed of two fields:
- * * The column to order by the results (must be in the
PhpName format)
- * * "asc" or "desc"
- * * criteria: A criteria to use when retrieving objects
- * * connection: The Propel connection to use (null by default)
- *
- * @param array $options An array of options
- * @param array $attributes An array of default HTML attributes
- *
- * @see sfUoWidget
- */
- protected function configure($options = array(), $attributes = array())
- {
- parent::configure($options, $attributes);
-
- $this->addRequiredOption('model');
- $this->addOption('method', '__toString');
- $this->addOption('attributes_method', null);
- $this->addOption('peer_method', 'doSelect');
- $this->addOption('order_by', null);
- $this->addOption('criteria', null);
- $this->addOption('connection', null);
- }
-
- /**
- * Return list choices.
- *
- * @return string
- */
- public function getChoices()
- {
- try
- {
- $this->checkObjectMethods();
- }
- catch (Exception $e)
- {
- throw $e;
- }
-
- $method = $this->getOption('method');
- $atributesMethod = $this->getOption('attributes_method');
- $choices = array();
- $objects = $this->getObjects();
-
- foreach ($objects as $object)
- {
- $choices[$object->getPrimaryKey()]['label'] = $object->$method();
- if (!empty($atributesMethod))
- {
- $choices[$object->getPrimaryKey()]['attributes'] =
$object->$atributesMethod();
- }
- }
-
- return $choices;
- }
-
- /**
- * Return objects list.
- *
- * @return array
- */
- protected function getObjects()
- {
- $class = $this->getOption('model').'Peer';
-
- $criteria = is_null($this->getOption('criteria')) ? new Criteria() : clone
$this->getOption('criteria');
- if ($order = $this->getOption('order_by'))
- {
- $method = sprintf('add%sOrderByColumn', 0 ===
strpos(strtoupper($order[1]), 'ASC') ? 'Ascending' : 'Descending');
- $criteria->$method(call_user_func(array($class, 'translateFieldName'),
$order[0], BasePeer::TYPE_PHPNAME, BasePeer::TYPE_COLNAME));
- }
-
- return call_user_func(array($class, $this->getOption('peer_method')),
$criteria, $this->getOption('connection'));
- }
-
- /**
- * Check object methods.
- * Throw an exception if a method missed.
- *
- * @return boolean
- */
- protected function checkObjectMethods()
- {
- $methods = array('method');
- $atributesMethod = $this->getOption('attributes_method');
-
- if (!empty($atributesMethod))
- {
- $methods[] = 'attributes_method';
- }
-
- foreach ($methods as $method)
- {
- if (!method_exists($this->getOption('model'), $this->getOption($method)))
- {
- throw new RuntimeException(sprintf('Class "%s" must implement a "%s"
method to be rendered in a "%s" widget', $this->getOption('model'),
$this->getOption($method), __CLASS__));
- }
- }
-
- return true;
- }
-}
\ No newline at end of file
Deleted:
plugins/sfUnobstrusiveWidgetPlugin/trunk/lib/widget/orm/propel/sfUoWidgetPropelNestedList.class.php
===================================================================
---
plugins/sfUnobstrusiveWidgetPlugin/trunk/lib/widget/orm/propel/sfUoWidgetPropelNestedList.class.php
2010-01-24 12:23:12 UTC (rev 27118)
+++
plugins/sfUnobstrusiveWidgetPlugin/trunk/lib/widget/orm/propel/sfUoWidgetPropelNestedList.class.php
2010-01-24 12:25:40 UTC (rev 27119)
@@ -1,156 +0,0 @@
-<?php
-
-/*
- * This file is part of the symfony package.
- * (c) Fabien Potencier <[email protected]>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-/**
- * sfUoWidgetPropelNestedList
- * Propel nested list widget rend a nested list from database using propel.
- *
- * @package symfony
- * @subpackage sfUnobstrusiveWidgetPlugin
- * @author François Béliveau <[email protected]>
- */
-class sfUoWidgetPropelNestedList extends sfUoWidgetPropelList
-{
- /**
- * Return list choices.
- *
- * @return string
- */
- public function getChoices()
- {
- try
- {
- $this->checkObjectMethods();
- }
- catch (Exception $e)
- {
- throw $e;
- }
-
- $objects = $this->getObjects();
- $scopeMethod = $this->getOption('scope_method');
- $choices = array();
- foreach ($objects as $object)
- {
- $choices[$object->$scopeMethod()][] = $object;
- }
-
- $result = array();
- foreach ($choices as $values)
- {
- $excludes = array();
- $result += $this->recursiveChoicesParser($values, $excludes);
- }
- return $result;
- }
-
- /**
- * Configures the current widget.
- *
- * * tree_left_method: The method to use to get tree left object values
("getTreeLeft" by default)
- * * tree_right_method: The method to use to get tree right object
values ("getTreeRight" by default)
- * * scope_method: The method to use to get scope object values
("getScope" by default)
- *
- * @param array $options An array of options
- * @param array $attributes An array of default HTML attributes
- *
- * @see sfUoWidget
- */
- protected function configure($options = array(), $attributes = array())
- {
- parent::configure($options, $attributes);
-
- $this->addOption('tree_left_method', 'getTreeLeft');
- $this->addOption('tree_right_method', 'getTreeRight');
- $this->addOption('scope_method', 'getScope');
- }
-
- /**
- * Create recursive choices.
- *
- * @param array $objects An array of objects
- * @param array $excludes An array of objects PK that allreay parsed
- * @param integer $options Parent tree left value
- * @param integer $options Parent tree right value
- *
- * @return boolean
- */
- protected function recursiveChoicesParser(Array $objects, &$excludes,
$parentTreeLeft = null, $parentTreeRight = null)
- {
- $result = array();
-
- $method = $this->getOption('method');
- $treeLeftMethod = $this->getOption('tree_left_method');
- $treeRightMethod = $this->getOption('tree_right_method');
- $atributesMethod = $this->getOption('attributes_method');
-
- foreach ($objects as $object)
- {
- if (count($excludes) == count($objects))
- {
- break;
- }
-
- $id = $object->getPrimaryKey();
- $label = $object->$method();
- $treeLeft = $object->$treeLeftMethod();
- $treeRight = $object->$treeRightMethod();
- $attributes = empty($atributesMethod) ? array() :
$object->$atributesMethod();
-
- if (
- ((is_null($parentTreeLeft) && is_null($parentTreeRight))
- || ($treeLeft>$parentTreeLeft && $treeRight<$parentTreeRight))
- && !in_array($id, $excludes)
- )
- {
- $result[$id]['label'] = $label;
- $result[$id]['attributes'] = $attributes;
-
- $excludes[] = $id;
- $diff = $treeRight - $treeLeft;
- if ($diff > 1)
- {
- $result[$id]['contents'] = $this->recursiveChoicesParser($objects,
$excludes, $treeLeft, $treeRight);
- }
- }
- }
-
- return $result;
- }
-
- /**
- * Check object methods.
- * Throw an exception if a method missed.
- *
- * @return boolean
- */
- protected function checkObjectMethods()
- {
- try
- {
- parent::checkObjectMethods();
- }
- catch (Exception $e)
- {
- throw $e;
- }
-
- $methods = array('tree_left_method', 'tree_right_method', 'scope_method');
- foreach ($methods as $method)
- {
- if (!method_exists($this->getOption('model'), $this->getOption($method)))
- {
- throw new RuntimeException(sprintf('Class "%s" must implement a "%s"
method to be rendered in a "%s" widget', $this->getOption('model'),
$this->getOption($method), __CLASS__));
- }
- }
-
- return true;
- }
-}
\ No newline at end of file
--
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.