本文整理汇总了PHP中EMongoDocument类的典型用法代码示例。如果您正苦于以下问题:PHP EMongoDocument类的具体用法?PHP EMongoDocument怎么用?PHP EMongoDocument使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了EMongoDocument类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: current
/**
* Return the current element
* @return EMongoDocument
* @since v1.3.4
*/
public function current()
{
$document = $this->_cursor->current();
if (empty($document)) {
return $document;
}
return $this->_model->populateRecord($document);
}
示例2: getCursorAsArray
public static function getCursorAsArray(EMongoDocument $model, $fn)
{
$useCursor = $model->getUseCursor();
$model->setUseCursor(TRUE);
$result = $fn($model)->getCursor();
$model->setUseCursor($useCursor);
return $result;
}
示例3: current
/**
* Gets the active record for the current row
* @return EMongoDocument|mixed
* @throws EMongoException
*/
public function current()
{
if (!$this->run) {
if ($this->model->getDbConnection()->queryCachingCount > 0 && $this->model->getDbConnection()->queryCachingDuration > 0 && $this->model->getDbConnection()->queryCacheID !== false && ($cache = Yii::app()->getComponent($this->model->getDbConnection()->queryCacheID)) !== null) {
$this->model->getDbConnection()->queryCachingCount--;
$info = $this->cursor()->info();
$cacheKey = 'yii:dbquery' . $this->model->getDbConnection()->server . ':' . $this->model->getDbConnection()->db . ':' . $this->model->getDbConnection()->getSerialisedQuery(is_array($info['query']) && isset($info['query']['$query']) ? $info['query']['$query'] : array(), $info['fields'], is_array($info['query']) && isset($info['query']['$orderby']) ? $info['query']['$orderby'] : array(), $info['skip'], $info['limit']) . ':' . $this->model->getCollection();
if (($result = $cache->get($cacheKey)) !== false) {
Yii::trace('Query result found in cache', 'extensions.MongoYii.EMongoDocument');
$this->cachedArray = $result;
$this->fromCache = true;
} else {
$this->cachedArray = iterator_to_array($this->cursor);
}
}
if (isset($cache, $cacheKey)) {
$cache->set($cacheKey, $this->cachedArray, $this->model->getDbConnection()->queryCachingDuration, $this->model->getDbConnection()->queryCachingDependency);
$this->fromCache = true;
}
$this->run = true;
}
if ($this->model === null) {
throw new EMongoException(Yii::t('yii', 'The MongoCursor must have a model'));
}
if ($this->fromCache) {
return $this->current = $this->model->populateRecord(current($this->cachedArray), true, $this->partial);
}
return $this->current = $this->model->populateRecord($this->cursor()->current(), true, $this->partial);
}
示例4: current
/**
* Gets the active record for the current row
* @return EMongoDocument|mixed
* @throws EMongoException
*/
public function current()
{
if ($this->model === null) {
throw new EMongoException(Yii::t('yii', 'The MongoCursor must have a model'));
}
return $this->current = $this->model->populateRecord($this->cursor()->current(), true, $this->partial);
}
示例5: __construct
/**
* Constructor.
* @param mixed $modelClass the model class (e.g. 'Post') or the model finder instance
* (e.g. <code>Post::model()</code>, <code>Post::model()->published()</code>).
* @param array $config configuration (name=>value) to be applied as the initial property values of this class.
* @since v1.0
*/
public function __construct($modelClass, $config = array())
{
if (is_string($modelClass)) {
$this->modelClass = $modelClass;
$this->model = EMongoDocument::model($modelClass);
} else {
if ($modelClass instanceof EMongoDocument) {
$this->modelClass = get_class($modelClass);
$this->model = $modelClass;
} else {
throw new EMongoException('Invalid model type for ' . __CLASS__);
}
}
$this->_criteria = $this->model->getDbCriteria();
if (isset($config['criteria'])) {
$this->_criteria->mergeWith($config['criteria']);
unset($config['criteria']);
}
$this->setId($this->modelClass);
foreach ($config as $key => $value) {
$this->{$key} = $value;
}
if ($this->keyField !== null && is_array($this->keyField)) {
throw new EMongoException('This DataProvider cannot handle multi-field primary key.');
} else {
$this->keyField = '_id';
}
}
示例6: current
/**
* Gets the active record for the current row
* @return EMongoDocument|mixed
* @throws EMongoException
*/
public function current()
{
if ($this->model === null) {
return $this->current = $this->cursor->current();
} else {
return $this->current = $this->model->populateRecord($this->cursor->current(), true, $this->partial);
}
}
示例7: __construct
/**
* Creates the EMongoDataProvider instance
* @param string|EMongoDocument $modelClass
* @param array $config
*/
public function __construct($modelClass, $config = array())
{
if (is_string($modelClass)) {
$this->modelClass = $modelClass;
$this->model = EMongoDocument::model($this->modelClass);
} elseif ($modelClass instanceof EMongoDocument) {
$this->modelClass = get_class($modelClass);
$this->model = $modelClass;
}
$this->setId($this->modelClass);
foreach ($config as $key => $value) {
$this->{$key} = $value;
}
}
示例8: validateAttribute
/**
* Validates the attribute of the object.
* If there is any error, the error message is added to the object.
* @param CModel $object the object being validated
* @param string $attribute the attribute being validated
*/
protected function validateAttribute($object, $attribute)
{
$value = $object->{$attribute};
if ($this->allowEmpty && $this->isEmpty($value)) {
return;
}
$className = $this->className === null ? get_class($object) : Yii::import($this->className);
$attributeName = $this->attributeName === null ? $attribute : $this->attributeName;
$finder = EMongoDocument::model($className);
$criteria = array($attributeName => $this->mongoId ? new MongoId($value) : $value);
if (!$finder->exists($criteria)) {
$message = $this->message !== null ? $this->message : Yii::t('yii', '{attribute} "{value}" is invalid.');
$this->addError($object, $attribute, $message, array('{value}' => CHtml::encode($value)));
}
}
示例9: resolveLabel
/**
* @see CSort::resolveLabel()
* @param string $attribute
* @return string
*/
public function resolveLabel($attribute)
{
$definition = $this->resolveAttribute($attribute);
if (is_array($definition)) {
if (isset($definition['label'])) {
return $definition['label'];
}
} elseif (is_string($definition)) {
$attribute = $definition;
}
if ($this->modelClass !== null) {
return EMongoDocument::model($this->modelClass)->getAttributeLabel($attribute);
}
return $attribute;
}
示例10: validateAttribute
/**
* Validates the attribute of the object.
* If there is any error, the error message is added to the object.
* @param CModel $object the object being validated
* @param string $attribute the attribute being validated
*/
protected function validateAttribute($object, $attribute)
{
$value = $object->{$attribute};
if ($this->allowEmpty && $this->isEmpty($value)) {
return;
}
$className = $this->className === null ? get_class($object) : Yii::import($this->className);
$attributeName = $this->attributeName === null ? $attribute : $this->attributeName;
// We get a RAW document here to prevent the need to make yet another active record instance
$doc = EMongoDocument::model($className)->getCollection()->findOne(array_merge($this->criteria, [$attributeName => $this->caseSensitive ? $value : ['$regex' => $value, '$options' => 'i']]));
// If a doc was fund and it isn't this doc, as decided by the primnary key
if ($doc && (string) $doc[$object->primaryKey()] != (string) $object->getPrimaryKey()) {
// Then it ain't unique
$message = $this->message !== null ? $this->message : Yii::t('yii', '{attribute} "{value}" has already been taken.');
$this->addError($object, $attribute, $message, ['{value}' => CHtml::encode($value)]);
} else {
}
}
示例11: validateAttribute
/**
* Validates the attribute of the object.
* If there is any error, the error message is added to the object.
* @param CModel $object the object being validated
* @param string $attribute the attribute being validated
*/
protected function validateAttribute($object, $attribute)
{
$value = $object->{$attribute};
if ($this->allowEmpty && $this->isEmpty($value)) {
return;
}
$className = $this->className === null ? get_class($object) : Yii::import($this->className);
$attributeName = $this->attributeName === null ? $attribute : $this->attributeName;
// We get a RAW document here to prevent the need to make yet another active record instance
$doc = EMongoDocument::model($className)->getCollection()->findOne(array_merge($this->criteria, array($attributeName => $this->caseSensitive ? $value : new MongoRegex('/' . $value . '/i'))));
// If a doc was found first test if the unique attribute is the primaryKey
// If we are uniquely id'ing the pk then check this is a new record and not
// an old one and check to see if the pks are the same
// If the found doc is not evaledd onm pk then make sure the two pks are not the same
if ($doc && ($attributeName === $object->primaryKey() && $object->getIsNewRecord() && (string) $doc[$object->primaryKey()] == (string) $object->getPrimaryKey() || (string) $doc[$object->primaryKey()] != (string) $object->getPrimaryKey())) {
// Then it ain't unique
$message = $this->message !== null ? $this->message : Yii::t('yii', '{attribute} "{value}" has already been taken.');
$this->addError($object, $attribute, $message, array('{value}' => CHtml::encode($value)));
} else {
}
}
示例12: validateAttribute
/**
* Validates the attribute of the object.
* If there is any error, the error message is added to the object.
* @param CModel $object the object being validated
* @param string $attribute the attribute being validated
*/
protected function validateAttribute($object, $attribute)
{
$value = $object->{$attribute};
if ($this->allowEmpty && $this->isEmpty($value)) {
return;
}
$className = $this->className === null ? get_class($object) : Yii::import($this->className);
$attributeName = $this->attributeName === null ? $attribute : $this->attributeName;
$finder = EMongoDocument::model($className);
$criteria = new EMongoCriteria();
$criteria->{$attribute} = $value;
if ($this->criteria !== array()) {
$criteria->mergeWith($this->criteria);
}
if (!$object instanceof EMongoDocument || $object->isNewRecord) {
$exists = $finder->exists($criteria);
} else {
$criteria->limit = 2;
$objects = $finder->findAll($criteria);
$n = count($objects);
if ($n === 1) {
if ($column->isPrimaryKey) {
// primary key is modified and not unique
$exists = $object->getOldPrimaryKey() != $object->getPrimaryKey();
} else {
// non-primary key, need to exclude the current record based on PK
$exists = $objects[0]->getPrimaryKey() != $object->getOldPrimaryKey();
}
} else {
$exists = $n > 1;
}
}
if ($exists) {
$message = $this->message !== null ? $this->message : Yii::t('yii', '{attribute} "{value}" has already been taken.');
$this->addError($object, $attribute, $message, array('{value}' => $value));
}
}
示例13: getRecord
/**
* Returns the specified EMongoDocument instance in the fixture data.
* @param string $name the fixture name
* @param string $alias the alias for the fixture data document
* @return EMongoDocument the MongoDocument instance. False is returned
* if there is no such fixture document.
*/
public function getRecord($name, $alias)
{
if (isset($this->_records[$name][$alias])) {
if (is_string($this->_records[$name][$alias])) {
$row = $this->_rows[$name][$alias];
$model = EMongoDocument::model($this->_records[$name][$alias]);
$pk = $row['_id'];
$this->_records[$name][$alias] = $model->findByPk($pk);
}
return $this->_records[$name][$alias];
} else {
return false;
}
}
示例14: offsetExists
/**
* Returns whether there is an element at the specified offset.
* This method is required by the interface ArrayAccess.
* @param mixed $offset the offset to check on
* @return boolean
*/
public function offsetExists($offset)
{
if (!isset($this->_array)) {
foreach ($this->_cursor as $document) {
$this->offsetSet(null, $this->_model->populateRecord($document));
}
}
if (isset($this->_array[$offset])) {
return true;
} else {
return false;
}
}
示例15: beforeSave
protected function beforeSave()
{
if (parent::beforeSave()) {
if ($this->isNewRecord) {
$this->id = $this->getAutoIncreaseId(false);
}
if (isset($this['last_uid'])) {
$this->last_uid = Yii::app()->user->id;
//添加操作者
}
if (isset($this['update_time'])) {
$this->update_time = time();
}
return true;
} else {
return false;
}
}