RecordModel_Base Class Reference

Inherited by RecordModel.

List of all members.

Public Member Functions

 RecordModel_Base ()
 depend ($model)
import_plugin ($name)
 purify ($data)
 invalidate ($id)
 find ()
 find_arr ($q, $args=array())
 fetch ($id)
 store ($data)
 erase ($id)
 create ()
 load ($id)
 load_all ($ids, $ignore_empty=true)
 save ($data)
 delete ($id)
 create_record ()
 load_record ($id)
 save_record ($data)
 delete_record ($id)
 validate ($data)
 sanitize ($data)
 enum_schema ()

Public Attributes

 $db = null
 $web = null
 $cache = null
 $depends = null
 $plugins = null
 $context = null
 $table = null
 $pk = 'id'
 $enable_cache = false
 $submodels = null
 $files = null

Detailed Description

PRONTO WEB FRAMEWORK Copyright (C) 2006, Judd Vinet

Author:
Judd Vinet <jvinet@zeroflux.org>

Description: Base class for all data models. The bottom seven methods in this class can (and will) typically be overridden by model subclasses.

Definition at line 13 of file record_model.php.


Member Function Documentation

RecordModel_Base::create (  ) 

Return a new/fresh entity. This method is responsible for returning a brand new, un-edited record that will be used to prepopulate form fields in a "Create" form for this data entity.

Returns:
array

Definition at line 296 of file record_model.php.

References create_record().

RecordModel_Base::create_record (  ) 

Return a new/fresh entity. This method is responsible for returning a brand new, un-edited record that will be used to prepopulate form fields in a "Create" form for this data entity.

This method can be overridden.

Returns:
array

Definition at line 376 of file record_model.php.

Referenced by create().

RecordModel_Base::delete ( id  ) 

Delete a full record from the DB.

Parameters:
int $id

Definition at line 356 of file record_model.php.

References delete_record(), and invalidate().

RecordModel_Base::delete_record ( id  ) 

Delete a full record. Override this method to control what else needs to happen when a record is deleted.

Parameters:
integer ID

Definition at line 441 of file record_model.php.

References erase().

Referenced by delete().

RecordModel_Base::depend ( model  ) 

Load another model as a dependency of this one.

Parameters:
string $model_name

Definition at line 135 of file record_model.php.

References Factory::model().

Referenced by load_record().

RecordModel_Base::enum_schema (  ) 

Define the enumeration schema for this model. This describes how Pronto can enumerate and/or search for records.

This method may be overridden.

Definition at line 479 of file record_model.php.

RecordModel_Base::erase ( id  ) 

Erase a bare record from the DB.

Parameters:
int $id

Definition at line 272 of file record_model.php.

Referenced by delete_record().

RecordModel_Base::fetch ( id  ) 

Load a bare record. This is just the row from the model's table, nothing else. The cache is never used for a raw fetch.

Parameters:
int $id
Returns:
mixed

Definition at line 244 of file record_model.php.

Referenced by load_record().

RecordModel_Base::find (  ) 

Build a result set matching the sub-query provided. This will return an object through which some basic data manipulation primitives can be used (get, set, load, delete)

Parameters:
string "Where" sub-query (leave blank to select all)
mixed Additional query argument (optional)
mixed Additional query argument (optional) ...
Returns:
object RecordSelector object.

Definition at line 209 of file record_model.php.

References $args.

RecordModel_Base::find_arr ( q,
args = array() 
)

Same as RecordSelector::find(), except this method accepts all query arguments in a single associative array.

Parameters:
string "Where" sub-query (leave blank to select all)
array Additional query arguments
Returns:
object RecordSelector object.

Definition at line 224 of file record_model.php.

References $args.

& RecordModel_Base::import_plugin ( name  ) 

Import a plugin (aka "page plugin").

Parameters:
string $name Plugin name

Definition at line 147 of file record_model.php.

References Registry::get(), and Factory::plugin().

RecordModel_Base::invalidate ( id  ) 

Remove an entry from the cache

Parameters:
mixed $id PK of the record to be invalidated from the cache. Use an array if invalidating multiple records.

Definition at line 188 of file record_model.php.

Referenced by delete(), and save().

RecordModel_Base::load ( id  ) 

Load a full record. This includes any additional data processing, and/or additional records from other models. If enabled, the cache will be checked first.

Parameters:
int $id
Returns:
mixed

Definition at line 309 of file record_model.php.

References load_record().

Referenced by load_all().

RecordModel_Base::load_all ( ids,
ignore_empty = true 
)

Return multiple records by PK, optionally ignoring empty/false records.

Parameters:
array $ids
boolean $ignore_empty Ignore empty records.
Returns:
array

Definition at line 330 of file record_model.php.

References load().

