Class: I2CE Form: Difference between revisions
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
This article desrcibes the class '''I2CE_Form''' | This article desrcibes the class '''I2CE_Form'''. | ||
*Extends the class: [[Class: I2CE_Fuzzy | I2CE_Fuzzy]]. | |||
*Implements the interface [http://www.php.net/manual/en/class.iterator.php Iterator ] | |||
It is contained in the module [[iHRIS Module List#forms|forms]] in the package [https://launchpad.net/i2ce I2CE] | It is contained in the module [[iHRIS Module List#forms|forms]] in the package [https://launchpad.net/i2ce I2CE] | ||
Line 27: | Line 27: | ||
===$parent=== | ===$parent=== | ||
String or boolean (false) The form and id of the parent record for this form if there is one. Of the form "$form|$id" | String or boolean (false) The form and id of the parent record for this form if there is one. Of the form "$form|$id" | ||
*Type: protected [http://www.php.net/manual/en/language.pseudo-types.php mixed] $parent | *Type: protected [http://www.php.net/manual/en/language.pseudo-types.php mixed ] $parent | ||
===$id=== | ===$id=== | ||
The record id for this entry. | The record id for this entry. | ||
*Type: protected [http://www.php.net/manual/en/language.pseudo-types.php mixed] $id | *Type: protected [http://www.php.net/manual/en/language.pseudo-types.php mixed ] $id | ||
===$children=== | ===$children=== | ||
Line 54: | Line 54: | ||
*Signature: public function __construct($form,$id) | *Signature: public function __construct($form,$id) | ||
Parameters: | Parameters: | ||
* [http://www.php.net/manual/en/language.types.string.php string] $form<br/>The name of this form | * [http://www.php.net/manual/en/language.types.string.php string ] $form<br/>The name of this form | ||
* integer $id | * integer $id | ||
**Default Value: '0' | **Default Value: '0' | ||
Line 60: | Line 60: | ||
Return the {@link I2CE_FormField form field} value from the {@link $fields} array. | Return the {@link I2CE_FormField form field} value from the {@link $fields} array. | ||
*Signature: protected function __get($key) | *Signature: protected function __get($key) | ||
*Returns: [http://www.php.net/manual/en/language.pseudo-types.php mixed] | *Returns: [http://www.php.net/manual/en/language.pseudo-types.php mixed ] | ||
Parameters: | Parameters: | ||
* [http://www.php.net/manual/en/language.types.string.php string] $key | * [http://www.php.net/manual/en/language.types.string.php string ] $key | ||
===__isset()=== | ===__isset()=== | ||
Check to see if a {@link I2CE_FormField form field} value has been set. | Check to see if a {@link I2CE_FormField form field} value has been set. | ||
*Signature: protected function __isset($key) | *Signature: protected function __isset($key) | ||
*Returns: [http://www.php.net/manual/en/language.types.boolean.php boolean] | *Returns: [http://www.php.net/manual/en/language.types.boolean.php boolean ] | ||
Parameters: | Parameters: | ||
* [http://www.php.net/manual/en/language.types.string.php string] $key | * [http://www.php.net/manual/en/language.types.string.php string ] $key | ||
===__set()=== | ===__set()=== | ||
Set the {@link I2CE_FormField form field} value in the {@link $fields} array. | Set the {@link I2CE_FormField form field} value in the {@link $fields} array. | ||
*Signature: protected function __set($key,$value) | *Signature: protected function __set($key,$value) | ||
Parameters: | Parameters: | ||
* [http://www.php.net/manual/en/language.types.string.php string] $key | * [http://www.php.net/manual/en/language.types.string.php string ] $key | ||
* [http://www.php.net/manual/en/language.pseudo-types.php mixed] $value | * [http://www.php.net/manual/en/language.pseudo-types.php mixed ] $value | ||
===__unset()=== | ===__unset()=== | ||
Unset a {@link I2CE_FormField form field}. | Unset a {@link I2CE_FormField form field}. | ||
*Signature: protected function __unset($key) | *Signature: protected function __unset($key) | ||
Parameters: | Parameters: | ||
* [http://www.php.net/manual/en/language.types.string.php string] $key | * [http://www.php.net/manual/en/language.types.string.php string ] $key | ||
===addChildForm()=== | ===addChildForm()=== | ||
Add a child form object to this forms list of children. | Add a child form object to this forms list of children. | ||
Line 85: | Line 85: | ||
Parameters: | Parameters: | ||
* [[Class: I2CE_Form | I2CE_Form]] $child_form<br/>The child form | * [[Class: I2CE_Form | I2CE_Form]] $child_form<br/>The child form | ||
* [http://www.php.net/manual/en/language.types.boolean.php boolean] $replace<br/>Overwrite the child object if it already exists. | * [http://www.php.net/manual/en/language.types.boolean.php boolean ] $replace<br/>Overwrite the child object if it already exists. | ||
**Default Value: false | **Default Value: false | ||
===addField()=== | ===addField()=== | ||
Adds a field to this form. | Adds a field to this form. | ||
*Signature: public function addField($name,$args) | *Signature: public function addField($name,$args) | ||
*Returns: [http://www.php.net/manual/en/language.pseudo-types.php mixed] I2CE_FormField or false on failure | *Returns: [http://www.php.net/manual/en/language.pseudo-types.php mixed ] I2CE_FormField or false on failure | ||
Parameters: | Parameters: | ||
* [http://www.php.net/manual/en/language.types.string.php string] $name | * [http://www.php.net/manual/en/language.types.string.php string ] $name | ||
* [http://www.php.net/manual/en/language.types.array.php array] $args<br/>The arguments for this field | * [http://www.php.net/manual/en/language.types.array.php array ] $args<br/>The arguments for this field | ||
===addFormFields()=== | ===addFormFields()=== | ||
*Signature: protected function addFormFields($data) | *Signature: protected function addFormFields($data) | ||
Line 113: | Line 113: | ||
*Signature: public function clearFields($fields,$keep) | *Signature: public function clearFields($fields,$keep) | ||
Parameters: | Parameters: | ||
* [http://www.php.net/manual/en/language.types.array.php array] $fields<br/>The fields being worked with. | * [http://www.php.net/manual/en/language.types.array.php array ] $fields<br/>The fields being worked with. | ||
* [http://www.php.net/manual/en/language.types.boolean.php boolean] $keep<br/>A flag to determine if the given fields should be removed or all except the given fields. | * [http://www.php.net/manual/en/language.types.boolean.php boolean ] $keep<br/>A flag to determine if the given fields should be removed or all except the given fields. | ||
**Default Value: true | **Default Value: true | ||
===current()=== | ===current()=== | ||
Return the current value for the {@link $fields} array for iterating through the form fields. | Return the current value for the {@link $fields} array for iterating through the form fields. | ||
*Signature: public function current() | *Signature: public function current() | ||
*Returns: [http://www.php.net/manual/en/language.pseudo-types.php mixed] | *Returns: [http://www.php.net/manual/en/language.pseudo-types.php mixed ] | ||
===displayField()=== | ===displayField()=== | ||
Display the field in the given node. | Display the field in the given node. | ||
*Signature: public function displayField($node,$template,$args) | *Signature: public function displayField($node,$template,$args) | ||
Parameters: | Parameters: | ||
* [http://www.php.net/manual/en/class.domnode.php | * [http://www.php.net/manual/en/class.domnode.php DOMNode ] $node | ||
* [[Class: I2CE_Template | I2CE_Template]] $template | * [[Class: I2CE_Template | I2CE_Template]] $template | ||
* [http://www.php.net/manual/en/language.types.array.php array] $args | * [http://www.php.net/manual/en/language.types.array.php array ] $args | ||
===form()=== | ===form()=== | ||
Return the form name for this form. | Return the form name for this form. | ||
*Signature: public function form() | *Signature: public function form() | ||
*Returns: [http://www.php.net/manual/en/language.types.string.php string] | *Returns: [http://www.php.net/manual/en/language.types.string.php string ] | ||
===getAllowedParentForms()=== | ===getAllowedParentForms()=== | ||
Gets the allowed parent forms for a given form | Gets the allowed parent forms for a given form | ||
*Signature: static public function getAllowedParentForms($form,$use_cache) | *Signature: static public function getAllowedParentForms($form,$use_cache) | ||
*Returns: [http://www.php.net/manual/en/language.types.array.php array] of string, the form names. | *Returns: [http://www.php.net/manual/en/language.types.array.php array ] of string, the form names. | ||
Parameters: | Parameters: | ||
* [http://www.php.net/manual/en/language.types.string.php string] $form | * [http://www.php.net/manual/en/language.types.string.php string ] $form | ||
* [http://www.php.net/manual/en/language.types.boolean.php boolean] $use_cache<br/>Defaults to true in which case we cached result of finding parent forms | * [http://www.php.net/manual/en/language.types.boolean.php boolean ] $use_cache<br/>Defaults to true in which case we cached result of finding parent forms | ||
**Default Value: true | **Default Value: true | ||
===getAttribute()=== | ===getAttribute()=== | ||
Return the attribute value for a given attribute. | Return the attribute value for a given attribute. | ||
*Signature: public function getAttribute($key) | *Signature: public function getAttribute($key) | ||
*Returns: [http://www.php.net/manual/en/language.pseudo-types.php mixed] | *Returns: [http://www.php.net/manual/en/language.pseudo-types.php mixed ] | ||
Parameters: | Parameters: | ||
* [http://www.php.net/manual/en/language.types.string.php string] $key | * [http://www.php.net/manual/en/language.types.string.php string ] $key | ||
===getChildForms()=== | ===getChildForms()=== | ||
Get the registered child forms for this form. | Get the registered child forms for this form. | ||
*Signature: public function getChildForms() | *Signature: public function getChildForms() | ||
*Returns: [http://www.php.net/manual/en/language.types.array.php array] The list of child form names registered for this form. | *Returns: [http://www.php.net/manual/en/language.types.array.php array ] The list of child form names registered for this form. | ||
===getChildFormsByForm()=== | ===getChildFormsByForm()=== | ||
Get the registered child forms for the given form. | Get the registered child forms for the given form. | ||
*Signature: static public function getChildFormsByForm($form) | *Signature: static public function getChildFormsByForm($form) | ||
*Returns: [http://www.php.net/manual/en/language.types.array.php array] The list of child form names registered for the form. | *Returns: [http://www.php.net/manual/en/language.types.array.php array ] The list of child form names registered for the form. | ||
Parameters: | Parameters: | ||
* [http://www.php.net/manual/en/language.types.string.php string] $form<br/>The form to get the children of. | * [http://www.php.net/manual/en/language.types.string.php string ] $form<br/>The form to get the children of. | ||
===getChildren()=== | ===getChildren()=== | ||
Get the added children for this form | Get the added children for this form | ||
otherwise we get the popoluated children with the specified form | otherwise we get the popoluated children with the specified form | ||
*Signature: public function getChildren($form) | *Signature: public function getChildren($form) | ||
*Returns: [http://www.php.net/manual/en/language.types.array.php array] If $form is null, it is an array with keys the form names and values array | *Returns: [http://www.php.net/manual/en/language.types.array.php array ] If $form is null, it is an array with keys the form names and values array | ||
of the children of that form type. If $form is | of the children of that form type. If $form is | ||
set, then it is an array of the forms of type $form | set, then it is an array of the forms of type $form | ||
Parameters: | Parameters: | ||
* [http://www.php.net/manual/en/language.types.string.php string] $form<br/>Defaults to null, in which case we get all children. | * [http://www.php.net/manual/en/language.types.string.php string ] $form<br/>Defaults to null, in which case we get all children. | ||
**Default Value: null | **Default Value: null | ||
===getDisplayName()=== | ===getDisplayName()=== | ||
Return the display name for this form object. | Return the display name for this form object. | ||
*Signature: public function getDisplayName() | *Signature: public function getDisplayName() | ||
*Returns: [http://www.php.net/manual/en/language.types.string.php string] | *Returns: [http://www.php.net/manual/en/language.types.string.php string ] | ||
===getField()=== | ===getField()=== | ||
Return the I2CE_FormField for the given field name. | Return the I2CE_FormField for the given field name. | ||
Line 174: | Line 174: | ||
*Returns: [[Class: I2CE_FormField | I2CE_FormField]] | *Returns: [[Class: I2CE_FormField | I2CE_FormField]] | ||
Parameters: | Parameters: | ||
* [http://www.php.net/manual/en/language.types.string.php string] $field<br/>the field name or a form name:field name | * [http://www.php.net/manual/en/language.types.string.php string ] $field<br/>the field name or a form name:field name | ||
===getFieldNames()=== | ===getFieldNames()=== | ||
Get the names of all the fields added in this form | Get the names of all the fields added in this form | ||
*Signature: public function getFieldNames() | *Signature: public function getFieldNames() | ||
*Returns: [http://www.php.net/manual/en/language.types.array.php array] of string, the field names. | *Returns: [http://www.php.net/manual/en/language.types.array.php array ] of string, the field names. | ||
===getFormFieldsData()=== | ===getFormFieldsData()=== | ||
*Signature: protected function getFormFieldsData($class,$data) | *Signature: protected function getFormFieldsData($class,$data) | ||
Line 187: | Line 187: | ||
Returns the form id for this record. | Returns the form id for this record. | ||
*Signature: public function getFormId() | *Signature: public function getFormId() | ||
*Returns: [http://www.php.net/manual/en/language.types.string.php string] of the form "$form|$id" | *Returns: [http://www.php.net/manual/en/language.types.string.php string ] of the form "$form|$id" | ||
===getHTMLName()=== | ===getHTMLName()=== | ||
Return the value for the name attribute to be used for this field in a form. | Return the value for the name attribute to be used for this field in a form. | ||
*Signature: public function getHTMLName() | *Signature: public function getHTMLName() | ||
*Returns: [http://www.php.net/manual/en/language.types.string.php string] | *Returns: [http://www.php.net/manual/en/language.types.string.php string ] | ||
===getId()=== | ===getId()=== | ||
Returns the id for this record. | Returns the id for this record. | ||
*Signature: public function getId() | *Signature: public function getId() | ||
*Returns: [http://www.php.net/manual/en/language.types.string.php string] | *Returns: [http://www.php.net/manual/en/language.types.string.php string ] | ||
===getParent()=== | ===getParent()=== | ||
Return the parent id for this record. | Return the parent id for this record. | ||
Line 217: | Line 217: | ||
Return the values of all the fields that are set. | Return the values of all the fields that are set. | ||
*Signature: public function getQueryDisplay() | *Signature: public function getQueryDisplay() | ||
*Returns: [http://www.php.net/manual/en/language.types.string.php string] | *Returns: [http://www.php.net/manual/en/language.types.string.php string ] | ||
===getQueryFields()=== | ===getQueryFields()=== | ||
Return all the fields as an associative array | Return all the fields as an associative array | ||
*Signature: public function getQueryFields() | *Signature: public function getQueryFields() | ||
*Returns: [http://www.php.net/manual/en/language.types.array.php array] | *Returns: [http://www.php.net/manual/en/language.types.array.php array ] | ||
===getQueryString()=== | ===getQueryString()=== | ||
Return all the fields as a query string to be sent to a URL | Return all the fields as a query string to be sent to a URL | ||
*Signature: public function getQueryString() | *Signature: public function getQueryString() | ||
*Returns: [http://www.php.net/manual/en/language.types.string.php string] | *Returns: [http://www.php.net/manual/en/language.types.string.php string ] | ||
===hasAttribute()=== | ===hasAttribute()=== | ||
Return true if a given attribute exists for this form. | Return true if a given attribute exists for this form. | ||
Line 231: | Line 231: | ||
*Returns: boolean; | *Returns: boolean; | ||
Parameters: | Parameters: | ||
* [http://www.php.net/manual/en/language.types.string.php string] $key | * [http://www.php.net/manual/en/language.types.string.php string ] $key | ||
===hasInvalid()=== | ===hasInvalid()=== | ||
Checks to see if any fields of form has in invalid message | Checks to see if any fields of form has in invalid message | ||
*Signature: public function hasInvalid() | *Signature: public function hasInvalid() | ||
*Returns: [http://www.php.net/manual/en/language.types.boolean.php boolean] | *Returns: [http://www.php.net/manual/en/language.types.boolean.php boolean ] | ||
===key()=== | ===key()=== | ||
Return the current key for the {@link $fields} array for iterating through the form fields. | Return the current key for the {@link $fields} array for iterating through the form fields. | ||
*Signature: public function key() | *Signature: public function key() | ||
*Returns: [http://www.php.net/manual/en/language.pseudo-types.php mixed] | *Returns: [http://www.php.net/manual/en/language.pseudo-types.php mixed ] | ||
===listFields()=== | ===listFields()=== | ||
If it is as an array of two integers, it is the offset and then number of results to limit to. | If it is as an array of two integers, it is the offset and then number of results to limit to. | ||
*Signature: static public function listFields($form,$fields,$where_data,$ordering,$limit) | *Signature: static public function listFields($form,$fields,$where_data,$ordering,$limit) | ||
*Returns: [http://www.php.net/manual/en/language.pseudo-types.php mixed] an array with key id's and value and array of values. the array of values has as keys the fields with their corresponding value. | *Returns: [http://www.php.net/manual/en/language.pseudo-types.php mixed ] an array with key id's and value and array of values. the array of values has as keys the fields with their corresponding value. | ||
Parameters: | Parameters: | ||
* [http://www.php.net/manual/en/language.types.string.php string] $form<br/>The form name | * [http://www.php.net/manual/en/language.types.string.php string ] $form<br/>The form name | ||
* [http://www.php.net/manual/en/language.types.array.php array] $fields<br/>of string. The fields we want returned | * [http://www.php.net/manual/en/language.types.array.php array ] $fields<br/>of string. The fields we want returned | ||
* [http://www.php.net/manual/en/language.pseudo-types.php mixed] $where_data<br/>Either I2CE_MagicDataNode or array. contains the where clause information about this form or a nested | * [http://www.php.net/manual/en/language.pseudo-types.php mixed ] $where_data<br/>Either I2CE_MagicDataNode or array. contains the where clause information about this form or a nested | ||
**Default Value: array() | **Default Value: array() | ||
* [http://www.php.net/manual/en/language.types.array.php array] $ordering<br/>An array of fields to order by. Defaults to the empty array. Prepend a - to order by in descending order. | * [http://www.php.net/manual/en/language.types.array.php array ] $ordering<br/>An array of fields to order by. Defaults to the empty array. Prepend a - to order by in descending order. | ||
**Default Value: array() | **Default Value: array() | ||
* [http://www.php.net/manual/en/language.pseudo-types.php mixed] $limit<br/>Defaults to false. It true, returns only one result. If an integer it is the numeber of records to limit to. | * [http://www.php.net/manual/en/language.pseudo-types.php mixed ] $limit<br/>Defaults to false. It true, returns only one result. If an integer it is the numeber of records to limit to. | ||
**Default Value: false | **Default Value: false | ||
===load()=== | ===load()=== | ||
Line 261: | Line 261: | ||
*Signature: public function load($post,$loadID,$populate_on_set_id) | *Signature: public function load($post,$loadID,$populate_on_set_id) | ||
Parameters: | Parameters: | ||
* [http://www.php.net/manual/en/language.types.array.php array] $post<br/>The Post vairables. Usually from an http request. | * [http://www.php.net/manual/en/language.types.array.php array ] $post<br/>The Post vairables. Usually from an http request. | ||
* [http://www.php.net/manual/en/language.types.boolean.php boolean] $loadID<br/>Defaults to true. If true, and there is | * [http://www.php.net/manual/en/language.types.boolean.php boolean ] $loadID<br/>Defaults to true. If true, and there is | ||
**Default Value: true | **Default Value: true | ||
*$populate_on_set_id | *$populate_on_set_id | ||
Line 269: | Line 269: | ||
Lookup a given id in the given array. | Lookup a given id in the given array. | ||
*Signature: static protected function lookupArray($id,$arr) | *Signature: static protected function lookupArray($id,$arr) | ||
*Returns: [http://www.php.net/manual/en/language.types.string.php string] | *Returns: [http://www.php.net/manual/en/language.types.string.php string ] | ||
Parameters: | Parameters: | ||
* integer $id<br/>The id to lookup. | * integer $id<br/>The id to lookup. | ||
* [http://www.php.net/manual/en/language.types.array.php array] $arr<br/>The array to search through. | * [http://www.php.net/manual/en/language.types.array.php array ] $arr<br/>The array to search through. | ||
===next()=== | ===next()=== | ||
Advance the internal pointer for the {@link $fields} array for iterating through the form fields. | Advance the internal pointer for the {@link $fields} array for iterating through the form fields. | ||
Line 280: | Line 280: | ||
*Signature: public function processDOM($node,$template,$method,$args) | *Signature: public function processDOM($node,$template,$method,$args) | ||
Parameters: | Parameters: | ||
* [http://www.php.net/manual/en/class.domnode.php | * [http://www.php.net/manual/en/class.domnode.php DOMNode ] $node | ||
* [[Class: I2CE_Template | I2CE_Template]] $template | * [[Class: I2CE_Template | I2CE_Template]] $template | ||
* [http://www.php.net/manual/en/language.types.string.php string] $method | * [http://www.php.net/manual/en/language.types.string.php string ] $method | ||
* [http://www.php.net/manual/en/language.types.array.php array] $args | * [http://www.php.net/manual/en/language.types.array.php array ] $args | ||
===removeField()=== | ===removeField()=== | ||
Removes a field from this form. | Removes a field from this form. | ||
Line 289: | Line 289: | ||
*Signature: public function removeField($name) | *Signature: public function removeField($name) | ||
Parameters: | Parameters: | ||
* [http://www.php.net/manual/en/language.types.string.php string] $name | * [http://www.php.net/manual/en/language.types.string.php string ] $name | ||
===reset()=== | ===reset()=== | ||
Reset this object to its original state. | Reset this object to its original state. | ||
Line 300: | Line 300: | ||
If it is as an array of two integers, it is the offset and then number of results to limit to. | If it is as an array of two integers, it is the offset and then number of results to limit to. | ||
*Signature: static public function search($form,$where_data,$ordering,$limit_one) | *Signature: static public function search($form,$where_data,$ordering,$limit_one) | ||
*Returns: [http://www.php.net/manual/en/language.pseudo-types.php mixed] an array of matching form ids. However, ff $limit_one is true or 1 or | *Returns: [http://www.php.net/manual/en/language.pseudo-types.php mixed ] an array of matching form ids. However, ff $limit_one is true or 1 or | ||
array ($offset,1) then then we return either the id or false, if none found or there was an error. | array ($offset,1) then then we return either the id or false, if none found or there was an error. | ||
Parameters: | Parameters: | ||
* [http://www.php.net/manual/en/language.types.string.php string] $form<br/>The form name. | * [http://www.php.net/manual/en/language.types.string.php string ] $form<br/>The form name. | ||
* [http://www.php.net/manual/en/language.pseudo-types.php mixed] $where_data<br/>Either I2CE_MagicDataNode or array. contains the where clause information about this form or a nested | * [http://www.php.net/manual/en/language.pseudo-types.php mixed ] $where_data<br/>Either I2CE_MagicDataNode or array. contains the where clause information about this form or a nested | ||
**Default Value: array() | **Default Value: array() | ||
* [http://www.php.net/manual/en/language.types.array.php array] $ordering<br/>An array of fields to order by. Defaults to the empty array. Prepend a - to order by in descending order. | * [http://www.php.net/manual/en/language.types.array.php array ] $ordering<br/>An array of fields to order by. Defaults to the empty array. Prepend a - to order by in descending order. | ||
**Default Value: array() | **Default Value: array() | ||
*$limit_one | *$limit_one | ||
Line 314: | Line 314: | ||
*Signature: public function setAttribute($key,$value) | *Signature: public function setAttribute($key,$value) | ||
Parameters: | Parameters: | ||
* [http://www.php.net/manual/en/language.types.string.php string] $key | * [http://www.php.net/manual/en/language.types.string.php string ] $key | ||
* [http://www.php.net/manual/en/language.pseudo-types.php mixed] $value | * [http://www.php.net/manual/en/language.pseudo-types.php mixed ] $value | ||
===setDisplayName()=== | ===setDisplayName()=== | ||
Set the display name for this form object. | Set the display name for this form object. | ||
*Signature: final public function setDisplayName($display) | *Signature: final public function setDisplayName($display) | ||
Parameters: | Parameters: | ||
* [http://www.php.net/manual/en/language.types.string.php string] $display | * [http://www.php.net/manual/en/language.types.string.php string ] $display | ||
===setForm()=== | ===setForm()=== | ||
Set the form name for this form object. | Set the form name for this form object. | ||
*Signature: final public function setForm($name) | *Signature: final public function setForm($name) | ||
Parameters: | Parameters: | ||
* [http://www.php.net/manual/en/language.types.string.php string] $name | * [http://www.php.net/manual/en/language.types.string.php string ] $name | ||
===setFromPost()=== | ===setFromPost()=== | ||
Load the member variables from an array | Load the member variables from an array | ||
Line 332: | Line 332: | ||
*Signature: public function setFromPost($post,$populate_on_set_id) | *Signature: public function setFromPost($post,$populate_on_set_id) | ||
Parameters: | Parameters: | ||
* [http://www.php.net/manual/en/language.types.array.php array] $post<br/>The post object is passed as a reference | * [http://www.php.net/manual/en/language.types.array.php array ] $post<br/>The post object is passed as a reference | ||
*$populate_on_set_id | *$populate_on_set_id | ||
**Default Value: false | **Default Value: false | ||
Line 339: | Line 339: | ||
*Signature: public function setId($id) | *Signature: public function setId($id) | ||
Parameters: | Parameters: | ||
* [http://www.php.net/manual/en/language.pseudo-types.php mixed] $id | * [http://www.php.net/manual/en/language.pseudo-types.php mixed ] $id | ||
===setParent()=== | ===setParent()=== | ||
Set the parent id for this record | Set the parent id for this record | ||
*Signature: public function setParent($parent,$set_id) | *Signature: public function setParent($parent,$set_id) | ||
Parameters: | Parameters: | ||
* [http://www.php.net/manual/en/language.pseudo-types.php mixed] $parent<br/>string or I2CE_Form | * [http://www.php.net/manual/en/language.pseudo-types.php mixed ] $parent<br/>string or I2CE_Form | ||
* [http://www.php.net/manual/en/language.types.boolean.php boolean] $set_id<br/>If the parent will only have one child object then you can set the id by setting this to true. | * [http://www.php.net/manual/en/language.types.boolean.php boolean ] $set_id<br/>If the parent will only have one child object then you can set the id by setting this to true. | ||
**Default Value: false | **Default Value: false | ||
===valid()=== | ===valid()=== | ||
Check to see if the current internal pointer for the {@link $fields} array is valid. | Check to see if the current internal pointer for the {@link $fields} array is valid. | ||
*Signature: public function valid() | *Signature: public function valid() | ||
*Returns: [http://www.php.net/manual/en/language.types.boolean.php boolean] | *Returns: [http://www.php.net/manual/en/language.types.boolean.php boolean ] | ||
===validate()=== | ===validate()=== | ||
Validate all fields that are marked as required or unique. | Validate all fields that are marked as required or unique. |
Revision as of 21:25, 16 October 2009
This article desrcibes the class I2CE_Form.
- Extends the class: I2CE_Fuzzy.
- Implements the interface Iterator
It is contained in the module forms in the package I2CE
The class is defined in the file: modules/Forms/lib/I2CE_Form.php
Abstract class for objects using the {@link I2CE_Template} class that interact with a database and HTML form. This class has a few default functions that are used when interacting with the template engine in setting up form values and displaying the data for objects that tie directly to database tables.
- Author: Luke Duncan <lduncan@intrahealth.org>
- Since: v1.0.0
- See: I2CE_Template
Variables
$form_name
The name of this form for the database.
- Type: private ng $form_name
$display_name
The text name of this form for display.
- Type: private ng $display_name
$fields
The list of fields with all the information about each field.
- Type: protected y $fields
$parent
String or boolean (false) The form and id of the parent record for this form if there is one. Of the form "$form|$id"
- Type: protected mixed $parent
$id
The record id for this entry.
- Type: protected mixed $id
$children
An array of children objects for this form.
It is an array of arrays. The first being an associative array with the name of the form, the second level is a simple array of the objects.
- Type: public y $children
$attributes
A list of attributes for this form.
- Type: protected y $attributes
$parent_forms
parent_forms. The array with keys form names and values which are arrays of form names, the form names which the form's parent id can take values in
- Type: static protected y $parent_forms
Methods
__construct()
Create a new instance of a I2CE_Form object.
- Signature: public function __construct($form,$id)
Parameters:
- string $form
The name of this form - integer $id
- Default Value: '0'
__get()
Return the {@link I2CE_FormField form field} value from the {@link $fields} array.
- Signature: protected function __get($key)
- Returns: mixed
Parameters:
- string $key
__isset()
Check to see if a {@link I2CE_FormField form field} value has been set.
- Signature: protected function __isset($key)
- Returns: boolean
Parameters:
- string $key
__set()
Set the {@link I2CE_FormField form field} value in the {@link $fields} array.
- Signature: protected function __set($key,$value)
Parameters:
__unset()
Unset a {@link I2CE_FormField form field}.
- Signature: protected function __unset($key)
Parameters:
- string $key
addChildForm()
Add a child form object to this forms list of children.
- Signature: public function addChildForm($child_form,$replace)
Parameters:
- I2CE_Form $child_form
The child form - boolean $replace
Overwrite the child object if it already exists.- Default Value: false
addField()
Adds a field to this form.
- Signature: public function addField($name,$args)
- Returns: mixed I2CE_FormField or false on failure
Parameters:
addFormFields()
- Signature: protected function addFormFields($data)
Parameters:
- $data
cleanup()
Clean up all the fields for this form.
This will unset all the fields associated with this form. This will remove all circular references to this form so it can be cleaned up by the garbage collector. This should only be called when the form is no longer needed. Trying to access it after this may cause unexpected results or errors.
- Signature: public function cleanup()
clearFields()
Remove fields from the form.
This is to be used when only certain fields of the form are being dealt with so the others can be removed to save processing.
- Signature: public function clearFields($fields,$keep)
Parameters:
- array $fields
The fields being worked with. - boolean $keep
A flag to determine if the given fields should be removed or all except the given fields.- Default Value: true
current()
Return the current value for the {@link $fields} array for iterating through the form fields.
- Signature: public function current()
- Returns: mixed
displayField()
Display the field in the given node.
- Signature: public function displayField($node,$template,$args)
Parameters:
- DOMNode $node
- I2CE_Template $template
- array $args
form()
Return the form name for this form.
- Signature: public function form()
- Returns: string
getAllowedParentForms()
Gets the allowed parent forms for a given form
- Signature: static public function getAllowedParentForms($form,$use_cache)
- Returns: array of string, the form names.
Parameters:
- string $form
- boolean $use_cache
Defaults to true in which case we cached result of finding parent forms- Default Value: true
getAttribute()
Return the attribute value for a given attribute.
- Signature: public function getAttribute($key)
- Returns: mixed
Parameters:
- string $key
getChildForms()
Get the registered child forms for this form.
- Signature: public function getChildForms()
- Returns: array The list of child form names registered for this form.
getChildFormsByForm()
Get the registered child forms for the given form.
- Signature: static public function getChildFormsByForm($form)
- Returns: array The list of child form names registered for the form.
Parameters:
- string $form
The form to get the children of.
getChildren()
Get the added children for this form otherwise we get the popoluated children with the specified form
- Signature: public function getChildren($form)
- Returns: array If $form is null, it is an array with keys the form names and values array
of the children of that form type. If $form is set, then it is an array of the forms of type $form Parameters:
- string $form
Defaults to null, in which case we get all children.- Default Value: null
getDisplayName()
Return the display name for this form object.
- Signature: public function getDisplayName()
- Returns: string
getField()
Return the I2CE_FormField for the given field name.
- Signature: public function getField($field)
- Returns: I2CE_FormField
Parameters:
- string $field
the field name or a form name:field name
getFieldNames()
Get the names of all the fields added in this form
- Signature: public function getFieldNames()
- Returns: array of string, the field names.
getFormFieldsData()
- Signature: protected function getFormFieldsData($class,$data)
Parameters:
- $class
- &$data
getFormId()
Returns the form id for this record.
- Signature: public function getFormId()
- Returns: string of the form "$form|$id"
getHTMLName()
Return the value for the name attribute to be used for this field in a form.
- Signature: public function getHTMLName()
- Returns: string
getId()
Returns the id for this record.
- Signature: public function getId()
- Returns: string
getParent()
Return the parent id for this record.
If there isn't a parent record set then return the id for this record.
- Signature: public function getParent()
- Returns: mixed. false if there is no parent id or string a parent id of the form "$form|$id"
getParentForm()
Return the name of the parent form for this record.
If there isn't a parent record set then return the id for this record.
- Signature: public function getParentForm()
- Returns: mixed. false if there is no parent the parent form
getParentID()
Return the parent id for this record.
If there isn't a parent record set then return the id for this record.
- Signature: public function getParentID()
- Returns: mixed. false if there is no parent id or string a parent id
getQueryDisplay()
Return the values of all the fields that are set.
- Signature: public function getQueryDisplay()
- Returns: string
getQueryFields()
Return all the fields as an associative array
- Signature: public function getQueryFields()
- Returns: array
getQueryString()
Return all the fields as a query string to be sent to a URL
- Signature: public function getQueryString()
- Returns: string
hasAttribute()
Return true if a given attribute exists for this form.
- Signature: public function hasAttribute($key)
- Returns: boolean;
Parameters:
- string $key
hasInvalid()
Checks to see if any fields of form has in invalid message
- Signature: public function hasInvalid()
- Returns: boolean
key()
Return the current key for the {@link $fields} array for iterating through the form fields.
- Signature: public function key()
- Returns: mixed
listFields()
If it is as an array of two integers, it is the offset and then number of results to limit to.
- Signature: static public function listFields($form,$fields,$where_data,$ordering,$limit)
- Returns: mixed an array with key id's and value and array of values. the array of values has as keys the fields with their corresponding value.
Parameters:
- string $form
The form name - array $fields
of string. The fields we want returned - mixed $where_data
Either I2CE_MagicDataNode or array. contains the where clause information about this form or a nested- Default Value: array()
- array $ordering
An array of fields to order by. Defaults to the empty array. Prepend a - to order by in descending order.- Default Value: array()
- mixed $limit
Defaults to false. It true, returns only one result. If an integer it is the numeber of records to limit to.- Default Value: false
load()
Load the member variables from an array
exactly one of entry in the array $post['forms'][$this->form_name], we set the values of the form's field, id and parent from that entry. If false, we set the values from $post['forms'][$this->form_name][$this->getID()] if it is present
- Signature: public function load($post,$loadID,$populate_on_set_id)
Parameters:
- array $post
The Post vairables. Usually from an http request. - boolean $loadID
Defaults to true. If true, and there is- Default Value: true
- $populate_on_set_id
- Default Value: true
lookupArray()
Lookup a given id in the given array.
- Signature: static protected function lookupArray($id,$arr)
- Returns: string
Parameters:
- integer $id
The id to lookup. - array $arr
The array to search through.
next()
Advance the internal pointer for the {@link $fields} array for iterating through the form fields.
- Signature: public function next()
processDOM()
Process the DOM for this form.
- Signature: public function processDOM($node,$template,$method,$args)
Parameters:
- DOMNode $node
- I2CE_Template $template
- string $method
- array $args
removeField()
Removes a field from this form. @param array $args The arguments for this field
- Signature: public function removeField($name)
Parameters:
- string $name
reset()
Reset this object to its original state.
- Signature: public function reset()
rewind()
Rewind the internal pointer for the {@link $fields} array for iterating through the form fields.
- Signature: public function rewind()
search()
@param mixed $limit. Defaults to false. It true, returns only one result. If an integer it is the numeber of records to limit to. If it is as an array of two integers, it is the offset and then number of results to limit to.
- Signature: static public function search($form,$where_data,$ordering,$limit_one)
- Returns: mixed an array of matching form ids. However, ff $limit_one is true or 1 or
array ($offset,1) then then we return either the id or false, if none found or there was an error. Parameters:
- string $form
The form name. - mixed $where_data
Either I2CE_MagicDataNode or array. contains the where clause information about this form or a nested- Default Value: array()
- array $ordering
An array of fields to order by. Defaults to the empty array. Prepend a - to order by in descending order.- Default Value: array()
- $limit_one
- Default Value: false
setAttribute()
Set an attribute for this form.
- Signature: public function setAttribute($key,$value)
Parameters:
setDisplayName()
Set the display name for this form object.
- Signature: final public function setDisplayName($display)
Parameters:
- string $display
setForm()
Set the form name for this form object.
- Signature: final public function setForm($name)
Parameters:
- string $name
setFromPost()
Load the member variables from an array The array can contain the keys 'id', 'parent', 'fields'. The later of which is an array indexed by field names and which contains the values of the field
- Signature: public function setFromPost($post,$populate_on_set_id)
Parameters:
- array $post
The post object is passed as a reference - $populate_on_set_id
- Default Value: false
setId()
Set the id for this record.
- Signature: public function setId($id)
Parameters:
- mixed $id
setParent()
Set the parent id for this record
- Signature: public function setParent($parent,$set_id)
Parameters:
- mixed $parent
string or I2CE_Form - boolean $set_id
If the parent will only have one child object then you can set the id by setting this to true.- Default Value: false
valid()
Check to see if the current internal pointer for the {@link $fields} array is valid.
- Signature: public function valid()
- Returns: boolean
validate()
Validate all fields that are marked as required or unique.
This will check all the fields in this form and if they're required or unique it will perform the required checks
- Signature: public function validate()
Inherited Fuzzy Methods
userMessage()
This method is inherited from I2CE_Fuzzy->userMessage()
Fuzzy Methods
isNumeric()
This method is implemented by I2CE_Module_CustomReports->isNumeric()
getLimitStyles()
This method is implemented by I2CE_Module_FormLimits->getLimitStyles()
checkLimit()
This method is implemented by I2CE_Module_FormLimits->checkLimit()
checkWhereClause()
This method is implemented by I2CE_Module_FormLimits->checkWhereClause()
createCheckFunction()
This method is implemented by I2CE_Module_FormLimits->createCheckFunction()
createCheckLimitString()
This method is implemented by I2CE_Module_FormLimits->createCheckLimitString()
generateLimit()
This method is implemented by I2CE_Module_FormLimits->generateLimit()
generateWhereClause()
This method is implemented by I2CE_Module_FormLimits->generateWhereClause()
processLimit()
This method is implemented by I2CE_Module_FormLimits->processLimit()
getDisplayedExistingLimit()
This method is implemented by I2CE_Module_FormLimits->getDisplayedExistingLimit()
isComponentized()
This method is implemented by I2CE_FormStorage->isComponentizedForm()
addChild()
This method is implemented by I2CE_FormStorage->addChild()
getChildIds()
This method is implemented by I2CE_FormStorage->getChildIds()
getStorage()
This method is implemented by I2CE_FormStorage->getStorage()
isWritable()
This method is implemented by I2CE_FormStorage->isWritable()
populate()
This method is implemented by I2CE_FormStorage->populate()
populateChild()
This method is implemented by I2CE_FormStorage->populateChild()
populateChildren()
This method is implemented by I2CE_FormStorage->populateChildren()
populateFirst()
This method is implemented by I2CE_FormStorage->populateFirst()
populateHistory()
This method is implemented by I2CE_FormStorage->populateHistory()
populateLast()
This method is implemented by I2CE_FormStorage->populateLast()
delete()
This method is implemented by I2CE_FormStorage->delete()
save()
This method is implemented by I2CE_FormStorage->save()
setChangeType()
This method is implemented by I2CE_FormStorage->setChangeType()