PHP Class FOF30\Model\DataModel

Type hinting -- start
Inheritance: extends Model, implements JTableInterface
ファイルを表示 Open project: akeeba/fof Class Usage Examples

Protected Properties

Property Type Description
$_assetKey string The asset key for items in this table. It's usually something in the com_example.viewname format. They asset name will be this key appended with the item's ID, e.g. com_example.viewname.123
$_behaviorParams Shared parameters for behaviors
$_formData The data to load into a form
$_forms Array of form objects
$_has_tags Does the resource support joomla tags?
$_rules The rules associated with this record.
$_trackAssets Should rows be tracked as ACL assets?
$aliasFields Table field name aliases, defined as aliasFieldName => actualFieldName
$autoChecks Should I run automatic checks on the table data?
$autoFill Should I auto-fill the fields of the model object when constructing it?
$behavioursDispatcher An event dispatcher for model behaviours
$contentType The UCM content type (typically: com_something.viewname, e.g. com_foobar.items)
$dbo The database driver for this model
$eagerRelations A list of all eager loaded relations and their attached callbacks
$fieldsSkipChecks Which fields should be exempt from automatic checks when autoChecks is enabled
$fillable Which fields should be auto-filled from the model state (by extent, the request)?
$formName The name of the XML form to load
$guarded Which fields should never be auto-filled from the model state (by extent, the request)?
$idFieldName The identity field's name
$knownFields A hash array with the table fields we know about and their information. Each key is the field name, the value is the field information
$prefixCasePermutations A list of permutations of the prefix with upper/lowercase letters
$recordData The data of the current record
$relationFilters A list of the relation filter definitions for this model
$relationManager The relation manager of this model
$softDelete What will delete() do? True: trash (enabled set to -2); false: hard delete (remove from database)
$tableCache A list of tables in the database
$tableFieldCache A list of table fields, keyed per table
$tableName The name of the database table we connect to
$touches A list of the relations which will be auto-touched by save() and touch() methods
$whereClauses A collection of custom, additional where clauses to apply during buildQuery

Public Methods

