| [ Index ] |
PHP Cross Reference of Akelos Framework |
[Source view] [Print]
(no description)
| Author: | Bermi Ferrer |
| Author: | Kaste 2007 |
| Copyright: | Copyright (c) 2002-2006, Akelos Media, S.L. http://www.akelos.org |
| License: | GNU Lesser General Public License |
| File Size: | 5513 lines (214 kb) |
| Included or required: | 6 times |
| Referenced: | 0 times |
| Includes or requires: | 4 files AkActiveRecord/AkDbAdapter.php AkActiveRecord/AkAssociatedActiveRecord.php AkInstaller.php AkActiveRecord/AkDbSchemaCache.php |
AkActiveRecord:: (257 methods):
__construct()
init()
__destruct()
newRecord()
cloneRecord()
isNewRecord()
reload()
create()
createOrUpdate()
findOrCreateBy()
_create()
_setRecordTimestamps()
save()
countBySql()
update()
updateAttribute()
updateAttributes()
updateAll()
_update()
delete()
deleteAll()
destroy()
_destroy()
destroyAll()
exists()
find()
_findInitial()
_findEvery()
_findFromIds()
_extractOptionsFromArgs()
_isOptionsHash()
_extractConditionsFromArgs()
_sanitizeConditionsVariables()
findFirst()
findAll()
findBySql()
findFirstBy()
findLastBy()
findAllBy()
findBy()
_getFindBySqlAndColumns()
_getVariableSqlCondition()
constructFinderSql()
addConditions()
getSanitizedConditionsArray()
getConditions()
_quoteColumnName()
_buildFinders()
instantiate()
descendsFromActiveRecord()
getInheritanceColumn()
setInheritanceColumn()
getSubclasses()
typeCondition()
setAttribute()
set()
setAttributes()
setId()
getAttribute()
get()
getAttributes()
getId()
toggleAttribute()
toggleAttributeAndSave()
incrementCounter()
decrementCounter()
decrementAttribute()
decrementAndSaveAttribute()
incrementAttribute()
incrementAndSaveAttribute()
setAccessibleAttributes()
setProtectedAttributes()
removeAttributesProtectedFromMassAssignment()
getSerializedAttributes()
getAvailableAttributes()
getAttributeCaption()
hasAttributesDefined()
getPrimaryKey()
getColumnNames()
getContentColumns()
getAttributeNames()
isAttributePresent()
hasAttribute()
isCombinedAttribute()
addCombinedAttributeConfiguration()
composeCombinedAttributes()
composeCombinedAttribute()
_getCombinedAttributesWhereThisAttributeIsUsed()
requiredForCombination()
hasCombinedAttributes()
getCombinedSubattributes()
decomposeCombinedAttributes()
decomposeCombinedAttribute()
getAvailableCombinedAttributes()
establishConnection()
isConnected()
getConnection()
setConnection()
_getDatabaseType()
setPrimaryKey()
getTableName()
setTableName()
getOnlyAvailableAttributes()
getColumnsForAttributes()
hasColumn()
attributesFromColumnDefinition()
_databaseTableInternals()
getColumnsWithRegexBoundaries()
_runCurrentModelInstallerIfExists()
getColumns()
getColumnSettings()
loadColumnsSettings()
setColumnSettings()
resetColumnInformation()
_getColumnsSettings()
_getModelColumnSettings()
_persistTableColumnSettings()
_getPersistedTableColumnSettings()
_clearPersitedColumnSettings()
initiateAttributeToNull()
initiateColumnsToNull()
getAkelosDataType()
getClassForDatabaseTableMapping()
getDisplayField()
setDisplayField()
t()
getInternationalizedColumns()
getAvailableLocales()
getCurrentLocale()
getAttributeByLocale()
getAttributeLocales()
setAttributeByLocale()
setAttributeLocales()
_delocalizeAttribute()
_isInternationalizeCandidate()
_addInternationalizedColumn()
_groupInternationalizedAttribute()
getAttributesBeforeTypeCast()
getAttributeBeforeTypeCast()
quotedId()
setSerializeAttribute()
getAvailableAttributesQuoted()
getAttributesQuoted()
getColumnType()
getColumnScale()
castAttributeForDatabase()
castAttributeFromDatabase()
_castDateParametersFromDateHelper_()
_addBlobQueryStack()
_updateBlobFields()
isLockingEnabled()
beforeCreate()
beforeValidation()
beforeValidationOnCreate()
beforeValidationOnUpdate()
beforeSave()
beforeUpdate()
afterUpdate()
afterValidation()
afterValidationOnCreate()
afterValidationOnUpdate()
afterInstantiate()
afterCreate()
afterDestroy()
beforeDestroy()
afterSave()
transactionStart()
transactionComplete()
transactionFail()
transactionHasFailed()
validatesConfirmationOf()
validatesAcceptanceOf()
validatesAssociated()
isBlank()
validatesPresenceOf()
validatesLengthOf()
validatesSizeOf()
validatesUniquenessOf()
validatesFormatOf()
validatesInclusionOf()
validatesExclusionOf()
validatesNumericalityOf()
isValid()
_runAutomatedValidators()
_setDefaultAttributeValuesAutomatically()
validate()
validateOnCreate()
validateOnUpdate()
_instantiateDefaultObserver()
notifyObservers()
setObservableState()
getObservableState()
addObserver()
getObservers()
getErrors()
addErrorToBase()
getBaseErrors()
addError()
addErrorOnEmpty()
addErrorOnBlank()
addErrorOnBoundaryBreaking()
addErrorOnBoundryBreaking()
isInvalid()
getErrorsOn()
yieldEachError()
yieldError()
yieldEachFullError()
getFullErrorMessages()
hasErrors()
clearErrors()
countErrors()
errorsToString()
actsAs()
_getActAsClassName()
_getActAsInstance()
_loadActAsBehaviours()
actsLike()
dbug()
toString()
dbugging()
debug()
select()
collect()
toJson()
_convert_column_to_xml_element()
_convert_column_from_xml_element()
_parseXmlAttributes()
_generateModelFromArray()
_fromArray()
fromXml()
_fromXmlCleanup()
fromJson()
toXml()
toYaml()
parseAkelosArgs()
getArrayFromAkString()
getAttributeCondition()
count()
average()
minimum()
maximum()
sum()
calculate()
_constructCountOptionsFromLegacyArgs()
_constructCalculationSql()
_executeSimpleCalculation()
_executeGroupedCalculation()
_validateCalculationOptions()
_getColumnAliasFor()
_getColumnFor()
_typeCastCalculatedValue()
hasBeenModified()
freeze()
isFrozen()
getType()
objectCache()
_extractValueFromDefault()
Class: AkActiveRecord - X-Ref
Active Record objects doesn't specify their attributes directly, but rather infer them from the table definition with| __construct() X-Ref |
| No description |
| init($attributes = array() X-Ref |
| No description |
| __destruct() X-Ref |
| No description |
| newRecord($attributes) X-Ref |
| New objects can be instantiated as either empty (pass no construction parameter) or pre-set with attributes but not yet saved (pass an array with key names matching the associated table column names). In both instances, valid attribute keys are determined by the column names of the associated table; hence you can't have attributes that aren't part of the table columns. |
| cloneRecord() X-Ref |
| Returns a clone of the record that hasn't been assigned an id yet and is treated as a new record. |
| isNewRecord() X-Ref |
| Returns true if this object hasn't been saved yet that is, a record for the object doesn't exist yet. |
| reload() X-Ref |
| Reloads the attributes of this object from the database. |
| create($attributes = null) X-Ref |
| Creates an object, instantly saves it as a record (if the validation permits it), and returns it. If the save fail under validations, the unsaved object is still returned. |
| createOrUpdate($validate = true) X-Ref |
| No description |
| findOrCreateBy() X-Ref |
| No description |
| _create() X-Ref |
| Creates a new record with values matching those of the instance attributes. Must be called as a result of a call to createOrUpdate. |
| _setRecordTimestamps() X-Ref |
| No description |
| save($validate = true) X-Ref |
| - No record exists: Creates a new record with values matching those of the object attributes. - A record does exist: Updates the record with values matching those of the object attributes. |
| countBySql($sql) X-Ref |
| Returns the result of an SQL statement that should only include a COUNT(*) in the SELECT part. $Product->countBySql("SELECT COUNT(*) FROM sales s, customers c WHERE s.customer_id = c.id"); |
| update($id, $attributes) X-Ref |
| Finds the record from the passed id, instantly saves it with the passed attributes (if the validation permits it), and returns it. If the save fail under validations, the unsaved object is still returned. |
| updateAttribute($name, $value, $should_validate=true) X-Ref |
| Updates a single attribute and saves the record. This is especially useful for boolean flags on existing records. |
| updateAttributes($attributes, $object = null) X-Ref |
| Updates all the attributes in from the passed array and saves the record. If the object is invalid, the saving will fail and false will be returned. |
| updateAll($updates, $conditions = null) X-Ref |
| Updates all records with the SET-part of an SQL update statement in updates and returns an integer with the number of rows updates. A subset of the records can be selected by specifying conditions. Example: <code>$Billing->updateAll("category = 'authorized', approved = 1", "author = 'David'");</code> Important note: Conditions are not sanitized yet so beware of accepting variable conditions when using this function |
| _update() X-Ref |
| Updates the associated record with values matching those of the instance attributes. Must be called as a result of a call to createOrUpdate. |
| delete($id) X-Ref |
| Deletes the record with the given id without instantiating an object first. If an array of ids is provided, all of them are deleted. |
| deleteAll($conditions = null) X-Ref |
| Deletes all the records that matches the condition without instantiating the objects first (and hence not calling the destroy method). Example: <code>$Post->destroyAll("person_id = 5 AND (category = 'Something' OR category = 'Else')");</code> Important note: Conditions are not sanitized yet so beware of accepting variable conditions when using this function |
| destroy($id = null) X-Ref |
| Destroys the record with the given id by instantiating the object and calling destroy (all the callbacks are the triggered). If an array of ids is provided, all of them are destroyed. Deletes the record in the database and freezes this instance to reflect that no changes should be made (since they can't be persisted). |
| _destroy() X-Ref |
| No description |
| destroyAll($conditions) X-Ref |
| Destroys the objects for all the records that matches the condition by instantiating each object and calling the destroy method. Example: $Person->destroyAll("last_login < '2004-04-04'"); |
| exists($id) X-Ref |
| Returns true if the given id represents the primary key of a record in the database, false otherwise. Example: $Person->exists(5); |
| find() X-Ref |
| Find operates with three different retrieval approaches: * Find by id: This can either be a specific id find(1), a list of ids find(1, 5, 6), or an array of ids find(array(5, 6, 10)). If no record can be found for all of the listed ids, then RecordNotFound will be raised. * Find first: This will return the first record matched by the options used. These options can either be specific conditions or merely an order. If no record can matched, false is returned. * Find all: This will return all the records matched by the options used. If no records are found, an empty array is returned. All approaches accepts an $option array as their last parameter. The options are: 'conditions' => An SQL fragment like "administrator = 1" or array("user_name = ?" => $username). See conditions in the intro. 'order' => An SQL fragment like "created_at DESC, name". 'limit' => An integer determining the limit on the number of rows that should be returned. 'offset' => An integer determining the offset from where the rows should be fetched. So at 5, it would skip the first 4 rows. 'joins' => An SQL fragment for additional joins like "LEFT JOIN comments ON comments.post_id = $id". (Rarely needed). 'include' => Names associations that should be loaded alongside using LEFT OUTER JOINs. The symbols named refer to already defined associations. See eager loading under Associations. Examples for find by id: <code> $Person->find(1); // returns the object for ID = 1 $Person->find(1, 2, 6); // returns an array for objects with IDs in (1, 2, 6), Returns false if any of those IDs is not available $Person->find(array(7, 17)); // returns an array for objects with IDs in (7, 17) $Person->find(array(1)); // returns an array for objects the object with ID = 1 $Person->find(1, array('conditions' => "administrator = 1", 'order' => "created_on DESC")); </code> Examples for find first: <code> $Person->find('first'); // returns the first object fetched by SELECT * FROM people $Person->find('first', array('conditions' => array("user_name = ':user_name'", ':user_name' => $user_name))); $Person->find('first', array('order' => "created_on DESC", 'offset' => 5)); </code> Examples for find all: <code> $Person->find('all'); // returns an array of objects for all the rows fetched by SELECT * FROM people $Person->find(); // Same as $Person->find('all'); $Person->find('all', array('conditions' => array("category IN (categories)", 'categories' => join(','$categories)), 'limit' => 50)); $Person->find('all', array('offset' => 10, 'limit' => 10)); $Person->find('all', array('include' => array('account', 'friends')); </code> |
| _findInitial($options) X-Ref |
| No description |
| _findEvery($options) X-Ref |
| No description |
| _findFromIds($ids, $options) X-Ref |
| No description |
| _extractOptionsFromArgs(&$args) X-Ref |
| No description |
| _isOptionsHash($options) X-Ref |
| No description |
| _extractConditionsFromArgs($args, $options) X-Ref |
| No description |
| _sanitizeConditionsVariables(&$options) X-Ref |
| No description |
| findFirst() X-Ref |
| No description |
| findAll() X-Ref |
| No description |
| findBySql($sql, $limit = null, $offset = null, $bindings = null) X-Ref |
| Works like find_all, but requires a complete SQL string. Examples: $Post->findBySql("SELECT p.*, c.author FROM posts p, comments c WHERE p.id = c.post_id"); $Post->findBySql(array("SELECT * FROM posts WHERE author = ? AND created_on > ?", $author_id, $start_date)); |
| findFirstBy() X-Ref |
| This function pretends to emulate RoR finders until AkActiveRecord::addMethod becomes stable on future PHP versions. |
| findLastBy() X-Ref |
| No description |
| findAllBy() X-Ref |
| No description |
| findBy() X-Ref |
| This method allows you to use finders in a more flexible way like: findBy('username AND password', $username, $password); findBy('age > ? AND name:contains', 18, 'Joe'); findBy('is_active = true AND session_id', session_id()); |
| _getFindBySqlAndColumns($find_by_sql, &$query_values) X-Ref |
| _getVariableSqlCondition($variable_condition) X-Ref |
| Given a condition that uses bindings like "user = ? AND created_at > ?" will return a string replacing the "?" bindings with the column values for current Active Record return: string |
| constructFinderSql($options, $select_from_prefix = 'default') X-Ref |
| No description |
| addConditions(&$sql, $conditions = null, $table_alias = null) X-Ref |
| Adds a sanitized version of $conditions to the $sql string. Note that the passed $sql string is changed. |
| getSanitizedConditionsArray($conditions_array) X-Ref |
| Gets a sanitized version of the input array. Each element will be escaped |
| getConditions($conditions, $prefix = '', $model_name = null) X-Ref |
| This functions is used to get the conditions from an AkRequest object |
| _quoteColumnName($column_name) X-Ref |
| _buildFinders($finderFunctions = array('find','findFirst') X-Ref |
| EXPERIMENTAL: Will allow to create finders when PHP includes aggregate_methods as a stable feature on PHP4, for PHP5 we might use __call |
| instantiate($record, $set_as_new = true) X-Ref |
| Finder methods must instantiate through this method to work with the single-table inheritance model and eager loading associations. that makes it possible to create objects of different types from the same table. |
| descendsFromActiveRecord(&$object) X-Ref |
| No description |
| getInheritanceColumn() X-Ref |
| Gets the column name for use with single table inheritance. Can be overridden in subclasses. |
| setInheritanceColumn($column_name) X-Ref |
| Defines the column name for use with single table inheritance. Can be overridden in subclasses. |
| getSubclasses() X-Ref |
| No description |
| typeCondition($table_alias = null) X-Ref |
| No description |
| setAttribute($attribute, $value, $inspect_for_callback_child_method = AK_ACTIVE_RECORD_ENABLE_CALLBACK_SETTERS, $compose_after_set = true) X-Ref |
| No description |
| set($attribute, $value = null, $inspect_for_callback_child_method = true, $compose_after_set = true) X-Ref |
| No description |
| setAttributes($attributes, $override_attribute_protection = false) X-Ref |
| Allows you to set all the attributes at once by passing in an array with keys matching the attribute names (which again matches the column names). Sensitive attributes can be protected from this form of mass-assignment by using the $this->setProtectedAttributes method. Or you can alternatively specify which attributes can be accessed in with the $this->setAccessibleAttributes method. Then all the attributes not included in that won?t be allowed to be mass-assigned. |
| setId($value) X-Ref |
| No description |
| getAttribute($attribute, $inspect_for_callback_child_method = AK_ACTIVE_RECORD_ENABLE_CALLBACK_GETTERS) X-Ref |
| No description |
| get($attribute = null, $inspect_for_callback_child_method = true) X-Ref |
| No description |
| getAttributes() X-Ref |
| Returns an array of all the attributes with their names as keys and clones of their objects as values in case they are objects. |
| getId() X-Ref |
| Every Active Record class must use "id" as their primary ID. This getter overwrites the native id method, which isn't being used in this context. |
| toggleAttribute($attribute) X-Ref |
| Turns an attribute that's currently true into false and vice versa. Returns attribute value. |
| toggleAttributeAndSave($attribute) X-Ref |
| Toggles the attribute and saves the record. |
| incrementCounter($counter_name, $id, $difference = 1) X-Ref |
| Increments the specified counter by one. So $DiscussionBoard->incrementCounter("post_count", $discussion_board_id); would increment the "post_count" counter on the board responding to $discussion_board_id. This is used for caching aggregate values, so that they doesn't need to be computed every time. Especially important for looping over a collection where each element require a number of aggregate values. Like the $DiscussionBoard that needs to list both the number of posts and comments. |
| decrementCounter($counter_name, $id, $difference = 1) X-Ref |
| Works like AkActiveRecord::incrementCounter, but decrements instead. |
| decrementAttribute($attribute) X-Ref |
| Initializes the attribute to zero if null and subtracts one. Only makes sense for number-based attributes. Returns attribute value. |
| decrementAndSaveAttribute($attribute) X-Ref |
| Decrements the attribute and saves the record. |
| incrementAttribute($attribute) X-Ref |
| Initializes the attribute to zero if null and adds one. Only makes sense for number-based attributes. Returns attribute value. |
| incrementAndSaveAttribute($attribute) X-Ref |
| Increments the attribute and saves the record. |
| setAccessibleAttributes() X-Ref |
| If this macro is used, only those attributed named in it will be accessible for mass-assignment, such as new ModelName($attributes) and $this->attributes($attributes). This is the more conservative choice for mass-assignment protection. If you'd rather start from an all-open default and restrict attributes as needed, have a look at AkActiveRecord::setProtectedAttributes(). |
| setProtectedAttributes() X-Ref |
| Attributes named in this macro are protected from mass-assignment, such as new ModelName($attributes) and $this->attributes(attributes). Their assignment will simply be ignored. Instead, you can use the direct writer methods to do assignment. This is meant to protect sensitive attributes to be overwritten by URL/form hackers. Example: <code> class Customer extends ActiveRecord { function Customer() { $this->setProtectedAttributes('credit_rating'); } } $Customer = new Customer('name' => 'David', 'credit_rating' => 'Excellent'); $Customer->credit_rating // => null $Customer->attributes(array('description' => 'Jolly fellow', 'credit_rating' => 'Superb')); $Customer->credit_rating // => null $Customer->credit_rating = 'Average' $Customer->credit_rating // => 'Average' </code> |
| removeAttributesProtectedFromMassAssignment($attributes) X-Ref |
| No description |
| getSerializedAttributes() X-Ref |
| Returns an array of all the attributes that have been specified for serialization as keys and the objects as values. |
| getAvailableAttributes() X-Ref |
| No description |
| getAttributeCaption($attribute) X-Ref |
| No description |
| hasAttributesDefined() X-Ref |
| This function is useful in case you need to know if attributes have been assigned to an object. |
| getPrimaryKey() X-Ref |
| Returns the primary key field. |
| getColumnNames() X-Ref |
| No description |
| getContentColumns() X-Ref |
| Returns an array of columns objects where the primary id, all columns ending in "_id" or "_count", and columns used for single table inheritance has been removed. |
| getAttributeNames() X-Ref |
| Returns an array of names for the attributes available on this object sorted alphabetically. |
| isAttributePresent($attribute) X-Ref |
| Returns true if the specified attribute has been set by the user or by a database load and is neither null nor empty? |
| hasAttribute($attribute) X-Ref |
| Returns true if given attribute exists for this Model. param: string $attribute return: boolean |
| isCombinedAttribute($attribute) X-Ref |
| Returns true if given attribute is a combined attribute for this Model. param: string $attribute return: boolean |
| addCombinedAttributeConfiguration($attribute) X-Ref |
| No description |
| composeCombinedAttributes() X-Ref |
| No description |
| composeCombinedAttribute($combined_attribute) X-Ref |
| No description |
| _getCombinedAttributesWhereThisAttributeIsUsed($attribute) X-Ref |
| requiredForCombination($attribute) X-Ref |
| No description |
| hasCombinedAttributes() X-Ref |
| No description |
| getCombinedSubattributes($attribute) X-Ref |
| No description |
| decomposeCombinedAttributes() X-Ref |
| No description |
| decomposeCombinedAttribute($combined_attribute, $used_on_combined_fields = false) X-Ref |
| No description |
| getAvailableCombinedAttributes() X-Ref |
| No description |
| establishConnection($specification_or_profile = AK_DEFAULT_DATABASE_PROFILE) X-Ref |
| Establishes the connection to the database. Accepts either a profile name specified in config/config.php or an array as input where the 'type' key must be specified with the name of a database adapter (in lower-case) example for regular databases (MySQL, Postgresql, etc): $AkActiveRecord->establishConnection('development'); $AkActiveRecord->establishConnection('super_user'); $AkActiveRecord->establishConnection( array( 'type' => "mysql", 'host' => "localhost", 'username' => "myuser", 'password' => "mypass", 'database' => "somedatabase" )); Example for SQLite database: $AkActiveRecord->establishConnection( array( 'type' => "sqlite", 'dbfile' => "path/to/dbfile" ) ) |
| isConnected() X-Ref |
| Returns true if a connection that's accessible to this class have already been opened. |
| getConnection() X-Ref |
| Returns the connection currently associated with the class. This can also be used to "borrow" the connection to do database work unrelated to any of the specific Active Records. |
| setConnection($db_adapter = null) X-Ref |
| Sets the connection for the class. |
| _getDatabaseType() X-Ref |
| setPrimaryKey($primary_key = 'id') X-Ref |
| Defines the primary key field ? can be overridden in subclasses. |
| getTableName($modify_for_associations = true) X-Ref |
| No description |
| setTableName($table_name = null, $check_for_existence = AK_ACTIVE_RECORD_VALIDATE_TABLE_NAMES, $check_mode = false) X-Ref |
| No description |
| getOnlyAvailableAttributes($attributes) X-Ref |
| No description |
| getColumnsForAttributes($attributes) X-Ref |
| No description |
| hasColumn($column) X-Ref |
| Returns true if given attribute exists for this Model. param: string $name Name of table to look in return: boolean |
| attributesFromColumnDefinition() X-Ref |
| Initializes the attributes array with keys matching the columns from the linked table and the values matching the corresponding default value of that column, so that a new instance, or one populated from a passed-in array, still has all the attributes that instances loaded from the database would. |
| _databaseTableInternals($table) X-Ref |
| Gets information from the database engine about a single table |
| getColumnsWithRegexBoundaries() X-Ref |
| No description |
| _runCurrentModelInstallerIfExists(&$column_objects) X-Ref |
| If is the first time we use a model this function will run the installer for the model if it exists |
| getColumns($force_reload = false) X-Ref |
| Returns an array of column objects for the table associated with this class. |
| getColumnSettings($force_reload = false) X-Ref |
| No description |
| loadColumnsSettings($force_reload = false) X-Ref |
| No description |
| setColumnSettings($column_name, $column_object) X-Ref |
| No description |
| resetColumnInformation() X-Ref |
| Resets all the cached information about columns, which will cause they to be reloaded on the next request. |
| _getColumnsSettings() X-Ref |
| _getModelColumnSettings() X-Ref |
| _persistTableColumnSettings() X-Ref |
| _getPersistedTableColumnSettings() X-Ref |
| _clearPersitedColumnSettings() X-Ref |
| initiateAttributeToNull($attribute) X-Ref |
| No description |
| initiateColumnsToNull() X-Ref |
| No description |
| getAkelosDataType(&$adodb_column_object) X-Ref |
| Akelos data types are mapped to phpAdodb data types Returns the Akelos data type for an Adodb Column Object 'C'=>'string', // Varchar, capped to 255 characters. 'X' => 'text' // Larger varchar, capped to 4000 characters (to be compatible with Oracle). 'XL' => 'text' // For Oracle, returns CLOB, otherwise the largest varchar size. 'C2' => 'string', // Multibyte varchar 'X2' => 'string', // Multibyte varchar (largest size) 'B' => 'binary', // BLOB (binary large object) 'D' => array('date', 'datetime'), // Date (some databases do not support this, and we return a datetime type) 'T' => array('datetime', 'timestamp'), //Datetime or Timestamp 'L' => 'boolean', // Integer field suitable for storing booleans (0 or 1) 'I' => // Integer (mapped to I4) 'I1' => 'integer', // 1-byte integer 'I2' => 'integer', // 2-byte integer 'I4' => 'integer', // 4-byte integer 'I8' => 'integer', // 8-byte integer 'F' => 'float', // Floating point number 'N' => 'integer' // Numeric or decimal number return: string One of this 'string','text','integer','float','datetime','timestamp', |
| getClassForDatabaseTableMapping() X-Ref |
| This method retrieves current class name that will be used to map your database to this object. |
| getDisplayField() X-Ref |
| No description |
| setDisplayField($attribute_name) X-Ref |
| No description |
| t($string, $array = null) X-Ref |
| No description |
| getInternationalizedColumns() X-Ref |
| No description |
| getAvailableLocales() X-Ref |
| No description |
| getCurrentLocale() X-Ref |
| No description |
| getAttributeByLocale($attribute, $locale) X-Ref |
| No description |
| getAttributeLocales($attribute) X-Ref |
| No description |
| setAttributeByLocale($attribute, $value, $locale) X-Ref |
| No description |
| setAttributeLocales($attribute, $values = array() X-Ref |
| No description |
| _delocalizeAttribute($attribute) X-Ref |
| _isInternationalizeCandidate($column_name) X-Ref |
| _addInternationalizedColumn($column_name) X-Ref |
| _groupInternationalizedAttribute($attribute, $value) X-Ref |
| Adds an internationalized attribute to an array containing other locales for the same column name Example: es_title and en_title will be available user title = array('es'=>'...', 'en' => '...') |
| getAttributesBeforeTypeCast() X-Ref |
| No description |
| getAttributeBeforeTypeCast($attribute) X-Ref |
| No description |
| quotedId() X-Ref |
| No description |
| setSerializeAttribute($attr_name, $class_name = null) X-Ref |
| Specifies that the attribute by the name of attr_name should be serialized before saving to the database and unserialized after loading from the database. If class_name is specified, the serialized object must be of that class on retrieval, as a new instance of the object will be loaded with serialized values. |
| getAvailableAttributesQuoted() X-Ref |
| No description |
| getAttributesQuoted($attributes_array) X-Ref |
| No description |
| getColumnType($column_name) X-Ref |
| No description |
| getColumnScale($column_name) X-Ref |
| No description |
| castAttributeForDatabase($column_name, $value, $add_quotes = true) X-Ref |
| No description |
| castAttributeFromDatabase($column_name, $value) X-Ref |
| No description |
| _castDateParametersFromDateHelper_(&$params) X-Ref |
| Joins date arguments into a single attribute. Like the array generated by the date_helper, so array('published_on(1i)' => 2002, 'published_on(2i)' => 'January', 'published_on(3i)' => 24) Will be converted to array('published_on'=>'2002-01-24') |
| _addBlobQueryStack($column_name, $blob_value) X-Ref |
| _updateBlobFields($condition) X-Ref |
| isLockingEnabled() X-Ref |
| Active Records support optimistic locking if the field <tt>lock_version</tt> is present. Each update to the record increments the lock_version column and the locking facilities ensure that records instantiated twice will let the last one saved return false on save() if the first was also updated. Example: $p1 = new Person(1); $p2 = new Person(1); $p1->first_name = "Michael"; $p1->save(); $p2->first_name = "should fail"; $p2->save(); // Returns false You're then responsible for dealing with the conflict by checking the return value of save(); and either rolling back, merging, or otherwise apply the business logic needed to resolve the conflict. You must ensure that your database schema defaults the lock_version column to 0. This behavior can be turned off by setting <tt>AkActiveRecord::lock_optimistically = false</tt>. |
| beforeCreate() X-Ref |
| Callbacks are hooks into the life-cycle of an Active Record object that allows you to trigger logic before or after an alteration of the object state. This can be used to make sure that associated and dependent objects are deleted when destroy is called (by overwriting beforeDestroy) or to massage attributes before they're validated (by overwriting beforeValidation). As an example of the callbacks initiated, consider the AkActiveRecord->save() call: - (-) save() - (-) needsValidation() - (1) beforeValidation() - (2) beforeValidationOnCreate() / beforeValidationOnUpdate() - (-) validate() - (-) validateOnCreate() - (4) afterValidation() - (5) afterValidationOnCreate() / afterValidationOnUpdate() - (6) beforeSave() - (7) beforeCreate() / beforeUpdate() - (-) create() - (8) afterCreate() / afterUpdate() - (9) afterSave() - (10) afterDestroy() - (11) beforeDestroy() That's a total of 15 callbacks, which gives you immense power to react and prepare for each state in the Active Record lifecycle. Examples: class CreditCard extends ActiveRecord { // Strip everything but digits, so the user can specify "555 234 34" or // "5552-3434" or both will mean "55523434" function beforeValidationOnCreate { if(!empty($this->number)){ $this->number = ereg_replace('[^0-9]*','',$this->number); } } } class Subscription extends ActiveRecord { // Note: This is not implemented yet var $beforeCreate = 'recordSignup'; function recordSignup() { $this->signed_up_on = date("Y-m-d"); } } class Firm extends ActiveRecord { //Destroys the associated clients and people when the firm is destroyed // Note: This is not implemented yet var $beforeDestroy = array('destroyAssociatedPeople', 'destroyAssociatedClients'); function destroyAssociatedPeople() { $Person = new Person(); $Person->destroyAll("firm_id=>", $this->id); } function destroyAssociatedClients() { $Client = new Client(); $Client->destroyAll("client_of=>", $this->id); } } == Canceling callbacks == If a before* callback returns false, all the later callbacks and the associated action are cancelled. If an after* callback returns false, all the later callbacks are cancelled. Callbacks are generally run in the order they are defined, with the exception of callbacks defined as methods on the model, which are called last. Override this methods to hook Active Records |
| beforeValidation() X-Ref |
| No description |
| beforeValidationOnCreate() X-Ref |
| No description |
| beforeValidationOnUpdate() X-Ref |
| No description |
| beforeSave() X-Ref |
| No description |
| beforeUpdate() X-Ref |
| No description |
| afterUpdate() X-Ref |
| No description |
| afterValidation() X-Ref |
| No description |
| afterValidationOnCreate() X-Ref |
| No description |
| afterValidationOnUpdate() X-Ref |
| No description |
| afterInstantiate() X-Ref |
| No description |
| afterCreate() X-Ref |
| No description |
| afterDestroy() X-Ref |
| No description |
| beforeDestroy() X-Ref |
| No description |
| afterSave() X-Ref |
| No description |
| transactionStart() X-Ref |
| Transaction support for database operations Transactions are enabled automatically for Active record objects, But you can nest transactions within models. This transactions are nested, and only the outermost will be executed $User->transactionStart(); $User->create('username'=>'Bermi'); $Members->create('username'=>'Bermi'); if(!checkSomething()){ $User->transactionFail(); } $User->transactionComplete(); |
| transactionComplete() X-Ref |
| No description |
| transactionFail() X-Ref |
| No description |
| transactionHasFailed() X-Ref |
| No description |
| validatesConfirmationOf($attribute_names, $message = 'confirmation') X-Ref |
| Encapsulates the pattern of wanting to validate a password or email address field with a confirmation. Example: Model: class Person extends ActiveRecord { function validate() { $this->validatesConfirmationOf('password'); $this->validatesConfirmationOf('email_address', "should match confirmation"); } } View: <?=$form_helper->password_field("person", "password"); ?> <?=$form_helper->password_field("person", "password_confirmation"); ?> The person has to already have a password attribute (a column in the people table), but the password_confirmation is virtual. It exists only as an in-memory variable for validating the password. This check is performed only if password_confirmation is not null. |
| validatesAcceptanceOf($attribute_names, $message = 'accepted', $accept = 1) X-Ref |
| Encapsulates the pattern of wanting to validate the acceptance of a terms of service check box (or similar agreement). Example: class Person extends ActiveRecord { function validateOnCreate() { $this->validatesAcceptanceOf('terms_of_service'); $this->validatesAcceptanceOf('eula', "must be abided"); } } The terms_of_service attribute is entirely virtual. No database column is needed. This check is performed only if terms_of_service is not null. param: accept 1 |
| validatesAssociated($attribute_names, $message = 'invalid') X-Ref |
| Validates whether the associated object or objects are all valid themselves. Works with any kind of association. class Book extends ActiveRecord { var $has_many = 'pages'; var $belongs_to = 'library'; function validate(){ $this->validatesAssociated(array('pages', 'library')); } } Warning: If, after the above definition, you then wrote: class Page extends ActiveRecord { var $belongs_to = 'book'; function validate(){ $this->validatesAssociated('book'); } } ...this would specify a circular dependency and cause infinite recursion. NOTE: This validation will not fail if the association hasn't been assigned. If you want to ensure that the association is both present and guaranteed to be valid, you also need to use validatesPresenceOf. |
| isBlank($value = null) X-Ref |
| No description |
| validatesPresenceOf($attribute_names, $message = 'blank') X-Ref |
| Validates that the specified attributes are not blank (as defined by AkActiveRecord::isBlank()). |
| validatesLengthOf($attribute_names, $options = array() X-Ref |
| Validates that the specified attribute matches the length restrictions supplied. Only one option can be used at a time: class Person extends ActiveRecord { function validate() { $this->validatesLengthOf('first_name', array('maximum'=>30)); $this->validatesLengthOf('last_name', array('maximum'=>30,'message'=> "less than %d if you don't mind")); $this->validatesLengthOf('last_name', array('within'=>array(7, 32))); $this->validatesLengthOf('last_name', array('in'=>array(6, 20), 'too_long' => "pick a shorter name", 'too_short' => "pick a longer name")); $this->validatesLengthOf('fav_bra_size', array('minimum'=>1, 'too_short'=>"please enter at least %d character")); $this->validatesLengthOf('smurf_leader', array('is'=>4, 'message'=>"papa is spelled with %d characters... don't play me.")); } } NOTE: Be aware that $this->validatesLengthOf('field', array('is'=>5)); Will match a string containing 5 characters (Ie. "Spain"), an integer 5, and an array with 5 elements. You must supply additional checking to check for appropriate types. Configuration options: <tt>minimum</tt> - The minimum size of the attribute <tt>maximum</tt> - The maximum size of the attribute <tt>is</tt> - The exact size of the attribute <tt>within</tt> - A range specifying the minimum and maximum size of the attribute <tt>in</tt> - A synonym(or alias) for :within <tt>allow_null</tt> - Attribute may be null; skip validation. <tt>too_long</tt> - The error message if the attribute goes over the maximum (default "is" "is too long (max is %d characters)") <tt>too_short</tt> - The error message if the attribute goes under the minimum (default "is" "is too short (min is %d characters)") <tt>wrong_length</tt> - The error message if using the "is" method and the attribute is the wrong size (default "is" "is the wrong length (should be %d characters)") <tt>message</tt> - The error message to use for a "minimum", "maximum", or "is" violation. An alias of the appropriate too_long/too_short/wrong_length message |
| validatesSizeOf($attribute_names, $options = array() X-Ref |
| No description |
| validatesUniquenessOf($attribute_names, $options = array() X-Ref |
| Validates whether the value of the specified attributes are unique across the system. Useful for making sure that only one user can be named "davidhh". class Person extends ActiveRecord { function validate() { $this->validatesUniquenessOf('passport_number'); $this->validatesUniquenessOf('user_name', array('scope' => "account_id")); } } It can also validate whether the value of the specified attributes are unique based on multiple scope parameters. For example, making sure that a teacher can only be on the schedule once per semester for a particular class. class TeacherSchedule extends ActiveRecord { function validate() { $this->validatesUniquenessOf('passport_number'); $this->validatesUniquenessOf('teacher_id', array('scope' => array("semester_id", "class_id")); } } When the record is created, a check is performed to make sure that no record exist in the database with the given value for the specified attribute (that maps to a column). When the record is updated, the same check is made but disregarding the record itself. Configuration options: <tt>message</tt> - Specifies a custom error message (default is: "has already been taken") <tt>scope</tt> - Ensures that the uniqueness is restricted to a condition of "scope = record.scope" <tt>case_sensitive</tt> - Looks for an exact match. Ignored by non-text columns (true by default). <tt>if</tt> - Specifies a method to call or a string to evaluate to determine if the validation should occur (e.g. 'if' => 'allowValidation', or 'if' => '$this->signup_step > 2'). The method, or string should return or evaluate to a true or false value. |
| validatesFormatOf($attribute_names, $regular_expression, $message = 'invalid', $regex_function = 'preg_match') X-Ref |
| Validates whether the value of the specified attribute is of the correct form by matching it against the regular expression provided. <code> class Person extends ActiveRecord { function validate() { $this->validatesFormatOf('email', "/^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/"); } } </code> A regular expression must be provided or else an exception will be raised. There are some regular expressions bundled with the Akelos Framework. You can override them by defining them as PHP constants (Ie. define('AK_EMAIL_REGULAR_EXPRESSION', '/^My custom email regex$/');). This must be done on your main configuration file. This are predefined perl-like regular extensions. * AK_NOT_EMPTY_REGULAR_EXPRESSION ---> /.+/ * AK_EMAIL_REGULAR_EXPRESSION ---> /^([a-z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-z0-9\-]+\.)+))([a-z]{2,4}|[0-9]{1,3})(\]?)$/i * AK_NUMBER_REGULAR_EXPRESSION ---> /^[0-9]+$/ * AK_PHONE_REGULAR_EXPRESSION ---> /^([\+]?[(]?[\+]?[ ]?[0-9]{2,3}[)]?[ ]?)?[0-9 ()\-]{4,25}$/ * AK_DATE_REGULAR_EXPRESSION ---> /^(([0-9]{1,2}(\-|\/|\.| )[0-9]{1,2}(\-|\/|\.| )[0-9]{2,4})|([0-9]{2,4}(\-|\/|\.| )[0-9]{1,2}(\-|\/|\.| )[0-9]{1,2})){1}$/ * AK_IP4_REGULAR_EXPRESSION ---> /^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/ * AK_POST_CODE_REGULAR_EXPRESSION ---> /^[0-9A-Za-z -]{2,7}$/ IMPORTANT: Predefined regular expressions may change in newer versions of the Framework, so is highly recommended to hardcode you own on regex on your validators. Params: <tt>$message</tt> - A custom error message (default is: "is invalid") <tt>$regular_expression</tt> - The regular expression used to validate the format with (note: must be supplied!) |
| validatesInclusionOf($attribute_names, $array_of_possibilities, $message = 'inclusion', $allow_null = false) X-Ref |
| Validates whether the value of the specified attribute is available in a particular array of elements. class Person extends ActiveRecord { function validate() { $this->validatesInclusionOf('gender', array('male', 'female'), "woah! what are you then!??!!"); $this->validatesInclusionOf('age', range(0, 99)); } Parameters: <tt>$array_of_ possibilities</tt> - An array of available items <tt>$message</tt> - Specifies a customer error message (default is: "is not included in the list") <tt>$allow_null</tt> - If set to true, skips this validation if the attribute is null (default is: false) |
| validatesExclusionOf($attribute_names, $array_of_possibilities, $message = 'exclusion', $allow_null = false) X-Ref |
| Validates that the value of the specified attribute is not in a particular array of elements. class Person extends ActiveRecord { function validate() { $this->validatesExclusionOf('username', array('admin', 'superuser'), "You don't belong here"); $this->validatesExclusionOf('age', range(30,60), "This site is only for under 30 and over 60"); } } Parameters: <tt>$array_of_possibilities</tt> - An array of items that the value shouldn't be part of <tt>$message</tt> - Specifies a customer error message (default is: "is reserved") <tt>$allow_null</tt> - If set to true, skips this validation if the attribute is null (default is: false) |
| validatesNumericalityOf($attribute_names, $message = 'not_a_number', $only_integer = false, $allow_null = false) X-Ref |
| Validates whether the value of the specified attribute is numeric. class Person extends ActiveRecord { function validate() { $this->validatesNumericalityOf('value'); } } Parameters: <tt>$message</tt> - A custom error message (default is: "is not a number") <tt>$only_integer</tt> Specifies whether the value has to be an integer, e.g. an integral value (default is false) <tt>$allow_null</tt> Skip validation if attribute is null (default is false). |
| isValid() X-Ref |
| Returns true if no errors were added otherwise false. |
| _runAutomatedValidators() X-Ref |
| By default the Active Record will validate for the maximum length for database columns. You can disable the automated validators by setting $this->_automated_validators_enabled to false. Specific validators are (for now): $this->_automated_max_length_validator = false; // false by default, but you can set it to true on your model $this->_automated_not_null_validator = false; // disabled by default |
| _setDefaultAttributeValuesAutomatically() X-Ref |
| $this->_set_default_attribute_values_automatically = true; // This enables automated attribute setting from database definition |
| validate() X-Ref |
| Overwrite this method for validation checks on all saves and use addError($field, $message); for invalid attributes. |
| validateOnCreate() X-Ref |
| Overwrite this method for validation checks used only on creation. |
| validateOnUpdate() X-Ref |
| Overwrite this method for validation checks used only on updates. |
| _instantiateDefaultObserver() X-Ref |
| notifyObservers($method = null) X-Ref |
| Calls the $method using the reference to each registered observer. return: true (this is used internally for triggering observers on default callbacks) |
| setObservableState($state_message) X-Ref |
| No description |
| getObservableState() X-Ref |
| No description |
| addObserver(&$observer) X-Ref |
| Register the reference to an object object param: $observer AkObserver param: $options array of options for the observer return: void |
| getObservers() X-Ref |
| Register the reference to an object object return: void |
| getErrors() X-Ref |
| Returns the Errors array that holds all information about attribute error messages. |
| addErrorToBase($message) X-Ref |
| Adds an error to the base object instead of any particular attribute. This is used to report errors that doesn't tie to any specific attribute, but rather to the object as a whole. These error messages doesn't get prepended with any field name when iterating with yieldEachFullError, so they should be complete sentences. |
| getBaseErrors() X-Ref |
| Returns errors assigned to base object through addToBase according to the normal rules of getErrorsOn($attribute). |
| addError($attribute, $message = 'invalid') X-Ref |
| Adds an error message ($message) to the ($attribute), which will be returned on a call to <tt>getErrorsOn($attribute)</tt> for the same attribute and ensure that this error object returns false when asked if <tt>hasErrors</tt>. More than one error can be added to the same $attribute in which case an array will be returned on a call to <tt>getErrorsOn($attribute)</tt>. If no $message is supplied, "invalid" is assumed. |
| addErrorOnEmpty($attribute_names, $message = 'empty') X-Ref |
| Will add an error message to each of the attributes in $attributes that is empty. |
| addErrorOnBlank($attribute_names, $message = 'blank') X-Ref |
| Will add an error message to each of the attributes in $attributes that is blank (using $this->isBlank). |
| addErrorOnBoundaryBreaking($attribute_names, $range_begin, $range_end, $too_long_message = 'too_long', $too_short_message = 'too_short') X-Ref |
| Will add an error message to each of the attributes in $attributes that has a length outside of the passed boundary $range. If the length is above the boundary, the too_long_message message will be used. If below, the too_short_message. |
| addErrorOnBoundryBreaking($attributes, $range_begin, $range_end, $too_long_message = 'too_long', $too_short_message = 'too_short') X-Ref |
| No description |
| isInvalid($attribute) X-Ref |
| Returns true if the specified $attribute has errors associated with it. |
| getErrorsOn($attribute) X-Ref |
| Returns false, if no errors are associated with the specified $attribute. Returns the error message, if one error is associated with the specified $attribute. Returns an array of error messages, if more than one error is associated with the specified $attribute. |
| yieldEachError() X-Ref |
| Yields each attribute and associated message per error added. |
| yieldError($message) X-Ref |
| No description |
| yieldEachFullError() X-Ref |
| Yields each full error message added. So Person->addError("first_name", "can't be empty") will be returned through iteration as "First name can't be empty". |
| getFullErrorMessages() X-Ref |
| Returns all the full error messages in an array. |
| hasErrors() X-Ref |
| Returns true if no errors have been added. |
| clearErrors() X-Ref |
| Removes all the errors that have been added. |
| countErrors() X-Ref |
| Returns the total number of errors added. Two errors added to the same attribute will be counted as such with this as well. |
| errorsToString($print = false) X-Ref |
| No description |
| actsAs($behaviour, $options = array() X-Ref |
| actAs provides a method for extending Active Record models. Example: $this->actsAs('list', array('scope' => 'todo_list')); |
| _getActAsClassName($behaviour) X-Ref |
| _getActAsInstance($class_name, $options) X-Ref |
| _loadActAsBehaviours() X-Ref |
| actsLike() X-Ref |
| Returns a comma separated list of possible acts like (active record, nested set, list).... |
| dbug() X-Ref |
| No description |
| toString($print = false) X-Ref |
| No description |
| dbugging($trace_this_on_debug_mode = null) X-Ref |
| No description |
| debug($data = 'active_record_class', $_functions=0) X-Ref |
| No description |
| select(&$source_array) X-Ref |
| Selects and filters a search result to include only specified columns $people_for_select = $People->select($People->find(),'name','email'); Now $people_for_select will hold an array with array ( array ('name' => 'Jose','email' => 'jose@example.com'), array ('name' => 'Alicia','email' => 'alicia@example.com'), array ('name' => 'Hilario','email' => 'hilario@example.com'), array ('name' => 'Bermi','email' => 'bermi@example.com') ); |
| collect(&$source_array, $key_index, $value_index) X-Ref |
| Collect is a function for selecting items from double depth array like the ones returned by the AkActiveRecord. This comes useful when you just need some fields for generating tables, select lists with only desired fields. $people_for_select = Ak::select($People->find(),'id','email'); Returns something like: array ( array ('10' => 'jose@example.com'), array ('15' => 'alicia@example.com'), array ('16' => 'hilario@example.com'), array ('18' => 'bermi@example.com') ); |
| toJson($options = array() X-Ref |
| Generate a json representation of the model record. parameters: param: array $options return: string in Json Format |
| _convert_column_to_xml_element($col) X-Ref |
| No description |
| _convert_column_from_xml_element($col) X-Ref |
| No description |
| _parseXmlAttributes($attributes) X-Ref |
| No description |
| _generateModelFromArray($modelName,$attributes) X-Ref |
| No description |
| _fromArray($array) X-Ref |
| No description |
| fromXml($xml) X-Ref |
| Reads Xml in the following format: <?xml version="1.0" encoding="UTF-8"?> <person> <id>1</id> <first-name>Hansi</first-name> <last-name>Müller</last-name> <email>hans@mueller.com</email> <created-at type="datetime">2008-01-01 13:01:23</created-at> </person> and returns an ActiveRecord Object param: string $xml return: AkActiveRecord |
| _fromXmlCleanup($array) X-Ref |
| No description |
| fromJson($json) X-Ref |
| Reads Json string in the following format: {"id":1,"first_name":"Hansi","last_name":"M\u00fcller", "email":"hans@mueller.com","created_at":"2008-01-01 13:01:23"} and returns an ActiveRecord Object param: string $json return: AkActiveRecord |
| toXml($options = array() X-Ref |
| Generate a xml representation of the model record. Example result: <?xml version="1.0" encoding="UTF-8"?> <person> <id>1</id> <first-name>Hansi</first-name> <last-name>Müller</last-name> <email>hans@mueller.com</email> <created-at type="datetime">2008-01-01 13:01:23</created-at> </person> parameters: param: array $options return: string in Xml Format |
| toYaml($data = null) X-Ref |
| converts to yaml-strings examples: User::toYaml($users->find('all')); $Bermi->toYaml(); param: array of ActiveRecords[optional] $data |
| parseAkelosArgs(&$args) X-Ref |
| Parses an special formated array as a list of keys and values This function generates an array with values and keys from an array with numeric keys. This allows to parse an array to a function in the following manner. create('first_name->', 'Bermi', 'last_name->', 'Ferrer'); //Previous code will be the same that create(array('first_name'=>'Bermi', 'last_name'=> 'Ferrer')); Use this syntax only for quick testings, not for production environments. If the number of arguments varies, the result might be unpredictable. This function syntax is disabled by default. You need to define('AK_ENABLE_AKELOS_ARGS', true) if you need this functionality. |
| getArrayFromAkString($string) X-Ref |
| Gets an array from a string. Acts like Php explode() function but uses any of this as valid separators ' AND ',' and ',' + ',' ',',',';' |
| getAttributeCondition($argument) X-Ref |
| No description |
| count() X-Ref |
| Count operates using three different approaches. * Count all: By not passing any parameters to count, it will return a count of all the rows for the model. * Count by conditions or joins * Count using options will find the row count matched by the options used. The last approach, count using options, accepts an option hash as the only parameter. The options are: * <tt>'conditions'</tt>: An SQL fragment like "administrator = 1" or array("user_name = ?", $username ). See conditions in the intro. * <tt>'joins'</tt>: An SQL fragment for additional joins like "LEFT JOIN comments ON comments.post_id = id". (Rarely needed). * <tt>'order'</tt>: An SQL fragment like "created_at DESC, name" (really only used with GROUP BY calculations). * <tt>'group'</tt>: An attribute name by which the result should be grouped. Uses the GROUP BY SQL-clause. * <tt>'select'</tt>: By default, this is * as in SELECT * FROM, but can be changed if you for example want to do a join. * <tt>'distinct'</tt>: Set this to true to make this a distinct calculation, such as SELECT COUNT(DISTINCT posts.id) ... Examples for counting all: $Person->count(); // returns the total count of all people Examples for count by +conditions+ and +joins+ (this has been deprecated): $Person->count("age > 26"); // returns the number of people older than 26 $Person->find("age > 26 AND job.salary > 60000", "LEFT JOIN jobs on jobs.person_id = ".$Person->id); // returns the total number of rows matching the conditions and joins fetched by SELECT COUNT(*). Examples for count with options: $Person->count('conditions' => "age > 26"); $Person->count('conditions' => "age > 26 AND job.salary > 60000", 'joins' => "LEFT JOIN jobs on jobs.person_id = $Person->id"); // finds the number of rows matching the conditions and joins. $Person->count('id', 'conditions' => "age > 26"); // Performs a COUNT(id) $Person->count('all', 'conditions' => "age > 26"); // Performs a COUNT(*) ('all' is an alias for '*') Note: $Person->count('all') will not work because it will use 'all' as the condition. Use $Person->count() instead. |
| average($column_name, $options = array() X-Ref |
| Calculates average value on a given column. The value is returned as a float. See #calculate for examples with options. $Person->average('age'); |
| minimum($column_name, $options = array() X-Ref |
| Calculates the minimum value on a given column. The value is returned with the same data type of the column.. See #calculate for examples with options. $Person->minimum('age'); |
| maximum($column_name, $options = array() X-Ref |
| Calculates the maximum value on a given column. The value is returned with the same data type of the column.. See #calculate for examples with options. $Person->maximum('age'); |
| sum($column_name, $options = array() X-Ref |
| Calculates the sum value on a given column. The value is returned with the same data type of the column.. See #calculate for examples with options. $Person->sum('age'); |
| calculate($operation, $column_name, $options = array() X-Ref |
| This calculates aggregate values in the given column: Methods for count, sum, average, minimum, and maximum have been added as shortcuts. Options such as 'conditions', 'order', 'group', 'having', and 'joins' can be passed to customize the query. There are two basic forms of output: * Single aggregate value: The single value is type cast to integer for COUNT, float for AVG, and the given column's type for everything else. * Grouped values: This returns an ordered hash of the values and groups them by the 'group' option. It takes a column name. $values = $Person->maximum('age', array('group' => 'last_name')); echo $values["Drake"] => 43 Options: * <tt>'conditions'</tt>: An SQL fragment like "administrator = 1" or array( "user_name = ?", username ). See conditions in the intro. * <tt>'joins'</tt>: An SQL fragment for additional joins like "LEFT JOIN comments ON comments.post_id = id". (Rarely needed). The records will be returned read-only since they will have attributes that do not correspond to the table's columns. * <tt>'order'</tt>: An SQL fragment like "created_at DESC, name" (really only used with GROUP BY calculations). * <tt>'group'</tt>: An attribute name by which the result should be grouped. Uses the GROUP BY SQL-clause. * <tt>'select'</tt>: By default, this is * as in SELECT * FROM, but can be changed if you for example want to do a join. * <tt>'distinct'</tt>: Set this to true to make this a distinct calculation, such as SELECT COUNT(DISTINCT posts.id) ... Examples: $Person->calculate('count', 'all'); // The same as $Person->count(); $Person->average('age'); // SELECT AVG(age) FROM people... $Person->minimum('age', array('conditions' => array('last_name != ?', 'Drake'))); // Selects the minimum age for everyone with a last name other than 'Drake' $Person->minimum('age', array('having' => 'min(age) > 17', 'group' => 'last'_name)); // Selects the minimum age for any family without any minors |
| _constructCountOptionsFromLegacyArgs($args) X-Ref |
| _constructCalculationSql($operation, $column_name, $options) X-Ref |
| _executeSimpleCalculation($operation, $column_name, $column, $options) X-Ref |
| _executeGroupedCalculation($operation, $column_name, $column, $options) X-Ref |
| _validateCalculationOptions($options = array() X-Ref |
| _getColumnAliasFor() X-Ref |
| Converts a given key to the value that the database adapter returns as as a usable column name. users.id #=> users_id sum(id) #=> sum_id count(distinct users.id) #=> count_distinct_users_id count(*) #=> count_all |
| _getColumnFor($field) X-Ref |
| _typeCastCalculatedValue($value, $column, $operation = null) X-Ref |
| hasBeenModified() X-Ref |
| No description |
| freeze() X-Ref |
| Just freeze the attributes hash, such that associations are still accessible even on destroyed records. |
| isFrozen() X-Ref |
| No description |
| getType() X-Ref |
| Alias for getModelName() |
| objectCache() X-Ref |
| No description |
| _extractValueFromDefault($default) X-Ref |
| No description |
| Generated: Mon Oct 27 12:43:49 2008 | Cross-referenced by PHPXref 0.6 |