[tipos commit] r1603 - branches/Solar_Form/Solar

0 views
Skip to first unread message

codesite...@google.com

unread,
Oct 3, 2008, 5:32:37 PM10/3/08
to tipo...@googlegroups.com
Author: rodrigo.moraes
Date: Fri Oct 3 14:31:59 2008
New Revision: 1603

Modified:
branches/Solar_Form/Solar/Form.php

Log:
More fixes: model records set values to *all* its columns in the form,
which results in exceptions because the elements are not found. Now
getElement() returns false if the element is not found, and the exception
is optional.

Modified: branches/Solar_Form/Solar/Form.php
==============================================================================
--- branches/Solar_Form/Solar/Form.php (original)
+++ branches/Solar_Form/Solar/Form.php Fri Oct 3 14:31:59 2008
@@ -224,21 +224,50 @@
*
* @param string $array Rename the element as a key in this array.
*
+ * @param bool $throw If true, throws an exception if the element is
not
+ * found.
+ *
* @return Solar_Form_Element
*
*/
- public function getElement($name, $array = null)
+ public function getElement($name, $array = null, $throw = false)
{
$name = $this->_prepareName($name, $array);
-
+
if (empty($this->elements[$name])) {
- throw $this->_exception('ERR_NO_SUCH_ELEMENT', array(
- 'name' => $name,
- ));
+ if ($throw) {
+ throw $this->_exception('ERR_NO_SUCH_ELEMENT', array(
+ 'name' => $name,
+ ));
+ } else {
+ return false;
+ }
}
-
+
return $this->elements[$name];
- }
+ }
+
+ /**
+ *
+ * Returns all elements of a certain type.
+ *
+ * @param string $type The element type.
+ *
+ * @return array List of elements.
+ *
+ */
+ public function getElementsByType($type)
+ {
+ $list = array();
+
+ foreach ($this->elements as $name => $elem) {
+ if ($elem['type'] == $type) {
+ $list[$name] = $elem;
+ }
+ }
+
+ return $list;
+ }

/**
*
@@ -264,7 +293,6 @@
$elem = $spec;
} else {
// set the name as part of the element data
- settype($spec, 'array');
$spec['name'] = $name;

// create the new element
@@ -312,7 +340,9 @@
*/
public function setAttribs($name, $attribs, $array = null)
{
- $this->getElement($name, $array)->setAttribs($attribs);
+ if ($elem = $this->getElement($name, $array)) {
+ $elem->setAttribs($attribs);
+ }
}

/**
@@ -330,7 +360,9 @@
*/
public function setType($name, $type, $array = null)
{
- $this->getElement($name, $array)->setType($type);
+ if ($elem = $this->getElement($name, $array)) {
+ $elem->setType($type);
+ }
}

/**
@@ -394,7 +426,9 @@
*/
public function addFilter($name, $spec, $array = null)
{
- $this->getElement($name, $array)->addFilter($spec);
+ if ($elem = $this->getElement($name, $array)) {
+ $elem->addFilter($spec);
+ }
}

/**
@@ -433,8 +467,10 @@
*/
public function addInvalid($name, $spec, $array = null)
{
- $this->getElement($name, $array)->addInvalid($spec);
- $this->_status = false;
+ if ($elem = $this->getElement($name, $array)) {
+ $elem->addInvalid($spec);
+ $this->_status = false;
+ }
}

/**
@@ -482,7 +518,9 @@
*/
public function setValue($name, $value, $array = null)
{
- $this->getElement($name, $array)->setValue($value);
+ if ($elem = $this->getElement($name, $array)) {
+ $elem->setValue($value);
+ }
}

/**

Reply all
Reply to author
Forward
0 new messages