ZenphotoCMS 1.6.3

PersistentObject
in package

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.

Table of Contents

Properties

$exists  : mixed
$loaded  : mixed
$table  : mixed
$transient  : mixed
$id  : mixed
$cache_by  : mixed
$data  : mixed
$tempdata  : mixed
$unique_set  : mixed
$updates  : mixed
$use_cache  : mixed

Methods

__construct()  : mixed
__toString()  : string
"Magic" function to return a string identifying the object when it is treated as a string
checkChanges()  : bool
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.
clearCache()  : mixed
Clears the object cache by setting it to an empty array completely or a specific object (class name) cache.
clearObjectCache()  : mixed
Shortcut to clear the cache of the current object class only
copy()  : mixed
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.
get()  : mixed
Get the value of a variable. If $current is false, return the value as of the last save of this object.
getData()  : array<string|int, mixed>
returns the database record of the object
getID()  : string
Returns the id
getLastChange()  : string
Returns the last change user
getLastChangeUser()  : string
Returns the last change user
instantiate()  : bool
}
move()  : mixed
Change one or more values of the unique set assigned to this record.
remove()  : bool
Deletes object from the database
save()  : mixed
Save the updates made to this object since the last update. Returns true if successful, false if not.
set()  : mixed
Set a variable in this object. Does not persist to the database until save() is called. So, IMPORTANT: Call save() after set() to persist.
setLastChange()  : mixed
stores the current date in the format 'Y-m-d H:i:s' as the last change date
setLastchangeUser()  : mixed
stores the last change user
setDefaults()  : mixed
Sets default values for new objects using the set() method.
addToCache()  : mixed
add the entry to the cache
getFromCache()  : mixed
check the cache for presence of the entry and return it if found
load()  : false
Load the data array from the database, using the unique id set to get the unique record.

Properties

Methods

__construct()

public __construct(mixed $tablename, mixed $unique_set[, mixed $cache_by = NULL ][, mixed $use_cache = true ][, mixed $is_transient = false ][, mixed $allowCreate = true ]) : mixed
Parameters
$tablename : mixed
$unique_set : mixed
$cache_by : mixed = NULL
$use_cache : mixed = true
$is_transient : mixed = false
$allowCreate : mixed = true
Tags
deprecated
1.6
  • Unser instantiate() instead
since
1.4.6

__toString()

"Magic" function to return a string identifying the object when it is treated as a string

public __toString() : string
Return values
string

checkChanges()

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.

public checkChanges([bool $update = true ]) : bool

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 : bool = true

True (default) to also update the $updates property with changes found or clear it. False to only check for changes.

Tags
see
save()
since
1.5.2
Return values
bool

clearCache()

Clears the object cache by setting it to an empty array completely or a specific object (class name) cache.

public static clearCache([mixed $class = null ]) : mixed

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
$class : mixed = null
Tags
since
1.5.8
since
1.6:

Method was made static

global

array $_zp_object_cache

clearObjectCache()

Shortcut to clear the cache of the current object class only

public clearObjectCache() : mixed
Tags
since
1.6

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.

public copy(mixed $new_unique_set) : mixed

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

Parameters
$new_unique_set : mixed

get()

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

public get(mixed $var[, mixed $current = true ]) : mixed
Parameters
$var : mixed
$current : mixed = true

getData()

returns the database record of the object

public getData() : array<string|int, mixed>
Return values
array<string|int, mixed>

getLastChange()

Returns the last change user

public getLastChange() : string
Return values
string

getLastChangeUser()

Returns the last change user

public getLastChangeUser() : string
Tags
since
1.5.2
Return values
string

instantiate()

}

public instantiate( $tablename,  $unique_set[,  $cache_by = NULL ][,  $use_cache = true ][,  $is_transient = false ][,  $allowCreate = true ]) : bool

Prime instantiator for Zenphoto objects

Parameters
$tablename :

The name of the database table

$unique_set :

An array of unique fields

$cache_by : = NULL
$use_cache : = true
$is_transient : = false

Set true to prevent database insertion

$allowCreate : = true

Set true to allow a new object to be made.

Return values
bool

will be true if the unique_set does not already exist

move()

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

public move(mixed $new_unique_set) : mixed

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 : mixed

save()

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

public save([bool $checkupdates = false ]) : mixed
Parameters
$checkupdates : bool = false

Default false. If true the internal $updates property is checked for actual changes so unnecessary saving is skipped. Applies to already existing objects only.

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.

public set(mixed $var, mixed $value) : mixed

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

Parameters
$var : mixed
$value : mixed

setLastChange()

stores the current date in the format 'Y-m-d H:i:s' as the last change date

public setLastChange() : mixed

setLastchangeUser()

stores the last change user

public setLastchangeUser(mixed $a) : mixed
Parameters
$a : mixed
Tags
since
1.5.2

setDefaults()

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

protected setDefaults() : mixed

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

addToCache()

add the entry to the cache

private addToCache( $entry) : mixed
Parameters
$entry :

getFromCache()

check the cache for presence of the entry and return it if found

private getFromCache() : mixed

load()

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

private load(bool $allowCreate) : false
Parameters
$allowCreate : bool

set to true to enable new object creation.

Return values
false

if the record already exists, true if a new record was created.


        
On this page

Search results