PHP Class Sprig_Core, sprig

Author: Woody Gilk
Afficher le fichier Open project: sittercity/sprig Class Usage Examples

Protected Properties

Свойство 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)

Méthodes publiques

Méthode 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.

Méthodes protégées

Méthode 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 méthode

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

__get() public méthode

Get the value of a field.
public __get ( $name ) : mixed
Résultat mixed

__isset() public méthode

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

__set() public méthode

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

__sleep() public méthode

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

__toString() public méthode

Returns the model name.
public __toString ( ) : string
Résultat string

__unset() public méthode

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

_init() abstract protected méthode

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

_unique_field() public méthode

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

as_array() public méthode

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

changed() public méthode

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

check() public méthode

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
Résultat array filtered data

count() public méthode

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

create() public méthode

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

db() public méthode

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

delete() public méthode

- 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 méthode

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

field() public méthode

Get a single field object.
public field ( $name ) : Sprig_Field
Résultat Sprig_Field

fields() public méthode

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

fk() public méthode

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

input() public méthode

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

inputs() public méthode

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

label() public méthode

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

load() public méthode

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 méthode

Object data loaded status.
public loaded ( ) : boolean
Résultat boolean

pk() public méthode

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

relate() public méthode

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

select_list() public méthode

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

state() public méthode

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
Résultat string when getting

table() public méthode

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

tk() public méthode

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

unrelate() public méthode

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

update() public méthode

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

values() public méthode

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 méthode

Return a single field value in verbose form.
public verbose ( $field ) : string
Résultat 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