
Public Member Functions | |
| __construct ($pk=null, $values=array()) | |
| init () | |
| _init () | |
| getForeignKeysToModel ($model) | |
| getData () | |
| setAssoc ($model) | |
| delAssoc ($model) | |
| batchAssoc ($model_name, $ids) | |
| _getConnection () | |
| getDbConnection () | |
| getSqlTable () | |
| __get ($prop) | |
| __set ($prop, $val) | |
| __call ($method, $args) | |
| get ($id) | |
| getOne ($p=array()) | |
| getList ($p=array()) | |
| getCount ($p=array()) | |
| getRelated ($model, $method=null, $p=array()) | |
| getSelect () | |
| update ($where='') | |
| create ($raw=false) | |
| getDeleteSideEffect () | |
| delete () | |
| _reset () | |
| __toString () | |
| restore () | |
| preSave ($create=false) | |
| postSave ($create=false) | |
| preDelete () | |
| setFromFormData ($cleaned_values) | |
| setView ($view, $def) | |
| _toDb ($val, $col) | |
| _fromDb ($val, $col) | |
| displayVal ($col) | |
Public Attributes | |
| $_model = __CLASS__ | |
| $_con = null | |
| $_a | |
Protected Attributes | |
| $_data = array() | |
| $_cache = array() | |
| $_fk = array() | |
| $_m | |
| Pluf_Model::__construct | ( | $ | pk = null, |
|
| $ | values = array() | |||
| ) |
| Pluf_Model::init | ( | ) |
Reimplemented in Pluf_DB_SchemaInfo, Pluf_Group, Pluf_Message, Pluf_Permission, Pluf_Queue, Pluf_RowPermission, Pluf_Search_Occ, Pluf_Search_Stats, Pluf_Search_Word, Pluf_Session, and Pluf_User.
| Pluf_Model::_init | ( | ) |
Define the list of methods for the model from the available model relationship.
Reimplemented in Pluf_Session.
| Pluf_Model::getForeignKeysToModel | ( | $ | model | ) |
Get the foreign keys relating to a given model.
| string | Model |
| Pluf_Model::getData | ( | ) |
Get the raw data of the object.
For the many to many relations, the value is an array of ids.
| Pluf_Model::setAssoc | ( | $ | model | ) |
Set the association of a model to another in many to many.
| object | Object to associate to the current object |
| Pluf_Model::delAssoc | ( | $ | model | ) |
Set the association of a model to another in many to many.
| object | Object to associate to the current object |
| Pluf_Model::batchAssoc | ( | $ | model_name, | |
| $ | ids | |||
| ) |
Bulk association of models to the current one.
| string | Model name | |
| array | Ids of Model name |
| Pluf_Model::_getConnection | ( | ) |
Get a database connection.
| Pluf_Model::getDbConnection | ( | ) |
Get a database connection.
| Pluf_Model::getSqlTable | ( | ) |
Get the table of the model.
Avoid doing the concatenation of the prefix and the table manually.
| Pluf_Model::__get | ( | $ | prop | ) |
Overloading of the get method.
| string | Property to get |
| Pluf_Model::__set | ( | $ | prop, | |
| $ | val | |||
| ) |
Overloading of the set method.
| string | Property to set | |
| mixed | Value to set |
| Pluf_Model::__call | ( | $ | method, | |
| $ | args | |||
| ) |
Overloading of the method call.
| string | Method | |
| array | Arguments |
| Pluf_Model::get | ( | $ | id | ) |
Get a given item.
| int | Id of the item. |
| Pluf_Model::getOne | ( | $ | p = array() |
) |
Get one item.
The parameters are the same as the ones of the getList method, but, the return value is either:
Usage:
$m = Pluf::factory('My_Model')->getOne(array('filter' => 'id=1'));
$m = Pluf::factory('My_Model')->getOne('id=1');
| array|string | Filter string or array given to getList |
| Pluf_Model::getList | ( | $ | p = array() |
) |
Get a list of items.
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.
| array | Associative array with the possible following keys: 'view': The view to use 'filter': The where clause to use 'order': The ordering of the result set 'start': The number of skipped rows in the result set 'nb': The number of items to get in the result set 'count': Run a count query and not a select if set to true |
| Pluf_Model::getCount | ( | $ | p = array() |
) |
Get the number of items.
| array | with associative keys 'view' and 'filter' |
| Pluf_Model::getRelated | ( | $ | model, | |
| $ | method = null, |
|||
| $ | p = array() | |||
| ) |
| Pluf_Model::getSelect | ( | ) |
Generate the SQL select from the columns
| Pluf_Model::update | ( | $ | where = '' |
) |
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.
| string | Where clause to update specific items. ('') |
| Pluf_Model::create | ( | $ | raw = false |
) |
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.
| bool | Raw insert (false) |
| Pluf_Model::getDeleteSideEffect | ( | ) |
Get models affected by delete.
| Pluf_Model::delete | ( | ) |
Delete the current model from the database.
If another model link to the current model through a foreign key, find it and delete it. If this model is linked to other through a many to many, delete the association.
FIXME: No real test of circular references. It can break.
| Pluf_Model::_reset | ( | ) |
Reset the fields to default values.
| Pluf_Model::__toString | ( | ) |
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.
Reimplemented in Pluf_Group, Pluf_Message, Pluf_Permission, Pluf_Search_Occ, Pluf_Search_Word, and Pluf_User.
| Pluf_Model::restore | ( | ) |
Hook run just after loading a model from the database.
Just overwrite it into your model to perform custom actions.
Reimplemented in Pluf_Session.
| Pluf_Model::preSave | ( | $ | create = false |
) |
Hook run just before saving a model in the database.
Just overwrite it into your model to perform custom actions.
| bool | Create. |
Reimplemented in Pluf_Queue, Pluf_Search_Stats, Pluf_Session, and Pluf_User.
| Pluf_Model::postSave | ( | $ | create = false |
) |
| Pluf_Model::preDelete | ( | ) |
Hook run just before deleting a model from the database.
Just overwrite it into your model to perform custom actions.
Reimplemented in Pluf_Group, and Pluf_User.
| Pluf_Model::setFromFormData | ( | $ | cleaned_values | ) |
Set the values from form data.
| Pluf_Model::setView | ( | $ | view, | |
| $ | def | |||
| ) |
Set a view.
| string | Name of the view. | |
| array | Definition of the view. |
| Pluf_Model::_toDb | ( | $ | val, | |
| $ | col | |||
| ) |
Prepare the value to be put in the DB.
| mixed | Value. | |
| string | Column name. |
| Pluf_Model::_fromDb | ( | $ | val, | |
| $ | col | |||
| ) |
Get the value from the DB.
| mixed | Value. | |
| string | Column name. |
| Pluf_Model::displayVal | ( | $ | col | ) |
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.
| string | Field to display the value. |
| Pluf_Model::$_model = __CLASS__ |
Reimplemented in Pluf_DB_SchemaInfo, Pluf_Group, Pluf_Message, Pluf_Permission, Pluf_Queue, Pluf_RowPermission, Pluf_Search_Occ, Pluf_Search_Stats, Pluf_Search_Word, Pluf_Session, and Pluf_User.
| Pluf_Model::$_con = null |
Database connection.
| Pluf_Model::$_a |
Initial value:
array('table' => 'model', 'model' => 'Pluf_Model', 'cols' => array(), 'idx' => array(), 'views' => array(), )
Description of the keys: '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.
Pluf_Model::$_data = array() [protected] |
Storage of the data.
The object data are stored in an associative array. Each key corresponds to a column and stores a Pluf_DB_Field_* variable.
Pluf_Model::$_cache = array() [protected] |
Storage cached data for methods_get
Pluf_Model::$_fk = array() [protected] |
List of the foreign keys.
Set by the init() method from the definition of the columns.
Pluf_Model::$_m [protected] |
Initial value:
array('list' => array(), // get_*_list methods 'many' => array(), // many to many 'get' => array(), // foreign keys 'extra' => array(), // added by some fields )