PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » Database » DB_DataObject_FormBuilder » Bug #3334

Support for "specialElements"

Details

Request #3334Support for "specialElements"
Submitted2005-01-31 01:55 UTC
Fromrolf at winmutt dot com
Assignedjustinpatrin
StatusNo Feedback
PackageDB_DataObject_FormBuilder
PHP Version5.0.3
OSANY
Roadmaps(Not assigned)

Comments

[2005-01-31 01:55 UTC] rolf at winmutt dot com

Description:
------------
This is a two part change request. One is the support of "specialElements" and the other is nested table entry (which for now could be treated as specialElements. I came accross this while trying to develop a "notes" table. One table (aka projects) has notes(basically contains note_title) and notes have note_entries. When displaying this in FormBuilder I would get a select box as expected. What I really wanted was a nested div of multiple note_entries and a textarea for a new note entry.

Below, I have included my suggested patch. I am obviously completely open to any type of comments. Essentially, you have additional functions fb_special_element and fb_process_special_element @ the dataobject extedned class level. This keeps most of the overhead out of FormBuilder. I have implemented this in order to support nested tables. The links file informs FormBuilder which subdo to call.

Furthermore, I believe a more generic handler should be part of FB for support of nested tables. In my Notes example, I wanted special rendering for note_entries. On the other hand, I have a "projects" table which has "time_segments" (time segments has a start and stop time, owner id and approval id). When creating a project, I want the user to be able to enter a time segment for the period of the project (atleast a start date, a stop date could be set later). This sub record needs to inserted or update before processing the parent record. My current hack allows for this to be handled manually.

Reproduce code:
---------------
winmutt@winmutt$ diff ~/tmp/DB_DataObject_FormBuilder-0.11.1/FormBuilder.php FormBuilder.php

116a117
> define ('DB_DATAOBJECT_FORMBUILDER_SPECIAL_ELEMENT',16777216);
573a575,581
> * Holds special elements data.
> * This list of Links will call $do->fb_special_element($this) of special DO.
> * Processing is handled via $do->fb_process_special_element($this)
> */
> var $specialElements = array();
>
> /**
782a791
>
1212a1222,1234
> case ($type & DB_DATAOBJECT_FORMBUILDER_SPECIAL_ELEMENT):
> list($linkedtable, $linkedfield) = explode(':', $links[$key]);
> $subDo = DB_DataObject::factory($linkedtable);
> if (method_exists($subDo, 'fb_special_element') && is_callable(array(get_class($subDo),'fb_special_element'))) {
> $ele =& $subDo->fb_special_element($key, $this);
> if (is_array($ele) ) {
> $specelements=&$ele;
> } else {
> $element=&$ele;
> }
> }
> //pre_r($element);
> break;
1234c1256,1260
< } elseif (isset($element)) {
---
> } elseif (isset($specelements)){
> foreach ($specelements as $v)
> $this->_addElementToForm($form, $v);
> unset($specelements);
> } elseif (isset($element)) {
1240c1266,1267
< } // End if
---
> }
> // End if
1396a1424,1426
> foreach ($this->specialElements as $specialElement) {
> $ret[$specialElement] = DB_DATAOBJECT_FORMBUILDER_SPECIAL_ELEMENT;
> }
1552a1583
>
2012d2042
<
2016a2047,2055
> // process specialElements
> foreach ($this->specialElements as $specialElement) {
> list($linkedtable, $linkedfield) = explode(':', $links[$specialElement]);
> $subDo = DB_DataObject::factory($linkedtable);
> if (method_exists($subDo, 'fb_process_special_element') && is_callable(array(get_class($subDo),'fb_process_special_element'))) {
> $subDo->fb_process_special_element($specialElement, &$values, &$this);
> }
> }
>
2098c2137,2138
< switch ($action) {
---
>
> switch ($action) {
2157c2197,2198
<
---
>
>