dev.obliquid.com: cal
[ class tree: cal ] [ index: cal ] [ all elements ]

Class: db_form

Source Location: Program_Root/classes/general/db_form.php

Class Overview


Builds simple select, update and delete queries (on a single table), and uses the values stored to build form elements.


Variables

Methods


Inherited Variables

Inherited Methods


Class Details

[line 41]
Builds simple select, update and delete queries (on a single table), and uses the values stored to build form elements.

This class works best coupled with a Metabase db connection, but it can also be used without a db, just to build a form.






[ Top ]


Class Variables

$def_attrib = array()

[line 79]

an associative array with a list of default attributes




Type:   mixed


[ Top ]

$logger =

[line 76]

an instance of the logger class




Type:   mixed


[ Top ]

$_tprefix =

[line 52]

an optional prefix to prepend to database table




Type:   mixed


[ Top ]



Class Methods


constructor db_form [line 84]

void db_form( )

db_form constructor





[ Top ]

method clearAllValues [line 237]

void clearAllValues( )

Sets all the values as not sent from a form and clears

all the db values






[ Top ]

method clearFormValues [line 248]

void clearFormValues( )

Sets all the values as not sent from a form





[ Top ]

method executeSqlDelete [line 601]

boolean executeSqlDelete( [boolean $debug = false], [text $logentry = ""], [text $module = ""], [boolean $sameop = true], [text $operation = "DELETE"])

execute a SQL delete statement, meant to delete a single record.

How to use it: be sure that the primary key field(s) are setted before calling this function




Tags:

return:  returns true if the query was successfully executed


Parameters:

boolean   $debug   optional, if it's true prints the query WITHOUT executing it
text   $logentry   an optional log message, log will be added only if not's empty
text   $module   module name, optional, but must be present if there is $logentry
boolean   $sameop   true, if you want to log a new entry in the same operation, default true
text   $operation   optional operation code (must be in sl_logop table), defaults to DELETE

[ Top ]

method executeSqlInsert [line 643]

boolean executeSqlInsert( [boolean $debug = false], [text $logentry = ""], [text $module = ""], [boolean $sameop = true], [text $operation = "INSERT"])

execute an insert statement



Tags:

return:  returns true if the query was successfully executed


Parameters:

boolean   $debug   optional, if it's true prints the query WITHOUT executing it
text   $logentry   an optional log message, log will be added only if not's empty
text   $module   module name, optional, but must be present if there is $logentry
boolean   $sameop   true, if you want to log a new entry in the same operation, default true
text   $operation   optional operation code (must be in sl_logop table), defaults to DELETE

[ Top ]

method executeSqlUpdate [line 545]

boolean executeSqlUpdate( [boolean $debug = false], [text $logentry = ""], [text $module = ""], [boolean $sameop = true], [text $operation = "UPDATE"])

execute an update statement



Tags:

return:  returns true if the query was successfully executed


Parameters:

boolean   $debug   if true, prints the query WITHOUT executing it
text   $logentry   an optional log message, log will be added only if not's empty
text   $module   module name, optional, but must be present if there is $logentry
boolean   $sameop   true, if you want to log a new entry in the same operation, default true
text   $operation   optional operation code (must be in sl_logop table), defaults to UPDATE

[ Top ]

method fetch [line 193]

true fetch( $id $id, [mixed $debug = false])

Fetches a record from db and fills internal status with it



Tags:

return:  in case of success, false otherwise


Parameters:

$id   $id   primary key of the record to fetch, supposed on a single field

[ Top ]

method getArraySelect [line 1067]

string getArraySelect( mixed $field, mixed $option, [mixed $attribute = array()])

gets a string to build a select form control. DEPRECATED This function builds a select form control trying to guess attributes from the db.

you can redefine any attribute you are not satisfied with or add new attributes with the $attribute associative array. The associative array $option used to build the must have two fields named "LABEL" and "VALUE"






[ Top ]

method getAssocArray [line 361]

index getAssocArray( )

creates an index array with all the DB field names



Tags:

return:  array


[ Top ]

