cvs: pear /DB_DataObject_FormBuilder FormBuilder.php

From: Date: Wed, 08 Dec 2004 00:22:14 +0000
Subject: cvs: pear /DB_DataObject_FormBuilder FormBuilder.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-27061@lists.php.net to get a copy of this message
justinpatrin Tue Dec 7 19:22:14 2004 EDT Modified files: /pear/DB_DataObject_FormBuilder FormBuilder.php Log: Added casting of '' to NULL for link fields (for selectAddEmpty) Added automatic entry of an empty option for link fields which are not DB_DATAOBJECT_NOTNULL Please comment on this. I'm not sure it should be a default option.. Makes sense, but do other DBMS have NOTNULL? http://cvs.php.net/diff.php/pear/DB_DataObject_FormBuilder/FormBuilder.php?r1=1.83&r2=1.84&ty=u Index: pear/DB_DataObject_FormBuilder/FormBuilder.php diff -u pear/DB_DataObject_FormBuilder/FormBuilder.php:1.83 pear/DB_DataObject_FormBuilder/FormBuilder.php:1.84 --- pear/DB_DataObject_FormBuilder/FormBuilder.php:1.83 Tue Dec 7 18:47:19 2004 +++ pear/DB_DataObject_FormBuilder/FormBuilder.php Tue Dec 7 19:22:14 2004 @@ -97,7 +97,7 @@ * * @package DB_DataObject_FormBuilder * @author Markus Wolff <mw21st@php.net> - * @version $Id: FormBuilder.php,v 1.83 2004/12/07 23:47:19 justinpatrin Exp $ + * @version $Id: FormBuilder.php,v 1.84 2004/12/08 00:22:14 justinpatrin Exp $ */ // Import requirements @@ -862,7 +862,7 @@ $element =& $this->preDefElements[$key]; } elseif (is_array($links) && isset($links[$key])) { // If this field links to another table, display selectbox or radiobuttons - $opt = $this->getSelectOptions($key); + $opt = $this->getSelectOptions($key, false, !($type & DB_DATAOBJECT_NOTNULL)); if (isset($this->linkElementTypes[$key]) && $this->linkElementTypes[$key] == 'radio') { $element =& $this->_createRadioButtons($key, $opt); } else { @@ -1373,10 +1373,12 @@ * * @param string $field The field to fetch the links from. You should make sure the field actually *has* links before calling this function (see: DB_DataObject::links()) * @param string $displayFields (Optional) The name of the field used for the display text of the options + * @param bool $selectAddEmpty (Optional) If true, an empty option will be added to the list of options + * If false, the selectAddEmpty member var will be checked * @return array strings representing all of the records in the table $field links to. * @access public */ - function getSelectOptions($field, $displayFields = false) + function getSelectOptions($field, $displayFields = false, $selectAddEmpty = false) { if (empty($this->_do->_database)) { // TEMPORARY WORKAROUND !!! Guarantees that DataObject config has @@ -1388,7 +1390,7 @@ $res = $this->_getSelectOptions($link[0], $displayFields, - in_array($field, $this->selectAddEmpty)); + $selectAddEmpty || in_array($field, $this->selectAddEmpty)); if ($res !== false) { return $res; @@ -1784,6 +1786,7 @@ $editableFields = $this->_getUserEditableFields(); $tableFields = $this->_do->table(); + $links = $this->_do->links(); foreach ($values as $field => $value) { $this->debug('Field '.$field.' '); @@ -1809,7 +1812,15 @@ $value = call_user_func($this->dateToDatabaseCallback, $value);*/ } } + if (is_array($links) && isset($links[$field])) { + if ($value === '') { + $this->debug('Casting to NULL'); + require_once('DB/DataObject/Cast.php'); + $value = DB_DataObject_Cast::sql('NULL'); + } + } $this->debug('is substituted with "'.print_r($value, true).'".<br/>'); + // See if a setter method exists in the DataObject - if so, use that one if (method_exists($this->_do, 'set' . $field)) { $this->_do->{'set'.$field}($value);

« previous php.pear.cvs (#27061) next »