PHP Class Habari\InfoRecords

Base class for managing metadata about various Habari objects
Inheritance: implements habari\URLProperties
ファイルを表示 Open project: habari/system

Protected Properties

Property Type Description
$__inforecord_array the info array
$_dirty set to true if any values here have been changed but not saved
$_key_name name of the primary key in the info record table
$_key_value value of the primary key - the master record
$_loaded set to true only when the inforecords have been loaded
$_table_name table which contains the info records
$url_args

Public Methods

Method Description
__construct ( string $table_name, string $key_name, mixed $key_value = null ) Takes three parameters. The table of the options table, the name of the master key and the record_id for which options are managed.
__get ( string $name ) : mixed Fetch info record value.
__isset ( string $name ) : boolean Test for the existence of specified info value
__set ( string $name, mixed $value ) Update the info record.
__unset ( string $name ) : boolean Remove an info option; immediately unsets from the storage AND removes from database. Use with caution.
commit ( mixed $metadata_key = null ) : boolean Commit all of the changed info options to the database.
count ( ) : integer Get the number of info records
delete_all ( ) : boolean Remove all info options. Primarily used when deleting the parent object.
getArrayCopy ( )
get_url_args ( ) : array Returns a set of properties used by URL::get to create URLs
is_key_set ( ) : boolean Test if the master record value has been set (and thus, safe to set info records).
set_key ( mixed $metadata_key ) function set_key For use in cases where the master record key is not known at the time of object instantiation (ie: a new post)

Protected Methods

Method Description
_load ( ) Populate the internal hashmap with the values from the DB.

Method Details

__construct() public method

posts take a slug as a record_id, comments take a comment_id and users take a user_id (user_name) IMPORTANT: if $primary_key_value is not set in the constructor, set_key MUST be called before inforecords can be set. Or bad things (think swarms of locusts o'er the land) will happen
public __construct ( string $table_name, string $key_name, mixed $key_value = null )
$table_name string name of the table to insert info (use the DB::o()->table_name syntax)
$key_name string name of the primary key (for example "post_id")
$key_value mixed (optional) the master record key value (for example, info for post_id = 1 managed by setting this param to 1). Use set_key method if not set here.

__get() public method

Fetch info record value.
public __get ( string $name ) : mixed
$name string Name of the key to get
return mixed Stored value for specified key

__isset() public method

Test for the existence of specified info value
public __isset ( string $name ) : boolean
$name string Name of the option to set
return boolean true if the info option exists, false in all other cases

__set() public method

The value will not be stored in the database until calling $this->commit();
public __set ( string $name, mixed $value )
$name string Name of the key to set
$value mixed Value to set

__unset() public method

Remove an info option; immediately unsets from the storage AND removes from database. Use with caution.
public __unset ( string $name ) : boolean
$name string Name of the option to unset
return boolean true if the option is successfully unset, false otherwise

_load() protected method

Populate the internal hashmap with the values from the DB.
protected _load ( )

commit() public method

If this function is not called, then the options will not be written.
public commit ( mixed $metadata_key = null ) : boolean
$metadata_key mixed (optional) Key to use when writing info data.
return boolean True if the commit succeeded.

count() public method

Get the number of info records
public count ( ) : integer
return integer Number of info records here

delete_all() public method

I.E. when deleting a user, the delete method would call this.
public delete_all ( ) : boolean
return boolean true if the options were successfully unset, false otherwise

getArrayCopy() public method

public getArrayCopy ( )

get_url_args() public method

Returns a set of properties used by URL::get to create URLs
public get_url_args ( ) : array
return array Properties of this post used to build a URL

is_key_set() public method

Test if the master record value has been set (and thus, safe to set info records).
public is_key_set ( ) : boolean
return boolean true if master record value has been set already, false otherwise

set_key() public method

function set_key For use in cases where the master record key is not known at the time of object instantiation (ie: a new post)
public set_key ( mixed $metadata_key )
$metadata_key mixed the id of the master record (could be int or string, most likely int)

Property Details

$__inforecord_array protected_oe property

the info array
protected $__inforecord_array

$_dirty protected_oe property

set to true if any values here have been changed but not saved
protected $_dirty

$_key_name protected_oe property

name of the primary key in the info record table
protected $_key_name

$_key_value protected_oe property

value of the primary key - the master record
protected $_key_value

$_loaded protected_oe property

set to true only when the inforecords have been loaded
protected $_loaded

$_table_name protected_oe property

table which contains the info records
protected $_table_name

$url_args protected_oe property

protected $url_args