method getButton [line 983]

string getButton( mixed $field, mixed $label, [mixed $attribute = array()])

shows a button of type button





[ Top ]

method getCheckbox [line 1169]

text getCheckbox( text $field, [text $attribute = array()], [text $label = ""])

Gets an html checkbox



Tags:

return:  html markup to display the checkbox


Parameters:

text   $field   field name, repeat the same name for radios of a group, don't use spaces, condider using only letters, numbers and underscore the field name will be used also as id
text   $attribute   an optional associative attributes array, useful to pass style information or javascript event handlers
text   $label   an optional label. Clicking on the label will activate the radio

[ Top ]

method getDateInput [line 1211]

string getDateInput( mixed $field, [mixed $start_year = 1998], [mixed $end_year = 0], [mixed $attribute = array()])

gets a date input control with drop downs for day, month and year.

By default the start year is 1998, and the end year is the current year, but it can be changed by assigning $start_year and $end_year parameters. Month names are returned according to current locale.






[ Top ]

method getDayInput [line 1233]

string getDayInput( mixed $field, [mixed $attribute = array()])



Tags:

return:  a drop down menu with days from 1 to 31


[ Top ]

method getDbSelect [line 1026]

string getDbSelect( mixed $field, mixed $query, [mixed $attribute = array()], [mixed $option = array()])

gets a string to build a select form control. DEPRECATED This function builds a select form control trying to guess attributes from the db.

the query used to build the must have two fields named "LABEL" and "VALUE" you can redefine any attribute you are not satisfied with or add new attributes with the $attribute associative array. you can add further options on top of db options with $option array






[ Top ]

method getDbValue [line 757]

string getDbValue( mixed $field_name)

returns the value of the fetched field from the db or an empty string



Tags:



[ Top ]

method getFieldArray [line 333]

index getFieldArray( )

creates an index array with all the DB field names



Tags:

return:  array


[ Top ]

method getFileInput [line 1197]

string getFileInput( mixed $field, [mixed $attribute = array()])

gets a file input control





[ Top ]

method getFormValue [line 775]

string getFormValue( mixed $field_name)

returns the value of the field in the sent and parsed form, or the value

setted with setFormValue, otherwise an empty string




Tags:



[ Top ]

method getHidden [line 1186]

string getHidden( mixed $field, [mixed $value = ""])

gets an hidden field





[ Top ]

method getHtmlPopup [line 926]

void getHtmlPopup( $field $field, [$add_hidden $add_hidden = true])

gets a string to be used as a html editor popup window.

The form containing it should have name="ewe" and id="ewe"






Parameters:

$field   $field   text the field name
$add_hidden   $add_hidden   boolean wether an hidden field named $field should be added or not

[ Top ]

method getImage [line 997]

string getImage( $field $field, $src $src, [$attribute $attribute = array()])

shows an image submit button





Parameters:

$field   $field   string field name
$src   $src   string image source name
$attribute   $attribute   string not used yet

[ Top ]

method getInput [line 811]

void getInput( string $type, string $field, array $attribute, [string $query = ""], [array $extraoption = array()])

returns an html control according to $type parameter





Parameters:

string   $type   any of TEXTINPUT, PASSWORD, TEXTAREA, DBSELECT, CHECKBOX, FILEINPUT, DATEINPUT
string   $field   form field name
array   $attribute   extra attributes to add in the html tag
string   $query   sql query to populate DBSELECT menus
array   $extraoption   extra options to be added before others in DBSELECT

[ Top ]

method getInputTypesArray [line 845]

void getInputTypesArray( )

gets an array with all supported input types in a format suitable for getSelect()





[ Top ]

method getLogger [line 98]

void &getLogger( )

Gets the logger object created by db_form





[ Top ]

method getMbInsert [line 502]

String getMbInsert( )

Gets a Metabase insert. It's a piece of XML. Example:

<insert><field><name>id</name><value>2</value></field></insert>






[ Top ]

method getMonthInput [line 1246]

string getMonthInput( mixed $field, [mixed $attribute = array()])



Tags:

return:  a drop down menu with month names