Method Description
__call ( string $name, mixed $arguments ) : static Magic caller. It works like the magic setter and returns ourselves for chaining. If no arguments are passed we'll only look for a scope filter.
__construct ( Container $container, array $config = [] ) Public constructor. Overrides the parent constructor, adding support for database-aware models.
__get ( string $name ) : static | mixed Magic getter. It will return the value of a field or, if no such field is found, the value of the relevant state variable.
__isset ( string $name ) : boolean Magic checker on a property. It follows the same logic of the __get magic method, however, if nothing is found, it won't return the state of a variable (we are checking if a property is set)
__set ( string $name, mixed $value ) : void Magic setter. It will set the value of a field or the value of a dynamic scope filter, or the value of the relevant state variable.
addBehaviour ( string $behaviour ) Adds a behaviour by its name. It will search the following classes, in this order: \component_namespace\Model\modelName\Behaviour\behaviourName \component_namespace\Model\DataModel\Behaviour\behaviourName \FOF30\Model\DataModel\Behaviour\behaviourName where: component_namespace is the namespace of the component as defined in the container modelName is the model's name, first character uppercase, e.g. Baz behaviourName is the $behaviour parameter, first character uppercase, e.g. Something
addKnownField ( string $fieldName, mixed $default = null, string $type = 'integer', boolean $replace = false ) Adds a known field to the DataModel. This is only necessary if you are using a custom buildQuery with JOINs or field aliases. Please note that you need to make further modifications for bind() and save() to work in this case. Please refer to the documentation blocks of these methods for more information. It is generally considered a very BAD idea using JOINs instead of relations. It complicates your life and is bound to cause bugs that are very hard to track back.
addSkipCheckField ( string $fieldName ) : void Add a field to the list of fields to be ignored by the check() method
applyAccessFiltering ( integer $userID = null ) : DataModel Applies view access level filtering for the specified user. Useful to filter a front-end items listing.
archive ( ) Archive the record, i.e. set enabled to 2
bind ( mixed $data, mixed $ignore = [] ) : static Method to bind an associative array or object to the DataModel instance. This method optionally takes an array of properties to ignore when binding.
blacklistFilters ( mixed $list = null, boolean $reset = false ) : void | array Set or get the backlisted filters
buildQuery ( boolean $overrideLimits = false ) : JDatabaseQuery Build the query to fetch data from the database
canDelete ( integer $oid = null, array $joins = null ) : void Generic check for whether dependencies exist for this object in the db schema. This method is NOT used by default. If you want to use it you will have to override your delete(), trash() or forceDelete() method, or create an onBeforeDelete and/or onBeforeTrash event handler.
check ( ) : static Check the data for validity. By default it only checks for fields declared as NOT NULL
checkContentType ( string $alias = null ) : null Check if a UCM content type exists for this resource, and create it if it does not
checkIn ( $userId = null ) Check-in an item. This works similar to unlock() but performs additional checks. If the item is locked by another user you need to have adequate ACL privileges to unlock it, i.e. core.admin or core.manage component-wide privileges; core.edit.state privileges component-wide or per asset; or be the creator of the item and have core.edit.own privileges component-wide or per asset.
chunk ( integer $chunkSize, callable $callback ) Process a large collection of records a few at a time.
copy ( $data = null ) : DataModel Creates a copy of the current record. After the copy is performed, the data model contains the data of the new record.
count ( ) : integer Get the number of all items
create ( array $data ) : static Create a new record with the provided data
databaseDataToRecordData ( ) : void Applies the getSomethingAttribute methods to $this->recordData, converting the database representation of the data to the record representation. $this->recordData is directly modified.
delete ( mixed $id = null ) Automatically performs a hard or soft delete, based on the value of $this->softDelete. A soft delete simply sets enabled to -2 whereas a hard delete removes the data from the database. If you want to force a specific behaviour directly call trash() for a soft delete or forceDelete() for a hard delete.
eagerLoad ( Collection &$dataCollection, array $relations = null ) Eager loads the provided relations and assigns their data to a data collection
find ( array | mixed $keys = null ) : static Find and load a single record based on the provided key values
findOrFail ( array | mixed $keys = null ) : static Find and load a single record based on the provided key values. If the record is not found an exception is thrown
firstOrCreate ( array $data ) : static Return the first item found or create a new one based on the provided $data
firstOrFail ( ) : static Return the first item found or throw a \RuntimeException
firstOrNew ( ) : static Return the first item found or create a new, blank one
forceDelete ( mixed $id = null ) Delete a record, either the currently loaded one or the one specified in $id. If an $id is specified that record is loaded before trying to delete it. In the end the data model is reset.
get ( boolean $overrideLimits = false, integer $limitstart, integer $limit ) : Collection Returns a DataCollection iterator based on your currently set Model state
getAssetKey ( ) : string Method to compute the default name of the asset.
getAssetName ( ) : string Method to compute the default name of the asset.
getAssetParentId ( DataModel $model = null, integer $id = null ) : integer Method to get the parent asset under which to register this one.
getAssetTitle ( ) : string Method to return the title to use for the asset table. In tracking the assets a title is kept for each asset so that there is some context available in a unified access manager. Usually this would just return $this->title or $this->name or whatever is being used for the primary name of the row. If this method is not overridden, the asset name is used.
getBehaviorParam ( string $name, mixed $default = null ) : mixed Get a behavior param
getBehavioursDispatcher ( ) : Dispatcher Gives you access to the behaviours dispatcher, allowing to attach/detach behaviour observers
getContentType ( ) : string Get the content type for ucm
getData ( ) : array Returns the data currently bound to the model in an array format. Similar to toArray() but returns a copy instead of the internal table itself.
getDbo ( ) : JDatabaseDriver Get the database connection associated with this data Model
getFieldAlias ( string $alias ) : string Get the real name of a field name based on its alias. If the field is not aliased $alias is returned
getFieldValue ( string $name, mixed $default = null ) : mixed Returns the value of a field. If a field is not set it uses the $default value. Automatically uses magic getter variables if required.
getFields ( ) : mixed Get the columns from database table. For JTableInterface compatibility.
getForm ( array $data = [], boolean $loadData = true, boolean $source = null ) : Form | boolean A method for getting the form from the model.
getFormName ( ) : string Gets the abstract XML form file name
getId ( ) : mixed Return the value of the identity column of the currently loaded record
getIdFieldName ( ) : string Returns the name of the table's id field (primary key) name
getItemsArray ( integer $limitstart, integer $limit, boolean $overrideLimits = false ) : array Returns a raw array of DataModel instances based on your currently set Model state
getKeyName ( ) : string Alias of getIdFieldName. Used for JTableInterface compatibility.
getRawDataArray ( integer $limitstart, integer $limit, boolean $overrideLimits = false ) : array Returns the raw data array, as fetched from the database, based on your currently set Model state
getRelationFields ( ) : array Returns an array mapping relation names to their local key field names.
getRelationFilters ( ) : array Gets the relation filter definitions, for use by the RelationFilters behaviour
getRelations ( ) : RelationManager Returns the relations manager of the model
getRules ( ) : JAccessRules Method to get the rules for the record.
getTableFields ( string $tableName = null ) : mixed Get the columns from a database table.
getTableName ( ) : string Returns the database table name this model talks to
getTouches ( ) : array Returns the list of relations which are touched by save() and touch()
has ( string $relation, string $operator = '>=', mixed $value = 1, boolean $replace = true ) Filter the model based on the fulfilment of relations. For example: $posts->has('comments', '>=', 10)->get(); will return all posts with at least 10 comments.
hasField ( string $fieldName ) : boolean Does this model know about a field called $fieldName? Automatically uses aliases when necessary.
hasSkipCheckField ( string $fieldName ) : boolean Is a field present in the list of fields to be ignored by the check() method?
hasTags ( ) : boolean Gets the has tags switch state
isAssetsTracked ( ) : boolean Method to check if the record is treated as an ACL asset
isLocked ( integer $userId = null ) : boolean Is this record locked by a different user than $userId?
load ( mixed $keys = null, boolean $reset = true ) : boolean Method to load a row from the database by primary key. Used for JTableInterface compatibility.
loadhistory ( integer $version_id, string $alias ) : boolean Method to load a row for editing from the version history table.
lock ( integer $userId = null ) Lock a record by setting its locked_on and/or locked_by columns
move ( integer $delta, string $where = '' ) : static Method to move a row in the ordering sequence of a group of rows defined by an SQL WHERE clause.
orderBy ( string $fieldName, string $direction = 'ASC' ) Set the field and direction of ordering for the query returned by buildQuery.
publish ( integer $state = 1 ) Change the publish state of a record. By default it will set it to 1 (published) unless you specify a different value.
push ( null | array $data = null, string $orderingFilter = '', array $ignore = null, array $relations = null ) Save a record, creating it if it doesn't exist or updating it if it exists. By default it uses the currently set data, unless you provide a $data array. On top of that, it also saves all specified relations. If $relations is null it will save all relations known to this model.
recordDataToDatabaseData ( ) : array Applies the setSomethingAttribute methods to $this->recordData, converting the record representation to database representation. It does not modify $this->recordData, it returns a copy of the data array.
removeBehaviour ( string $behaviour ) Removes a behaviour by its name. It will search the following classes, in this order: \component_namespace\Model\modelName\Behaviour\behaviourName \component_namespace\Model\DataModel\Behaviour\behaviourName \FOF30\Model\DataModel\Behaviour\behaviourName where: component_namespace is the namespace of the component as defined in the container modelName is the model's name, first character uppercase, e.g. Baz behaviourName is the $behaviour parameter, first character uppercase, e.g. Something
removeSkipCheckField ( string $fieldName ) : void Remove a field from the list of fields to be ignored by the check() method
reorder ( string $where = '' ) : static Change the ordering of the records of the table
reset ( boolean $useDefaults = true, boolean $resetRelations = false ) : static Reset the record data
restore ( mixed $id = null ) Untrashes a record, either the currently loaded one or the one specified in $id. If an $id is specified that record is loaded before trying to untrash it. Please note that enabled is set to 0 (unpublished) when you untrash an item.
save ( null | array $data = null, string $orderingFilter = '', array $ignore = null, $resetRelations = true ) : DataModel Save a record, creating it if it doesn't exist or updating it if it exists. By default it uses the currently set data, unless you provide a $data array.
setAssetKey ( string $assetKey ) : void This method sets the asset key for the items of this table. Obviously, it is only meant to be used when you have a table with an asset field.
setAssetsTracked ( $state ) Method to manually set this record as ACL asset or not.
setBehaviorParam ( string $name, mixed $value ) Set a behavior param
setFieldValue ( string $name, mixed $value = null ) : void Sets the value of a field.
setFormName ( string $formName ) : void Sets the abstract XML form file name
setHasTags ( boolean $newState = false ) Sets the has tags switch state
setRules ( mixed $input ) : void Method to set rules for the record.
skip ( integer $limitStart = null ) Set the limitStart for the query, i.e. how many records to skip.
store ( boolean $updateNulls = false ) : boolean Alias of save. For JTableInterface compatibility.
take ( integer $limit = null ) Set the limit for the query, i.e. how many records to return.
tmpInstance ( ) Returns a temporary instance of the model. Please note that this returns a _clone_ of the model object, not the original object. The new object is set up to not save its stats, ignore the request when getting state variables and comes with an empty state. The temporary object instance has its data reset as well.
toArray ( ) : array Return the record's data as an array
toJson ( boolean $prettyPrint = false ) : string Returns the record's data as a JSON string
touch ( integer $userId = null ) Touch a record, updating its modified_on and/or modified_by columns
trash ( mixed $id = null ) Trashes a record, either the currently loaded one or the one specified in $id. If an $id is specified that record is loaded before trying to trash it. Unlike a hard delete, trashing is a "soft delete", only setting the enabled field to -2.
unlock ( ) Unlock a record by resetting its locked_on and/or locked_by columns
unpublish ( ) Unpublish the record, i.e. set enabled to 0
updateUcmContent ( ) : boolean This method is called by Joomla! itself when it needs to update the UCM content
validateForm ( Form $form, array $data, string $group = null ) : mixed Method to validate the form data.
where ( string $fieldName, string $method = '=', mixed $values = null ) Automatically uses the Filters behaviour to filter records in the model based on your criteria.
whereHas ( string $relation, callable $callBack, boolean $replace = true ) Advanced model filtering on the fulfilment of relations. Unlike has() you can provide your own callback which modifies the COUNT subquery used to compare against the relation. The $callBack has the signature function(\JDatabaseQuery $query) and MUST return a string. The $query you are passed is the COUNT subquery of the relation, e.g.
whereRaw ( string $rawWhereClause ) Add custom, pre-compiled WHERE clauses for use in buildQuery. The raw WHERE clause you specify is added as is to the query generated by buildQuery. You are responsible for quoting and escaping the field names and data found inside the WHERE clause.
with ( array $relations ) Instructs the model to eager load the specified relations. The $relations array can have the format:

