public function actionAdmin() { $model = new Droits('search'); $model->unsetAttributes(); if (isset($_GET['Droits'])) { $model->setAttributes($_GET['Droits']); } $criteria = new EMongoCriteria(); $criteriaClinique = new EMongoCriteria($criteria); $criteriaClinique->type = "clinique"; $criteriaClinique->profil('!=', "administrateur"); $dataProviderClinique = new EMongoDocumentDataProvider('Droits'); $dataProviderClinique->setCriteria($criteriaClinique); $criteriaNeuropath = new EMongoCriteria($criteria); $criteriaNeuropath->type = "neuropathologique"; $criteriaNeuropath->profil('!=', "administrateur"); $dataProviderNeuropath = new EMongoDocumentDataProvider('Droits'); $dataProviderNeuropath->setCriteria($criteriaNeuropath); $criteriaGene = new EMongoCriteria($criteria); $criteriaGene->type = "genetique"; $criteriaGene->profil('!=', "administrateur"); $dataProviderGene = new EMongoDocumentDataProvider('Droits'); $dataProviderGene->setCriteria($criteriaGene); $this->render('admin', array('model' => $model, 'dataProviderClinique' => $dataProviderClinique, 'dataProviderNeuropath' => $dataProviderNeuropath, 'dataProviderGene' => $dataProviderGene)); }
/** * export pdf avec mpdf et liste d'index : Technique HTML to PDF */ public function actionExportPdf() { $criteria = new EMongoCriteria(); $criteria->sort('name', EMongoCriteria::SORT_ASC); $models = Biobank::model()->findAll($criteria); BiobanksPDFExporter::exporter($models); }
public function search($caseSensitive = false) { $criteria = new EMongoCriteria(); //$criteria->conditions['id'] = $this->id; $criteria->sort('id', EMongoCriteria::SORT_DESC); return new EMongoDocumentDataProvider($this, array('criteria' => $criteria)); }
public function actionList() { $page = intval(Yii::app()->request->getParam('page', 1)) - 1; $gameId = trim(Yii::app()->request->getParam('game_id')); $cond = new EMongoCriteria(); if ($gameId != '') { $cond->compare('game_id', $gameId); } $count = SelfConsume::model()->count($cond); $pages = new EMongoPagination($count); $pages->pageSize = self::PAGE_SIZE; $pages->currentPage = $page; $pages->applyLimit($cond); $data = SelfConsume::model()->find($cond); $rows = array(); $games = CHtml::listData(BasicGame::model()->getGames(), 'game_code', 'game_name'); foreach ($data as $value) { $tmp = $value->getAttributes(); $tmp['game'] = isset($games[$tmp['game_id']]) ? $games[$tmp['game_id']] : ''; $tmp['id'] = (string) $value->getPrimaryKey(); unset($tmp['_id']); $rows[] = $tmp; } echo json_encode(array('count' => $count, 'rows' => $rows)); }
/** * 操作日志列表 * @author gentle */ public function actionIndex() { $data = array(); $attr = $this->_logObj->attributeLabels(); $criteria = new EMongoCriteria(); //其他人无法看见admin的操作记录 if (Yii::app()->user->name != 'admin') { $criteria->addCond('uname', '!=', 'admin'); } //添加查询条件 if (isset($_GET['sub'])) { $criteria = $this->fillCond($criteria, $this->_logObj->attributeLabels()); } // FunctionUTL::Debug($criteria); $count = $this->_logObj->count($criteria); $pages = new CPagination($count); $perPage = 20; $pages->pageSize = $perPage; $offset = isset($_GET['page']) ? intval($_GET['page']) : 1; $offset = ($offset - 1) * $perPage; $criteria->limit($perPage)->offset($offset)->sort('id', EMongoCriteria::SORT_DESC); $logModel = $this->_logObj->findAll($criteria); $data['logModels'] = $logModel; $data['pages'] = $pages; $data['attr'] = $attr; //模型属性 $this->render('index', $data); }
public static function getByBiobank($biobankId, $limit) { $criteria = new EMongoCriteria(); $criteria->addCond('biobank_id', '==', $biobankId); $criteria->sort('date', EMongoCriteria::SORT_DESC); $criteria->limit($limit); return BiobankStats::model()->findAll($criteria); }
public function actionGetMessageByDate() { $criteria = new EMongoCriteria(); // find the single user with the personal_number == 12345 $criteria->from('==', $_POST["message_date"]); $message_date = Message::model()->findAll($criteria); $this->render('GetMessageByDate', array('message_date' => CJSON::encode($message_date))); }
/** * @see CActiveDataProvider::setCriteria() * @param array|EMongoCriteria $value */ public function setCriteria($value) { if ($value instanceof EMongoCriteria) { $this->_criteria = $value->toArray(); } if (is_array($value)) { $this->_criteria = $value; } }
/** * @param EMongoCriteria $criteria * @param string $group * @return array */ public function findAllIds(EMongoCriteria $criteria = null, $group = '') { $id = property_exists($this, 'id') ? 'id' : '_id'; $select = [$id]; if ($group) { array_push($select, $group); } $cursor = $this->findAllAsArray($criteria->select($select)); return $group ? ArrayHelper::groupByAttribute($cursor, $group, $id) : ArrayHelper::pickAttribute($cursor, $id, false); }
/** * @param array $ids * @param null | array | EMongoCriteria $criteria * @param bool $useCursor * @return $this[] | EMongoCursor */ public function findAllByIds(array $ids, $criteria = NULL, $useCursor = TRUE) { /** @var EMongoDocument $this */ $criteria = new EMongoCriteria($criteria); $criteria->id('in', array_values(array_map('strval', $ids))); $_useCursor = $this->getUseCursor(); $this->setUseCursor($useCursor); $result = $this->findAll($criteria); $this->setUseCursor($_useCursor); return $result; }
public function getDateLastImportByBiobank($biobank_id) { $criteria = new EMongoCriteria(); $criteria->biobank_id = $biobank_id; $criteria->limit(1); $criteria->sort('date_import', EMongoCriteria::SORT_DESC); $criteria->select(array('date_import')); $result = $this->find($criteria); if ($result != null) { return $result->date_import; } }
/** * Retrieves a list of models based on the current search/filter conditions. * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions. */ public function search($caseSensitive = false) { // Warning: Please modify the following code to remove attributes that // should not be searched. $criteria = new EMongoCriteria(); if ($this->nom != null) { $criteria->addCond('nom', '==', new MongoRegex('/' . $this->nom . '*/i')); } if ($this->prenom != null) { $criteria->addCond('prenom', '==', new MongoRegex('/' . $this->name . '*/i')); } //always sort with alphabetical order $criteria->sort('nom', EMongoCriteria::SORT_ASC); return new EMongoDocumentDataProvider($this, array('criteria' => $criteria)); }
public function run($args) { //upper case for each last name of contact $criteria = new EMongoCriteria(); $criteria->sort('nom', EMongoCriteria::SORT_ASC); $users = User::model()->findAll($criteria); foreach ($users as $model) { $model->cleanAttributesFormat(); //catch exception on update if problem ( utf8 encoding for example?) try { $model->update(); } catch (Exception $e) { echo 'Exception reçue pour le model: ' . $model->_id . " " . $model->nom . " " . $model->prenom, $e->getMessage(), "\n"; } } }
/** * Authenticates a user. * The example implementation makes sure if the username and password * are both 'demo'. * In practical applications, this should be changed to authenticate * against some persistent user identity storage (e.g. database). * @return boolean whether authentication succeeds. */ public function authenticate() { $criteria = new EMongoCriteria(); $criteria->username('==', $this->username); $userInfo = Admin::model()->find($criteria); if ($userInfo == NULL) { $this->errorCode = self::ERROR_USERNAME_INVALID; return false; } if ($userInfo->password !== md5($this->password)) { $this->errorCode = self::ERROR_PASSWORD_INVALID; return false; } $this->errorCode = self::ERROR_NONE; return true; }
public function validateAttribute($object, $attribute) { $value = $object->{$attribute}; if ($this->allowEmpty && ($value === null || $value === '')) { return; } $criteria = new EMongoCriteria(); if (!$object->getIsNewRecord()) { $criteria->addCond('_id', '!=', $object->getPrimaryKey()); } $criteria->addCond($attribute, '==', $value); $count = $object->model()->count($criteria); if ($count !== 0) { $this->addError($object, $attribute, Yii::t('yii', '{attribute} is not unique in DB.')); } }
public function search($caseSensitive = false) { $criteria = new EMongoCriteria(); if (isset($this->title) && !empty($this->title)) { $regex = '/'; foreach ($this->title as $value) { $regex .= $value; if ($value != end($this->title)) { $regex .= '|'; } } $regex .= '/i'; $criteria->addCond('title', '==', new MongoRegex($regex)); } Yii::app()->session['criteria'] = $criteria; return new EMongoDocumentDataProvider($this, array('criteria' => $criteria, 'sort' => array('defaultOrder' => 'title ASC'))); }
public function run($args) { //uppar case for each last name of contact $criteria = new EMongoCriteria(); $criteria->sort('last_name', EMongoCriteria::SORT_ASC); $contacts = Contact::model()->findAll($criteria); foreach ($contacts as $model) { $town = $model->ville; $postalCode = $this->getPostalCode($town); if ($postalCode != null) { try { $model->code_postal = $postalCode; $model->update(); } catch (Exception $e) { echo 'Exception reçue pour le model: ' . $model->ville, $e->getMessage(), "\n"; } } } }
public function run($args) { //uppar case for each last name of contact $criteria = new EMongoCriteria(); $criteria->sort('last_name', EMongoCriteria::SORT_ASC); $contacts = Contact::model()->findAll($criteria); foreach ($contacts as $model) { //last name to upper case automatically /prevent pb to sort and display // echo $model->_id."\n"; $model->last_name = mb_strtoupper($model->last_name, "UTF-8"); //convertie first name en lower case et mettant les caracteres en utf-8 ( cas possible de bug sur chaines mixtes) $model->first_name = mb_strtolower($model->first_name, "UTF-8"); //phone without withespace, point a 0> +33 $model->phone = mb_ereg_replace('/\\s+/', '', $model->phone); $model->phone = mb_ereg_replace('/\\./', '', $model->phone); //replace first zero and add +33 $model->phone = mb_ereg_replace('/^0/', '+33', $model->phone); //pays = FR $model->pays = "FR"; $model->inactive = 0; //catch exception on update if problem ( utf8 encoding for example?) try { $model->update(); } catch (Exception $e) { echo 'Exception reçue pour le model: ' . $model->_id . " " . $model->last_name . " " . $model->first_name, $e->getMessage(), "\n"; //detection de le ncodage si pb d estring echo "first name encoding :" . mb_detect_encoding($model->first_name) . "\n"; } } //update relation biobank->contact_id if old id contact, si ancien attribut id utilisé alors on mets le nouvel attribut _id $criteriaB = new EMongoCriteria(); $criteriaB->sort('name', EMongoCriteria::SORT_ASC); $biobanks = Biobank::model()->findAll($criteriaB); foreach ($biobanks as $biobank) { $contact = Contact::model()->findByAttributes(array('id' => $biobank->contact_id)); if ($contact != null) { // echo "current value from migration:" . $contact->last_name . " " . $contact->first_name."\n"; $biobank->contact_id = $contact->_id; $biobank->update(); } } }
public function search($caseSensitive = false) { $criteria = new EMongoCriteria(); if (!empty($this->id)) { $criteria->id = $this->id; } if (!empty($this->name)) { $criteria->name = $this->name; } if (!empty($this->en_name)) { $criteria->en_name = $this->en_name; } if (!empty($this->request_times)) { $criteria->request_times = $this->request_times; } $criteria->sort('id', EMongoCriteria::SORT_DESC); //$criteria->last_uid = $this->last_uid; //$criteria->update_time = $this->update_time; return new EMongoDocumentDataProvider($this, array('criteria' => $criteria)); }
public function actionTables() { $page = intval(Yii::app()->request->getParam('page', 1)) - 1; $name = trim(Yii::app()->request->getParam('name')); $cond = new EMongoCriteria(); if ($name != '') { $cond->compare('name', $name, true); } $count = QuestTable::model()->count($cond); $pages = new EMongoPagination($count); $pages->pageSize = self::PAGE_SIZE; $pages->currentPage = $page; $pages->applyLimit($cond); $data = QuestTable::model()->find($cond); $rows = array(); foreach ($data as $value) { $tmp = $value->getAttributes(); $tmp['id'] = (string) $value->getPrimaryKey(); unset($tmp['_id']); $rows[] = $tmp; } echo json_encode(array('count' => $count, 'rows' => $rows)); }
/** * 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)); } }
public function findByParams(array $params) { $criteria = new EMongoCriteria(); $sortedField = isset($params['sorted_field']) ? $params['sorted_field'] : 'created_time'; if (empty($params['limit'])) { $params['limit'] = 25; } if (!empty($params['pid'])) { $criteria->addCondition('pid', $params['pid']); } if (empty($params['since'])) { $criteria->setSort([$sortedField => 'desc']); } if (!empty($params['since'])) { $criteria->addCondition($sortedField, (int) $params['since'], '$gt'); $criteria->setSort([$sortedField => 'asc']); } if (!empty($params['until'])) { $criteria->addCondition($sortedField, (int) $params['until'], '$lt'); $criteria->setSort([$sortedField => 'desc']); } $criteria->setLimit($params['limit']); return $this->find($criteria); }
/** * Fetches the data from the persistent data storage. * @return array list of data items * @since v1.0 */ protected function fetchData() { if (($pagination = $this->getPagination()) !== false) { $pagination->setItemCount($this->getTotalItemCount()); $this->_criteria->setLimit($pagination->getLimit()); $this->_criteria->setOffset($pagination->getOffset()); } /*if(($sort=$this->getSort())!==false && ($order=$sort->getOrderBy())!='') { $sort=array(); foreach($this->getSortDirections($order) as $name=>$descending) { $sort[$name]=$descending ? EMongoCriteria::SORT_DESC : EMongoCriteria::SORT_ASC; } $this->_criteria->setSort($sort); } */ if (($sort = $this->getSort()) !== false) { $sort->applyOrder($this->_criteria); } return $this->model->findAll($this->_criteria); }
/** * Retrieves a list of models based on the current search/filter conditions. * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions. */ public function search($options = array()) { $criteria = new EMongoCriteria(); if (isset($this->old_value) && !empty($this->old_value)) { $criteria->addCond('old_value', '==', new MongoRegex('/' . $this->old_value . '/i')); } if (isset($this->new_value) && !empty($this->new_value)) { $criteria->addCond('new_value', '==', new MongoRegex('/' . $this->new_value . '/i')); } if (isset($this->action) && !empty($this->action)) { $criteria->addCond('action', '==', new MongoRegex('/' . $this->action . '/i')); } if (isset($this->model) && !empty($this->model)) { $criteria->addCond('model', '==', new MongoRegex('/' . $this->model . '/i')); } if (isset($this->field) && !empty($this->field)) { $criteria->addCond('field', '==', new MongoRegex('/' . $this->field . '/i')); } if (isset($this->stamp) && !empty($this->stamp)) { $criteria->stamp = array('$gte' => $this->stamp, '$lte' => $this->stamp); } return new EMongoDocumentDataProvider($this, array('criteria' => $criteria)); }
protected static function analyzeCsv($bytes, $biobank_id, $fileImportedId, $add) { $import = fopen(CommonTools::data_uri($bytes, 'text/csv'), 'r'); $row = 1; $keysArray = array(); $listBadSamples = array(); $newSamples = array(); // $tempSaveList = new MongoInsertBatch(Sample::model()->getCollection()); $tempSaveList = array(); /** * Version 1 : Les champs non repertorés sont ajoutés en notes */ while (($data = fgetcsv($import, 1000, ",")) !== FALSE) { /* * Traitement de la ligne d'entete */ if ($row == 1) { foreach ($data as $key => $value) { if ($value != null && $value != "") { $keysArray[$key] = $value; } } } else { $model = new Sample(); $model->disableBehavior('LoggableBehavior'); $model->_id = new MongoId(); while (!$model->validate(array('_id'))) { $model->_id = new MongoId(); } $model->biobank_id = $biobank_id; $model->file_imported_id = $fileImportedId; foreach ($keysArray as $key2 => $value2) { if ($value2 != "biobank_id" && $value2 != "file_imported_id") { if (in_array($value2, Sample::model()->attributeNames())) { $model->{$value2} = $data[$key2]; if (!$model->validate(array($value2))) { // Yii::log("Problem with item" . $model->getAttributeLabel($value2) . ",set to null.\n " . implode(", ", $model->errors[$value2]), CLogger::LEVEL_ERROR); $model->{$value2} = null; } } else { $note = new Note(); $note->key = $value2; $note->value = $data[$key2]; $model->notes[] = $note->attributes; } } } if (!$model->validate()) { Yii::log("Problem with sample validation " . print_R($model->errors, true), CLogger::LEVEL_ERROR); $listBadSamples[] = $row; } else { $tempSaveList[] = $model->attributes; // $tempSaveList->add($model->attributes); $newSamples[] = $model->_id; } } $row++; if ($row != 2 && $row % 400 == 2) { Yii::log("Nb treated : " . $row, 'error'); Sample::model()->getCollection()->batchInsert($tempSaveList, array()); $tempSaveList = array(); //$tempSaveList->execute(array()); //$tempSaveList = new MongoInsertBatch(Sample::model()->getCollection()); } } Sample::model()->getCollection()->batchInsert($tempSaveList, array("w" => 1)); /* * Version 2 : seuls nes champs dont la colonne est annotée avec le préfixe 'notes' sont pris en note */ // while (($data = fgetcsv($import, 1000, ",")) !== FALSE) { // // /* // * Traitement de la ligne d'entete // */ // // // // if ($row == 1) { // foreach ($data as $key => $value) { // if (in_array($value, Sample::model()->attributeNames())) { // $keysArray[$key] = $value; // } elseif (substr($value, 0, 5) == 'notes') { // $keysArray[$key] = $value; // } // } // /* // * Traitement des lignes de données // */ // } else { // $model = new Sample(); // $model->disableBehavior('LoggableBehavior'); // $model->biobank_id = $biobank_id; // $model->file_imported_id = $fileImportedId; // foreach ($keysArray as $key2 => $value2) { // if (substr($value2, 0, 5) != 'notes') { // // $model->$value2 = $data[$key2]; // if (!$model->validate($value2)) { // // Yii::log("Problem with item" . $model->getAttributeLabel($value2) . ",set to null.", CLogger::LEVEL_ERROR); // $model->$value2 = null; // } // } else { // // $noteKey = end(explode(':', $value2)); // $note = new Note(); // $note->key = $noteKey; // $note->value = $data[$key2]; // $model->notes[] = $note; // } // } // // if (!$model->save()) { // $listBadSamples[] = $row; // } else { // $newSamples[] = $model->_id; // } // } // $row++; // } fclose($import); if (!$add && count($newSamples) > 0) { $deleteCriteria = new EMongoCriteria(); $deleteCriteria->biobank_id('==', $biobank_id); $deleteCriteria->_id('notIn', $newSamples); Sample::model()->deleteAll($deleteCriteria); } if (count($listBadSamples) != 0) { $log = ''; foreach ($listBadSamples as $badSample) { $log = 'Error with manual import. File id : ' . $fileImportedId . ' - line : ' . $badSample; Yii::log($log, CLogger::LEVEL_ERROR); } } return count($listBadSamples); }
/** * 批量清理指定天数之前的备份 * @param $days int 有效期的天数,默认30(之前的都会被清理掉) * @return 清理结果 true */ protected function cleanFile($days = 30) { $criteria = new EMongoCriteria(); $criteria->addCond('metadata.addTime', '<', time() - $days * 24 * 3600); //指明对象 return File::model()->deleteAll($criteria); }
public function search($caseSensitive = false) { $criteria = new EMongoCriteria(); if (isset($this->login) && !empty($this->login)) { $regex = '/'; foreach ($this->login as $value) { $regex .= $value; if ($value != end($this->login)) { $regex .= '|'; } } $regex .= '/i'; $criteria->addCond('login', '==', new MongoRegex($regex)); } if (isset($this->profil) && !empty($this->profil)) { $regex = '/'; foreach ($this->profil as $value) { $regex .= $value; if ($value != end($this->profil)) { $regex .= '|'; } } $regex .= '/i'; $criteria->addCond('profil', '==', new MongoRegex($regex)); } if (isset($this->nom) && !empty($this->nom)) { $regex = '/'; foreach ($this->nom as $value) { $regex .= $value; if ($value != end($this->nom)) { $regex .= '|'; } } $regex .= '/i'; $criteria->addCond('nom', '==', new MongoRegex($regex)); } if (isset($this->prenom) && !empty($this->prenom)) { $regex = '/'; foreach ($this->prenom as $value) { $regex .= $value; if ($value != end($this->prenom)) { $regex .= '|'; } } $regex .= '/i'; $criteria->addCond('prenom', '==', new MongoRegex($regex)); } if (isset($this->email) && !empty($this->email)) { $regex = '/'; foreach ($this->email as $value) { $regex .= $value; if ($value != end($this->email)) { $regex .= '|'; } } $regex .= '/i'; $criteria->addCond('email', '==', new MongoRegex($regex)); } Yii::app()->session['criteria'] = $criteria; return new EMongoDocumentDataProvider($this, array('criteria' => $criteria, 'sort' => array('defaultOrder' => 'login ASC'))); }
/** * 从cursor游标得到数组 * 同时获取该记录的操作者 */ public static function getRowsFromCursor($e_cursor) { $rows = array(); $e_cursor->next(); $_ids = array(); $user_ids = array(); while ($row = $e_cursor->current()) { $t = $row->attributes; $rows[] = $t; $_ids[] = $t['_id']; if (isset($t['user'])) { if (!is_numeric($t['user'])) { //不是管理员用户 $user_ids[] = $t['user']; } } $e_cursor->next(); } $total = count($rows); if ($total > 0) { $model = $e_cursor->getModel(); $db_name = $model->getMongoDBComponent()->dbName; $c_name = $model->getCollectionName(); $criteria = new EMongoCriteria(); $criteria->db_name('==', $db_name); $criteria->c_name('==', $c_name); $criteria->r_id('in', $_ids); $criteria->limit($total); $cursor = DbAction::model()->findAll($criteria); //var_dump($_ids);exit; if ($cursor->count() > 0) { $action_info = array(); $admin_user_ids = array(); foreach ($cursor as $v) { $_id = (string) $v->r_id; $action = $v->action; $last = count($action) - 1; $admin_user_ids[] = $action[$last]['user']; $action_info[$_id] = array('action_time' => date("Y-m-d H:i", $action[$last]['time']), 'admin_id' => $action[$last]['user'], 'action_log' => isset($action[$last]['action_log']) ? $action[$last]['action_log'] : ''); } $criteria = new EMongoCriteria(); $criteria->_id('in', $admin_user_ids); $user_cursor = User::model()->findAll($criteria); $ruser_cursor = RUser::model()->findAll($criteria); $admin_names = array(); foreach ($user_cursor as $v) { $admin_names[$v->_id] = $v->name; } foreach ($ruser_cursor as $v) { $admin_names[(string) $v->_id] = $v->user_name; } foreach ($rows as $k => $v) { $_id = (string) $v['_id']; if (isset($action_info[$_id])) { $admin_id = (string) $action_info[$_id]['admin_id']; $admin_user = $admin_names[$admin_id]; $rows[$k]['action_user'] = $admin_user; $rows[$k]['action_time'] = $action_info[$_id]['action_time']; $rows[$k]['action_log'] = $action_info[$_id]['action_log']; } else { $rows[$k]['action_user'] = ''; $rows[$k]['action_time'] = ''; $rows[$k]['action_log'] = ''; } } } else { foreach ($rows as $k => $v) { $rows[$k]['action_user'] = ''; $rows[$k]['action_time'] = ''; $rows[$k]['action_log'] = ''; } } } return $rows; }
/** * Finds all documents with the specified primary keys. * In MongoDB world every document has '_id' unique field, so with this method that * field is in use as PK by default. * See {@link find()} for detailed explanation about $condition. * @param mixed $pk primary key value(s). Use array for multiple primary keys. For composite key, each key value must be an array (column name=>column value). * @param array|EMongoCriteria $condition query criteria. * @return the document found. An null is returned if none is found. * @since v1.0 */ public function findAllByPk($pk, $criteria = null) { Yii::trace(get_class($this) . '.findAllByPk()', 'ext.MongoDb.EMongoDocument'); $criteria = new EMongoCriteria($criteria); $criteria->mergeWith($this->createPkCriteria($pk, true)); return $this->findAll($criteria); }
public function searchFilter($caseSensitive = false) { $criteria = new EMongoCriteria(); if (isset($_SESSION['id_patient'])) { $criteria->id_patient = new MongoRegex($_SESSION['id_patient']); } if (isset($this->dynamics) && !empty($this->dynamics)) { $index = 0; $nbCriteria = array(); foreach ($this->dynamics as $questionId => $answerValue) { if ($answerValue != null && !empty($answerValue)) { if ($index != 0) { $nbCriteria = '$criteria' . $index; $nbCriteria = new EMongoCriteria(); } if (isset($this->compare[$questionId])) { if ($index == 0) { if ($this->compare[$questionId] == "between") { $answerDate = $this->formatDatePicker($answerValue); $criteria->addCond('answers_group.answers', 'elemmatch', array('id' => $questionId, 'answer.date' => array('$gte' => $answerDate['date_from'] . " 00:00:00.000000", '$lte' => $answerDate['date_to'] . " 23:59:59.000000"))); } else { $criteria->addCond('answers_group.answers', 'elemmatch', array('id' => $questionId, 'answer' => array(EMongoCriteria::$operators[$this->compare[$questionId]] => (int) $answerValue))); } } else { if ($this->compare[$questionId] == "between") { $answerDate = $this->formatDatePicker($answerValue); $nbCriteria->addCond('answers_group.answers', 'elemmatch', array('id' => $questionId, 'answer.date' => array('$gte' => $answerDate['date_from'] . " 00:00:00.000000", '$lte' => $answerDate['date_to'] . " 23:59:59.000000"))); } else { $nbCriteria->addCond('answers_group.answers', 'elemmatch', array('id' => $questionId, 'answer' => array(EMongoCriteria::$operators[$this->compare[$questionId]] => (int) $answerValue))); } } } else { $values = !is_array($answerValue) ? split(',', $answerValue) : $answerValue; if ($index == 0) { $criteria->addCond('answers_group.answers', 'elemmatch', array('id' => $questionId, 'answer' => new MongoRegex($this->regexString($values)))); } else { $nbCriteria->addCond('answers_group.answers', 'elemmatch', array('id' => $questionId, 'answer' => new MongoRegex($this->regexString($values)))); } } } if ($index != 0) { $criteria->mergeWith($nbCriteria, $this->condition[$questionId]); } $index++; } } $criteria->sort('id_patient', EMongoCriteria::SORT_ASC); $criteria->sort('type', EMongoCriteria::SORT_ASC); $criteria->sort('last_updated', EMongoCriteria::SORT_DESC); Yii::app()->session['criteria'] = $criteria; return new EMongoDocumentDataProvider($this, array('criteria' => $criteria)); }