PHP Класс Gdn_Model, vanilla

Наследование: extends Gdn_Pluggable
Показать файл Открыть проект Примеры использования класса

Открытые свойства

Свойство Тип Описание
$Data An object representation of the current working dataset.
$Database Database object.
$DateInserted The name of the field that stores the insert date for a record. This field will be automatically filled by the model if it exists.
$DateUpdated The name of the field that stores the update date for a record. This field will be automatically filled by the model if it exists.
$InsertUserID The name of the field that stores the id of the user that inserted it. This field will be automatically filled by the model if it exists and
$Name The name of the table that this model is intended to represent. The default value assigned to $this->Name will be the name that the model was instantiated with (defined in $this->__construct()).
$PrimaryKey name of the primary key field of this model. The default is 'id'. If $this->DefineSchema() is called, this value will be automatically changed to any primary key discovered when examining the table schema.
$SQL Contains the sql driver for the object.
$Schema An object that is used to store and examine database schema information related to this model. This object is defined and populated with $this->DefineSchema().
$UpdateUserID The name of the field that stores the id of the user that updated it. This field will be automatically filled by the model if it exists and @@Session::UserID is a valid integer.
$Validation An object that is used to manage and execute data integrity rules on this object. By default, this object only enforces maxlength, data types, and required fields (defined when $this->DefineSchema() is called).

Защищенные свойства (Protected)

Свойство Тип Описание
$filterFields The fields that should be filtered out via {@link Gdn_Model::filterForm()}.

Открытые методы

Метод Описание
__construct ( string $Name = '' ) Class constructor. Defines the related database table name.
addFilterField ( string | array $field ) : Gdn_Model Add one or more filter field names to the list of fields that will be removed during save.
defineSchema ( ) : Gdn_Schema Connects to the database and defines the schema associated with $this->Name.
delete ( array | integer $where = [], array | true $options = [] ) : Gdn_Dataset Delete records from a table.
deleteID ( mixed $id, array $options = [] ) : boolean Delete a record by primary key.
filterForm ( array $data ) : array Filter out any potentially insecure fields before they go to the database.
filterSchema ( array $Data ) : array Returns an array with only those keys that are actually in the schema.
get ( string $OrderFields = '', string $OrderDirection = 'asc', integer | boolean $Limit = false, $PageNumber = false ) : Gdn_Dataset
getCount ( array $Wheres = '' ) : Gdn_Dataset Returns a count of the # of records in the table.
getFilterFields ( ) : array Get all of the field names that will be filtered out during save.
getID ( mixed $ID, string $DatasetType = false, array $Options = [] ) : array | object Get the data from the model based on its primary key.
getRecordAttribute ( array &$Record, string $Attribute, mixed $Default = null ) : mixed Get something from $Record['Attributes'] by dot-formatted key.
getWhere ( array | boolean $Where = false, string $OrderFields = '', string $OrderDirection = 'asc', integer | false $Limit = false, integer | false $Offset = false ) : Gdn_DataSet Get a dataset for the model with a where filter.
insert ( array $Fields ) : boolean
options ( string | array $Key, mixed $Value = null ) : mixed Gets/sets an option on the object.
removeFilterField ( string | array $field ) : Gdn_Model Remove one or more fields from the filter field array.
save ( array $FormPostValues, array $Settings = false ) : unknown Takes a set of form data ($Form->_PostValues), validates them, and inserts or updates them to the datatabase.
saveToSerializedColumn ( string $Column, integer $RowID, string $Name, string $Value = '' ) : boolean | Gdn_DataSet | object | string
serializeRow ( array &$Row ) Serialize Attributes and Data columns in a row.
setField ( integer $RowID, array | string $Property, atom $Value = false ) Update a row in the database.
setFilterFields ( array $fields ) : Gdn_Model Set the array of filter field names.
setProperty ( integer $RowID, string $Property, boolean $ForceValue = false ) : boolean | string
setRecordAttribute ( array &$Record, string $Attribute, mixed $Value ) : mixed Set something on $Record['Attributes'] by dot-formatted key.
update ( array $Fields, array $Where = false, array $Limit = false ) : Gdn_Dataset
validate ( array $FormPostValues, boolean $Insert = false ) : boolean
validationResults ( ) : array Returns the $this->Validation->ValidationResults() array.

Защищенные методы

Метод Описание
_beforeGet ( ) A overridable function called before the various get queries.
addInsertFields ( array &$Fields ) Adds $this->InsertUserID and $this->DateInserted fields to an associative array of fieldname/values if those fields exist on the table being inserted.
addUpdateFields ( array &$Fields ) Adds $this->UpdateUserID and $this->DateUpdated fields to an associative array of fieldname/values if those fields exist on the table being updated.
coerceData ( array $row, boolean $strip = true ) : array Coerce the data in a given row to conform to the data types in this model's schema.
collapseAttributes ( array $Data, string $Name = 'Attributes' ) : array Take all of the values that aren't in the schema and put them into the attributes column.
expandAttributes ( array $Row, string $Name = 'Attributes' ) : array Expand all of the values in the attributes column so they become part of the row.