Protected Methods

Method Description
getAsset ( ) : boolean | JTableAsset Loads the asset table related to this table.
getPrefixCasePermutations ( ) : array Returns all lower and upper case permutations of the database prefix
getUcmCoreAlias ( string $alias, string $null = "null" ) : string Utility methods that fetches the column name for the field.
loadForm ( string $name, string $source, array $options = [], boolean $clear = false, boolean | string $xpath = false ) : Form | boolean Method to get a form object.
loadFormData ( ) : array Method to get the data that should be injected in the form.
preprocessForm ( Form &$form, &$data, string $group = 'content' ) : void Method to allow derived classes to preprocess the form.

Method Details

__call() public method

Magic caller. It works like the magic setter and returns ourselves for chaining. If no arguments are passed we'll only look for a scope filter.
public __call ( string $name, mixed $arguments ) : static
$name string
$arguments mixed
return static

__construct() public method

You can use the $config array to pass some configuration values to the object: tableName String The name of the database table to use. Default: #__appName_viewNamePlural (Ruby on Rails convention) idFieldName String The table key field name. Default: appName_viewNameSingular_id (Ruby on Rails convention) knownFields Array The known fields in the table. Default: read from the table itself autoChecks Boolean Should I turn on automatic data validation checks? fieldsSkipChecks Array List of fields which should not participate in automatic data validation checks. aliasFields Array Associative array of "magic" field aliases. behavioursDispatcher EventDispatcher The model behaviours event dispatcher. behaviourObservers Array The model behaviour observers to attach to the behavioursDispatcher. behaviours Array A list of behaviour names to instantiate and attach to the behavioursDispatcher. fillable_fields Array Which fields should be auto-filled from the model state (by extent, the request)? guarded_fields Array Which fields should never be auto-filled from the model state (by extent, the request)? relations Array (hashed) The relations to autoload on model creation. contentType String The UCM content type, e.g. "com_foobar.items" Setting either fillable_fields or guarded_fields turns on automatic filling of fields in the constructor. If both are set only guarded_fields is taken into account. Fields are not filled automatically outside the constructor.
See also: Model::__construct()
public __construct ( Container $container, array $config = [] )
$container FOF30\Container\Container The configuration variables to this model
$config array Configuration values for this model

