PHP Class Sprig_Core, sprig

Author: Woody Gilk
Datei anzeigen Open project: sittercity/sprig Class Usage Examples

Protected Properties

Property Type Description
$_changed Changed object data
$_db database instance name
$_fields field list (name => object)
$_init Initialization status
$_model model name
$_original Original object data
$_primary_key primary key string or array (for composite keys)
$_related Related object data
$_relations Model many-to-many relations
$_sorting default sorting parameters
$_state Object state
$_table database table name
$_title_key title key string (for select lists)

Public Methods

Method Description
__get ( $name ) : mixed Get the value of a field.
__isset ( $name ) : boolean Check if a value exists within the mode.
__set ( $name, $value ) : void Set the value of a field.
__sleep ( ) : array Allow serialization of initialized object containing related objects as a Database_Result
__toString ( ) : string Returns the model name.
__unset ( $name ) : void Unset the changed the value of a field.
_unique_field ( Validate $array, $field ) : void Callback for validating unique fields.
as_array ( $verbose = FALSE ) : array Get the model data as an associative array.
changed ( $field = NULL ) : array Get all of the changed fields as an associative array.
check ( array $data = NULL ) : array Check the given data is valid. Only values that have editable fields will be included and checked.
count ( Database_Query_Builder_Select $query = NULL ) Count the number of records using the current data.
create ( ) Create a new record using the current data.
db ( $db = NULL ) : string Gets and sets the database instance used for this model.
delete ( Database_Query_Builder_Delete $query = NULL ) Delete the current record:
factory ( $name, array $values = NULL ) : Sprig Load an empty sprig model.
field ( $name ) : Sprig_Field Get a single field object.
fields ( ) : array Get all fields as an associative array.
fk ( $table = NULL ) : string Returns the foreign key of the model, optionally with a table name.
input ( $name, array $attr = NULL ) : string Return a single field input.
inputs ( $labels = TRUE ) : array Get all fields as an array of inputs.
label ( $field, array $attr = NULL ) : string Return a single field label.
load ( Database_Query_Builder_Select $query = NULL, $limit = 1 ) Load a single record using the current data.
loaded ( ) : boolean Object data loaded status.
pk ( $table = NULL ) : string Returns the primary key of the model, optionally with a table name.
relate ( $name, $value ) Adds a relationship to the model
related ( $name, $value ) : boolean Determines if this object has a relation
select_list ( $key = NULL, $value = NULL ) : array Get all of the records for this table as an associative array.
state ( $state = NULL ) : string Get or set the model status.
table ( $table = NULL ) : string Gets and sets the table name of the model.
tk ( $table = NULL ) : string Returns the title key of the model, optionally with a table name.
unrelate ( $name, $value ) Removes a relationship to the model
update ( ) Update the current record using the current data.
values ( array $values ) Load all of the values in an associative array. Ignores all fields are not in the model.
verbose ( $field ) : string Return a single field value in verbose form.

Protected Methods

Method Description
__construct ( ) : void Initialize the fields and add validation rules based on field properties.
_init ( ) : void Initialize the fields. This method will only be called once by Sprig::init(). All models must define this method!

Method Details

__construct() protected method

Initialize the fields and add validation rules based on field properties.
protected __construct ( ) : void
return void

__get() public method

Get the value of a field.
public __get ( $name ) : mixed
return mixed

__isset() public method

Check if a value exists within the mode.
public __isset ( $name ) : boolean
return boolean

__set() public method

Set the value of a field.
public __set ( $name, $value ) : void
return void

__sleep() public method

Allow serialization of initialized object containing related objects as a Database_Result
public __sleep ( ) : array
return array list of properties to serialize

__toString() public method

Returns the model name.
public __toString ( ) : string
return string

__unset() public method

Unset the changed the value of a field.
public __unset ( $name ) : void
return void

_init() abstract protected method

Initialize the fields. This method will only be called once by Sprig::init(). All models must define this method!
abstract protected _init ( ) : void
return void

_unique_field() public method

