PHP 클래스 Gdn_Model, vanilla

상속: extends Gdn_Pluggable
파일 보기 프로젝트 열기: vanilla/vanilla 1 사용 예제들

공개 프로퍼티들

프로퍼티 타입 설명
$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).

보호된 프로퍼티들

프로퍼티 타입 설명
$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