PHP Class EMongoDocument, MongoYii

The active record itself
Inheritance: extends EMongoModel
Afficher le fichier Open project: sammaye/mongoyii Class Usage Examples

Méthodes publiques

Méthode Description
__call ( string $name, array $parameters ) : EMongoDocument | mixed This, in addition to EMongoModels edition, will also call scopes on the model
__construct ( string $scenario = 'insert' ) Sets up our model and set the field cache just like in EMongoModel
aggregate ( array $pipeline ) : mixed This is an aggregate helper on the model Note: This does not return the model but instead the result array directly from MongoDB.
cache ( integer $duration, CCacheDependency | ICacheDependency $dependency = null, integer $queryCount = 1 ) : EMongoDocument Sets the parameters for query caching.
collectionName ( ) : string Returns the collection name as a string
count ( EMongoCriteria | array $criteria = [] ) : integer Count() allows you to count all the documents returned by a certain condition, it is analogous to $db->collection->find()->count() and basically does exactly that.
defaultScope ( ) : array Sets the default scope
delete ( ) : boolean Deletes this record
deleteAll ( array | EMongoCriteria $criteria = [], array $options = [] ) : mixed Delete all records matching a criteria
deleteByPk ( string | MongoId $pk, array | EMongoCriteria $criteria = [], array $options = [] ) : mixed Delete record by pk
distinct ( string $key, array $query = [] ) : mixed A distinct helper on the model, this is not the same as the aggregation framework distinct
ensureIndexes ( unknown $indexes ) Allows a user to ensure a number of indexes using the format:
equals ( EMongoDocument $record ) : boolean Compares current active record with another one.
exists ( array $criteria = [] ) : boolean Checks if a record exists in the database
find ( array | EMongoCriteria $criteria = [], array | string[] $fields = [] ) : EMongoCursor | EMongoDocument[] Find some records
findAll ( array $criteria = [], array | string[] $fields = [] ) : EMongoCursor | EMongoDocument[] Alias of find
findAllByAttributes ( array $criteria = [], array | string[] $fields = [] ) : EMongoCursor | EMongoDocument[] Alias of find
findAllByPk ( mixed $pk, array | string[] $fields = [] ) : EMongoCursor | EMongoDocument[] Finds all records based on $pk
findAndModify ( $criteria = [], $updateDoc = [], $fields = [], $options = [] ) : null | EMongoDocument Find one record, modifies, and returns it.
findByPk ( string | MongoId $pk, array | string[] $fields = [] ) : EMongoDocument | null An alias for findBy_id() that relates to Yiis own findByPk
findBy_id ( string | MongoId $_id, array | string[] $fields = [] ) : EMongoDocument | null Finds one by _id
findOne ( array | EMongoCriteria $criteria = [], array | string[] $fields = [] ) : EMongoDocument | null Find one record
getAttributeLabel ( string $attribute ) : string Returns the text label for the specified attribute.
getCollection ( ) : MongoCollection Gets the collection for this model
getDbCriteria ( boolean $createIfNull = true ) : array gets and if null sets the db criteria for this model
getIsNewRecord ( ) : boolean Returns if the current record is new.
getLastError ( ) : array A bit deceptive, this actually gets the last response from either save() or update(). The reason it is called this is because MongoDB calls it this and so it seems better to have unity on that front.
getLatest ( ) : null | EMongoDocument Is basically a find one of the last version to be saved
getMongoId ( string | MongoId $value = null ) : MongoId Returns MongoId based on $value
getPrimaryKey ( string | MongoId $value = null ) : MongoId Returns the value of the primary key
getProjectedFields ( ) : array | string[] Gets a list of the projected fields for the model
incrementVersion ( ) : boolean Forceably increments the version of this document
insert ( array $attributes = null ) : boolean Inserts this record
mapreduce ( MongoCode $map, MongoCode $reduce, MongoCode $finalize = null, array $out = [], array $query = [], array $options = [] ) : mixed A mapreduce helper for this model
mergeCriteria ( array $oldCriteria, array $newCriteria ) : array Merges two criteria objects. Best used for scopes
mergeDbCriteria ( array | EMongoCriteria $newCriteria ) : array Merges the current DB Criteria with the inputted one
model ( string $className = __CLASS__ ) : EMongoDocument Returns the static model of the specified AR class.
onAfterDelete ( CEvent $event )
onAfterFind ( CEvent $event )
onAfterSave ( CEvent $event )
onBeforeDelete ( CEvent $event )
onBeforeFind ( CEvent $event )
onBeforeSave ( CEvent $event )
populateRecord ( array $attributes, boolean $callAfterFind = true, boolean $partial = false ) : EMongoDocument | null Creates an active record with the given attributes.
populateRecords ( array $data, boolean $callAfterFind = true, string $index = null ) : array Returns an array of records populated by incoming data
refresh ( ) : boolean Refreshes the data from the database
resetScope ( boolean $resetDefault = true ) : EMongoDocument Resets the scopes applied to the model clearing the _criteria variable
save ( boolean $runValidation = true, array $attributes = null ) : boolean Saves this record
saveAttributes ( array $attributes ) : boolean Saves only a specific subset of attributes as defined by the param
saveCounters ( array $counters, null $lower = null, null $upper = null ) : boolean
scopes ( ) : array The scope attached to this model
search ( array $query = [], array $project = [], boolean $partialMatch = false, array $sort = [] ) : EMongoDataProvider Gives basic searching abilities for things like CGridView
setAttribute ( string $name, mixed $value ) : boolean Sets the attribute of the model
setDbCriteria ( array $criteria ) : array Sets the db criteria for this model
setIsNewRecord ( boolean $value ) Sets if the record is new.
setProjectedFields ( array $fields ) Sets the projected fields of the model
setVersion ( mixed $n ) : boolean Forceably sets the version of this document
trace ( string $func ) Produces a trace message for functions in this class
update ( array $attributes = null ) : boolean Updates this record
updateAll ( array | EMongoCriteria $criteria = [], array $updateDoc = [], array $options = ['multiple' => true] ) : boolean Update all records matching a criteria
updateByPk ( string | MongoId $pk, array $updateDoc = [], array | EMongoCriteria $criteria = [], array $options = [] ) : boolean Update record by PK
version ( ) : string Gets the version of this document
versionField ( ) : string Denotes the field tob e used to house the version number
versioned ( ) : boolean Denotes whether or not this document is versioned