__get() public method

Tip: Trying to get fltSomething will always return the value of the state variable "something" Tip: You can define custom field getter methods as getFieldNameAttribute, where FieldName is your field's name, in CamelCase (even if the field name itself is in snake_case).
public __get ( string $name ) : static | mixed
$name string The name of the field / state variable to retrieve
return static | mixed

__isset() public method

Magic checker on a property. It follows the same logic of the __get magic method, however, if nothing is found, it won't return the state of a variable (we are checking if a property is set)
public __isset ( string $name ) : boolean
$name string The name of the field to check
return boolean Is the field set?

__set() public method

Tip: Trying to set fltSomething will always return the value of the state variable "something" Tip: Trying to set scopeSomething will always return the value of the dynamic scope filter "something" Tip: You can define custom field setter methods as setFieldNameAttribute, where FieldName is your field's name, in CamelCase (even if the field name itself is in snake_case).
public __set ( string $name, mixed $value ) : void
$name string The name of the field / scope / state variable to set
$value mixed The value to set
return void

addBehaviour() public method

Adds a behaviour by its name. It will search the following classes, in this order: \component_namespace\Model\modelName\Behaviour\behaviourName \component_namespace\Model\DataModel\Behaviour\behaviourName \FOF30\Model\DataModel\Behaviour\behaviourName where: component_namespace is the namespace of the component as defined in the container modelName is the model's name, first character uppercase, e.g. Baz behaviourName is the $behaviour parameter, first character uppercase, e.g. Something
public addBehaviour ( string $behaviour )
$behaviour string The behaviour's name

addKnownField() public method

Basically, if you find yourself using this method you are probably doing something very wrong or very advanced. If you do not feel confident with debugging FOF code STOP WHATEVER YOU'RE DOING and rethink your Model. Why are you using a JOIN? If you want to filter the records by a field found in another table you can still use relations and whereHas with a callback. If you want to display data from related entries in an XML form you can do that with relations, using the dot notation (name_from="relationName.fieldName"). If you want to do advanced grouping of records (GROUP clauses) then allright, you can't use relations. But if you are doing this kind of advanced stuff you needn't be reading introductory texts like this so get back to coding already!
public addKnownField ( string $fieldName, mixed $default = null, string $type = 'integer', boolean $replace = false )
$fieldName string The name of the field
$default mixed Default value, used by reset() (default: null)
$type string Database type for the field. If unsure use 'integer', 'float' or 'text'.
$replace boolean Should we replace an existing known field definition?

addSkipCheckField() public method

Add a field to the list of fields to be ignored by the check() method
public addSkipCheckField ( string $fieldName ) : void
$fieldName string The field to add (can be a field alias)
return void

applyAccessFiltering() public method

Applies view access level filtering for the specified user. Useful to filter a front-end items listing.
public applyAccessFiltering ( integer $userID = null ) : DataModel
$userID integer The user ID to use. Skip it to use the currently logged in user.
return DataModel Reference to self

archive() public method

Archive the record, i.e. set enabled to 2
public archive ( )

bind() public method

Special note if you are using a custom buildQuery with JOINs or field aliases: You will need to use addKnownField to let FOF know that the fields from your JOINs and the aliased fields should be bound to the record data. If you are using aliased fields you may also want to override the databaseDataToRecordData method. Generally, it is a BAD idea using JOINs instead of relations.
public bind ( mixed $data, mixed $ignore = [] ) : static
$data mixed An associative array or object to bind to the DataModel instance.
$ignore mixed An optional array or space separated list of properties to ignore while binding.
return static Self, for chaining

blacklistFilters() public method

Set or get the backlisted filters
public blacklistFilters ( mixed $list = null, boolean $reset = false ) : void | array
$list mixed A filter or list of filters to backlist. If null return the list of backlisted filter
$reset boolean Reset the blacklist if true
return void | array Return an array of value if $list is null

buildQuery() public method

Build the query to fetch data from the database
public buildQuery ( boolean $overrideLimits = false ) : JDatabaseQuery
$overrideLimits boolean Should I override limits
return JDatabaseQuery The database query to use

canDelete() public method

Generic check for whether dependencies exist for this object in the db schema. This method is NOT used by default. If you want to use it you will have to override your delete(), trash() or forceDelete() method, or create an onBeforeDelete and/or onBeforeTrash event handler.
public canDelete ( integer $oid = null, array $joins = null ) : void
$oid integer The primary key of the record to delete
$joins array Any joins to foreign table, used to determine if dependent records exist
return void

check() public method

Check the data for validity. By default it only checks for fields declared as NOT NULL
public check ( ) : static
return static Self, for chaining

checkContentType() public method

Check if a UCM content type exists for this resource, and create it if it does not
public checkContentType ( string $alias = null ) : null
$alias string The content type alias (optional)
return null

checkIn() public method

Check-in an item. This works similar to unlock() but performs additional checks. If the item is locked by another user you need to have adequate ACL privileges to unlock it, i.e. core.admin or core.manage component-wide privileges; core.edit.state privileges component-wide or per asset; or be the creator of the item and have core.edit.own privileges component-wide or per asset.
public checkIn ( $userId = null )

chunk() public method

Process a large collection of records a few at a time.
public chunk ( integer $chunkSize, callable $callback )
$chunkSize integer How many records to process at once
$callback callable A callable to process each record

copy() public method

Creates a copy of the current record. After the copy is performed, the data model contains the data of the new record.
public copy ( $data = null ) : DataModel
return DataModel

count() public method

Get the number of all items
public count ( ) : integer
return integer

create() public method

Create a new record with the provided data
public create ( array $data ) : static
$data array The data to use in the new record
return static Self, for chaining

