Jeff PHP framework  0.99
Modular, extensible, OOP, MVC, lightweight php framework designed to ease the programmers in the development of web applications.
adminTable Class Reference

Class which generates automatically the backoffice for the management of a database table. More...

+ Inheritance diagram for adminTable:

Public Member Functions

 __construct ($table, $opts=null)
 Constructs an adminTable instance.
 editFields ($opts=null)
 The method which returns the admin insertion/modification/deletion/export views and functionality.
 formRecord ($pk, $myform=null, $formaction=null)
 The insertion/modification form of the given record.
 manage ()
 Entry point for the autogenerated backoffice gui.
 parseDateFields ($row)
 Parses the results from a database query substituting the date/datetime fields values with format set in the site configuration.
 parseForeignKeys ($row)
 Parses the results from a database query substituting the foreign keys values with the related fields values of the related table.
 parsePluginFields ($row)
 Parses the results from a database query substituting the plugin fields values with the way they have to be displayed.
 parseSpecialFields ($row, $opts=null)
 Parses the results from a database query substituting the special fields values with the way they have to be displayed.
 saveFields ()
 Saves the form submitted data (one or more records)
 setChangelistFields ($fields)
 Sets the $_changelist_field property.
 setFilterFields ($filter_fields)
 Sets the filter fields.
 setForeignKeys ($fkeys)
 Sets table foreign keys.
 setHtmlFields ($fields)
 Sets the table html fields.
 setPluginFields ($pfields)
 Sets plugin fields.
 setSpecialFields ($sfields)
 Sets table special fields.
 view ()
 The method which returns the admin list view.

Protected Member Functions

 checkUpload ()
 Checks if at least one of the special fields requires a file upload.
 cleanField ($name, $type, $opts=null)
 Cleans inputs from the user.
 cleanSpecialField ($model, $fname, $pk, $type, $insert)
 Cleans special fields inputs from the user and sets the model properties.
 deleteFiles ($f_s)
 Checks if the given records are associated to files and deletes them.
 export ($f_s, $where='')
 Exports the given records.
 formElement ($myform, $fname, $field, $id, $opts=null)
 The html form element for the given field.
 formFilters ()
 Form which contains filters in the admin list view.
 saveRecord ($pk, $pkeys)
 Saves the given record.
 setSessionSearch ()
 Sets the session variables used to filter records in the admin list.
 setWhereClause ($fkeysorder)
 Sets the where clause used to filter records in the admin list view.

Protected Attributes

 $_arrow_down_path
 relative path to the arrow down icon
 $_arrow_up_path
 relative path to the arrow up icon
 $_changelist_fields
 array of fields shown in the admin list
 $_cls_cbk_del
 delete action callback class
 $_custom_tpl
 associative array of custom templates
 $_deletion
 allow record deletion
 $_edit_deny
 deny record modification
 $_editor
 charge dojo editor for html fields
 $_efp
 number of records for page
 $_fields
 the table column names
 $_filter_fields
 array of fields used to filter records in the admin list
 $_fkeys
 definition of the foreign keys
 $_html_fields
 definition of the html fields
 $_insertion
 allow record insertion
 $_mth_cbk_del
 delete action callback method
 $_pfields
 definition of the plugin fields
 $_primary_key
 the primary key name defined for the table
 $_registry
 the registry singleton instance
 $_sfields
 definition of the special fields
 $_table
 the database table
 $_view
 view instance

Detailed Description

Class which generates automatically the backoffice for the management of a database table.

This class creates a default back-office interface for managing a database table (which has a primary key field). It gets the table structure directly from the database and constructs a navigation view to surf through inserted data, an insertion/edit view (the form) to add or update records and all the necessary actions to perform insertion, modification, deletion and exportation.

The adminTable class can also manage automatically foreign keys, some particular fields (password, bool, enum, email, multicheck, file, image), html fields (charging dojo html editor if needed) and fields managed by extra plugins. Also it is possible to automatically add filters for the list view. It's enough to set the filters fields and the class adds for you the filters form and performs the research. Filters field may be text, int, float, bool and foreign keys fields.

