Class ActiveRecord
Base active record class definition providing database storage via the configured provider.
Direct known subclasses
Alpha\Model\ActionLog
,
Alpha\Model\Article
,
Alpha\Model\Type\DEnum
,
Alpha\Model\Type\DEnumItem
,
Alpha\Model\Type\RelationLookup
,
Alpha\Model\Type\Sequence
,
Alpha\Model\ArticleComment
,
Alpha\Model\ArticleVote
,
Alpha\Model\BadRequest
,
Alpha\Model\BlacklistedClient
,
Alpha\Model\BlacklistedIP
,
Alpha\Model\Person
,
Alpha\Model\Rights
,
Alpha\Model\Tag
Namespace: Alpha\Model
Copyright:
Copyright (c) 2018, John Collins (founder of Alpha Framework). All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the Alpha Framework nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
License: The BSD License
Author: John Collins dev@alphaframework.org
Since: 1.0
Located at Model/ActiveRecord.php
Methods summary
public
|
|
public static
|
|
public
array
|
|
public
|
|
public
array
|
#
loadAllOldVersions( integer $ID )
Load all old versions (if any) of this record from the [tablename]_history table. |
public
|
#
loadByAttribute( string $attribute, string $value, boolean $ignoreClassType = false, array $loadAttributes = array() )
Populates the child object from the database table by the given attribute value. |
public
array
|
|
public
array
|
#
loadAllByAttribute( string $attribute, string $value, integer $start = 0, integer $limit = 0, string $orderBy = 'ID', string $order = 'ASC', boolean $ignoreClassType = false, array $constructorArgs = array() )
Loads all of the objects of this class by the specified attribute into an array which is returned. |
public
array
|
#
loadAllByAttributes( array $attributes = array(), array $values = array(), integer $start = 0, integer $limit = 0, string $orderBy = 'ID', string $order = 'ASC', boolean $ignoreClassType = false )
Loads all of the objects of this class by the specified attributes into an array which is returned. |
public
array
|
#
loadAllByDayUpdated( string $date, integer $start = 0, integer $limit = 0, string $orderBy = 'ID', string $order = 'ASC', boolean $ignoreClassType = false )
Loads all of the objects of this class that where updated (updated_ts value) on the date indicated. |
public
array
|
#
loadAllFieldValuesByAttribute( string $attribute, string $value, string $returnAttribute, string $order = 'ASC', boolean $ignoreClassType = false )
Loads all of the specified attribute values of this class by the specified attribute into an array which is returned. |
public
|
|
public
|
|
public
|
#
saveAttribute( string $attribute, mixed $value )
Saves the field specified with the value supplied. Only works for persistent records. Note that no Alpha type validation is performed with this method! |
public
|
#
saveHistory( )
Saves the history of the object in the [tablename]_history table. It will always perform an insert. |
protected
|
|
public
|
|
public
integer
|
#
deleteAllByAttribute( string $attribute, mixed $value )
Delete all object instances from the database by the specified attribute matching the value provided. |
public
integer
|
#
getVersion( )
Gets the version_num of the object from the database (returns 0 if the Record is not saved yet). |
public
|
|
public
|
#
makeHistoryTable( )
Builds a new database table for the Record class to story it's history of changes. |
public
|
|
public
|
|
public
|
#
addProperty( string $propName )
Adds in a new class property without loosing existing data (does an ALTER TABLE query on the database). |
public
|
#
populateFromArray( array $hashArray )
Populates the current business object from the provided hash array. |
public
integer
|
|
public
integer
|
|
public
integer
|
#
getHistoryCount( )
Gets the count from the database for the amount of entries in the [tableName]_history table for this business object. Only call this method on classes where maintainHistory = true, otherwise an exception will be thrown. |
final public
string
|
|
public
|
|
protected
|
|
public
mixed
|
#
get( string $prop, boolean $noChildMethods = false )
Generic getter method for accessing class properties. Will use the method get.ucfirst($prop) instead if that method exists at a child level (by default). Set $noChildMethods to true if you don't want to use any get.ucfirst($prop) method even if it exists, false otherwise (default). |
public
|
#
set( string $prop, mixed $value, boolean $noChildMethods = false )
Generic setter method for setting class properties. Will use the method set.ucfirst($prop) instead if that method exists at a child level (by default). Set $noChildMethods to true if you don't want to use any get.ucfirst($prop) method even if it exists, false otherwise (default). |
public
|
#
getPropObject( string $prop )
Gets the property object rather than the value for complex attributes. Returns false if the property exists but is private. |
public
boolean
|
#
checkTableExists( boolean $checkHistoryTable = false )
Checks to see if the table exists in the database for the current business class. |
public static
boolean
|
#
checkRecordTableExists( string $recordClassName, boolean $checkHistoryTable = false )
Static method to check the database and see if the table for the indicated Record class name exists (assumes table name will be $recordClassName less "Object"). |
public
boolean
|
#
checkTableNeedsUpdate( )
Checks to see if the table in the database matches (for fields) the business class definition, i.e. if the database table is in sync with the class definition. |
public
array
|
#
findMissingFields( )
Returns an array containing any properties on the class which have not been created on the database table yet. |
public
string
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
#
markTransient( string $attributeName )
Adds the name of the attribute provided to the list of transient (non-saved) attributes for this record. |
public
|
#
markPersistent( string $attributeName )
Removes the name of the attribute provided from the list of transient (non-saved) attributes for this record, ensuring that it will be saved on the next attempt. |
protected
|
#
markUnique( string $attribute1Name, string $attribute2Name = '', string $attribute3Name = '' )
Adds the name of the attribute(s) provided to the list of unique (constrained) attributes for this record. |
public
array
|
|
public
array
|
|
public
|
#
createForeignIndex( string $attributeName, string $relatedClass, string $relatedClassAttribute, string $indexName = null )
Creates a foreign key constraint (index) in the database on the given attribute. |
public
|
#
createUniqueIndex( string $attribute1Name, string $attribute2Name = '', string $attribute3Name = '' )
Creates a unique index in the database on the given attribute(s). |
public
array
|
|
public
|
|
public
string
|
|
public static
array
|
#
getRecordClassNames( )
Loops over the core and custom Record directories and builds an array of all of the Record class names in the system. |
public
array
|
|
public
array
|
|
public
array
|
#
getPersistentAttributes( )
Get the array of persistent attribute names, i.e. those that are saved in the database. |
public
|
|
public
boolean
|
#
isTransient( )
Inspector to see if the business object is transient (not presently stored in the database). |
public
string
|
|
public
|
|
public static
|
#
loadClassDef( string $classname )
Loads the definition from the file system for the Record class name provided. |
public
boolean
|
|
public
boolean
|
#
isTableOverloaded( )
Checks to see if the table name matches the classname, and if not if the table name matches the classname name of another record, i.e. the table is used to store multiple types of records. |
public static
|
|
public static
|
|
public static
|
|
public static
boolean
|
#
isInstalled( )
Static method that tries to determine if the system database has been installed or not. |
public
boolean
|
|
public
array
|
#
getTaggedAttributes( )
Returns the contents of the taggedAttributes array, or an empty array if that does not exist. |
public
|
#
cast( string $targetClassName,
Cast a Record to another type of record. A new Record will be returned with the same ID and version_num as the old record, so this is NOT a true cast but is a copy. All attribute values will be copied accross. |
public
string
|
|
public
boolean
|
|
public
|
|
public
|
|
public
boolean
|
|
public
|
|
public
|
|
public
|
|
public
boolean
|
|
public
array
|
|
public static
boolean
|
|
public static
|
|
public static
|
|
public static
|
Properties summary
protected
integer
|
$ID
The object ID. |
|
protected
string
|
$lastQuery
The last database query run by this object. Useful for tracing an error. |
|
protected
|
$version_num
The version number of the object, used for locking mechanism. |
|
protected
|
$created_ts
The timestamp of creation. |
|
protected
|
$created_by
The ID of the person who created this record. |
|
protected
|
$updated_ts
The timestamp of the last update. |
|
protected
|
$updated_by
The ID of the person who last updated this record. |
|
protected
array
|
$defaultAttributes
An array of the names of all of the default attributes of a persistent Record defined in this class. |
#
array('ID', 'lastQuery', 'version_num', 'dataLabels', 'created_ts', 'created_by', 'updated_ts', 'updated_by', 'defaultAttributes', 'transientAttributes', 'uniqueAttributes', 'TABLE_NAME', 'logger')
|
protected
array
|
$transientAttributes
An array of the names of all of the transient attributes of a persistent Record which are not saved to the DB. |
#
array('lastQuery', 'dataLabels', 'defaultAttributes', 'transientAttributes', 'uniqueAttributes', 'TABLE_NAME', 'logger')
|
protected
array
|
$uniqueAttributes
An array of the uniquely-constained attributes of this persistent record. |
#
array()
|
protected
array
|
$dataLabels
An array of the data labels used for displaying class attributes. |
#
array()
|