Méthodes protégées

Méthode Description
afterDelete ( )
afterFind ( )
afterSave ( )
beforeDelete ( ) : boolean
beforeFind ( )
beforeSave ( ) : boolean
instantiate ( array $document ) : EMongoDocument Instantiates a model from an array

Method Details

__call() public méthode

This, in addition to EMongoModels edition, will also call scopes on the model
See also: EMongoModel::__call()
public __call ( string $name, array $parameters ) : EMongoDocument | mixed
$name string
$parameters array
Résultat EMongoDocument | mixed

__construct() public méthode

It will also set the default scope on the model so be aware that if you want the default scope to not be applied you will need to run resetScope() straight after making this model
public __construct ( string $scenario = 'insert' )
$scenario string

afterDelete() protected méthode

protected afterDelete ( )

afterFind() protected méthode

protected afterFind ( )

afterSave() protected méthode

protected afterSave ( )

aggregate() public méthode

This is an aggregate helper on the model Note: This does not return the model but instead the result array directly from MongoDB.
public aggregate ( array $pipeline ) : mixed
$pipeline array
Résultat mixed

beforeDelete() protected méthode

protected beforeDelete ( ) : boolean
Résultat boolean

beforeFind() protected méthode

protected beforeFind ( )

beforeSave() protected méthode

protected beforeSave ( ) : boolean
Résultat boolean

cache() public méthode

This is a shortcut method to {@link CDbConnection::cache()}. It changes the query caching parameter of the {@link dbConnection} instance.
public cache ( integer $duration, CCacheDependency | ICacheDependency $dependency = null, integer $queryCount = 1 ) : EMongoDocument
$duration integer the number of seconds that query results may remain valid in cache. If this is 0, the caching will be disabled.
$dependency CCacheDependency | ICacheDependency the dependency that will be used when saving the query results into cache.
$queryCount integer number of MongoDB queries that need to be cached after calling this method. Defaults to 1, meaning that the next MongoDB query will be cached.
Résultat EMongoDocument the active record instance itself.

