Properties

$_model

$_model : 

Type

$_con

$_con : 

Database connection.

Type

$_a

$_a : 

Store the attributes of the model.

To minimize pollution of the property space, all the attributes are stored in this array.

Description of the keys: 'multitenant: Determines possibility of define the model in each tenant separately 'mapped': Determines that the model is a mapped model of another model. A mapped model have not a separate table. 'table': The table in which the model is stored. 'model': The name of the model. 'cols': The definition of the columns. 'idx': The definition of the indexes. 'views': The definition of the views. 'verbose': The verbose name of the model.

Type

$_data

$_data : 

Storage of the data.

The object data are stored in an associative array. Each key corresponds to a column and stores a Pluf_DBField* variable.

Type

$_cache

$_cache : 

Storage cached data for methods_get

Type

$_fk

$_fk : 

List of the foreign keys.

Set by the init() method from the definition of the columns.

Type

$_m

$_m : 

Methods available, this array is dynamically populated by init method.

Type

$tenant_field

$tenant_field : array

Tenant field

This field is added to model in the multi-tenancy mode automaticlly.

Type

array

Methods

__construct()

__construct(  $pk = null,   $values = array()) 

Parameters

$pk
$values

init()

init() 

ساختار داده‌ای را ایجاد می‌کند.

این فراخوانی تمام ساختارهای داده‌ای اصلی را ایجاد می‌کند. تمام زیر کلاس‌ها باید این کلاس را پیاده سازی کنند و ساختارهای داده‌ای خود را ایجاد کنند.

_init()

_init() 

Load and init the model

getRelationKeysToModel()

getRelationKeysToModel(string  $model, string  $type) : array

Retrieve key relationships of a given model.

Parameters

string $model
string $type

Relation type: 'foreignkey' or 'manytomany'.

Returns

array —

Key relationships.

getForeignKeysToModel()

getForeignKeysToModel(  $model) : array

Get the foreign keys relating to a given model.

Parameters

$model

Returns

array —

Foreign keys

getData()

getData() : array

Get the raw data of the object.

For the many to many relations, the value is an array of ids.

Returns

array —

Associative array of the data.

setAssoc()

setAssoc(  $model) 

Set the association of a model to another in many to many.

Parameters

$model

delAssoc()

delAssoc(  $model) 

Set the association of a model to another in many to many.

Parameters

$model

batchAssoc()

batchAssoc(  $model_name,   $ids) : boolean

Bulk association of models to the current one.

Parameters

$model_name
$ids

Returns

boolean —

Success

_getConnection()

_getConnection() 

Get a database connection.

getDbConnection()

getDbConnection() 

Get a database connection.

getSqlTable()

getSqlTable() 

Get the table of the model.

Avoid doing the concatenation of the prefix and the table manually.

__get()

__get(  $prop) 

Overloading of the get method.

Parameters

$prop

__set()

__set(  $prop,   $val) 

Overloading of the set method.

Parameters

$prop
$val

__call()

__call(  $method,   $args) 

Overloading of the method call.

Parameters

$method
$args

get()

get(  $id) : mixed

Get a given item.

Parameters

$id

Returns

mixed —

Item or false if not found.

getOne()

getOne(  $p = array()) : \Pluf_Model|null

Get one item.

The parameters are the same as the ones of the getList method, but, the return value is either:

  • The object
  • null if no match
  • Exception if the match results in more than one item.

Usage:

$m = Pluf::factory(My_Model::class)->getOne(array('filter' => 'id=1'));
$m = Pluf::factory(My_Model::class)->getOne('id=1');

Parameters

$p

Returns

\Pluf_Model|null —

find model

getList()

getList(  $p = array()) : \ArrayObject

یک فهرست از موجودیت‌ها را تعیین می‌کند

The filter should be used only for simple filtering. If you want a complex query, you should create a new view. Both filter and order accept an array or a string in case of multiple parameters: Filter: array('col1=toto', 'col2=titi') will be used in a AND query or simply 'col1=toto' Order: array('col1 ASC', 'col2 DESC') or 'col1 ASC'

This is modelled on the DB_Table pear module interface.

Parameters

$p

Returns

\ArrayObject —

of items or through an exception if database failure

getCount()

getCount(  $p = array()) : integer

Get the number of items.

Parameters

$p

Returns

integer —

The number of items

getRelated()

getRelated(  $model,   $method = null,   $p = array()) : array

Get a list of related items.

See the getList() method for usage of the view and filters.

Parameters

$model
$method
$p

