Difference between revisions of "ModelBase API"

From Warwick Student Cinema
Jump to: navigation, search
(New page: An API that should be common to all model classes. Includes core methods that should be available in all classes, and optional methods that provide a common structure for frequently used e...)
 
m
 
(8 intermediate revisions by 2 users not shown)
Line 1: Line 1:
  +
An API Reference for classes that are imbued with ModelBase/SuperClass awesomeness.
An API that should be common to all model classes. Includes core methods that should be available in all classes, and optional methods that provide a common structure for frequently used extensions.
 
   
  +
PLEASE NOTE: This reference is '''very''' incomplete at the moment. Additions are being made as convenient. Though the API is fairly fixed, changes may be made without notice, so please be sure to read commit logs on bazaar regularly, as these are much more up to date than this page will be.
=Core API=
 
   
==Static methods==
+
==Static Methods==
   
===loadByID===
+
=== get ===
  +
<code>ModelBase ModelBase::get( mixed $primarykey )
  +
ModelBase ModelBase::get( Array $searchparameters )</code>
   
  +
Possibly the most important method on the class, use this to retrieve a single object from the database. You can either pass the objects primary key (usually the ID) or you can pass an array containing key/value pairs corresponding to fields and desired values. Note that if the specified parameters do not identify a single unique object, an exception will be thrown. If you wish to retrieve several objects based on a common parameter, use getSet.
===get===
 
<code>mixed get(QueryCondition condition)</code>
 
   
  +
<code>Film::get(47);</code>
====description====
 
  +
<code>Film::get( Array( 'shortname' => 'inception' ) );</code>
Returns a single object matching the condition. Raises an exception if 0 or more than one object match.
 
   
===filter===
 
<code>mixed get(QueryCondition condition)</code>
 
   
====description====
+
=== getSet ===
  +
<code>Collection<ModelBase> ModelBase::getSet( Array $searchparameters, [ Array $order = Array() ], [ integer $limit = 0 ], [ integer $start = 0 ])</code>
Returns a list of objects matching the condition.
 
   
  +
Used to retrieve a Collection of objects with the specified parameters. This will always return a Collection, whether or not any objects actually matched the specified parameters.
==Instance methods==
 
   
  +
You must specify at least one field/value pair in $searchparamaters. If you wish to retrieve all objects, use getAll.
===save===
 
   
  +
$order allows you to order the objects in the collection. It should be an array containing fields to order by as keys, and "ASC" or "DSC" as values. You CANNOT order by fields that are other ModelBase objects, only basic types, such as integer or string.
===delete===
 
   
  +
$limit allows you to limit the number of objects retrieved. It should be an integer greater than 0. A limit of 0 will result in unlimited results.
   
  +
$start allows you to "skip" a number of objects. It should be an integer greater than 0. A start value of 0 will result in no "skipping".
==Common Extensions==
 
  +
  +
<code>$films_in_2009 = Film::getSet( Array ( 'year' => 2009 ) );</code>
  +
  +
=== getAll ===
  +
<code>Collection<ModelBase> ModelBase::getAll( [ Array $order = Array() ], [ integer $limit = 0 ], [ integer $start = 0 ])</code>
  +
  +
Similar to getSet, except that all objects are retrieved, rather than a subset. The $order, $limit and $start parameters act as in getSet.
  +
  +
<code>$five_latest_news = News::getAll( Array( 'time'=>'DSC' ), 5);</code>
  +
  +
  +
  +
[[Category:API_Reference]]
  +
[[Category:Website_Version_3]]

Latest revision as of 22:33, 1 February 2019

An API Reference for classes that are imbued with ModelBase/SuperClass awesomeness.

PLEASE NOTE: This reference is very incomplete at the moment. Additions are being made as convenient. Though the API is fairly fixed, changes may be made without notice, so please be sure to read commit logs on bazaar regularly, as these are much more up to date than this page will be.

Static Methods

get

ModelBase ModelBase::get( mixed $primarykey ) ModelBase ModelBase::get( Array $searchparameters )

Possibly the most important method on the class, use this to retrieve a single object from the database. You can either pass the objects primary key (usually the ID) or you can pass an array containing key/value pairs corresponding to fields and desired values. Note that if the specified parameters do not identify a single unique object, an exception will be thrown. If you wish to retrieve several objects based on a common parameter, use getSet.

Film::get(47); Film::get( Array( 'shortname' => 'inception' ) );


getSet

Collection<ModelBase> ModelBase::getSet( Array $searchparameters, [ Array $order = Array() ], [ integer $limit = 0 ], [ integer $start = 0 ])

Used to retrieve a Collection of objects with the specified parameters. This will always return a Collection, whether or not any objects actually matched the specified parameters.

You must specify at least one field/value pair in $searchparamaters. If you wish to retrieve all objects, use getAll.

$order allows you to order the objects in the collection. It should be an array containing fields to order by as keys, and "ASC" or "DSC" as values. You CANNOT order by fields that are other ModelBase objects, only basic types, such as integer or string.

$limit allows you to limit the number of objects retrieved. It should be an integer greater than 0. A limit of 0 will result in unlimited results.

$start allows you to "skip" a number of objects. It should be an integer greater than 0. A start value of 0 will result in no "skipping".

$films_in_2009 = Film::getSet( Array ( 'year' => 2009 ) );

getAll

Collection<ModelBase> ModelBase::getAll( [ Array $order = Array() ], [ integer $limit = 0 ], [ integer $start = 0 ])

Similar to getSet, except that all objects are retrieved, rather than a subset. The $order, $limit and $start parameters act as in getSet.

$five_latest_news = News::getAll( Array( 'time'=>'DSC' ), 5);