Handles custom fields.
| DLCustomField | Handles custom fields. |
| Author | Duc Tri Le <cmsmadesimple---at---email.tiger-inc.com> |
| License | This class is released under the GNU General Public License. |
| Member Data | |
| $data | (array) An array containing the structure of the table containing the values of the custom fields. |
| $options | (array) An array containing all of the required options for each of the custom fields. |
| $types | (array) An array containing the available types for the options. |
| Abstract Methods | The user are required to overwrite these methods. |
| GetCustomFieldTable | Get the name of the table containing the custom field information. |
| GetDataTable | Get the name of the table containing the data. |
| Singleton | Retrieve a single instance of this class. |
| Normal Methods | The user can just use these methods as is or overwrite it if necessary. |
| AddCustomField | Add a custom field into the database. |
| GetTypes | Get the available types. |
| OverwriteDefaultData | Overwrite the default data. |
| OverwriteDefaultOptions | Overwrite the default options. |
| OverwriteDefaultTypes | Overwrite the default types. |
| Final Methods | The use can only use these methods as is. |
| Factory | Get an instance of a sub class of this class. |
| GetAllCustomFields | Retrieve an array from database with all of the custom fields. |
| GetDataValues | Retrieve the values of the custom fields. |
| InstallTables | Install the necessary tables in the database. |
| RemoveTables | Removed the installed tables. |
private $data
(array) An array containing the structure of the table containing the values of the custom fields.
In most cases, this should not need to be overwritten. However, if it does, overwrite the method OverwriteDefaultData.
Refer to $options for more information on how the structure of this array should look like.
private $options
(array) An array containing all of the required options for each of the custom fields.
In most cases, this should not need to be overwritten. However, if it does, overwrite the method OverwriteDefaultOptions.
Use the following as a guide on how the structure of this variable should look like:
array(
{The name of the column.} => array(
auto_increment => {
(boolean) Whether or not the column should have the auto
increment property. Defaults to FALSE.
},
default => {
(string) The default value for the column if it is not
given. Defaults to an empty string.
},
default_quotes => {
(boolean) Whether or not the default value should be
surrounded by double quotes. Defaults to TRUE.
}
index => {
(boolean) Whether or not the column should be indexed.
Defaults to FALSE.
},
null => {
(boolean) Whether or not the column can be null.
Defaults to FALSE.
},
primary => {
(boolean) Whether or not the column should be the
primary key. Defaults to FALSE.
},
type => {
(string) The type of the column. Default to "VARCHAR".
},
unique => {
(boolean) Whether or not the column's data should be
unique. Defaults to FALSE.
},
value => {
(string) The value or length for the column. Default to
an empty string.
}
),
...
)
private $types
(array) An array containing the available types for the options.
If you need to overwrite this method, use the method OverwriteDefaultTypes.
Use the following as a guide on how the structure of this variable should look like:
array(
{The unique name for the type.} => array(
'type' => {
(String) The type of data this should holds. It can be
one of the following: "boolean", "date", "decimal",
"integer", "string".
},
'options' => array(
{An option used by this type.},
...
)
),
...
)
public function AddCustomField( $name, $type, $required, $id = NULL, $options = array() )
Add a custom field into the database.
| $name | (String) The name for the custom field. |
| $type | (String) The type for the custom field. |
| $required | (Boolean) Whether or not this custom field is required. |
| $id | (mixed) Optional and defaults to NULL. If provided, this will be used as the ID, otherwise, when inserting, the ID is not added to the SQL. |
| $options | (array) Optional and defaults to an empty array. An array containing all the other options used by this custom field. |
The structure of the parameter $options, if given, should look like the following:
array(
{The name of the option.} => {
(String) The value for the option.
}
)
protected function OverwriteDefaultData()
Overwrite the default data.
Note that the current default data will be merged with the returned array.
(array) An array containing the default data to overwrite. Refer to $options for more information on the structure of the returned array.
protected function OverwriteDefaultOptions()
Overwrite the default options.
Note that the current default options will be merged with the returned array.
(array) An array containing the default options to overwrite. Refer to $options for more information on the structure of the returned array.
protected function OverwriteDefaultTypes()
Overwrite the default types.
Note that the current default types will be merged with the returned array.
(array) An array containing the default types to overwrite. Refer to $options for more information on the structure of the returned array.
final public function GetAllCustomFields( $id = NULL )
Retrieve an array from database with all of the custom fields.
| $id | (Numeric) Optional and defaults to NULL. If set, the returned result will just be the custom field with the provided ID. |
(array) An array containing the custom fields. If no ID was given, then the result will be an array of the following, otherwise it is just the following array:
array(
'id' => {
(String) The ID of the custom field.
},
'name' => {
(String) The name of the custom field.
},
'type' => {
(String) The type of the custom field.
},
'required' => {
(Boolean) Whether or not the custom field is required.
},
{Any other option used by the type.} => {
(String) The value for the option.
},
...
)
final public function GetDataValues( $where = '', $options = array() )
Retrieve the values of the custom fields.
| $where | (mixed) Either a string of the WHERE clause or an array containing all the constraints. If it is an array, refer to the method DLDatabase::BuildWhereClause. Defaults to an empty string. |
| $options | (array) An array containing data used in this method. Refer to the methods DLDatabase::BuildJoinOnClause and DLDatabase::BuildGroupByClause, DLDatabase::BuildOrderByClause for more information regarding some of the attributes. Defaults to an empty array. |
The structure of the $options parameter, if given, should look like the following:
array(
and_or => {
(string) The joining string of the first level in the WHERE
clause. Defaults to "AND".
},
and_or_join => {
(string) The joining string of the first level in the JOIN
ON clause. Defaults to "AND".
},
distinct => {
(boolean) Whether or not the result should be distinct.
Defaults to FALSE.
},
freeform => {
(string) Anything else to be attached at the end of the SQL
right before the semicolon. Defaults to an empty string.
},
group_by => {
(mixed) Either a strinf of the GROUP BY clause or an array
containing the grouping. Refer to the method
DLDatabase::BuildGroupByClause. Defaults to an empty string.
}
join => {
(mixed) Either a string of the JOIN ON clause or an array
containing the joining condition. Refer to the method
DLDatabase::BuildJoinOnClause. Defaults to an empty string.
},
order => {
(mixed) Either a string of the ORDER BY clause or an array
containing the sorting preference. Refer to the method
DLDatabase::BuildOrderByClause. Defaults to an empty string.
}
)(array) An array containing all the rows in the database that match the search criteria. The result array will look something similar to the following:
array(
array(
{The name of the column.} => {
(string) The value of the column.
},
...
),
...
)(array) An array containing the structure of the table containing the values of the custom fields.
private $data
(array) An array containing all of the required options for each of the custom fields.
private $options
(array) An array containing the available types for the options.
private $types
Get the name of the table containing the custom field information.
abstract protected function GetCustomFieldTable()
Get the name of the table containing the data.
abstract protected function GetDataTable()
Add a custom field into the database.
public function AddCustomField( $name, $type, $required, $id = NULL, $options = array() )
Get the available types.
public function GetTypes()
Overwrite the default data.
protected function OverwriteDefaultData()
Overwrite the default options.
protected function OverwriteDefaultOptions()
Overwrite the default types.
protected function OverwriteDefaultTypes()
Get an instance of a sub class of this class.
public static function Factory( $subclass )
Retrieve an array from database with all of the custom fields.
final public function GetAllCustomFields( $id = NULL )
Retrieve the values of the custom fields.
final public function GetDataValues( $where = '', $options = array() )
Install the necessary tables in the database.
final public function InstallTables()
Removed the installed tables.
final public function RemoveTables()
Build the WHERE clause from an array.
public static function BuildWhereClause( $data, $join = 'AND' )
Build the JOIN clause.
public static function BuildJoinOnClause( $data, $join = 'AND' )
Build the GROUP BY clause.
public static function BuildGroupByClause( $data )
Build the ORDER BY clause from an array.
public static function BuildOrderByClause( $data )