collectionName() public méthode

Returns the collection name as a string
public collectionName ( ) : string
Résultat string

count() public méthode

..
public count ( EMongoCriteria | array $criteria = [] ) : integer
$criteria EMongoCriteria | array
Résultat integer

defaultScope() public méthode

Sets the default scope
public defaultScope ( ) : array
Résultat array - An array which represents a single scope within the scope() function

delete() public méthode

Deletes this record
public delete ( ) : boolean
Résultat boolean

deleteAll() public méthode

Delete all records matching a criteria
public deleteAll ( array | EMongoCriteria $criteria = [], array $options = [] ) : mixed
$criteria array | EMongoCriteria
$options array
Résultat mixed

deleteByPk() public méthode

Delete record by pk
public deleteByPk ( string | MongoId $pk, array | EMongoCriteria $criteria = [], array $options = [] ) : mixed
$pk string | MongoId
$criteria array | EMongoCriteria
$options array
Résultat mixed

distinct() public méthode

A distinct helper on the model, this is not the same as the aggregation framework distinct
public distinct ( string $key, array $query = [] ) : mixed
$key string
$query array
Résultat mixed

ensureIndexes() public méthode

ensureIndexes(array( array(array('email' => 1), array('unique' => true)) )) where the 0 offset in each nested array is the fields for the index and the 1 offset is the options. You don't have to define options for the index. or: ensureIndexes(array( array('email' => 1, 'address' => -1) ))
public ensureIndexes ( unknown $indexes )
$indexes unknown

equals() public méthode

The comparison is made by comparing table name and the primary key values of the two active records.
public equals ( EMongoDocument $record ) : boolean
$record EMongoDocument - record to compare to
Résultat boolean - whether the two active records refer to the same row in the database table.

exists() public méthode

Checks if a record exists in the database
public exists ( array $criteria = [] ) : boolean
$criteria array
Résultat boolean

find() public méthode

Find some records
public find ( array | EMongoCriteria $criteria = [], array | string[] $fields = [] ) : EMongoCursor | EMongoDocument[]
$criteria array | EMongoCriteria
$fields array | string[]
Résultat EMongoCursor | EMongoDocument[]

findAll() public méthode

Alias of find
public findAll ( array $criteria = [], array | string[] $fields = [] ) : EMongoCursor | EMongoDocument[]
$criteria array
$fields array | string[]
Résultat EMongoCursor | EMongoDocument[]

findAllByAttributes() public méthode

Alias of find
public findAllByAttributes ( array $criteria = [], array | string[] $fields = [] ) : EMongoCursor | EMongoDocument[]
$criteria array
$fields array | string[]
Résultat EMongoCursor | EMongoDocument[]

findAllByPk() public méthode

Finds all records based on $pk
public findAllByPk ( mixed $pk, array | string[] $fields = [] ) : EMongoCursor | EMongoDocument[]
$pk mixed - String, MongoID or array of strings or MongoID values (one can mix strings and MongoID in the array)
$fields array | string[]
Résultat EMongoCursor | EMongoDocument[]

findAndModify() public méthode

Find one record, modifies, and returns it.
public findAndModify ( $criteria = [], $updateDoc = [], $fields = [], $options = [] ) : null | EMongoDocument
Résultat null | EMongoDocument

findByPk() public méthode

An alias for findBy_id() that relates to Yiis own findByPk
public findByPk ( string | MongoId $pk, array | string[] $fields = [] ) : EMongoDocument | null
$pk string | MongoId
$fields array | string[]
Résultat EMongoDocument | null

findBy_id() public méthode

Finds one by _id
public findBy_id ( string | MongoId $_id, array | string[] $fields = [] ) : EMongoDocument | null
$_id string | MongoId
$fields array | string[]
Résultat EMongoDocument | null

findOne() public méthode