databaseDataToRecordData() public method

Applies the getSomethingAttribute methods to $this->recordData, converting the database representation of the data to the record representation. $this->recordData is directly modified.
public databaseDataToRecordData ( ) : void
return void

delete() public method

Automatically performs a hard or soft delete, based on the value of $this->softDelete. A soft delete simply sets enabled to -2 whereas a hard delete removes the data from the database. If you want to force a specific behaviour directly call trash() for a soft delete or forceDelete() for a hard delete.
public delete ( mixed $id = null )
$id mixed Primary key (id field) value

eagerLoad() public method

Eager loads the provided relations and assigns their data to a data collection
public eagerLoad ( Collection &$dataCollection, array $relations = null )
$dataCollection FOF30\Model\DataModel\Collection The data collection on which the eager loaded relations will be applied
$relations array The relations to eager load. Leave empty to use the already defined relations

find() public method

Find and load a single record based on the provided key values
public find ( array | mixed $keys = null ) : static
$keys array | mixed An optional primary key value to load the row by, or an array of fields to match. If not set the "id" state variable or, if empty, the identity column's value is used
return static Self, for chaining

findOrFail() public method

Find and load a single record based on the provided key values. If the record is not found an exception is thrown
public findOrFail ( array | mixed $keys = null ) : static
$keys array | mixed An optional primary key value to load the row by, or an array of fields to match. If not set the "id" state variable or, if empty, the identity column's value is used
return static Self, for chaining

firstOrCreate() public method

Return the first item found or create a new one based on the provided $data
public firstOrCreate ( array $data ) : static
$data array Data for the newly created item
return static

firstOrFail() public method

Return the first item found or throw a \RuntimeException
public firstOrFail ( ) : static
return static

firstOrNew() public method

Return the first item found or create a new, blank one
public firstOrNew ( ) : static
return static

forceDelete() public method

Delete a record, either the currently loaded one or the one specified in $id. If an $id is specified that record is loaded before trying to delete it. In the end the data model is reset.
public forceDelete ( mixed $id = null )
$id mixed Primary key (id field) value

get() public method

Returns a DataCollection iterator based on your currently set Model state
public get ( boolean $overrideLimits = false, integer $limitstart, integer $limit ) : Collection
$overrideLimits boolean Should I ignore limits set in the Model?
$limitstart integer How many items to skip from the start, only when $overrideLimits = true
$limit integer How many items to return, only when $overrideLimits = true
return FOF30\Model\DataModel\Collection The data collection

getAsset() protected method

This will help tests, too, since we can mock this function.
protected getAsset ( ) : boolean | JTableAsset
return boolean | JTableAsset False on failure, otherwise JTableAsset

getAssetKey() public method

The default name is in the form table_name.id where id is the value of the primary key of the table.
public getAssetKey ( ) : string
return string

getAssetName() public method

The default name is in the form table_name.id where id is the value of the primary key of the table.
public getAssetName ( ) : string
return string

getAssetParentId() public method

By default, all assets are registered to the ROOT node with ID, which will default to 1 if none exists. The extended class can define a table and id to lookup. If the asset does not exist it will be created.
public getAssetParentId ( DataModel $model = null, integer $id = null ) : integer
$model DataModel A model object for the asset parent.
$id integer Id to look up
return integer

getAssetTitle() public method

Method to return the title to use for the asset table. In tracking the assets a title is kept for each asset so that there is some context available in a unified access manager. Usually this would just return $this->title or $this->name or whatever is being used for the primary name of the row. If this method is not overridden, the asset name is used.
public getAssetTitle ( ) : string
return string The string to use as the title in the asset table.

getBehaviorParam() public method

Get a behavior param
public getBehaviorParam ( string $name, mixed $default = null ) : mixed
$name string The name of the param you want to get
$default mixed The default value returned if not set
return mixed

getBehavioursDispatcher() public method

Gives you access to the behaviours dispatcher, allowing to attach/detach behaviour observers
public getBehavioursDispatcher ( ) : Dispatcher
return FOF30\Event\Dispatcher

getContentType() public method

Get the content type for ucm
public getContentType ( ) : string
return string The content type alias

getData() public method

Returns the data currently bound to the model in an array format. Similar to toArray() but returns a copy instead of the internal table itself.
public getData ( ) : array
return array

getDbo() public method

Get the database connection associated with this data Model
public getDbo ( ) : JDatabaseDriver
return JDatabaseDriver

getFieldAlias() public method

Get the real name of a field name based on its alias. If the field is not aliased $alias is returned
public getFieldAlias ( string $alias ) : string
$alias string The field to get an alias for
return string The real name of the field

getFieldValue() public method

Returns the value of a field. If a field is not set it uses the $default value. Automatically uses magic getter variables if required.
public getFieldValue ( string $name, mixed $default = null ) : mixed
$name string The name of the field to retrieve
$default mixed Default value, if the field is not set and doesn't have a getter method
return mixed The value of the field

getFields() public method

Get the columns from database table. For JTableInterface compatibility.
public getFields ( ) : mixed
return mixed An array of the field names, or false if an error occurs.

getForm() public method

A method for getting the form from the model.
Since: 2.0
public getForm ( array $data = [], boolean $loadData = true, boolean $source = null ) : Form | boolean
$data array Data for the form.
$loadData boolean True if the form is to load its own data (default case), false if not.
$source boolean The name of the form. If not set we'll try the form_name state variable or fall back to default.
return FOF30\Form\Form | boolean A Form object on success, false on failure

getFormName() public method

Gets the abstract XML form file name
public getFormName ( ) : string
return string The abstract form file name to set, e.g. "form.default"

getId() public method

Return the value of the identity column of the currently loaded record
public getId ( ) : mixed
return mixed

getIdFieldName() public method