So if it's not necessary to have a specific logic that regulates the access and actions doable over a database table, with few lines of code is possible to create the entire table back office. All you have to do is set the foreign keys and/or special fields if needed and then call the manage method. Then Jeff shows you a list of inserted records with the possibility to edit/delete them or insert a new one. All these operations are managed automatically by the manage method. In alternative you may use only some features of this class, like using only the records paginated list (setting as not editable the fields: edit_deny='all') or using only the auto generated form. Clearly even if the module requires something different, it's always possible to extend this class in order to overwrite only the aspects that need a proper customization.

Author:
abidibo abidi.nosp@m.bo@g.nosp@m.mail..nosp@m.com
Version:
0.99
Date:
2011-2012

Definition at line 48 of file adminTable.class.php.


Constructor & Destructor Documentation

adminTable::__construct ( table,
opts = null 
)

Constructs an adminTable instance.

Parameters:
string$tablethe database table
array$optsAssociative array of options:
  • insertion: bool default true. Whether to allow records insertion or not.
  • deletion: bool default true. Whether to allow records deletion or not.
  • edit_deny: mixed default array(). Deny modification for some records. Possible values are 'all', or an array of record id.
  • changelist_fields: array default null. Array of fields to be shown in the admin list.
  • editor: bool default false. Charge dojo editor for html fields insertion/modification.
  • export: bool default false. Add export buttons in the admin list.
  • custom_tpl: array default array(). Associative array defining custom templates, available keys are 'view', 'insert', 'edit'.
  • efp: int default 20. Number of records shown in the admin list.
  • cls_callback_delete: string default null. Class to call when performing a delete action.
  • mth_callback_delete: string default null. Method to call when performing a delete action.
Returns:
void

Reimplemented in menuAdminTable.

Definition at line 174 of file adminTable.class.php.

+ Here is the call graph for this function:


Member Function Documentation

adminTable::checkUpload ( ) [protected]

Checks if at least one of the special fields requires a file upload.

Returns:
bool, true if there's at least an image or file special field set.

Definition at line 783 of file adminTable.class.php.

+ Here is the caller graph for this function:

adminTable::cleanField ( name,
type,
opts = null 
) [protected]

Cleans inputs from the user.

Parameters:
string$namethe field name
string$typethe field data type
mixed$optsAssociative array of options
  • escape bool default true. Whether to escape values or not.
Returns:
cleaned input

Definition at line 1175 of file adminTable.class.php.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

adminTable::cleanSpecialField ( model,
fname,
pk,
type,
insert 
) [protected]

Cleans special fields inputs from the user and sets the model properties.

Parameters:
mixed$modelthe model instance
string$fnamethe field name
mixed$pkthe primary key value
string$typethe field data type
bool$insertwhether the user action is an insertion or not.
Returns:
void

Definition at line 1204 of file adminTable.class.php.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

adminTable::deleteFiles ( f_s) [protected]

Checks if the given records are associated to files and deletes them.

Parameters:
array$f_sArray containing the identifiers of the records that have to be deleted
Returns:
int 0 if there aren't special fields or 1

Definition at line 901 of file adminTable.class.php.

+ Here is the caller graph for this function:

adminTable::editFields ( opts = null)

The method which returns the admin insertion/modification/deletion/export views and functionality.

Parameters:
mixed$optsassociative array of options
  • insert: bool default null. Force a record insertion
  • action: string default '?save'. The url of the form action
  • f_s: array default null. Array containing the identifiers of the records that have to be managed. By default are taken from POST or SESSION.
Returns:
string the requested view (insertion form, modification form) or the requested action (export, deletion)

Definition at line 801 of file adminTable.class.php.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

adminTable::export ( f_s,
where = '' 
) [protected]

Exports the given records.

Parameters:
mixed$f_sthe id of the fields that have to be exported. Possible values are 'all' or an array of fields' id
string$wherethe where clause used to select records if the $f_s parameter is null
Returns:
void

Definition at line 1255 of file adminTable.class.php.

+ Here is the caller graph for this function:

adminTable::formElement ( myform,
fname,
field,
id,
opts = null 
) [protected]

The html form element for the given field.

Parameters:
form$myformthe form instance
mixed$fnamethe field name
array$fieldassociative array containing the database structure information for the field (null, max_length, int...)
mixed$idthe value of the primary key
mixed$optsAssociative array of options
  • value: mixed. The field value
  • size: int default 40. The size attribute of the input element
Returns:
the html form element

Reimplemented in menuAdminTable.