Описание методов

__construct() публичный Метод

Class constructor. Defines the related database table name.
public __construct ( string $Name = '' )
$Name string An optional parameter that allows you to explicitly define the name of the table that this model represents. You can also explicitly set this value with $this->Name.

_beforeGet() защищенный Метод

A overridable function called before the various get queries.
protected _beforeGet ( )

addFilterField() публичный Метод

Add one or more filter field names to the list of fields that will be removed during save.
public addFilterField ( string | array $field ) : Gdn_Model
$field string | array Either a field name or an array of field names to filter.
Результат Gdn_Model Returns $this for chaining.

addInsertFields() защищенный Метод

Adds $this->InsertUserID and $this->DateInserted fields to an associative array of fieldname/values if those fields exist on the table being inserted.
protected addInsertFields ( array &$Fields )
$Fields array The array of fields to add the values to.

addUpdateFields() защищенный Метод

Adds $this->UpdateUserID and $this->DateUpdated fields to an associative array of fieldname/values if those fields exist on the table being updated.
protected addUpdateFields ( array &$Fields )
$Fields array The array of fields to add the values to.

coerceData() защищенный Метод

This method doesn't do full data cleansing yet because that is too much of a change at this point. For this reason this method has been kept protected. The main purpose here is to clean the data enough to work better with MySQL's strict mode.
protected coerceData ( array $row, boolean $strip = true ) : array
$row array The row of data to coerce.
$strip boolean Whether or not to strip missing columns.
Результат array Returns a new data row with cleansed data.

collapseAttributes() защищенный Метод

Take all of the values that aren't in the schema and put them into the attributes column.
protected collapseAttributes ( array $Data, string $Name = 'Attributes' ) : array
$Data array
$Name string
Результат array

defineSchema() публичный Метод

Also instantiates and automatically defines $this->Validation.
public defineSchema ( ) : Gdn_Schema
Результат Gdn_Schema Returns the schema for this model.

delete() публичный Метод

Delete records from a table.
public delete ( array | integer $where = [], array | true $options = [] ) : Gdn_Dataset
$where array | integer The where clause to delete or an integer value.
$options array | true An array of options to control the delete. - limit: A limit to the number of records to delete. - reset: Deprecated. Whether or not to reset this SQL statement after the delete. Defaults to false.
Результат Gdn_Dataset Returns the result of the delete.

deleteID() публичный Метод

Delete a record by primary key.
public deleteID ( mixed $id, array $options = [] ) : boolean
$id mixed The primary key value of the record to delete.
$options array An array of options to affect the delete behaviour. Reserved for future use.
Результат boolean Returns **true** if the delete was successful or **false** otherwise.

expandAttributes() защищенный Метод

Expand all of the values in the attributes column so they become part of the row.
С версии: 2.2
protected expandAttributes ( array $Row, string $Name = 'Attributes' ) : array
$Row array
$Name string
Результат array

filterForm() публичный Метод

Filter out any potentially insecure fields before they go to the database.
public filterForm ( array $data ) : array
$data array The array of data to filter.
Результат array Returns a copy of {@link $data} with fields removed.

filterSchema() публичный Метод

Returns an array with only those keys that are actually in the schema.
public filterSchema ( array $Data ) : array
$Data array An array of key/value pairs.
Результат array The filtered array.

get() публичный Метод

public get ( string $OrderFields = '', string $OrderDirection = 'asc', integer | boolean $Limit = false, $PageNumber = false ) : Gdn_Dataset
$OrderFields string
$OrderDirection string
$Limit integer | boolean
Результат Gdn_Dataset

getCount() публичный Метод

Returns a count of the # of records in the table.
public getCount ( array $Wheres = '' ) : Gdn_Dataset
$Wheres array
Результат Gdn_Dataset

getFilterFields() публичный Метод

Get all of the field names that will be filtered out during save.
public getFilterFields ( ) : array
Результат array Returns an array of field names.

getID() публичный Метод

Get the data from the model based on its primary key.
С версии: 2.3 Added the $Options parameter.
public getID ( mixed $ID, string $DatasetType = false, array $Options = [] ) : array | object
$ID mixed The value of the primary key in the database.
$DatasetType string The format of the result dataset.
$Options array options to pass to the database.
Результат array | object

getRecordAttribute() публичный статический Метод

Pass record byref.
public static getRecordAttribute ( array &$Record, string $Attribute, mixed $Default = null ) : mixed
$Record array
$Attribute string
$Default mixed Optional.
Результат mixed

getWhere() публичный Метод

