Hawk - PHP documentation
  • Namespace
  • Class
  • Tree

Namespaces

  • Hawk
    • View
      • Plugins

Classes

  • App
  • ButtonInput
  • Cache
  • CheckboxInput
  • ColorInput
  • Conf
  • Controller
  • Crypto
  • DatabaseSessionHandler
  • DatetimeInput
  • DB
  • DBExample
  • DeleteInput
  • Dialogbox
  • EmailInput
  • ErrorHandler
  • Event
  • FileInput
  • FileSystem
  • FloatInput
  • Form
  • FormFieldset
  • FormInput
  • GenericModel
  • GifImage
  • HawkApi
  • HawkUpdater
  • HiddenInput
  • HtmlInput
  • HTTPRequest
  • Icon
  • Image
  • IntegerInput
  • ItemList
  • ItemListField
  • JpegImage
  • Lang
  • Language
  • LeftSidebarTab
  • Less
  • Logger
  • Mail
  • MenuItem
  • Model
  • NoSidebarTab
  • NumberInput
  • ObjectInput
  • Option
  • Panel
  • PasswordInput
  • Permission
  • Plugin
  • PluginInstaller
  • PngImage
  • ProfileQuestion
  • ProfileQuestionValue
  • RadioInput
  • Request
  • Response
  • RightSidebarTab
  • Role
  • RolePermission
  • Route
  • Router
  • SelectInput
  • Session
  • Singleton
  • SubmitInput
  • Tabs
  • TextareaInput
  • TextInput
  • Theme
  • TimeInput
  • Upload
  • User
  • View
  • ViewPlugin
  • Widget
  • WysiwygInput

Traits

  • Utils

Exceptions

  • AppStopException
  • DBExampleException
  • DBException
  • FileSystemException
  • HawkApiException
  • ImageException
  • MailException
  • UploadException
  • ViewException

Class Model

This class describes the data models behavior. each model defined in plugin must inherits this class

Hawk\Model uses Hawk\Utils

Direct known subclasses

Hawk\GenericModel, Hawk\Language, Hawk\MenuItem, Hawk\Permission, Hawk\ProfileQuestion, Hawk\ProfileQuestionValue, Hawk\Role, Hawk\RolePermission, Hawk\User

Namespace: Hawk
Package: Core
Located at Model.php

Methods summary

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

Hawk\Model
The found Model instance
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

Hawk\Model
The found Model instance
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

Hawk\Model[]
The array containing found models
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

Hawk\Model
The found Model instance
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
  • The binded values

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
  • the binded values
$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

Hawk\Model
The added instance
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

Methods used from Hawk\Utils

debug(), getSerializedVersion(), map()

Properties summary

protected static string $tablename

The table name containing the data in database

The table name containing the data in database

#
protected static string $primaryColumn

The primary column of the elements in the table (default 'id')

The primary column of the elements in the table (default 'id')

# 'id'
protected static string $dbname

The DB instance name to get data in database default MAINDB

The DB instance name to get data in database default MAINDB

# MAINDB
Hawk - PHP documentation API documentation generated by ApiGen