Definition at line 977 of file adminTable.class.php.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

adminTable::formFilters ( ) [protected]

Form which contains filters in the admin list view.

Returns:
the filters html form

Definition at line 626 of file adminTable.class.php.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

adminTable::formRecord ( pk,
myform = null,
formaction = null 
)

The insertion/modification form of the given record.

This method can return all the form elements without the start and end form tags, or a complete form.
The complete form is generally used when calling this method outside from the adminTable class. In this case it is possible to set the form action which by default is '?save'

Parameters:
mixed$pkthe value of the record primary key
form$myforma form instance default null. If the form is started and closed independently by this method.
string$formactiondefault null. The url of the form action if the method starts the form
Returns:
void

Definition at line 941 of file adminTable.class.php.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Entry point for the autogenerated backoffice gui.

This is the method called by client classes to generate their tables backoffice

Returns:
the requested view or action

Definition at line 341 of file adminTable.class.php.

+ Here is the call graph for this function:

Parses the results from a database query substituting the date/datetime fields values with format set in the site configuration.

Parameters:
mixed$rowassociative array deriving from a db query result
Returns:
void

Definition at line 761 of file adminTable.class.php.

+ Here is the caller graph for this function:

Parses the results from a database query substituting the foreign keys values with the related fields values of the related table.

Parameters:
array$rowassociative array deriving from a db query result
Returns:
void

Definition at line 660 of file adminTable.class.php.

+ Here is the caller graph for this function:

Parses the results from a database query substituting the plugin fields values with the way they have to be displayed.

Parameters:
mixed$rowassociative array deriving from a db query result
Returns:
void

Definition at line 739 of file adminTable.class.php.

+ Here is the caller graph for this function:

adminTable::parseSpecialFields ( row,
opts = null 
)

Parses the results from a database query substituting the special fields values with the way they have to be displayed.

Parameters:
mixed$rowassociative array deriving from a db query result
mixed$optsAssociative array of options:
  • show_pwd: bool default false: Whether to show a clear-text password or not
  • mailto: bool default false: Whether to ass a mailto link or not
Returns:
void

Definition at line 688 of file adminTable.class.php.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Saves the form submitted data (one or more records)

Returns:
void

Definition at line 1061 of file adminTable.class.php.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

adminTable::saveRecord ( pk,
pkeys 
) [protected]

Saves the given record.

Parameters:
mixed$pkthe primary key value
mixed$pkeysList of primary keys of the records edited in the form
Returns:
void

Definition at line 1105 of file adminTable.class.php.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Sets the $_changelist_field property.

Parameters:
array$fieldsSee adminTable() options
Returns:
void

Definition at line 300 of file adminTable.class.php.

adminTable::setFilterFields ( filter_fields)

Sets the filter fields.

Parameters:
array$filter_fieldsArray of fields used to filter records in the admin list
Returns:
void

Definition at line 314 of file adminTable.class.php.

Sets table foreign keys.

Parameters:
array$fkeysAssociative array in the form 'field_name'=>properties. Properties is an associative array having keys:
  • table: the table related with the field
  • field: the representative field of the related table record
  • where: the where clause used to filter the related table records
  • order: the order clause used to order the related table records
Returns:
void

Definition at line 218 of file adminTable.class.php.

Sets the table html fields.

Parameters:
mixed$fieldsarray of fields which allow html content
Returns:
void

Definition at line 327 of file adminTable.class.php.

Sets plugin fields.

Parameters:
array$pfieldsassociative array where the key is the name of the "plugin type" field and the value is an array which contains the options required by the plugin itself
Returns:
void

Definition at line 283 of file adminTable.class.php.

+ Here is the call graph for this function:

Sets the session variables used to filter records in the admin list.

Returns:
void

Definition at line 548 of file adminTable.class.php.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Sets table special fields.

The supported special fields types are: password, bool, enum, email, multicheck (many to many), file, image

