public
|
#
__construct( array $data = array() )
Constructor : Instanciate a new Model object
Constructor : Instanciate a new Model object
Parameters
- $data
- The initial data to set.
|
public static
array
|
#
getAll( string $index = null, array $fields = array(), array $order = array() )
Get all the elements of the table
Get all the elements of the table
Parameters
- $index
The field that will be used to affect the result array keys.
If not set, the method will return a non associative array
- $fields
- The fields to set in the instances
- $order
The order to get the results. Each key of this array must be a column name in the table,
and the associated value is the order value ('ASC' or 'DESC')
Returns
array An array of all Model instances
|
public static
Hawk\Model
|
#
getById( integer $id, array $fields = array() )
Get a model instance by it primary column
Get a model instance by it primary column
Parameters
- $id
- The id of the instance to get
- $fields
- The fields to set in the instance
Returns
|
public static
Hawk\Model
|
#
getByExample( Hawk\DBExample $example = null, array $fields = array() )
Get a model instance by an example
Get a model instance by an example
Parameters
- $example
- The example to find the data line
- $fields
- The fields to set in the model instance
Returns
|
public static
Hawk\Model[]
|
#
getListByExample( Hawk\DBExample $example = null, string $index = null, array $fields = array(), array $order = array() )
Get a list of model instances by an example
Get a list of model instances by an example
Parameters
- $example
- The example to find the data lines
- $index
The field that will be used as array key in the result.
If not set, the result will be a non associative array
- $fields
- The fields to set in the instances
- $order
The order to get the results. Each key of this array must be a column name in the table,
and the associated value is the order value ('ASC' or 'DESC')
Returns
|
public static
Hawk\Model
|
#
getBySQL( string $where = null, array $binds = array(), array $fields = array() )
Get a model instance by sql condition
Get a model instance by sql condition
Parameters
- $where
- The SQL condition
- $binds
- The binded values
- $fields
- The fields to set in the instance
Returns
|
public static
Hawk\Model[]
|
#
getListBySQL( string $where = null, array $binds = array(), string $index = null, array $fields = array(), array $order = array() )
Get a list of model instances by a SQL condition
Get a list of model instances by a SQL condition
Parameters
- $where
- The SQL condition to find the elements
- $binds
- The binded values
- $index
The field that will be used as array key in the result.
If not set, the result will be a non associative array
- $fields
- The fields to set in the instances
- $order
The order to get the results. Each key of this array must be a column name in the table,
and the associated value is the order value ('ASC' or 'DESC')
Returns
Hawk\Model[] the array containing found models instances
|
public static
integer
|
#
deleteByExample( Hawk\DBExample $example = null )
Delete data in the database from an example
Delete data in the database from an example
Parameters
- $example
- The example to find the lines to delete
Returns
integer the number of deleted elements in the database
|
public static
integer
|
#
deleteBySQL( string $where = null, array $binds = array() )
Delete data in the database from a SQL condition
Delete data in the database from a SQL condition
Parameters
- $where
- The SQL condition to find the lines to delete
- $binds
Returns
integer The number of deleted elements in the database
|
public static
integer
|
#
countElementsByExample( Hawk\DBExample $example = null, array $group = array() )
Count the number of elements filtered by an example
Count the number of elements filtered by an example
Parameters
- $example
- The example to find the lines to delete
- $group
- The fields used to group the results
Returns
integer The number of found elements in the database
|
public static
integer
|
#
countElementsBySQL( string $where = null, array $binds = array(), array $group = array() )
Count the number of elements filtered by a SQL condition
Count the number of elements filtered by a SQL condition
Parameters
- $where
- The SQL condition
- $binds
- $group
- The fields used to group the results
Returns
integer The number of found elements in the database
|
public
|
#
save( )
This method save a new Model in the database or update it if it exists.
It is based on INSERT ... ON DUPLICATE KEY.
If a new element is saved, then the id (or the value of the primary key) is set on the instance corresponding property
This method save a new Model in the database or update it if it exists.
It is based on INSERT ... ON DUPLICATE KEY.
If a new element is saved, then the id (or the value of the primary key) is set on the instance corresponding property
|
public static
Hawk\Model
|
#
add( array $data )
Create a new element in the database
Create a new element in the database
Parameters
- $data
- The data to insert in the database
Returns
|
public
|
#
addIfNotExists( )
Add the model in the database only if does not alreay exists
Add the model in the database only if does not alreay exists
|
public
|
#
update( )
Update the model data in the database
Update the model data in the database
|
public
true
|
#
delete( )
Delete the model data from the database
Delete the model data from the database
Returns
true if the data has been sucessfully removed from the database, false in other cases
|
public
array
|
#
getData( )
Get the model data, only the data present in the database.
Get the model data, only the data present in the database.
Returns
array The object properties with their value
|
public
|
#
set( string|array $field, mixed $value = null )
Set a property value to the object.
You can use this method to set only one property, or an array of properties
Set a property value to the object.
You can use this method to set only one property, or an array of properties
Parameters
- $field
If a string is set, then it is the name of the property.
If an array is set, then set multiple properties will be set
- $value
- The value to set to the property, only if $field is a string
|
public static
string
|
#
getTable( )
Get the table name of this model
Get the table name of this model
Returns
string the table name of the model
|
public static
string
|
#
getPrimaryColumn( )
Get the primary column of the model
Get the primary column of the model
Returns
string The primary column of the model
|
public static
string
|
#
getDbName( )
Get the DB instance name of the model
Get the DB instance name of the model
Returns
string The name of the DB instance for the model
|
public static
Hawk\DB
|
#
getDbInstance( )
Get the DB instance of the model
Get the DB instance of the model
Returns
Hawk\DB The DB instance of the model
|
public static
|
#
setTable( string $table )
Set the table name of the model
Set the table name of the model
Parameters
- $table
- The table name to set
|
public static
|
#
setPrimaryColumn( string $primaryColumn )
Set the primary column of the model
Set the primary column of the model
Parameters
- $primaryColumn
- The column to set as primary column
|
public static
|
#
setDbName( string $name )
Set the DB instance name of the model
Set the DB instance name of the model
Parameters
- $name
- The instance name to set
|