Property | Type | Description | |
---|---|---|---|
$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). |
Property | Type | Description | |
---|---|---|---|
$filterFields | The fields that should be filtered out via {@link Gdn_Model::filterForm()}. |
Method | Description | |
---|---|---|
__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. |
Method | Description | |
---|---|---|
_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. |
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. |
protected _beforeGet ( ) |
public addFilterField ( string | array $field ) : Gdn_Model | ||
$field | string | array | Either a field name or an array of field names to filter. |
return | Gdn_Model | Returns $this for chaining. |
protected addInsertFields ( array &$Fields ) | ||
$Fields | array | The array of fields to add the values to. |
protected addUpdateFields ( array &$Fields ) | ||
$Fields | array | The array of fields to add the values to. |
public defineSchema ( ) : Gdn_Schema | ||
return | Gdn_Schema | Returns the schema for this model. |
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. |
return | Gdn_Dataset | Returns the result of the delete. |
public filterForm ( array $data ) : array | ||
$data | array | The array of data to filter. |
return | array | Returns a copy of {@link $data} with fields removed. |
public filterSchema ( array $Data ) : array | ||
$Data | array | An array of key/value pairs. |
return | array | The filtered array. |
public getFilterFields ( ) : array | ||
return | array | Returns an array of field names. |
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. |
return | Gdn_DataSet |
public removeFilterField ( string | array $field ) : Gdn_Model | ||
$field | string | array | One or more field names to remove. |
return | Gdn_Model | Returns $this for chaining. |
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. |
return | unknown |
public static serializeRow ( array &$Row ) | ||
$Row | array |
public setFilterFields ( array $fields ) : Gdn_Model | ||
$fields | array | An array of field names. |
return | Gdn_Model | Returns $this for chaining. |
public validationResults ( ) : array | ||
return | array |
public $DateInserted |
public $DateUpdated |
public $InsertUserID |
public $Name |
public $PrimaryKey |
public $Schema |
public $UpdateUserID |
public $Validation |