public static function getPreferences() { $user = CommonTools::getConnectedUser(); $user->disableBehavior('LoggableBehavior'); $result = $user->preferences; $user->save(); return $result; }
/** * affichage de la page de recherche des echantillons */ public function actionSearch() { $model = new Sample('search'); $model->unsetAttributes(); $biobankId = null; if (isset($_GET['id']) && isset($_GET['layout']) && $_GET['layout'] == 'vitrine_layout') { $biobankId = $_GET['id']; } $model->biobank_id = $biobankId; $user = CommonTools::getConnectedUser(); if (isset($_GET['Preferences'])) { $user->preferences->attributes = $_GET['Preferences']; $user->disableBehavior('LoggableBehavior'); if ($user->validate(array('preferences'))) { $user->save(false); } else { var_dump($user->preferences->errors); } } if (isset($_GET['Sample'])) { $model->attributes = $_GET['Sample']; //Used to search terms in model->biobank->collection_id and model->biobank->collection_name $arrayOfBiobanks = array(); if (!empty($_GET['collection_id'])) { $criteria = new EMongoCriteria(); $listWords = explode(",", $_GET['collection_id']); $regexId = ""; foreach ($listWords as $word) { $regexId .= "{$word}|"; } $regexId = substr($regexId, 0, -1); $criteria->addCond('collection_id', '==', new MongoRegex("/({$regexId})/i")); $criteria->select(array('_id')); $biobanks = Biobank::model()->findAll($criteria); foreach ($biobanks as $biobank) { $arrayOfBiobanks[(string) $biobank->_id] = (string) $biobank->_id; } } if (!empty($_GET['collection_name'])) { $criteria = new EMongoCriteria(); $listWords = explode(",", $_GET['collection_name']); $regexId = ""; foreach ($listWords as $word) { $regexId .= "{$word}|"; } $regexId = substr($regexId, 0, -1); $criteria->addCond('collection_name', '==', new MongoRegex("/({$regexId})/i")); $criteria->select(array('_id')); $biobanks = Biobank::model()->findAll($criteria); foreach ($biobanks as $biobank) { $arrayOfBiobanks[$biobank->_id] = (string) $biobank->_id; } } if (!empty($arrayOfBiobanks)) { // $model->arrayOfBiobanks; $model->setArrayOfBiobanks(array_values($arrayOfBiobanks)); } $content = ''; foreach ($_GET['Sample'] as $key => $value) { if (is_array($value)) { foreach ($value as $vkey => $vval) { $content = $content . (string) $vkey . '=' . str_replace(';', ',', (string) $vval) . ';'; } } else { if ($value != null && !empty($value) && (string) $value != '0') { $content = $content . (string) $key . '=' . str_replace(';', ',', (string) $value) . ';'; } } } if (Yii::app()->session['SampleForm'] != $_GET['Sample']) { $_GET['Echantillon_page'] = null; $this->logAdvancedSearch($content); } Yii::app()->session['SampleForm'] = $_GET['Sample']; } //form de la recherche intelligente $smartForm = new SampleSmartForm(); if (isset($_POST['SampleSmartForm'])) { $model->unsetAttributes(); $smartForm->attributes = $_POST['SampleSmartForm']; if (Yii::app()->session['keywords'] != $smartForm->keywords) { $_GET['Echantillon_page'] = null; $this->logSmartSearch($smartForm->keywords); } Yii::app()->session['keywords'] = $smartForm->keywords; $model = SmartResearcherTool::search($smartForm->keywords, $biobankId); } $this->render('search_samples', array('model' => $model, 'smartForm' => $smartForm)); }