cvs: pear /DB_Table package.xml /DB_Table/DB Table.php /DB_Table/DB/Table QuickForm.php

From: Date: Wed, 17 Aug 2005 15:24:33 +0000
Subject: cvs: pear /DB_Table package.xml /DB_Table/DB Table.php /DB_Table/DB/Table QuickForm.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-34068@lists.php.net to get a copy of this message
wiesemann Wed Aug 17 11:24:33 2005 EDT Modified files: /pear/DB_Table package.xml /pear/DB_Table/DB Table.php /pear/DB_Table/DB/Table QuickForm.php Log: - first PEAR commit from the new maintainer of DB_Table - re-introduce feature request #4610: new "label" key for columns, as an addition to the "qf_label" key for column header in tabular formats - feature request #4941: new "qf_label_append" key for columns that will be displayed after (adv)checkbox QuickForm elements - bugfix: QuickForm's date "element" is a group, therefore we have to use addGroupRule() instead of addRule() for such elements; this also fixes a bug with non-standard rules when only an error message was given in the rule definition (missing $format param) - feature request #5029: new "qf_filters" key for columns that applies filters to DB_Table generated forms; with the new $formFilters parameter in getForm() one can apply filters to all form elements (thanks to ieure at php dot net)

http://cvs.php.net/diff.php/pear/DB_Table/package.xml?r1=1.32&r2=1.33&ty=u Index: pear/DB_Table/package.xml diff -u pear/DB_Table/package.xml:1.32 pear/DB_Table/package.xml:1.33 --- pear/DB_Table/package.xml:1.32 Sun Aug 7 15:33:54 2005 +++ pear/DB_Table/package.xml Wed Aug 17 11:24:32 2005 @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="ISO-8859-1" ?> <!DOCTYPE package SYSTEM "http://pear.php.net/dtd/package-1.0"> -<!-- $Id: package.xml,v 1.32 2005/08/07 19:33:54 pmjones Exp $ --> +<!-- $Id: package.xml,v 1.33 2005/08/17 15:24:32 wiesemann Exp $ --> <package version="1.0"> <name>DB_Table</name> <summary>Builds on PEAR DB to abstract datatypes and automate table creation, data validation, insert, update, delete, and select; combines these with PEAR HTML_QuickForm to automatically generate input forms that match the table column definitions.</summary> @@ -13,33 +13,38 @@ <email>pmjones@php.net</email> <role>lead</role> </maintainer> + <maintainer> + <user>wiesemann</user> + <name>Mark Wiesemann</name> + <email>wiesemann@php.net</email> + <role>lead</role> + </maintainer> </maintainers> <release> - <version>1.1.0</version> - <date>2005-08-07</date> + <version>1.2.0</version> + <date>2005-08-??</date> <state>stable</state> <notes> - * Added 'mysqli' support; thanks, James Kachel. - - * Applied patch to allow passing of placeholder - substitutions in select(), selectResult(), and - selectCount(). Thanks, Matthew Weier O'Phinney. - - * Added request #4610 to add a 'label' key to column - definitions. this is in addition to the 'qf_label' key; - the qf_label key is for form labels, but the label key is - for column headers on tabular formats. - - * Added more-reliable way of generating the name and label - for a group when using addElements(), particularly with - respect to radio button sets. This fixes bug #4935, - "element names as array-keys not respected for radio - buttons." - - * Fixed bug #4614; you can now specify the separator string - for radio buttons using the 'qf_radiosep' key; default is - '&lt;br /&gt;'. - + * Re-added request #4610 to add a 'label' key to column + definitions. this is in addition to the 'qf_label' key; + the qf_label key is for form labels, but the label key is + for column headers on tabular formats. + + * Feature request #4941: new "qf_label_append" key for + columns that will be displayed after (adv)checkbox + QuickForm elements. + + * Bugfix: QuickForm's date "element" is a group, therefore + we have to use addGroupRule() instead of addRule() for such + elements; this also fixes a bug with non-standard rules + when only an error message was given in the rule definition + (missing $format param). + + * Feature request #5029: new "qf_filters" key for columns + that applies filters to DB_Table generated forms; with the + new $formFilters parameter in getForm() one can apply + filters to all form elements + (thanks to ieure at php dot net) </notes> <filelist> http://cvs.php.net/diff.php/pear/DB_Table/DB/Table.php?r1=1.32&r2=1.33&ty=u Index: pear/DB_Table/DB/Table.php diff -u pear/DB_Table/DB/Table.php:1.32 pear/DB_Table/DB/Table.php:1.33 --- pear/DB_Table/DB/Table.php:1.32 Sat Aug 6 13:14:21 2005 +++ pear/DB_Table/DB/Table.php Wed Aug 17 11:24:32 2005 @@ -18,7 +18,7 @@ * * @license http://www.gnu.org/copyleft/lesser.html LGPL * -* @version $Id: Table.php,v 1.32 2005/08/06 17:14:21 pmjones Exp $ +* @version $Id: Table.php,v 1.33 2005/08/17 15:24:32 wiesemann Exp $ * */ @@ -342,7 +342,7 @@ * * @author Paul M. Jones <pmjones@php.net> * -* @version @package_version@ +* @version 1.1.0 * */ @@ -1901,6 +1901,14 @@ * 'trackSubmit' : Boolean, whether to track if the form was * submitted by adding a special hidden field * + * @param string $clientValidate By default, validation will match + * the 'qf_client' value from the column definition. However, + * if you set $clientValidate to true or false, this will + * override the value from the column definition. + * + * @param array $formFilters An array with filter function names or + * callbacks that will be applied to all form elements. + * * @return object HTML_QuickForm * * @see HTML_QuickForm @@ -1910,12 +1918,12 @@ */ function &getForm($columns = null, $array_name = null, $args = array(), - $clientValidate = null) + $clientValidate = null, $formFilters = null) { include_once 'DB/Table/QuickForm.php'; $coldefs = $this->_getFormColDefs($columns); return DB_Table_QuickForm::getForm($coldefs, $array_name, $args, - $clientValidate); + $clientValidate, $formFilters); } http://cvs.php.net/diff.php/pear/DB_Table/DB/Table/QuickForm.php?r1=1.24&r2=1.25&ty=u Index: pear/DB_Table/DB/Table/QuickForm.php diff -u pear/DB_Table/DB/Table/QuickForm.php:1.24 pear/DB_Table/DB/Table/QuickForm.php:1.25 --- pear/DB_Table/DB/Table/QuickForm.php:1.24 Sat Aug 6 12:37:33 2005 +++ pear/DB_Table/DB/Table/QuickForm.php Wed Aug 17 11:24:32 2005 @@ -8,10 +8,11 @@ * @package DB_Table * * @author Paul M. Jones <pmjones@php.net> +* @author Mark Wiesemann <wiesemann@php.net> * * @license http://www.gnu.org/copyleft/lesser.html LGPL * -* @version $Id: QuickForm.php,v 1.24 2005/08/06 16:37:33 pmjones Exp $ +* @version $Id: QuickForm.php,v 1.25 2005/08/17 15:24:32 wiesemann Exp $ * */ @@ -45,6 +46,7 @@ * @package DB_Table * * @author Paul M. Jones <pmjones@ciaweb.net> +* @author Mark Wiesemann <wiesemann@php.net> * */ @@ -91,6 +93,9 @@ * the 'qf_client' value from the column definition. However, * if you set $clientValidate to true or false, this will * override the value from the column definition. + * + * @param array $formFilters An array with filter function names or + * callbacks that will be applied to all form elements. * * @return object HTML_QuickForm * @@ -101,11 +106,12 @@ */ function &getForm($cols, $arrayName = null, $args = array(), - $clientValidate = null) + $clientValidate = null, $formFilters = null) { $form =& DB_Table_QuickForm::createForm($args); DB_Table_QuickForm::addElements($form, $cols, $arrayName); DB_Table_QuickForm::addRules($form, $cols, $arrayName, $clientValidate); + DB_Table_QuickForm::addFilters($form, $cols, $arrayName, $formFilters); return $form; } @@ -317,7 +323,8 @@ 'advcheckbox', $elemname, $col['qf_label'], - null, + isset($col['qf_label_append']) ? + $col['qf_label_append'] : null, $col['qf_attrs'], $col['qf_vals'] ); @@ -571,6 +578,55 @@ /** + * + * Adds DB_Table filters to a pre-existing HTML_QuickForm object. + * + * @static + * + * @access public + * + * @param object &$form An HTML_QuickForm object. + * + * @param array $cols A sequential array of DB_Table column definitions + * from which to create form elements. + * + * @param string $arrayName By default, the form will use the names + * of the columns as the names of the form elements. If you pass + * $arrayName, the column names will become keys in an array named + * for this parameter. + * + * @param array $formFilters An array with filter function names or + * callbacks that will be applied to all form elements. + * + * @return void + * + */ + function addFilters(&$form, $cols, $arrayName = null, + $formFilters = null) + { + foreach ($cols as $name => $col) { + if ($arrayName) { + $elemname = $arrayName . "[$name]"; + } else { + $elemname = $name; + } + + DB_Table_QuickForm::fixColDef($col, $elemname); + + foreach (array_keys($col['qf_filters']) as $fk) { + $form->applyFilter($elemname, $col['qf_filters'][$fk]); + } + } + + if (is_array($formFilters)) { + foreach (array_keys($formFilters) as $fk) { + $form->applyFilter('__ALL__', $formFilters[$fk]); + } + } + } + + + /** * * Adds element rules to a pre-existing HTML_QuickForm object. * @@ -655,7 +711,8 @@ case 'required': case 'uploadedfile': // $opts is the error message - $form->addRule($elemname, $opts, $type, null, $validate); + $message = $opts; + $format = null; break; case 'filename': @@ -666,23 +723,43 @@ case 'regex': // $opts[0] is the message // $opts[1] is the size, mimetype, or regex - $form->addRule($elemname, $opts[0], $type, $opts[1], - $validate); + $message = $opts[0]; + $format = $opts[1]; break; default: // by Alex Hoebart: this should allow any registered rule. if (in_array($type,$form->getRegisteredRules())) { if (is_array($opts)) { - // $opts[0] is the message, $opts[1] is the size or regex - $form->addRule($elemname, $opts[0], $type, $opts[1], $validate); + // $opts[0] is the message + // $opts[1] is the size or regex + $message = $opts[0]; + $format = $opts[1]; } else { // $opts is the error message - $form->addRule($elemname, $opts, $type, $validate); + $message = $opts; + $format = null; } + } else { // rule is not registered ==> do not add a rule + continue; } break; } + + switch ($col['qf_type']) { + case 'date': + case 'time': + case 'timestamp': + // date "elements" are groups ==> use addGroupRule() + $form->addGroupRule($elemname, $message, $type, $format, + null, $validate); + break; + default: // use addRule() for all other elements + $form->addRule($elemname, $message, $type, $format, + $validate); + break; + } + } } } @@ -726,6 +803,10 @@ if (! isset($col['qf_client'])) { $col['qf_client'] = false; } + + if (! isset($col['qf_filters'])) { + $col['qf_filters'] = array(); + } // the element type; if not set, // assigns an element type based on the column type. @@ -769,12 +850,6 @@ // label for the element; defaults to the element // name. adds both quickform label and table-header // label if qf_label is not set. - - if (! isset($col['qf_label'])) { - $col['qf_label'] = $elemname . ':'; - } - - /* if (! isset($col['qf_label'])) { if (isset($col['label'])) { $col['qf_label'] = $col['label']; @@ -783,7 +858,6 @@ $col['qf_label'] = $elemname . ':'; } } - */ // special options for the element, typically used // for 'date' element types
« previous php.pear.cvs (#34068) next »