RecordModel_Base::load_record ( id  ) 

Load a full record. Override this method to control what gets loaded into the final record.

Definition at line 385 of file record_model.php.

References depend(), DS, and fetch().

Referenced by load().

RecordModel_Base::purify ( data  ) 

Use the HTML checker to remove any possible XSS attacks (eg, <script> tags)

Parameters:
array $data
Returns:
array

Definition at line 167 of file record_model.php.

References DS.

Referenced by sanitize().

RecordModel_Base::RecordModel_Base (  ) 

Constructor for all models

Definition at line 109 of file record_model.php.

References Registry::get().

Referenced by RecordModel::RecordModel().

RecordModel_Base::sanitize ( data  ) 

Used to do any necessary sanitization on the data before putting it in the DB. Escaping is not necessary. You can override this method to control how input data should be sanitized. By default it is scrubbed by the RecordModel::purify() method.

Parameters:
array $data
Returns:
array

Definition at line 466 of file record_model.php.

References purify().

Referenced by store().

RecordModel_Base::save ( data  ) 

Save a full record to the DB.

Parameters:
array $data

Definition at line 345 of file record_model.php.

References invalidate(), and save_record().

RecordModel_Base::save_record ( data  ) 

Save a full record. Override this method to control what gets saved into the final record.

Parameters:
array $data
Returns:
ID of the inserted/updated record

Definition at line 430 of file record_model.php.

References store().

Referenced by save().

RecordModel_Base::store ( data  ) 

Store a bare record in the DB.

Parameters:
array $data
Returns:
ID of the inserted/updated record

Definition at line 256 of file record_model.php.

References sanitize().

Referenced by save_record().

RecordModel_Base::validate ( data  ) 

Validate data before a save. Override this method.

Parameters:
array $data
Returns:
array Associative array of errors

Definition at line 452 of file record_model.php.


Member Data Documentation

RecordModel_Base::$cache = null

Definition at line 17 of file record_model.php.

RecordModel_Base::$context = null

This can be set by the page controller acting on the model. It defines the context with which a record is being modified. For example, a Page_CRUD controller may set the model's context to 'ADMIN', indicating that an authorized administrator is modifying a record from a backend admin console, and so regular validation should be bypassed.

The model can then act on this setting in its overridden methods (such as validate, insert, update, etc.)

This setting is optional.

Definition at line 34 of file record_model.php.

RecordModel_Base::$db = null

Definition at line 15 of file record_model.php.

RecordModel_Base::$depends = null

Definition at line 18 of file record_model.php.

RecordModel_Base::$enable_cache = false

Enable caching for this entity. Only enable this if you plan to be diligent about _only_ inserting/updating/fetching/deleting this entity _through_ the model interface. If you interact with the data yourself (eg, through $this->db in a controller) then you will undermine the caching layer.

Definition at line 55 of file record_model.php.

RecordModel_Base::$files = null

An array of files associated with this model, used by Page_CRUD to handle file uploads. The 'type' element determines the acceptable MIME type(s). Use an array for multiple types, or "image" to accept normal image types. Omit it to accept any file.

If type==image, then images will be converted to JPEG for consistency. If type==image, then use 'max_width' and 'max_height' to optionally resize images, maintaining aspect ratio.

The filename parameter can include any values from the record returned from the model's get() method. Each data key should be surrounded in angle brackets (eg, "<name>").

Array keys in $files must match those of the create/edit form defined in the template.

Example:

         var $files = array(
           'image' => array(
             'type'       => 'image',
             'max_width'  => '640',      // used for type==image only
             'max_height' => '800',      // used for type==image only
             'webroot'    => DIR_WS_DATA_IMG,
             'fileroot'   => DIR_FS_DATA_IMG,
             'filename'   => "<id>.jpg"
           )
         );

Definition at line 103 of file record_model.php.

RecordModel_Base::$pk = 'id'

Name of the PK column in this table (one column only)

Definition at line 47 of file record_model.php.

RecordModel_Base::$plugins = null

Definition at line 19 of file record_model.php.

RecordModel_Base::$submodels = null

An array of other models that this model links to. To use this, the model's table should have a "<model>_id" column for each depending module.

If the column name does not match the "<model>_id" pattern, you can use a 2-dimensional array, with the first value being the model name and the second value being the column name in the table.

eg: var $submodels = array('user'); eg: var $submodels = array('user', array('blog','blog_id'));

Definition at line 70 of file record_model.php.

RecordModel_Base::$table = null

Name of database table this model will use

Definition at line 43 of file record_model.php.

RecordModel_Base::$web = null

Definition at line 16 of file record_model.php.


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

Generated on Wed Jan 13 09:21:05 2010 for Pronto Framework by  doxygen 1.6.1