[ Top ]

method getMultiSelect [line 1118]

string getMultiSelect( mixed $field, mixed $option, mixed $values, [mixed $attribute = array()])

gets a string to build a multi select form control.

This function builds a select form control that allows multiple selections you can redefine any attribute you are not satisfied with or add new attributes with the $attribute associative array. the index array $option is an array of options, each of them is an array with value in position 0 and label in position 1. the index array $values contains the options which should be selected.






[ Top ]

method getPasswordInput [line 953]

string getPasswordInput( attribute $field, [mixed $attribute = array()])

gets a string to build a password input form control.

This function builds a text input form control trying to guess attributes. you can redefine any attribute you are not satisfied with or add new attributes with the $attribute associative array. example: $extra_html = array("maxlength" => 10, "size" => 12); The already setted attributes are the following: NAME - setted to $field_name VALUE - setted to the form value of this field, or to the db value if the form was not posted. If there isn't a db value too is setted to the empty string. maxlength - setted to the db field length






Parameters:

attribute   $field   an associative array with which you can redefine or add attributes

[ Top ]

method getPrimaryKeys [line 476]

array getPrimaryKeys( )

Get an array with the primary keys



Tags:

return:  of String


[ Top ]

method getRadio [line 1148]

text getRadio( text $field, text $value, [text $label = ""], [text $attribute = array()])

Gets a radio button



Tags:

return:  html markup to display the radio button


Parameters:

text   $field   field name, repeat the same name for radios of a group, don't use spaces, condider using only letters, numbers and underscore
text   $value   field value, don't use spaces, condider using only letters, numbers and underscore the radio id will be $field.$value
text   $label   an optional label. Clicking on the label will activate the radio
text   $attribute   an optional associative attributes array, useful to pass style information or javascript event handlers

[ Top ]

method getSelect [line 1092]

string getSelect( mixed $field, mixed $option, [mixed $attribute = array()])

gets a string to build a select form control.

This function builds a select form control trying to guess attributes from the db. you can redefine any attribute you are not satisfied with or add new attributes with the $attribute associative array. the index array $option is an array of options, each of them is an array with value in position 0 and label in position 1.






[ Top ]

method getSqlDelete [line 585]

text getSqlDelete( )

returns a SQL statement to delete data according to the primary key value





[ Top ]

method getSqlInsert [line 492]

String getSqlInsert( )

Gets the sql insert statement





[ Top ]

method getSqlUpdate [line 530]

String getSqlUpdate( )

returns a SQL statement to modify data according to form values





[ Top ]

method getSubmit [line 972]

string getSubmit( mixed $field, mixed $label, [mixed $attribute = array()])

shows a submit button





[ Top ]

method getTextArea [line 1009]

string getTextArea( $attribute $field, [mixed $attribute = array()])

shows a text area fetching data from db





Parameters:

$attribute   $field   to set properties value

[ Top ]

method getTextInput [line 886]

string getTextInput( attribute $field, [mixed $attribute = array()])

gets a string to build a text input form control.

This function builds a text input form control trying to guess attributes. you can redefine any attribute you are not satisfied with or add new attributes with the $attribute associative array. Use upper case attribute names or they won't get recognized. example: $attribute = array("maxlength" => 10, "size" => 12); The already setted attributes are the following:

  NAME      - setted to $field_name
  VALUE     - setted to the form value of this field, or to the db value if the form
      was not posted. If there isn't a db value too is setted to the empty string.
  maxlength - setted to the db field length, can be changed with maxlength attribute
  






Parameters:

attribute   $field   an associative array with which you can redefine or add attributes

[ Top ]

method getTextPopup [line 908]

void getTextPopup( $field $field, [$add_hidden $add_hidden = true])

gets a string to be used as a text editor popup window.

The form containing it should have name="ewe" and id="ewe" db_form fields used are $field and $field."_type" for the text type. Allowed values are t/h for text and html.






Parameters:

$field   $field   text the field name
$add_hidden   $add_hidden   boolean wether an hidden field named $field should be added or not

[ Top ]