Returns

array —

Array of items

getSelect()

getSelect() 

Generate the SQL select from the columns

update()

update(  $where = '') : boolean

Update the model into the database.

If no where clause is provided, the index definition is used to find the sequence. These are used to limit the update to the current model.

Parameters

$where

Returns

boolean —

Success

create()

create(  $raw = false) : boolean

Create the model into the database.

If raw insert is requested, the preSave/postSave methods are not called and the current id of the object is directly used. This is particularily used when doing backup/restore of data.

Parameters

$raw

Returns

boolean —

Success

getDeleteSideEffect()

getDeleteSideEffect() : array

Get models affected by delete.

Returns

array —

Models deleted if deleting current model.

delete()

delete() 

Delete the current model from the database.

If another model link to the current model through a foreign key, the DB is responsible to mange relations.

_reset()

_reset() 

Reset the fields to default values.

__toString()

__toString() : string

Represents the model in auto generated lists.

You need to overwrite this method to have a nice display of your objects in the select boxes, logs.

Returns

string —

reperesentation of the current object

restore()

restore() 

Hook run just after loading a model from the database.

Just overwrite it into your model to perform custom actions.

preSave()

preSave(boolean  $create = false) 

پیش ذخیره را انجام می‌دهد

در صورتی که نیاز به انجام پردازش‌هایی قبل از ذخیره شدن مدل داده‌ای دارید، این فراخوانی را بازنویسی کنید.

Parameters

boolean $create

حالت ساخت یا به روز رسانی را تعیین می‌کند

postSave()

postSave(string  $create = false) 

حالت کار ایجاد شده را به روز می‌کند

Parameters

string $create

preDelete()

preDelete() 

\brief عملیاتی که قبل از پاک شدن است انجام می‌شود

عملیاتی که قبل از پاک شدن است انجام می‌شود در این متد فایل مربوط به است حذف می شود. این عملیات قابل بازگشت نیست

setFromFormData()

setFromFormData(  $cleaned_values) 

مقادیر مدل را بر اساس یک فرم تعیین می‌کند

این مقادیر به صورت یک آرایه به عنوان ورودی دریافت شده و بر اساس آن داده‌های مورد نیاز مدل تعیین می‌شود.

Parameters

$cleaned_values

setView()

setView(  $view,   $def) 

Set a view.

Parameters

$view
$def

_toDb()

_toDb(  $val,   $col) : string

Prepare the value to be put in the DB.

Parameters

$val
$col

Returns

string —

SQL ready string.

_fromDb()

_fromDb(  $val,   $col) : mixed

Get the value from the DB.

Create DB field and returns. The field type is used as the output value type.

Parameters

$val
$col

Returns

mixed —

Value.

displayVal()

displayVal(  $col) : mixed

Display value.

When you have a list of choices for a field and you want to get the display value of the current stored value.

Parameters

$col

Returns

mixed —

Display value, if not available default to the value.

isAnonymous()

isAnonymous() : boolean

بررسی می‌کند که آیا مدل داده‌ای وجود دارد یا نه

در صورتی که مدل داده‌ای ذخیره نشده باشد به عنوان داده بی نام و نشان در نظر گرفته می‌شود. در مورد کاربران این تابع کاربرد فراوان دارد.

Returns

boolean —

True if the user is anonymous.

getClass()

getClass() : string

مدل داده‌ای را تعیین می‌کند

هر مدل داده‌ای یک نام دارد.

این فراخوانی نام مدل داده‌ای را تعیین می‌کند که معادل با نام کلاس است.

Returns

string

getId()

getId() : integer

شناسه را تعیین می‌کند.

Returns

integer —

id

jsonSerialize()

jsonSerialize() 

(non-PHPdoc)

getName()

getName() 

getSchema()

getSchema() 

getAbsloutPath()

getAbsloutPath() : string

مسیر کامل محتوی را تعیین می‌کند.

این مسیر حاوی اسم فایل هم هست.

Returns

string

_setupAutomaticListMethods()

_setupAutomaticListMethods(string  $type) 

متدهای اتوماتیک را برای مدل ورودی ایجاد می‌کند.

Adds the get_xx_list method when the methods of the model contains custom names.

Parameters

string $type

Relation type: 'foreignkey' or 'manytomany'.

_setupMultitenantFields()

_setupMultitenantFields() 

Add tenant required fields

Adds extra fields if multi-tenant is enabled

getFieldInfo()

getFieldInfo(  $name,   $field) 

Parameters

$name
$field