Find one record
public findOne ( array | EMongoCriteria $criteria = [], array | string[] $fields = [] ) : EMongoDocument | null
$criteria array | EMongoCriteria
$fields array | string[]
Résultat EMongoDocument | null

getAttributeLabel() public méthode

This method overrides the parent implementation by supporting returning the label defined in relational object. In particular, if the attribute name is in the form of "post.author.name", then this method will derive the label from the "author" relation's "name" attribute.
See also: CModel::generateAttributeLabel()
public getAttributeLabel ( string $attribute ) : string
$attribute string - the attribute name
Résultat string - the attribute label

getCollection() public méthode

Gets the collection for this model
public getCollection ( ) : MongoCollection
Résultat MongoCollection

getDbCriteria() public méthode

gets and if null sets the db criteria for this model
public getDbCriteria ( boolean $createIfNull = true ) : array
$createIfNull boolean
Résultat array

getIsNewRecord() public méthode

Whether the record is new and should be inserted when calling {@link save}. This property is automatically set in constructor and {@link populateRecord}. Defaults to false, but it will be set to true if the instance is created using the new operator.
public getIsNewRecord ( ) : boolean
Résultat boolean

getLastError() public méthode

A bit deceptive, this actually gets the last response from either save() or update(). The reason it is called this is because MongoDB calls it this and so it seems better to have unity on that front.
public getLastError ( ) : array
Résultat array

getLatest() public méthode

Is basically a find one of the last version to be saved
public getLatest ( ) : null | EMongoDocument
Résultat null | EMongoDocument

getMongoId() public méthode

Returns MongoId based on $value
Deprecation: This function will become deprecated in favour of consistently using the getPrimaryKey() function instead. Atm, however, the getPrimaryKey function actually chains onto this method. If you see this and are wondering about what you should do if you want custom primary keys etc just use the getPrimaryKey function as you would the getMongoId function. These two functions should never have been separate for they are the same essentially. As to what version this will become deprecated:- I dunno. It will not be soon since it will be a functionality breaker...
public getMongoId ( string | MongoId $value = null ) : MongoId
$value string | MongoId
Résultat MongoId

getPrimaryKey() public méthode

Returns the value of the primary key
public getPrimaryKey ( string | MongoId $value = null ) : MongoId
$value string | MongoId
Résultat MongoId

getProjectedFields() public méthode

Gets a list of the projected fields for the model
public getProjectedFields ( ) : array | string[]
Résultat array | string[]

incrementVersion() public méthode

Forceably increments the version of this document
public incrementVersion ( ) : boolean
Résultat boolean

insert() public méthode

Inserts this record
public insert ( array $attributes = null ) : boolean
$attributes array
Résultat boolean

instantiate() protected méthode

Instantiates a model from an array
protected instantiate ( array $document ) : EMongoDocument
$document array
Résultat EMongoDocument

mapreduce() public méthode

A mapreduce helper for this model
public mapreduce ( MongoCode $map, MongoCode $reduce, MongoCode $finalize = null, array $out = [], array $query = [], array $options = [] ) : mixed
$map MongoCode
$reduce MongoCode
$finalize MongoCode
$out array
$query array
$options array // All other options for input to the command
Résultat mixed

mergeCriteria() public méthode

Merges two criteria objects. Best used for scopes
public mergeCriteria ( array $oldCriteria, array $newCriteria ) : array
$oldCriteria array
$newCriteria array
Résultat array

mergeDbCriteria() public méthode

Merges the current DB Criteria with the inputted one
public mergeDbCriteria ( array | EMongoCriteria $newCriteria ) : array
$newCriteria array | EMongoCriteria
Résultat array

model() public static méthode

The model returned is a static instance of the AR class. It is provided for invoking class-level methods (something similar to static class methods.) EVERY derived AR class must override this method as follows,
public static function model($className=__CLASS__)
{
    return parent::model($className);
}
public static model ( string $className = __CLASS__ ) : EMongoDocument
$className string
Résultat EMongoDocument

onAfterDelete() public méthode

public onAfterDelete ( CEvent $event )
$event CEvent

onAfterFind() public méthode