Returns the name of the table's id field (primary key) name
public getIdFieldName ( ) : string
return string

getItemsArray() public method

Returns a raw array of DataModel instances based on your currently set Model state
public getItemsArray ( integer $limitstart, integer $limit, boolean $overrideLimits = false ) : array
$limitstart integer How many items from the start to skip (0 = do not skip)
$limit integer How many items to return (0 = all)
$overrideLimits boolean Set to true to override limitstart, limit and ordering
return array Array of DataModel objects

getKeyName() public method

Alias of getIdFieldName. Used for JTableInterface compatibility.
public getKeyName ( ) : string
return string The name of the primary key for the table.

getPrefixCasePermutations() protected method

Returns all lower and upper case permutations of the database prefix
protected getPrefixCasePermutations ( ) : array
return array

getRawDataArray() public method

Returns the raw data array, as fetched from the database, based on your currently set Model state
public getRawDataArray ( integer $limitstart, integer $limit, boolean $overrideLimits = false ) : array
$limitstart integer How many items from the start to skip (0 = do not skip)
$limit integer How many items to return (0 = all)
$overrideLimits boolean Set to true to override limitstart, limit and ordering
return array Array of hashed arrays

getRelationFields() public method

For example, given a relation "foobar" with local key name "example_item_id" it will return: ["foobar" => "example_item_id"]
public getRelationFields ( ) : array
return array Array of [relationName => fieldName] arrays

getRelationFilters() public method

Gets the relation filter definitions, for use by the RelationFilters behaviour
public getRelationFilters ( ) : array
return array

getRelations() public method

Returns the relations manager of the model
public getRelations ( ) : RelationManager
return FOF30\Model\DataModel\RelationManager

getRules() public method

Method to get the rules for the record.
public getRules ( ) : JAccessRules
return JAccessRules object

getTableFields() public method

Get the columns from a database table.
public getTableFields ( string $tableName = null ) : mixed
$tableName string Table name. If null current table is used
return mixed An array of the field names, or false if an error occurs.

getTableName() public method

Returns the database table name this model talks to
public getTableName ( ) : string
return string

getTouches() public method

Returns the list of relations which are touched by save() and touch()
public getTouches ( ) : array
return array

getUcmCoreAlias() protected method

If it does not exists, returns a "null" string
protected getUcmCoreAlias ( string $alias, string $null = "null" ) : string
$alias string The alias for the column
$null string What to return if no column exists
return string The column name

has() public method

Filter the model based on the fulfilment of relations. For example: $posts->has('comments', '>=', 10)->get(); will return all posts with at least 10 comments.
public has ( string $relation, string $operator = '>=', mixed $value = 1, boolean $replace = true )
$relation string The relation to query
$operator string The comparison operator. Same operators as the where() method.
$value mixed The value(s) to compare against.
$replace boolean When true (default) any existing relation filters for the same relation will be replaced

hasField() public method

Does this model know about a field called $fieldName? Automatically uses aliases when necessary.
public hasField ( string $fieldName ) : boolean
$fieldName string Field name to check
return boolean True if the field exists

hasSkipCheckField() public method

Is a field present in the list of fields to be ignored by the check() method?
public hasSkipCheckField ( string $fieldName ) : boolean
$fieldName string The field to check (can be a field alias)
return boolean True if the field is skipped from checks, false if not or if the field doesn't exist.

hasTags() public method

Gets the has tags switch state
public hasTags ( ) : boolean
return boolean

isAssetsTracked() public method

Method to check if the record is treated as an ACL asset
public isAssetsTracked ( ) : boolean
return boolean [description]

isLocked() public method

Is this record locked by a different user than $userId?
public isLocked ( integer $userId = null ) : boolean
$userId integer
return boolean True if the record is locked

load() public method

Method to load a row from the database by primary key. Used for JTableInterface compatibility.
public load ( mixed $keys = null, boolean $reset = true ) : boolean
$keys mixed An optional primary key value to load the row by, or an array of fields to match. If not set the instance property value is used.
$reset boolean True to reset the default values before loading the new row.
return boolean True if successful. False if row not found.

loadForm() protected method

Method to get a form object.
See also: Form
Since: 2.0
protected loadForm ( string $name, string $source, array $options = [], boolean $clear = false, boolean | string $xpath = false ) : Form | boolean
$name string The name of the form.
$source string The form filename (e.g. form.browse)
$options array Optional array of options for the form creation.
$clear boolean Optional argument to force load a new form.
$xpath boolean | string An optional xpath to search for the fields.
return FOF30\Form\Form | boolean Form object on success, False on error.

loadFormData() protected method

Method to get the data that should be injected in the form.
Since: 2.0
protected loadFormData ( ) : array
return array The default data is an empty array.

loadhistory() public method

Method to load a row for editing from the version history table.
Since: 2.3
public loadhistory ( integer $version_id, string $alias ) : boolean
$version_id integer Key to the version history table.
$alias string The type_alias in #__content_types
return boolean True on success

lock() public method

Lock a record by setting its locked_on and/or locked_by columns
public lock ( integer $userId = null )
$userId integer

move() public method

Negative numbers move the row up in the sequence and positive numbers move it down.
public move ( integer $delta, string $where = '' ) : static
$delta integer The direction and magnitude to move the row in the ordering sequence.
$where string WHERE clause to use for limiting the selection of rows to compact the ordering values.
return static Self, for chaining

orderBy() public method

Alias of $this->setState('filter_order', $fieldName) and $this->setState('filter_order_Dir', $direction)
public orderBy ( string $fieldName, string $direction = 'ASC' )
$fieldName string The field name to order by
$direction string The direction to order by (ASC for ascending or DESC for descending)

preprocessForm() protected method

