$tableName
$tableName :
Base class for handling database records and their forms.
You can subclass dbRecord to create your own type of record. Inside it, you will define the database table and the form fiels configuration. Then the dbRecord class will handle easy storage of your record using the store() method and loading using the load() method. An editable list of your records can also easily be generated using the showRecordEditTable() function.
loadKey( $row, $key, $value)
Loads a key from the given SQL row and stores its value into the object data['key'] array
$row | array an SQL row |
|
$key | string the column identifier in the SQL row and in the data array (both must always match) |
|
$value | string the value to store in the key |
glueWithTemplateInfo( $templateName, $strippedTemplateContent)
glues 'value' keys of template content with the rest of the record definition This is required since only keys named 'value' are stored in the database to minimize space taken
$templateName | String the name of the template to load the specification from |
|
$strippedTemplateContent | Array the content loaded from the database, stripped from the useless fields, keeping only value fields |
glueWithMicrotemplateInfo( $microtemplateName, $strippedTemplateContent)
glues 'value' keys of microtemplate content with the rest of the record definition This is required since only keys named 'value' are stored in the database to minimize space taken
$microtemplateName | ||
$strippedTemplateContent | Array the content loaded from the database, stripped from the useless fields, keeping only value fields |
getNextAvailableUid() : integer
Returns the next available Uid if you badly need it before storing your record.
USE WITH CAUTION : it DOES NOT RESERVE the uid, so there is a slight risk that a record can be created by another script between the time you ask for the Uid and the time you effectively create your record. If possible prefer using the autoincrement feature by setting a void value "" to the uid field. This can be usefull for performance reason sometimes though
the uid of the next record created.
diff(array $arr1, array $arr2) : array|null
Compute the difference between $arr1 and $arr2.
The result is an array (can be empty) giving the differences between the 2 arrays.
Note the differences are expressed in a form you can use the resulting array to "patch" $arr1 to obtain $arr2.
This is basically the same stuff than for "diff" command (from UNIX).
array | $arr1 | the first array |
array | $arr2 | the second array |
returns the diff array if both input arguments are arrays, null otherwise.
getKeySQL( $keyName, $keyData) : string
Returns the SQL command for storing a given key from the data array, processing the values : dates are converted from localized format to SQL format, slug texts are slugified, arrays are serialized
$keyName | string the name of the key |
|
$keyData | array the data associated with the key |
the sql segment prepared for storing the given key
showRecordEditTable( $request, $moduleName, $subModuleName, $mainKey, $keyProcessors = array(), $page = NULL, $availableActions = array('create' => 1, 'view' => 0, 'edit' => 1, 'delete' => 1, 'clone' => 1), $advancedOptions = array('ajaxActions' => 0, 'showPrint' => false, 'showResultsCount' => true), $recordEditTableID = null) : string
Outputs an HTML table of all the records available in this class
$request | array The list of keys fetched from SQL, which will make the columns of the table. format must be array('SELECT' => '', 'FROM' => '', 'JOIN' => '', 'WHERE' => ''); |
|
$moduleName | string The name of the module or plugin displaying this record |
|
$subModuleName | ||
$mainKey | string The key of the field best describing the name of this record, used for deletion dialog : "Are you sure you want to delete the record $mainKey ?" |
|
$keyProcessors | array An array of processing functions indexed by key name (as found in $keysList) for pre-processing values before displaying these in the table. processing function definition must be located in the record's own class file |
|
$page | int requests displaying the page number given from the results list |
|
$availableActions | array lists the action icons available in the actions column. Default value is array('view'=>0,'edit'=>1,'delete'=>1). Additionally, a custom function can be supplied as a string for the value of 'view','edit','delete','sortUp','sortDown'. This URL can contain some of the following markers that will be automatically substituted : {subdir}, {record_class}, {record_uid}, {module_id}, {submodule_id}, {your_custom_column_name} (this latest value has to exist as a valid column in the record table). Example value for $availableActions : array( 'create' => 1, 'view' => 'myClass::makeHTMLActionLink("viewFaq","{subdir}","{record_uid}")', 'edit' => 'myClass::makeHTMLActionLink("editFaq","{subdir}","{record_uid}")', 'delete' => 1, 'sortUp' => 'myClass::makeJSONActionLink("sortUp","{subdir}","{record_uid}")', 'sortDown' => 'myClass::makeJSONActionLink("sortDown","{subdir}","{record_uid}")', 'myCustomAction1' => 'myClass::makeJSONActionLink("customAction1","{subdir}","{record_uid}")', ), |
|
$advancedOptions | array allows specifying more options using the following format array(
) |
|
$recordEditTableID | string forces the recordEditTableID in order to keep it the same when refreshing an existing recordEditTable |
getUrl() : string
This function must be overloaded with your custom code.
Returns the URL for viewing the record from a frontend page This function may return different URL values according to the context the record is being viewed : Say you have a website with 3 main sections : foot trips, car trips, bike trips. You want to display a news record which is generic to the 3 sections, but you want it to be seen in each section. So according to which section the news item is called from, getUrl() may return : /foot-trips/news/my-news-item.html or /car-trips/news/my-news-item.html
getCanonicalUrl() : string
This function must be overloaded with your custom code.
Returns the MAIN URL for viewing the record from a frontend page If a record may have different display URLs (see getUrl() function doc about this), often you must only supply one main / unique / canonical URL to search engines so you avoid duplicate contents This function will return the canonical URL of your object
formatDate(string $key, string $value, string $locale, array $row) : string
Formats a date for displaying it in the showRecordEditTable
string | $key | current key name |
string | $value | value of the key |
string | $locale | currently displayed locale |
array | $row | whole row data for the current record. Usefull if it is required to check the value of another key |
the formated date
formatDateTimeMs(string $key, string $value, string $locale, array $row) : string
Formats a datetime featuring milliseconds for displaying it in the showRecordEditTable
string | $key | current key name |
string | $value | value of the key |
string | $locale | currently displayed locale |
array | $row | whole row data for the current record. Usefull if it is required to check the value of another key |
the formated date
formatDateTime(string $key, string $value, string $locale, array $row) : string
Formats a datetime for displaying it in the showRecordEditTable
string | $key | current key name |
string | $value | value of the key |
string | $locale | currently displayed locale |
array | $row | whole row data for the current record. Usefull if it is required to check the value of another key |
the formated date
formatTime(string $key, string $value, string $locale, array $row) : string
Formats a time for displaying it in the showRecordEditTable
string | $key | current key name |
string | $value | value of the key |
string | $locale | currently displayed locale |
array | $row | whole row data for the current record. Usefull if it is required to check the value of another key |
the formated date
formatTimestamp(string $value, string $locale, array $row) : string
Formats a timestamp for displaying it in the showRecordEditTable
string | $value | value of the key |
string | $locale | currently displayed locale |
array | $row | whole row data for the current record. Usefull if it is required to check the value of another key |
the formated date
searchRecordTypeahead( $searchValue, $formID, $fulltextFields, $varcharFields, $equalFields, $searchWhere, $orderByFields, $titleFields, $tableName, $recordClass, $callingFieldName, $callingRecordClass, $debug = false) : array
Searches the given $searchValue into the given $tableName and tries to match it with the specified $fieldNames. This function is intended to be executed from the recordSelectField search function
$searchValue | string the value we are searching for |
|
$formID | string the id attribute associated with the form the recordSelectField search function is being executed from |
|
$fulltextFields | string coma separated list of fulltext fields/columns being searched in |
|
$varcharFields | ||
$equalFields | string coma separated list of varchar fields/columns being searched in |
|
$searchWhere | ||
$orderByFields | string coma separated list fields/columns to sort the result by |
|
$titleFields | string coma separated list of fields to display as title for the found items in the search result set |
|
$tableName | string the table name in the SQL database of the type of record being investigated |
|
$recordClass | string the class name of the type of record being investigated |
|
$callingFieldName | string the field name (or you may call it key) of the record from which the search was launched |
|
$callingRecordClass | string the class name of the record from which the search was launched |
|
$debug |
createSQLTable(integer $showSQL, $html = array(), boolean $importInitializationData = false) : integer
Creates the SQL table for this record in the database.
If you have set $oneTablePerLocale to true, the function will only create the table for the currently defined locale. If you want to create different tables for different locales, you will have to alter the locale value in $mf->info['data_editing_locale'] prior creating a table for the desired locale.
integer | $showSQL | generate HTML showing the result of the SQL request and feed the $html array passed by reference with it |
$html | ||
boolean | $importInitializationData | Fill the table with initialization data after creation if this data is available |
returns 1 if successful creation, 0 otherwise.