public onAfterFind ( CEvent $event )
$event CEvent

onAfterSave() public méthode

public onAfterSave ( CEvent $event )
$event CEvent

onBeforeDelete() public méthode

public onBeforeDelete ( CEvent $event )
$event CEvent

onBeforeFind() public méthode

public onBeforeFind ( CEvent $event )
$event CEvent

onBeforeSave() public méthode

public onBeforeSave ( CEvent $event )
$event CEvent

populateRecord() public méthode

This method is internally used by the find methods. Null is returned if the input data is false.
public populateRecord ( array $attributes, boolean $callAfterFind = true, boolean $partial = false ) : EMongoDocument | null
$attributes array - attribute values (column name=>column value)
$callAfterFind boolean whether to call {@link afterFind} after the record is populated.
$partial boolean
Résultat EMongoDocument | null - the newly created active record. The class of the object is the same as the model class.

populateRecords() public méthode

Returns an array of records populated by incoming data
public populateRecords ( array $data, boolean $callAfterFind = true, string $index = null ) : array
$data array
$callAfterFind boolean
$index string
Résultat array - Array of the records

refresh() public méthode

Refreshes the data from the database
public refresh ( ) : boolean
Résultat boolean

resetScope() public méthode

Resets the scopes applied to the model clearing the _criteria variable
public resetScope ( boolean $resetDefault = true ) : EMongoDocument
$resetDefault boolean
Résultat EMongoDocument

save() public méthode

If an attributes specification is sent in it will only validate and save those attributes
public save ( boolean $runValidation = true, array $attributes = null ) : boolean
$runValidation boolean
$attributes array
Résultat boolean

saveAttributes() public méthode

Saves only a specific subset of attributes as defined by the param
public saveAttributes ( array $attributes ) : boolean
$attributes array
Résultat boolean

saveCounters() public méthode

See also: http://www.yiiframework.com/doc/api/1.1/CActiveRecord#saveCounters-detail
public saveCounters ( array $counters, null $lower = null, null $upper = null ) : boolean
$counters array
$lower null - define a lower that the counter should not pass. IS NOT ATOMIC
$upper null
Résultat boolean

scopes() public méthode

It is very much like how Yii normally uses scopes except the params are slightly different.
public scopes ( ) : array
Résultat array

setAttribute() public méthode

Sets the attribute of the model
public setAttribute ( string $name, mixed $value ) : boolean
$name string
$value mixed
Résultat boolean

setDbCriteria() public méthode

Sets the db criteria for this model
public setDbCriteria ( array $criteria ) : array
$criteria array
Résultat array

setIsNewRecord() public méthode

Whether the record is new and should be inserted when calling {@link save}.
See also: EMongoDocument::getIsNewRecord()
public setIsNewRecord ( boolean $value )
$value boolean

setProjectedFields() public méthode

Sets the projected fields of the model
public setProjectedFields ( array $fields )
$fields array

setVersion() public méthode

Forceably sets the version of this document
public setVersion ( mixed $n ) : boolean
$n mixed
Résultat boolean

trace() public méthode

Produces a trace message for functions in this class
public trace ( string $func )
$func string

update() public méthode

Updates this record
public update ( array $attributes = null ) : boolean
$attributes array
Résultat boolean

updateAll() public méthode

Update all records matching a criteria
public updateAll ( array | EMongoCriteria $criteria = [], array $updateDoc = [], array $options = ['multiple' => true] ) : boolean
$criteria array | EMongoCriteria
$updateDoc array
$options array
Résultat boolean

updateByPk() public méthode

Update record by PK
public updateByPk ( string | MongoId $pk, array $updateDoc = [], array | EMongoCriteria $criteria = [], array $options = [] ) : boolean
$pk string | MongoId
$updateDoc array
$criteria array | EMongoCriteria
$options array
Résultat boolean

version() public méthode

Gets the version of this document
public version ( ) : string
Résultat string

versionField() public méthode

Denotes the field tob e used to house the version number
public versionField ( ) : string
Résultat string

versioned() public méthode

Denotes whether or not this document is versioned
public versioned ( ) : boolean
Résultat boolean