Namespace: Alpha\
Model
Copyright:
Copyright (c) 2015, John Collins (founder of Alpha Framework). All rights
reserved. <pre> 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. </pre>
License:
The BSD License
Author:
John Collins <
dev@alphaframework.org>
Since:
1.1
Located at Model/ActiveRecordProviderInterface.php
Methods summary
public static
mixed
|
#
getConnection( )
Gets the current connection singleton, or creates a new one if none
exists.
Gets the current connection singleton, or creates a new one if none
exists.
Returns
mixed mixed
Since
1.1
|
public static
|
#
disconnect( )
Disconnects the current database connection if one exists (self::$connection
is set).
Disconnects the current database connection if one exists (self::$connection
is set).
Since
1.1
|
public static
string
|
#
getLastDatabaseError( )
Returns the last database error string for the current connection.
Returns the last database error string for the current connection.
Returns
string string
Since
1.1
|
public
|
#
load( integer $OID, integer $version = 0 )
Populates the record object with the properties retrived from the database
for the record $OID.
Populates the record object with the properties retrived from the database
for the record $OID.
Parameters
- $OID
- int $OID The object ID of the record to load.
- $version
- int $version Optionaly, provide the version to load that version from the
[tablename]_history table.
Throws
Alpha\Exception\RecordFoundException Alpha\Exception\RecordFoundException
Since
1.1
|
public
array
|
#
loadAllOldVersions( integer $OID )
Load all old versions (if any) of this record from the [tablename]_history
table.
Load all old versions (if any) of this record from the [tablename]_history
table.
Parameters
- $OID
- int $OID The object ID of the record to load.
Returns
array An array containing objects of this type of record object, order by version.
Throws
Alpha\Exception\RecordFoundException Alpha\Exception\RecordFoundException
Since
2.0
|
public
|
#
loadByAttribute( string $attribute, string $value, boolean $ignoreClassType = false, array $loadAttributes = array() )
Populates the record object from the database table by the given attribute
value.
Populates the record object from the database table by the given attribute
value.
Parameters
- $attribute
- string $atribute The name of the attribute to load the record by.
- $value
- string $value The value of the attribute to load the record by.
- $ignoreClassType
- bool $ignoreClassType Default is false, set to true if you want to load from
overloaded tables and ignore the class type
- $loadAttributes
- array $loadAttributes The attributes to load from the database to this object
(leave blank to load all attributes)
Throws
Alpha\Exception\RecordFoundException Alpha\Exception\RecordFoundException
Since
1.1
|
public
array
|
#
loadAll( integer $start = 0, integer $limit = 0, string $orderBy = 'OID', string $order = 'ASC', boolean $ignoreClassType = false )
Loads all of the record objects of this class into an array which is
returned.
Loads all of the record objects of this class into an array which is
returned.
Parameters
- $start
- int $start The start of the SQL LIMIT clause, useful for pagination.
- $limit
- int $limit The amount (limit) of records to load, useful for pagination.
- $orderBy
- string $orderBy The name of the field to sort the records by.
- $order
- string $order The order to sort the records by.
- $ignoreClassType
- bool $ignoreClassType Default is false, set to true if you want to load from
overloaded tables and ignore the class type
Returns
array An array containing objects of this type of record object.
Throws
Alpha\Exception\RecordFoundException Alpha\Exception\RecordFoundException
Since
1.1
|
public
array
|
#
loadAllByAttribute( string $attribute, string $value, integer $start = 0, integer $limit = 0, string $orderBy = 'OID', 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.
Loads all of the objects of this class by the specified attribute into an
array which is returned.
Parameters
- $attribute
- string $atribute The attribute to load the objects by.
- $value
- string $value The value of the attribute to load the objects by.
- $start
- int $start The start of the SQL LIMIT clause, useful for pagination.
- $limit
- int $limit The amount (limit) of objects to load, useful for pagination.
- $orderBy
- string $orderBy The name of the field to sort the objects by.
- $order
- string $order The order to sort the objects by.
- $ignoreClassType
- bool $ignoreClassType Default is false, set to true if you want to load from
overloaded tables and ignore the class type.
- $constructorArgs
- array $constructorArgs An optional array of contructor arguements to pass to the
BOs that will be generated and returned. Supports a maximum of 5 arguements.
Returns
array An array containing objects of this type of business object.
Throws
Since
1.1
|
public
array
|
#
loadAllByAttributes( array $attributes = array(), array $values = array(), integer $start = 0, integer $limit = 0, string $orderBy = 'OID', string $order = 'ASC', boolean $ignoreClassType = false, array $constructorArgs = array() )
Loads all of the record objects of this class by the specified attributes
into an array which is returned.
Loads all of the record objects of this class by the specified attributes
into an array which is returned.
Parameters
- $attributes
- array $atributes The attributes to load the records by.
- $values
- array $values The values of the attributes to load the records by.
- $start
- int $start The start of the SQL LIMIT clause, useful for pagination.
- $limit
- int $limit The amount (limit) of records to load, useful for pagination.
- $orderBy
- string $orderBy The name of the field to sort the records by.
- $order
- string $order The order to sort the records by.
- $ignoreClassType
- bool $ignoreClassType Default is false, set to true if you want to load from
overloaded tables and ignore the class type
- $constructorArgs
- array $constructorArgs An optional array of contructor arguements to pass to the
BOs that will be generated and returned. Supports a maximum of 5 arguements.
Returns
array An array containing objects of this type of record object.
Throws
Since
1.1
|
public
array
|
#
loadAllByDayUpdated( string $date, integer $start = 0, integer $limit = 0, string $orderBy = 'OID', string $order = 'ASC', boolean $ignoreClassType = false )
Loads all of the record objects of this class that where updated (updated_ts
value) on the date indicated.
Loads all of the record objects of this class that where updated (updated_ts
value) on the date indicated.
Parameters
- $date
- string $date The date for which to load the records updated on, in the format
'YYYY-MM-DD'.
- $start
- int $start The start of the SQL LIMIT clause, useful for pagination.
- $limit
- int $limit The amount (limit) of records to load, useful for pagination.
- $orderBy
- string $orderBy The name of the field to sort the records by.
- $order
- string $order The order to sort the records by.
- $ignoreClassType
- bool $ignoreClassType Default is false, set to true if you want to load from
overloaded tables and ignore the class type
Returns
array An array containing objects of this type of record object.
Throws
Alpha\Exception\RecordFoundException Alpha\Exception\RecordFoundException
Since
1.1
|
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.
Loads all of the specified attribute values of this class by the specified
attribute into an array which is returned.
Parameters
- $attribute
- string $attribute The attribute name to load the field values by.
- $value
- string $value The value of the attribute to load the field values by.
- $returnAttribute
- string $returnAttribute The name of the attribute to return.
- $order
- string $order The order to sort the records by.
- $ignoreClassType
- bool $ignoreClassType Default is false, set to true if you want to load from
overloaded tables and ignore the class type.
Returns
array An array of field values.
Throws
Alpha\Exception\RecordFoundException Alpha\Exception\RecordFoundException
Since
1.1
|
public
|
#
save( )
Saves the record. If $this->OID is empty or null it will INSERT, otherwise
UPDATE.
Saves the record. If $this->OID is empty or null it will INSERT, otherwise
UPDATE.
Throws
Since
1.1
|
public
|
#
saveAttribute( string $attribute, mixed $value )
Saves the field specified with the value supplied. Only works for persistent
BOs. Note that no Alpha type validation is performed with this method!
Saves the field specified with the value supplied. Only works for persistent
BOs. Note that no Alpha type validation is performed with this method!
Parameters
- $attribute
- string $attribute The name of the attribute to save.
- $value
- mixed $value The value of the attribute to save.
Throws
Since
1.1
|
public
|
#
saveHistory( )
Saves the object history to the [tablename]_history table. It always does an
INSERT.
Saves the object history to the [tablename]_history table. It always does an
INSERT.
Throws
Since
1.2
|
public
|
#
delete( )
Deletes the current object from the database.
Deletes the current object from the database.
Throws
Since
1.1
|
public
integer
|
#
getVersion( )
Gets the version_num of the object from the database (returns 0 if the BO is
not saved yet).
Gets the version_num of the object from the database (returns 0 if the BO is
not saved yet).
Returns
integer int
Throws
Alpha\Exception\RecordFoundException Alpha\Exception\RecordFoundException
Since
1.1
|
public
|
#
makeTable( )
Builds a new database table for the BO class.
Builds a new database table for the BO class.
Throws
Since
1.1
|
public
|
#
makeHistoryTable( )
Builds a new database table for the BO class to store it's history.
Builds a new database table for the BO class to store it's history.
Throws
AlphaException AlphaException
Since
1.2
|
public
|
#
rebuildTable( )
Re-builds the table if the model requirements have changed. All data is
lost!
Re-builds the table if the model requirements have changed. All data is
lost!
Throws
Since
1.1
|
public
|
#
dropTable( string $tableName = null )
Drops the table if the model requirements have changed. All data is lost!
Drops the table if the model requirements have changed. All data is lost!
Parameters
- $tableName
- string $tableName Optional table name, leave blank for the defined table for
this class to be dropped
Throws
Since
1.1
|
public
|
#
addProperty( string $propName )
Adds in a new class property without loosing existing data (does an ALTER
TABLE query on the database).
Adds in a new class property without loosing existing data (does an ALTER
TABLE query on the database).
Parameters
- $propName
- string $propName The name of the new field to add to the database table.
Throws
Since
1.1
|
public
integer
|
#
getMAX( )
Gets the maximum OID value from the database for this class type.
Gets the maximum OID value from the database for this class type.
Returns
integer The maximum OID value in the class table.
Throws
Since
1.1
|
public
integer
|
#
getCount( array $attributes = array(), array $values = array() )
Gets the count from the database for the amount of objects of this class.
Gets the count from the database for the amount of objects of this class.
Parameters
- $attributes
- array $atributes The attributes to count the objects by (optional).
- $values
- array $values The values of the attributes to count the objects by (optional).
Returns
integer int
Throws
Since
1.1
|
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.
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.
Returns
integer int
Throws
Since
1.2
|
public
|
#
setEnumOptions( )
Populate all of the enum options for this object from the database.
Populate all of the enum options for this object from the database.
Throws
Since
1.1
|
public
boolean
|
#
checkTableExists( boolean $checkHistoryTable = false )
Checks to see if the table exists in the database for the current business
class.
Checks to see if the table exists in the database for the current business
class.
Parameters
- $checkHistoryTable
- bool $checkHistoryTable Set to true if you want to check for the existance of
the _history table for this DAO.
Returns
boolean bool
Throws
Since
1.1
|
public static
boolean
|
#
checkBOTableExists( string $BOClassName, boolean $checkHistoryTable = false )
Static method to check the database and see if the table for the indicated BO
class name exists (assumes table name will be $BOClassName less "Object").
Static method to check the database and see if the table for the indicated BO
class name exists (assumes table name will be $BOClassName less "Object").
Parameters
- $BOClassName
- string $BOClassName The name of the business object class we are checking.
- $checkHistoryTable
- bool $checkHistoryTable Set to true if you want to check for the existance of
the _history table for this DAO.
Returns
boolean bool
Throws
Since
1.1
|
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.
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.
Returns
boolean bool
Throws
Since
1.1
|
public
array
|
#
findMissingFields( )
Returns an array containing any properties on the class which have not been
created on the database table yet.
Returns an array containing any properties on the class which have not been
created on the database table yet.
Returns
array An array of missing fields in the database table.
Throws
Since
1.1
|
public
array
|
#
getIndexes( )
Gets an array of all of the names of the active database indexes for this
class.
Gets an array of all of the names of the active database indexes for this
class.
Returns
array An array of database indexes on this table.
Throws
Since
1.1
|
public
|
#
createForeignIndex( string $attributeName, string $relatedClass, string $relatedClassAttribute, boolean $indexName = null )
Creates a foreign key constraint (index) in the database on the given
attribute.
Creates a foreign key constraint (index) in the database on the given
attribute.
Parameters
- $attributeName
- string $attributeName The name of the attribute to apply the index on.
- $relatedClass
- string $relatedClass The fully-qualified name of the related class.
- $relatedClassAttribute
- string $relatedClassAttribute The name of the field to relate to on the related
class.
- $indexName
- bool $allowNullValues For foreign key indexes that don't allow null values, set
this to false (default is true).
Throws
Since
1.1
|
public
|
#
createUniqueIndex( string $attribute1Name, string $attribute2Name = '', string $attribute3Name = '' )
Creates a unique index in the database on the given attribute(s).
Creates a unique index in the database on the given attribute(s).
Parameters
- $attribute1Name
- string $attribute1Name The first attribute to mark unique in the database.
- $attribute2Name
- string $attribute2Name The second attribute to mark unique in the databse
(optional, use only for composite keys).
- $attribute3Name
- string $attribute3Name The third attribute to mark unique in the databse
(optional, use only for composite keys).
Throws
Since
1.1
|
public
|
#
reload( )
Reloads the object from the database, overwritting any attribute values in
memory.
Reloads the object from the database, overwritting any attribute values in
memory.
Throws
Since
1.1
|
public
boolean
|
#
checkRecordExists( integer $OID )
Checks that a record exists for the BO in the database.
Checks that a record exists for the BO in the database.
Parameters
- $OID
- int $OID The Object ID of the object we want to see whether it exists or not.
Returns
boolean bool
Throws
Since
1.1
|
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 BO, i.e. the table is used to
store multiple types of BOs.
Checks to see if the table name matches the classname, and if not if the
table name matches the classname name of another BO, i.e. the table is used to
store multiple types of BOs.
Returns
boolean bool
Throws
Alpha\Exception\BadBOTableNameException Alpha\Exception\BadBOTableNameException
Since
1.1
|
public static
|
#
begin( )
Starts a new database transaction.
Starts a new database transaction.
Throws
Since
1.1
|
public static
|
#
commit( )
Commits the current database transaction.
Commits the current database transaction.
Throws
Since
1.1
|
public static
|
#
rollback( )
Aborts the current database transaction.
Aborts the current database transaction.
Throws
Since
1.1
|
public
|
#
setBO( Alpha\Model\ActiveRecord $BO )
Provide the BO that we are going to map the data to from this provider.
Provide the BO that we are going to map the data to from this provider.
Parameters
- $BO
- Alpha\Model\ActiveRecord $BO
Since
1.1
|
public
array
|
#
query( string $sqlQuery )
Returns a 2d array, where each element in the array is another array
representing a database row.
Returns a 2d array, where each element in the array is another array
representing a database row.
Parameters
- $sqlQuery
- string $sqlQuery
Returns
array array
Throws
Since
1.1
|
public static
boolean
|
#
checkDatabaseExists( )
Check to see if the configured database exists.
Check to see if the configured database exists.
Returns
boolean bool
Since
2.0
|
public static
|
#
createDatabase( )
Creates the configured database.
Creates the configured database.
Throws
Since
2.0
|
public static
|
#
dropDatabase( )
Drops the configured database.
Drops the configured database.
Throws
Since
2.0
|