Pluf_Model Class Reference

Inheritance diagram for Pluf_Model:

Pluf_DB_SchemaInfo Pluf_Group Pluf_Message Pluf_Permission Pluf_Queue Pluf_RowPermission Pluf_Search_Occ Pluf_Search_Stats Pluf_Search_Word Pluf_Session Pluf_User

List of all members.

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


Detailed Description

Sort of Active Record Class

Constructor & Destructor Documentation

Pluf_Model::__construct ( pk = null,
values = array() 
)


Member Function Documentation

Pluf_Model::init (  ) 

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.

Parameters:
string Model
Returns:
array Foreign keys

Pluf_Model::getData (  ) 

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.

Pluf_Model::setAssoc ( model  ) 

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

Parameters:
object Object to associate to the current object

Pluf_Model::delAssoc ( model  ) 

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

Parameters:
object Object to associate to the current object

Pluf_Model::batchAssoc ( model_name,
ids 
)

Bulk association of models to the current one.

Parameters:
string Model name
array Ids of Model name
Returns:
bool Success

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.

Parameters:
string Property to get

Pluf_Model::__set ( prop,
val 
)

Overloading of the set method.

Parameters:
string Property to set
mixed Value to set

Pluf_Model::__call ( method,
args 
)

Overloading of the method call.

Parameters:
string Method
array Arguments

Pluf_Model::get ( id  ) 

Get a given item.

Parameters:
int Id of the item.
Returns:
mixed Item or false if not found.

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:

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

Usage:

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

Parameters:
array|string Filter string or array given to getList
See also:
self::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.

Parameters:
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
Returns:
ArrayObject of items or through an exception if database failure

Pluf_Model::getCount ( p = array()  ) 

Get the number of items.

See also:
getList() for definition of the keys
Parameters:
array with associative keys 'view' and 'filter'
Returns:
int The number of items

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

Get a list of related items.

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

Parameters:
string Class of the related items
string Method call in a many to many related
array Parameters, see getList() for the definition of the keys
Returns:
array Array of items

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.

Parameters:
string Where clause to update specific items. ('')
Returns:
bool Success

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.

Parameters:
bool Raw insert (false)
Returns:
bool Success

Pluf_Model::getDeleteSideEffect (  ) 

Get models affected by delete.

Returns:
array Models deleted if deleting current model.

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.

Parameters:
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.

Parameters:
string Name of the view.
array Definition of the view.

Pluf_Model::_toDb ( val,
col 
)

Prepare the value to be put in the DB.

Parameters:
mixed Value.
string Column name.
Returns:
string SQL ready string.

Pluf_Model::_fromDb ( val,
col 
)

Get the value from the DB.

Parameters:
mixed Value.
string Column name.
Returns:
mixed Value.

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.

Parameters:
string Field to display the value.
Returns:
mixed Display value, if not available default to the value.


Member Data Documentation

Pluf_Model::$_model = __CLASS__

Pluf_Model::$_con = null

Database connection.

Pluf_Model::$_a

Initial value:

 array('table' => 'model',
                       'model' => 'Pluf_Model',
                       'cols' => array(),
                       'idx' => array(),
                       'views' => array(),
                       )
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: '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
                          )
Methods available, this array is dynamically populated by init method.


The documentation for this class was generated from the following file:

Generated on Wed Feb 3 15:44:52 2010 for Pluf by  doxygen