Method to allow derived classes to preprocess the form.
Since: 2.0
protected preprocessForm ( Form &$form, &$data, string $group = 'content' ) : void
$form FOF30\Form\Form
$group string The name of the plugin group to import (defaults to "content").
return void

publish() public method

Change the publish state of a record. By default it will set it to 1 (published) unless you specify a different value.
public publish ( integer $state = 1 )
$state integer The publish state. Default: 1 (published).

push() public method

Save a record, creating it if it doesn't exist or updating it if it exists. By default it uses the currently set data, unless you provide a $data array. On top of that, it also saves all specified relations. If $relations is null it will save all relations known to this model.
public push ( null | array $data = null, string $orderingFilter = '', array $ignore = null, array $relations = null )
$data null | array [Optional] Data to bind
$orderingFilter string A WHERE clause used to apply table item reordering
$ignore array A list of fields to ignore when binding $data
$relations array Which relations to save with the model's record. Leave null for all relations

recordDataToDatabaseData() public method

If you are using custom knownFields to cater for table JOINs you need to override this method and _remove_ the fields which do not belong to the table you are saving to. It's generally a bad idea using JOINs instead of relations. You have been warned!
public recordDataToDatabaseData ( ) : array
return array

removeBehaviour() public method

Removes a behaviour by its name. It will search the following classes, in this order: \component_namespace\Model\modelName\Behaviour\behaviourName \component_namespace\Model\DataModel\Behaviour\behaviourName \FOF30\Model\DataModel\Behaviour\behaviourName where: component_namespace is the namespace of the component as defined in the container modelName is the model's name, first character uppercase, e.g. Baz behaviourName is the $behaviour parameter, first character uppercase, e.g. Something
public removeBehaviour ( string $behaviour )
$behaviour string The behaviour's name

removeSkipCheckField() public method

Remove a field from the list of fields to be ignored by the check() method
public removeSkipCheckField ( string $fieldName ) : void
$fieldName string The field to remove (can be a field alias)
return void

reorder() public method

Change the ordering of the records of the table
public reorder ( string $where = '' ) : static
$where string The WHERE clause of the SQL used to fetch the order
return static Self, for chaining

reset() public method

Reset the record data
public reset ( boolean $useDefaults = true, boolean $resetRelations = false ) : static
$useDefaults boolean Should I use the default values? Default: yes
$resetRelations boolean Should I reset the relations too? Default: no
return static Self, for chaining

restore() public method

Untrashes a record, either the currently loaded one or the one specified in $id. If an $id is specified that record is loaded before trying to untrash it. Please note that enabled is set to 0 (unpublished) when you untrash an item.
public restore ( mixed $id = null )
$id mixed Primary key (id field) value

save() public method

Special note if you are using a custom buildQuery with JOINs or field aliases: You will need to override the recordDataToDatabaseData method. Make sure that you _remove_ or rename any fields which do not exist in the table defined in $this->tableName. Otherwise Joomla! will not know how to insert / update the data on the table and will throw an Exception denoting a database error. It is generally a BAD idea using JOINs instead of relations. If unsure, use relations.
public save ( null | array $data = null, string $orderingFilter = '', array $ignore = null, $resetRelations = true ) : DataModel
$data null | array [Optional] Data to bind
$orderingFilter string A WHERE clause used to apply table item reordering
$ignore array A list of fields to ignore when binding $data
return DataModel Self, for chaining

setAssetKey() public method

This method sets the asset key for the items of this table. Obviously, it is only meant to be used when you have a table with an asset field.
public setAssetKey ( string $assetKey ) : void
$assetKey string The name of the asset key to use
return void

setAssetsTracked() public method

We have to do this since the automatic check is made in the constructor, but here we can't set any alias. So, even if you have an alias for asset_id, it wouldn't be reconized and assets won't be tracked.
public setAssetsTracked ( $state )
$state

setBehaviorParam() public method

Set a behavior param
public setBehaviorParam ( string $name, mixed $value )
$name string The name of the param you want to set
$value mixed The value to set

setFieldValue() public method

Sets the value of a field.
public setFieldValue ( string $name, mixed $value = null ) : void
$name string The name of the field to set
$value mixed The value to set it to
return void

setFormName() public method

Sets the abstract XML form file name
public setFormName ( string $formName ) : void
$formName string The abstract form file name to set, e.g. "form.default"
return void

setHasTags() public method

Sets the has tags switch state
public setHasTags ( boolean $newState = false )
$newState boolean

setRules() public method

Method to set rules for the record.
public setRules ( mixed $input ) : void
$input mixed A JAccessRules object, JSON string, or array.
return void

skip() public method

Alias of $this->setState('limitstart', $limitStart);
public skip ( integer $limitStart = null )
$limitStart integer Records to skip from the start

store() public method

Alias of save. For JTableInterface compatibility.
public store ( boolean $updateNulls = false ) : boolean
$updateNulls boolean Blatantly ignored.
return boolean True on success.

take() public method

Alias of $this->setState('limit', $limit);
public take ( integer $limit = null )
$limit integer Maximum number of records to return

tmpInstance() public method

Returns a temporary instance of the model. Please note that this returns a _clone_ of the model object, not the original object. The new object is set up to not save its stats, ignore the request when getting state variables and comes with an empty state. The temporary object instance has its data reset as well.
public tmpInstance ( )

toArray() public method

Return the record's data as an array
public toArray ( ) : array
return array

toJson() public method

Returns the record's data as a JSON string
public toJson ( boolean $prettyPrint = false ) : string
$prettyPrint boolean Should I format the JSON for pretty printing
return string

touch() public method

Touch a record, updating its modified_on and/or modified_by columns
public touch ( integer $userId = null )
$userId integer Optional user ID of the user touching the record

trash() public method