Callback for validating unique fields.
public _unique_field ( Validate $array, $field ) : void
$array Validate
return void

as_array() public method

Get the model data as an associative array.
public as_array ( $verbose = FALSE ) : array
return array field => value

changed() public method

Get all of the changed fields as an associative array.
public changed ( $field = NULL ) : array
return array field => value

check() public method

Check the given data is valid. Only values that have editable fields will be included and checked.
public check ( array $data = NULL ) : array
$data array
return array filtered data

count() public method

Count the number of records using the current data.
public count ( Database_Query_Builder_Select $query = NULL )
$query Database_Query_Builder_Select

create() public method

Create a new record using the current data.
public create ( )

db() public method

Gets and sets the database instance used for this model.
public db ( $db = NULL ) : string
return string

delete() public method

- If the record is loaded, it will be deleted using primary key(s). - If the record is not loaded, it will be deleted using all changed fields. - If no data has been changed, the delete will be ignored.
public delete ( Database_Query_Builder_Delete $query = NULL )
$query Database_Query_Builder_Delete

factory() public static method

Load an empty sprig model.
public static factory ( $name, array $values = NULL ) : Sprig
$values array
return Sprig

field() public method

Get a single field object.
public field ( $name ) : Sprig_Field
return Sprig_Field

fields() public method

Get all fields as an associative array.
public fields ( ) : array
return array name => object

fk() public method

Returns the foreign key of the model, optionally with a table name.
public fk ( $table = NULL ) : string
return string

input() public method

Return a single field input.
public input ( $name, array $attr = NULL ) : string
$attr array
return string

inputs() public method

Get all fields as an array of inputs.
public inputs ( $labels = TRUE ) : array
return array label => input

label() public method

Return a single field label.
public label ( $field, array $attr = NULL ) : string
$attr array
return string

load() public method

Load a single record using the current data.
public load ( Database_Query_Builder_Select $query = NULL, $limit = 1 )
$query Database_Query_Builder_Select

loaded() public method

Object data loaded status.
public loaded ( ) : boolean
return boolean

pk() public method

Returns the primary key of the model, optionally with a table name.
public pk ( $table = NULL ) : string
return string

relate() public method

Adds a relationship to the model
public relate ( $name, $value )

select_list() public method

Get all of the records for this table as an associative array.
public select_list ( $key = NULL, $value = NULL ) : array
return array key => value

state() public method

Setting the model status can have side effects. Changing the state to "loaded" will merge the currently changed data with the original data. Changing to "new" will reset the original data to the default values. Setting a "deleted" state will reset the changed data. Possible model states: - new: record has not been created - deleted: record has been deleted - loaded: record has been loaded
public state ( $state = NULL ) : string
return string when getting

table() public method

Gets and sets the table name of the model.
public table ( $table = NULL ) : string
return string table name

tk() public method

Returns the title key of the model, optionally with a table name.
public tk ( $table = NULL ) : string
return string

unrelate() public method

Removes a relationship to the model
public unrelate ( $name, $value )

update() public method

Update the current record using the current data.
public update ( )

values() public method

Load all of the values in an associative array. Ignores all fields are not in the model.
public values ( array $values )
$values array

verbose() public method

Return a single field value in verbose form.
public verbose ( $field ) : string
return string

Property Details

$_changed protected_oe property

Changed object data
protected $_changed

$_db protected_oe property

database instance name
protected $_db

$_fields protected_oe property

field list (name => object)
protected $_fields

$_init protected_oe property

Initialization status
protected $_init

$_model protected_oe property

model name
protected $_model

$_original protected_oe property

Original object data
protected $_original

$_primary_key protected_oe property

primary key string or array (for composite keys)
protected $_primary_key

$_relations protected_oe static_oe property

Model many-to-many relations
protected static $_relations

$_sorting protected_oe property

default sorting parameters
protected $_sorting

$_state protected_oe property

Object state
protected $_state

$_table protected_oe property

database table name
protected $_table

$_title_key protected_oe property

title key string (for select lists)
protected $_title_key