[ class tree: classes ] [ index: classes ] [ all elements ]

Class: PersistentObject

Source Location: /classes.php

Class PersistentObject

Class Overview

***************************************************************************** ****************************************************************************** Persistent Object Class *****************************************************

Parent ABSTRACT class of all persistent objects. This class should not be instantiated, only used for subclasses. This cannot be enforced, but please follow it!

Documentation/Instructions: A child class should run the follwing in its constructor:

$new = parent::PersistentObject('tablename', array('uniquestring'=>$value, 'uniqueid'=>$uniqueid));

where 'tablename' is the name of the database table to use for this object type, and array('uniquestring'=>$value, ...) defines a unique set of columns (keys) and their current values which uniquely identifies a single record in that database table for this object. The return value of the constructor (stored in $new in the above example) will be (=== TRUE) if a new record was created, and (=== FALSE) if an existing record was updated. This can then be used to set() default values for NEW objects and save() them.

Note: This is a persistable model that does not save automatically. You MUST call $this->save(); explicitly to persist the data in child classes.

****************************************************************************** ****************************************************************************

Located in /classes.php [line 45]



		
		
		
		

Properties

Methods

[ Top ]
Descendants
Child Class Description
Album Album Class
Comment Comment Class
_Image handles 'picture' images
Zenphoto_Administrator ***************************************************************************** ****************************************************************************** Persistent Object Class *****************************************************
ZenpageNews zenpage news class
ZenpagePage zenpage page class

[ Top ]
Property Summary
mixed   $cache_by  
mixed   $data  
mixed   $id  
mixed   $loaded  
mixed   $table  
mixed   $transient  
mixed   $unique_set  
mixed   $updates  
mixed   $use_cache  

[ Top ]
Method Summary
PersistentObject   PersistentObject()  
a   cache()   Caches the current set of objects defined by a variable key $cache_by.
void   copy()   Copy this record to another unique set. Checks if the record exists there first, if so returns false. If successful returns true. No changes are made to this object and no other objects are created, just the database entry.
void   get()   Get the value of a variable. If $current is false, return the value as of the last save of this object.
false   load()   Load the data array from the database, using the unique id set to get the unique record.
void   move()   Change one or more values of the unique set assigned to this record.
bool   remove()   Deletes object from the database
void   save()   Save the updates made to this object since the last update. Returns true if successful, false if not.
void   set()   Set a variable in this object. Does not persist to the database until save() is called. So, IMPORTANT: Call save() after set() to persist.
void   setDefaults()   Sets default values for new objects using the set() method.

[ Top ]
Properties
mixed   $cache_by [line 52]

[ Top ]
mixed   $data [line 47]

[ Top ]
mixed   $id [line 53]

[ Top ]
mixed   $loaded = false [line 49]

[ Top ]
mixed   $table [line 50]

[ Top ]
mixed   $transient [line 55]

[ Top ]
mixed   $unique_set = NULL [line 51]

[ Top ]
mixed   $updates = NULL [line 48]

[ Top ]
mixed   $use_cache = false [line 54]

[ Top ]
Methods
Constructor PersistentObject  [line 57]

  PersistentObject PersistentObject( $tablename, $unique_set, [ $cache_by = NULL], [ $use_cache = true], [ $is_transient = false]  )

Parameters:
   $tablename: 
   $unique_set: 
   $cache_by: 
   $use_cache: 
   $is_transient: 


[ Top ]
cache  [line 81]

  a cache( [ $entry = NULL]  )

Caches the current set of objects defined by a variable key $cache_by.

Uses a global array to store the results of a single database query, where subsequent requests for the object look for data.

Parameters:
   $entry: 

API Tags:
Return:  reference to the array location where this class' cache is stored indexed by the field $cache_by.


[ Top ]
copy  [line 174]

  void copy( $new_unique_set  )

Copy this record to another unique set. Checks if the record exists there first, if so returns false. If successful returns true. No changes are made to this object and no other objects are created, just the database entry.

A call to copy is instant, it does not require a save() following it.

Parameters:
   $new_unique_set: 


[ Top ]
get  [line 225]

  void get( $var, [ $current = true]  )

Get the value of a variable. If $current is false, return the value as of the last save of this object.

Parameters:
   $var: 
   $current: 


[ Top ]
load  [line 241]

  false load( )

Load the data array from the database, using the unique id set to get the unique record.


API Tags:
Return:  if the record already exists, true if a new record was created.


[ Top ]
move  [line 151]

  void move( $new_unique_set  )

Change one or more values of the unique set assigned to this record.

Checks if the record already exists first, if so returns false. If successful returns true and changes $this->unique_set A call to move is instant, it does not require a save() following it.

Parameters:
   $new_unique_set: 


[ Top ]
remove  [line 215]

  bool remove( )

Deletes object from the database



[ Top ]
save  [line 283]

  void save( )

Save the updates made to this object since the last update. Returns true if successful, false if not.



[ Top ]
set  [line 126]

  void set( $var, $value  )

Set a variable in this object. Does not persist to the database until save() is called. So, IMPORTANT: Call save() after set() to persist.

If the requested variable is not in the database, sets it in temp storage, which won't be persisted to the database.

Parameters:
   $var: 
   $value: 


[ Top ]
setDefaults  [line 141]

  void setDefaults( )

Sets default values for new objects using the set() method.

Should do nothing in the base class; subclasses should override.



Redefined in descendants as:

[ Top ]

Documentation generated on Mon, 09 Aug 2010 17:23:55 +0200 by phpDocumentor 1.4.1