Parameters:
array$sfieldsAssociative array in the form 'field_name'=>properties. Properties is an associative array having keys:
  • type: string. The type of special field. Possible values are: 'password', 'bool', 'enum', 'email', 'multicheck', 'file', 'image'
  • edit_label: (password type) string. The label displayed in the edit form
  • true_label: (bool type) string. The label tied to the value true
  • false_label: (bool type) string. The label tied to the value false
  • default: (bool type) mixed. The deafult value
  • data: (enum type) array. The associative array containing the allowed values in the form 'value'=>'label'
  • key_type: (enum type) string. The data type of the values (int, string, float, ...)
  • list_mailto: (email type) bool. Whether to show or not a mailto link in the admin list view
  • value_type: (multicheck type) string. The type of the values (int, string, float, ...)
  • table: (multicheck type) string. The name of the related table
  • field: (multicheck type) string. The field of the related table to display in the multicheck form element
  • where: (multicheck type) string. The where clause used to select only some records from the related table
  • order: (multicheck type) string. The order clause used to order the records selected from the related table
  • label: (image and file types) string. The field label
  • path: (image and file types) string. The absolute path of the uploading directory
  • rel_path: (image and file types) string. The relative path of the uploading directory
  • preview: (image and file types) bool. Whether to show file preview in the list view and the edit form view
  • extensions: (image and file types) array. List of allowed extensions (all allowed if empty)
  • check_content: (image and file types) bool default true. Whether to check the file mime-type agains the allowed ones
  • contents_allowed: (image and file types) array. List of allowed mime types in substitution of the default ones
  • resize: (image type) bool. Whether to resize the image or not
  • scale: (image type) mixed. Whether to scale the image or not. Possible values: false or an integer which represents the percentage to scale the image to
  • resize_enlarge: (image type) mixed. Whether to allow image enlargement during resize or not. The enlargement is always allowed for the thumbnail
  • make_thumb: (image type) bool. Whether to make a thumbnail of the image or not
  • prefix: (image type) string. The prefix added to the image filename
  • prefix_thumb: (image type) string default 'thumb_'. The prefix added to the thumbnail file. It sums to the image prefix
  • resize_width: (image type) int. The width of the resized image
  • resize_height: (image type) int. The height of the resized image
  • thumb_width: (image type) int. The width of the thumb image
  • thumb_height: (image type) int. The height of the thumb image
Returns:
void

Definition at line 266 of file adminTable.class.php.

adminTable::setWhereClause ( fkeysorder) [protected]

Sets the where clause used to filter records in the admin list view.

Parameters:
bool$fkeysorderWhether records are ordered by a foreign key field or not
Returns:
the where clause

Definition at line 592 of file adminTable.class.php.

+ Here is the caller graph for this function:

The method which returns the admin list view.

Returns:
the admin list view

Reimplemented in menuAdminTable.

Definition at line 372 of file adminTable.class.php.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:


Field Documentation

relative path to the arrow down icon

Definition at line 148 of file adminTable.class.php.

relative path to the arrow up icon

Definition at line 153 of file adminTable.class.php.

array of fields shown in the admin list

Definition at line 123 of file adminTable.class.php.

delete action callback class

Definition at line 98 of file adminTable.class.php.

associative array of custom templates

Definition at line 138 of file adminTable.class.php.

allow record deletion

Definition at line 113 of file adminTable.class.php.

deny record modification

Definition at line 118 of file adminTable.class.php.

adminTable::$_editor [protected]

charge dojo editor for html fields

Definition at line 133 of file adminTable.class.php.

adminTable::$_efp [protected]

number of records for page

Definition at line 93 of file adminTable.class.php.

adminTable::$_fields [protected]

the table column names

Definition at line 68 of file adminTable.class.php.

array of fields used to filter records in the admin list

Definition at line 128 of file adminTable.class.php.

adminTable::$_fkeys [protected]

definition of the foreign keys

Definition at line 73 of file adminTable.class.php.

definition of the html fields

Definition at line 88 of file adminTable.class.php.

allow record insertion

Definition at line 108 of file adminTable.class.php.

delete action callback method

Definition at line 103 of file adminTable.class.php.

adminTable::$_pfields [protected]

definition of the plugin fields

Definition at line 83 of file adminTable.class.php.

the primary key name defined for the table

Definition at line 63 of file adminTable.class.php.

the registry singleton instance

Definition at line 53 of file adminTable.class.php.

adminTable::$_sfields [protected]

definition of the special fields

Definition at line 78 of file adminTable.class.php.

adminTable::$_table [protected]

the database table

Definition at line 58 of file adminTable.class.php.

adminTable::$_view [protected]

view instance

Definition at line 143 of file adminTable.class.php.


The documentation for this class was generated from the following file: