/** * Собирает и отправляет запрос * Вызывать после чейнинга методов выборки, группировки и тд * @return array */ public function aggregate() { $result = $this->model->getCollection()->aggregate($this->aggregationPipeline); $this->aggregationPipeline = []; if (isset($result['result']) && isset($result['result'])) { return $result['result']; } return $result; }
public function __construct() { parent::__construct(); $this->_collection = 'cl_yl_widget_record_' . date("Ymd"); }
public function __construct() { parent::__construct(); $this->_collection = 'cl_yl_albums_record_' . date('Ymd'); }
/** * Given active record class name returns new model instance. * * @param string $className active record class name. * @return MongoRecord active record model instance. * * @since 1.1.14 */ protected function getModel($className) { return MongoRecord::model($className); }
public function __construct() { parent::__construct(); $this->_collection = 'cl_yl_apply_record'; }
/** * Связи по ObjectId соединяются только через строки! * * @param string $name * @return MongoRecord|MongoRecord[]|bool * @throws \CDbException */ public function getRelated($name) { $params = null; foreach ($this->relations() as $relationName => $relation) { if ($name === $relationName) { $params = $relation; break; } } if ($params === null) { return null; } list($relationType, $relationCollection, $foreignKey) = $params; $criteria = new MongoDbCriteria(); $modelObject = MongoRecord::model($relationCollection); $result = null; switch ($relationType) { case self::BELONGS_TO: if (!isset($this->{$foreignKey})) { throw new CDbException("Неправильно задана связь {$name} c ключем: {$foreignKey}=>_id"); } $criteria->addCondition('_id', '=', (string) $this->{$foreignKey}); $criteria->setLimit(1); $result = $modelObject->find($criteria, false); break; case self::HAS_ONE: if (!property_exists($modelObject, $foreignKey)) { throw new CDbException("Неправильно задана связь {$name} c ключем: _id=>{$foreignKey}"); } $criteria->addCondition($foreignKey, '=', (string) $this->id); $criteria->setLimit(1); $result = $modelObject->find($criteria, false); break; case self::HAS_MANY: if (!property_exists($modelObject, $foreignKey)) { throw new CDbException("Неправильно задана связь {$name} c ключем: _id=>{$foreignKey}"); } $criteria->addCondition($foreignKey, '=', $this->id); $result = $modelObject->findAll($criteria); break; case self::HAS_RELATION_WITH: $cursor = $modelObject->getCollection()->find([$foreignKey => (string) $this->id], [$foreignKey]); $cursor->limit(1); $result = $cursor->count() === 1; break; default: throw new CDbException("Wrong relation type for relation: {$name}"); } $this->relations[$name] = $result; return $result; }
public function __construct() { parent::__construct(); $this->_collection = 'cl_yl_setting_record'; //'cl_yl_setting_record_'.date('Ymd'); }
public function validate(MongoRecord $model) { $modelFields = $model->attributeNames(); $modelClass = get_class($model); $sortFields = $this->getOrder(); $selectFields = $this->getSelect(); if (is_array($sortFields)) { foreach ($sortFields as $name => $arrow) { if (!in_array($name, $modelFields)) { throw new CDbException("Bad sorting criteria. Field \"{$name}\" does not exists in model {$modelClass}"); } } } foreach ($selectFields as $name => $arrow) { if (!in_array($name, $modelFields)) { throw new CDbException("Bad select criteria. Field \"{$name}\" does not exists in model {$modelClass}"); } } }