method getValue [line 732]

string getValue( mixed $field)

returns the form value of the field if $field_name is a form field and

the form was sent and parsed, otherwise the db value if $field_name is a db field, otherwise the empty string




Tags:



[ Top ]

method getValueArray [line 347]

index getValueArray( )

creates an index array with the values for each database field



Tags:

return:  array


[ Top ]

method getValueForSql [line 677]

string getValueForSql( mixed $field)

Returns a field value, in the same way getValue does, but delimits

and escapes the field, as necessary to build the query






[ Top ]

method getYearInput [line 1259]

string getYearInput( mixed $field, [mixed $start_year = 1998], [mixed $end_year = 0], [mixed $attribute = array()])



Tags:

return:  a drop down menu with years from $start_year to $end_year


[ Top ]

method isDB [line 1275]

boolean isDB( mixed $field_name)

Returns boolean whether the field is defined in the DB or not.





[ Top ]

method isForm [line 1289]

boolean isForm( mixed $field_name)

Returns boolean whether the field is defined in the FORM or not.





[ Top ]

method is_uploaded_file [line 184]

true is_uploaded_file( mixed $field_name)

Tests to see whether the $field_name was set from a valid file upload



Tags:

return:  if yes, false otherwise (same as "isset")


[ Top ]

method newId [line 518]

int newId( )

finds a new id for the table and sets the primary key (primary key must be simple and numeric). returns the generated id The table must have a sequence.



Tags:

return:  the new id


[ Top ]

method parseForm [line 141]

void parseForm( )

parses the form and copies values into the _field array





[ Top ]

method setDatadict [line 293]

void setDatadict( mixed $datadict)

Sets a custom data dictionary for a table not contained in tabledesc.

Example:


1 $dbf->setTable("page", "sl_", false);
2 $datadict = array();
3 $datadict[] = array("name", "text", 32, true);
4 $datadict[] = array("id_module", "integer");
5 $datadict[] = array("is_common", "boolean", 0, true);
6 $datadict[] = array("comment", "text", 255);
7 $dbf->setDatadict($datadict);






[ Top ]

method setDBConnection [line 91]

void setDBConnection( mixed &$mb)

sets a reference to an already created Metabase DB object





[ Top ]

method setDefaultAttrib [line 788]

void setDefaultAttrib( mixed $def_attrib)

Sets the default attributes for building a form control.

The attribute can be redefined in the form control and in this case the default value will be ignored






[ Top ]

method setFormValue [line 797]

void setFormValue( mixed $field, mixed $value)

allows to modify a value in the sent and parsed form or to set any value

as sent from a form






[ Top ]

method setTable [line 114]

true setTable( $table_name $table_name, [$tprefix $tprefix = ""], [$tabledesc $tabledesc = true])

sets the table name to be used and reads meta data from db.

it's possible to reuse this object for more than one table.




Tags:

return:  if success, false if failure


Parameters:

$table_name   $table_name   name of a db table
$tprefix   $tprefix   an optional table prefix (default none)
$tabledesc   $tabledesc   an optional parameter to load data dictionary from tabledesc or not (default true)

[ Top ]

method setTableMetabase [line 130]

true setTableMetabase( $table_name $table_name, $tprefix $tprefix, $meta $meta)

sets the table name to be used and sets meta data from '$meta' it's possible to reuse this object for more than one table.



Tags:

return:  if success, false if failure


Parameters:

$table_name   $table_name   name of a db table
$tprefix   $tprefix   table prefix
$meta   $meta   array of meta data from 'ParseDatabaseDefinitionFile'.

[ Top ]

method ucfields [line 411]

void ucfields( mixed $fields)

Applies ucwords to all fields listed in the array





[ Top ]

method _getAttributeString [line 858]

void _getAttributeString( mixed &$res, mixed $attribute)

Private function returning the attribute string from the attribute array

and the defaults attributes. If a value is defined in the attribute array it will have precedence over the default value






[ Top ]


Documentation generated on Tue, 29 Mar 2005 09:03:48 -0800 by phpDocumentor 1.2.0rc2