Trashes a record, either the currently loaded one or the one specified in $id. If an $id is specified that record is loaded before trying to trash it. Unlike a hard delete, trashing is a "soft delete", only setting the enabled field to -2.
public trash ( mixed $id = null )
$id mixed Primary key (id field) value

unlock() public method

Unlock a record by resetting its locked_on and/or locked_by columns
public unlock ( )

unpublish() public method

Unpublish the record, i.e. set enabled to 0
public unpublish ( )

updateUcmContent() public method

This method is called by Joomla! itself when it needs to update the UCM content
public updateUcmContent ( ) : boolean
return boolean

validateForm() public method

Method to validate the form data.
See also: JFormRule
See also: JFilterInput
Since: 2.0
public validateForm ( Form $form, array $data, string $group = null ) : mixed
$form FOF30\Form\Form The form to validate against.
$data array The data to validate.
$group string The name of the field group to validate.
return mixed Array of filtered data if valid, false otherwise.

where() public method

Automatically uses the Filters behaviour to filter records in the model based on your criteria.
public where ( string $fieldName, string $method = '=', mixed $values = null )
$fieldName string The field name to filter on
$method string The filtering method, e.g. <>, =, != and so on
$values mixed The value you're filtering on. Some filters (e.g. interval or between) require an array of values

whereHas() public method

SELECT COUNT(*) FROM #__comments AS reltbl WHERE reltbl.user_id = user_id You have to return a WHERE clause for the model's query, e.g. (SELECT COUNT(*) FROM #__comments AS reltbl WHERE reltbl.user_id = user_id) BETWEEN 1 AND 20
public whereHas ( string $relation, callable $callBack, boolean $replace = true )
$relation string The relation to query against
$callBack callable The callback to use for filtering
$replace boolean When true (default) any existing relation filters for the same relation will be replaced

whereRaw() public method

Using this method is a generally bad idea. You are better off overriding buildQuery and using state variables to customise the query build built instead of using this method to push raw SQL to the query builder. Mixing your business logic with raw SQL makes your application harder to maintain and refactor as dependencies to your database schema creep in areas of your code that should have nothing to do with it.
public whereRaw ( string $rawWhereClause )
$rawWhereClause string The raw WHERE clause to add

with() public method

array('relation1', 'relation2') Eager load relation1 and relation2 without any callbacks array('relation1' => $callable1, 'relation2' => $callable2) Eager load relation1 with callback $callable1 etc array('relation1', 'relation2' => $callable2) Eager load relation1 without a callback, relation2 with callback $callable2 The callback must have the signature function(\JDatabaseQuery $query) and doesn't return a value. It is supposed to modify the query directly. Please note that eager loaded relations produce their queries without going through the respective model. Instead they generate a SQL query directly, then map the loaded results into a DataCollection.
public with ( array $relations )
$relations array The relations to eager load. See above for more information.

Property Details

$_assetKey protected_oe property

The asset key for items in this table. It's usually something in the com_example.viewname format. They asset name will be this key appended with the item's ID, e.g. com_example.viewname.123
protected string $_assetKey
return string

$_behaviorParams protected_oe property

Shared parameters for behaviors
protected $_behaviorParams

$_formData protected_oe property

The data to load into a form
protected $_formData

$_forms protected_oe property

Array of form objects
protected $_forms

$_has_tags protected_oe property

Does the resource support joomla tags?
protected $_has_tags

$_rules protected_oe property

The rules associated with this record.
protected $_rules

$_trackAssets protected_oe property

Should rows be tracked as ACL assets?
protected $_trackAssets

$aliasFields protected_oe property

Table field name aliases, defined as aliasFieldName => actualFieldName
protected $aliasFields

$autoChecks protected_oe property

Should I run automatic checks on the table data?
protected $autoChecks

$autoFill protected_oe property

Should I auto-fill the fields of the model object when constructing it?
protected $autoFill

$behavioursDispatcher protected_oe property

An event dispatcher for model behaviours
protected $behavioursDispatcher

$contentType protected_oe property

The UCM content type (typically: com_something.viewname, e.g. com_foobar.items)
protected $contentType

$dbo protected_oe property

The database driver for this model
protected $dbo

$eagerRelations protected_oe property

A list of all eager loaded relations and their attached callbacks
protected $eagerRelations

$fieldsSkipChecks protected_oe property

Which fields should be exempt from automatic checks when autoChecks is enabled
protected $fieldsSkipChecks

$fillable protected_oe property

Which fields should be auto-filled from the model state (by extent, the request)?
protected $fillable

$formName protected_oe property

The name of the XML form to load
protected $formName

$guarded protected_oe property

Which fields should never be auto-filled from the model state (by extent, the request)?
protected $guarded

$idFieldName protected_oe property

The identity field's name
protected $idFieldName

$knownFields protected_oe property

A hash array with the table fields we know about and their information. Each key is the field name, the value is the field information
protected $knownFields

$prefixCasePermutations protected_oe static_oe property

A list of permutations of the prefix with upper/lowercase letters
protected static $prefixCasePermutations

$recordData protected_oe property

The data of the current record
protected $recordData

$relationFilters protected_oe property

A list of the relation filter definitions for this model
protected $relationFilters

$relationManager protected_oe property

The relation manager of this model
protected $relationManager

$softDelete protected_oe property

What will delete() do? True: trash (enabled set to -2); false: hard delete (remove from database)
protected $softDelete

$tableCache protected_oe static_oe property

A list of tables in the database
protected static $tableCache

$tableFieldCache protected_oe static_oe property

A list of table fields, keyed per table
protected static $tableFieldCache

$tableName protected_oe property

The name of the database table we connect to
protected $tableName

$touches protected_oe property

A list of the relations which will be auto-touched by save() and touch() methods
protected $touches

$whereClauses protected_oe property

A collection of custom, additional where clauses to apply during buildQuery
protected $whereClauses