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!
A child class should run the follwing in its constructor:
$new = $this->instantiate('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.
Note: This is a persistable model that does not save automatically. You MUST
call $this->save(); explicitly to persist the data in child classes.
Methods summary
public
|
#
__construct( $tablename, $unique_set, $cache_by = NULL, $use_cache = true, $is_transient = false, $allowCreate = true )
Deprecated
Zenphoto 1.6 - Unser instantiate() instead
Since
1.4.6
|
public
boolean
|
#
instantiate( $tablename, $unique_set, $cache_by = NULL, $use_cache = true, $is_transient = false, $allowCreate = true )
}
Prime instantiator for Zenphoto objects
Parameters
- $tablename
- name of the database table
- $unique_set
- array of unique fields
- $cache_by
- $use_cache
- $is_transient
- true to prevent database insertion
- $allowCreate
- true to allow a new object to be made.
Returns
boolean will be true if the unique_set does not already exist
|
public
|
#
clearCache( string $classname = null )
Clears the object cache by setting it to an empty array completely or a specific object (class name) cache.
Clears the object cache by setting it to an empty array completely or a specific object (class name) cache.
Note: You normally never need to use this. But on certain occasions it may be necessary
to avoid memory issues if you loop through a lot of object creations.
Parameters
- $classname
- A classname to clear the cache specifially (optional, default null)
Since
ZenphotoCMS 1.5.8
|
public
|
#
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.
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.
|
protected
|
#
setDefaults( )
Sets default values for new objects using the set() method.
Should do nothing in the base class; subclasses should override.
Sets default values for new objects using the set() method.
Should do nothing in the base class; subclasses should override.
|
public
|
#
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.
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.
|
public
|
#
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.
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.
|
public
boolean
|
#
remove( )
Deletes object from the database
Deletes object from the database
Returns
boolean
|
public
string
|
#
getID( )
Returns the id
Returns
string
|
public
array
|
#
getData( )
returns the database record of the object
Returns
array
|
public
|
#
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.
Get the value of a variable. If $current is false, return the value
as of the last save of this object.
|
public
|
#
save( boolean $checkupdates = false )
Save the updates made to this object since the last update. Returns
true if successful, false if not.
Save the updates made to this object since the last update. Returns
true if successful, false if not.
Parameters
- $checkupdates
- Default false. If true the internal $updates property is checked for actual changes so unnecessary saving is skipped. Applies to already existing objects only.
|
public
string
|
#
__toString( )
"Magic" function to return a string identifying the object when it is treated as a string
Returns
string
|
public
string
|
#
getLastChange( )
Returns the last change user
Returns the last change user
Returns
string
|
public
|
#
setLastChange( )
stores the current date in the format 'Y-m-d H:i:s' as the last change date
stores the current date in the format 'Y-m-d H:i:s' as the last change date
|
public
string
|
#
getLastChangeUser( )
Returns the last change user
Returns the last change user
Returns
string
Since
ZenphotoCMS 1.5.2
|
public
|
#
setLastchangeUser( $a )
stores the last change user
stores the last change user
Since
ZenphotoCMS 1.5.2
|
public
boolean
|
#
checkChanges( boolean $update = true )
By default the object is saved if there are any updates within the property $updates no matter if these are actual changes to existing data.
This checks that and internally updates the $updates property with the actual changes obky so you optionally can skip unnecessary object saves.
By default the object is saved if there are any updates within the property $updates no matter if these are actual changes to existing data.
This checks that and internally updates the $updates property with the actual changes obky so you optionally can skip unnecessary object saves.
Standard object fields lastchange and lastchangeuser are exclude because lastchange always changes and both make no sense
if there is no actual content change at all.
This can be used before calling the save() method or enabled within the save() method optionally
Parameters
- $update
- True (default) to also update the $updates property with changes found or clear it. False to only check for changes.
Returns
boolean
Since
ZenphotoCMS 1.5.2
See
|