Get a dataset for the model with a where filter.
public getWhere ( array | boolean $Where = false, string $OrderFields = '', string $OrderDirection = 'asc', integer | false $Limit = false, integer | false $Offset = false ) : Gdn_DataSet
$Where array | boolean A filter suitable for passing to Gdn_SQLDriver::Where().
$OrderFields string A comma delimited string to order the data.
$OrderDirection string One of **asc** or **desc**.
$Limit integer | false The database limit.
$Offset integer | false The database offset.
Результат Gdn_DataSet

insert() публичный Метод

public insert ( array $Fields ) : boolean
$Fields array
Результат boolean

options() публичный Метод

Gets/sets an option on the object.
С версии: 2.3
public options ( string | array $Key, mixed $Value = null ) : mixed
$Key string | array The key of the option.
$Value mixed The value of the option or not specified just to get the current value.
Результат mixed The value of the option or $this if $Value is specified.

removeFilterField() публичный Метод

Remove one or more fields from the filter field array.
public removeFilterField ( string | array $field ) : Gdn_Model
$field string | array One or more field names to remove.
Результат Gdn_Model Returns $this for chaining.

save() публичный Метод

Takes a set of form data ($Form->_PostValues), validates them, and inserts or updates them to the datatabase.
public save ( array $FormPostValues, array $Settings = false ) : unknown
$FormPostValues array An associative array of $Field => $Value pairs that represent data posted from the form in the $_POST or $_GET collection.
$Settings array If a custom model needs special settings in order to perform a save, they would be passed in using this variable as an associative array.
Результат unknown

saveToSerializedColumn() публичный Метод

public saveToSerializedColumn ( string $Column, integer $RowID, string $Name, string $Value = '' ) : boolean | Gdn_DataSet | object | string
$Column string
$RowID integer
$Name string
$Value string
Результат boolean | Gdn_DataSet | object | string

serializeRow() публичный статический Метод

Serialize Attributes and Data columns in a row.
С версии: 2.1
public static serializeRow ( array &$Row )
$Row array

setField() публичный Метод

Update a row in the database.
С версии: 2.1
public setField ( integer $RowID, array | string $Property, atom $Value = false )
$RowID integer
$Property array | string
$Value atom

setFilterFields() публичный Метод

Set the array of filter field names.
public setFilterFields ( array $fields ) : Gdn_Model
$fields array An array of field names.
Результат Gdn_Model Returns $this for chaining.

setProperty() публичный Метод

public setProperty ( integer $RowID, string $Property, boolean $ForceValue = false ) : boolean | string
$RowID integer
$Property string
$ForceValue boolean
Результат boolean | string

setRecordAttribute() публичный статический Метод

Pass record byref.
public static setRecordAttribute ( array &$Record, string $Attribute, mixed $Value ) : mixed
$Record array
$Attribute string
$Value mixed
Результат mixed

update() публичный Метод

public update ( array $Fields, array $Where = false, array $Limit = false ) : Gdn_Dataset
$Fields array
$Where array
$Limit array
Результат Gdn_Dataset

validate() публичный Метод

public validate ( array $FormPostValues, boolean $Insert = false ) : boolean
$FormPostValues array
$Insert boolean
Результат boolean

validationResults() публичный Метод

Returns the $this->Validation->ValidationResults() array.
public validationResults ( ) : array
Результат array

Описание свойств

$Data публичное свойство

An object representation of the current working dataset.
public $Data

$Database публичное свойство

Database object.
public $Database

$DateInserted публичное свойство

The name of the field that stores the insert date for a record. This field will be automatically filled by the model if it exists.
public $DateInserted

$DateUpdated публичное свойство

The name of the field that stores the update date for a record. This field will be automatically filled by the model if it exists.
public $DateUpdated

$InsertUserID публичное свойство

The name of the field that stores the id of the user that inserted it. This field will be automatically filled by the model if it exists and
public $InsertUserID

$Name публичное свойство

The name of the table that this model is intended to represent. The default value assigned to $this->Name will be the name that the model was instantiated with (defined in $this->__construct()).
public $Name

$PrimaryKey публичное свойство

name of the primary key field of this model. The default is 'id'. If $this->DefineSchema() is called, this value will be automatically changed to any primary key discovered when examining the table schema.
public $PrimaryKey

$SQL публичное свойство

Contains the sql driver for the object.
public $SQL

$Schema публичное свойство

An object that is used to store and examine database schema information related to this model. This object is defined and populated with $this->DefineSchema().
public $Schema

$UpdateUserID публичное свойство

The name of the field that stores the id of the user that updated it. This field will be automatically filled by the model if it exists and @@Session::UserID is a valid integer.
public $UpdateUserID

$Validation публичное свойство

An object that is used to manage and execute data integrity rules on this object. By default, this object only enforces maxlength, data types, and required fields (defined when $this->DefineSchema() is called).
public $Validation

$filterFields защищенное свойство

The fields that should be filtered out via {@link Gdn_Model::filterForm()}.
protected $filterFields