public function run() { echo 'Massive Run for samples'; $biobanks = Biobank::model()->findAll(); foreach ($biobanks as $biobank) { $modifier = new EMongoModifier(); $modifier->addModifier('biobank_id', 'set', (string) $biobank->_id); $criteria = new EMongoCriteria(); $criteria->biobank_id = $biobank->id; $status = Sample::model()->updateAll($modifier, $criteria); $criteriaAfter = new EMongoCriteria(); $criteriaAfter->biobank_id = (string) $biobank->_id; $count = Sample::model()->count($criteriaAfter); echo "Done for biobank {$biobank->_id} - {$biobank->name} : {$count}\n"; } }
/** * Deletes a particular model. * If deletion is successful, the browser will be redirected to the 'admin' page. * @param integer $id the ID of the model to be deleted */ public function actionDelete($id) { $model = $this->loadModel($id); $name = $model->name; $sampleCount = Sample::model()->countByAttributes(array('biobank_id' => (string) $model->id)); $adminCount = User::model()->countByAttributes(array('biobank_id' => (string) $model->_id)); if ($adminCount == 0 && $sampleCount == 0) { try { $model->delete(); Yii::app()->user->setFlash('success', 'La biobanque a bien été supprimée.'); } catch (Exception $ex) { Yii::app()->user->setFlash('error', 'La biobanque n\'a pas pu être supprimée : ' . $ex->getMessage()); } } else { $message = "Suppression de la biobanque \"{$name}\" impossible : "; if ($adminCount > 0) { $message .= "<br> - Il reste {$adminCount} administrateur(s) lié(s) à la biobanque."; } if ($sampleCount > 0) { $message .= "<br> reste {$sampleCount} échantillon(s) lié(s) à la biobanque."; } Yii::app()->user->setFlash('error', $message); } // if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser if (!isset($_GET['ajax'])) { $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin')); } else { $flashMessages = Yii::app()->user->getFlashes(); $flashMessagesHtml = ''; if ($flashMessages) { foreach ($flashMessages as $key => $message) { $flashMessagesHtml .= '<br><div class="flash-' . $key . '">' . $message . "</div>"; } } echo $flashMessagesHtml; } }
public function loadEchModel($id) { $model = Sample::model()->findByPk(new MongoID($id)); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
<?php echo CHtml::activeDropDownList($model, 'dataset_id', CHtml::listData(Util::getDois(), 'id', 'identifier')); ?> <?php echo $form->error($model, 'dataset_id'); ?> </div> </div> <div class="control-group"> <?php echo $form->labelEx($model, 'sample_id', array('class' => 'control-label')); ?> <div class="controls"> <?php echo CHtml::activeDropDownList($model, 'sample_id', CHtml::listData(Sample::model()->findAll(), 'id', 'id')); ?> <?php echo $form->error($model, 'sample_id'); ?> </div> </div> <div class="row buttons"> <a href="/adminDatasetSample/admin" class="btn">Cancel</a> <?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save', array('class' => 'btn')); ?> </div> <?php
/** * effectue le calcul de statistiques de la biobanque fournie en parametre si elle possede des echantillons, * @param type $biobank_id * @return null */ public static function getCompletionRateByBiobank($biobank_id) { //nombre total d'échantillons de la biobanque $criteria = new EMongoCriteria(); $criteria->biobank_id = $biobank_id; $compte = Sample::model()->count($criteria); if ($compte != 0 && $compte != null) { $details = array(); $rateCount = 0; $listAttributes = StatTools::getAttributesForRating(); foreach ($listAttributes as $attributeName => $attributeConstraint) { $echCriteria = new EMongoCriteria(); $echCriteria->biobank_id = $biobank_id; $echCriteria->addCond($attributeName, "exists", true); if (is_array($attributeConstraint)) { foreach ($attributeConstraint as $operator => $values) { $echCriteria->addCond($attributeName, $operator, $values); } } $nbEch = Sample::model()->count($echCriteria); $details[$attributeName] = round($nbEch / $compte * 100, 2); $rateCount += $nbEch; } $rate = $rateCount / ($compte * count($listAttributes)); return array($rate * 100, $details); } else { return null; } }
<h1>View File #<?php echo $model->id; ?> </h1> <? if (Yii::app()->user->checkAccess('admin')) { ?> <div class="actionBar"> [<?php echo MyHtml::link('Manage Files', array('admin')); ?> ] </div> <? } ?> <?php $sample_id = FileSample::model()->find('file_id=:file_id', array(':file_id' => $model->id)); if (isset($sample_id)) { $sample_name = Sample::model()->find('id=:id', array(':id' => $sample_id->sample_id)); } $name = "Not Set"; if (isset($sample_id) && isset($sample_name)) { $name = $sample_name->name; } $this->widget('zii.widgets.CDetailView', array('data' => $model, 'attributes' => array('id', 'dataset_id', 'name', 'location', 'extension', 'size', 'description', 'date_stamp', 'format_id', 'type_id', array('name' => 'Sample', 'value' => $name))));
$tabCount = 0; foreach ($globalStats[0]->values as $attributeName => $attribute) { $datas = array(); for ($i = 0; $i <= $max; $i++) { if (isset($biobankStats[$max - $i])) { $datas['biobanque'][] = $biobankStats[$max - $i]->values[$attributeName]; } else { $datas['biobanque'][] = null; } if (isset($globalStats[$max - $i])) { $datas['global'][] = $globalStats[$max - $i]->values[$attributeName]; } else { $datas['global'][] = null; } } $listWidgets[$attributeName] = array('label' => Sample::model()->getAttributeLabel($attributeName), 'url' => Yii::app()->createUrl('mybiobank/detailGraph'), 'ajax' => array('type' => 'POST', 'update' => '#detailData', 'data' => array('datas' => $datas, 'attributeName' => $attributeName, 'theme' => $theme))); } ?> <div style="overflow: hidden;display: inline-block"> <div id="detailsMenu" style="float:left;width:200px;padding-left:5px;padding-right:5px;padding-top:5px;"> <div class="span-5 last"> <?php $this->beginWidget('zii.widgets.CPortlet', array('title' => 'Détails')); $this->widget('ext.AjaxMenu', array('items' => $listWidgets)); $this->endWidget(); ?> </div></div>
public function getAllSamples() { $criteria = new CdbCriteria(); $criteria->join = "join dataset_sample ds on ds.sample_id = t.id"; $criteria->addCondition("ds.dataset_id = " . $this->id); return Sample::model()->findAll($criteria); }
public function getSamples() { $samples = array(); if ($this->sampleList != null) { foreach ($this->sampleList as $sampleDemand) { $samples[] = new MongoID($sampleDemand->id_sample); } } $dataProvider = Sample::model()->getSamplesFromArray($samples); return $dataProvider; }
/** * print de la liste dechantillons */ public function actionPrint() { // $model = new Sample('search'); if (isset($_SESSION['criteria']) && $_SESSION['criteria'] != null && $_SESSION['criteria'] instanceof EMongoCriteria) { $criteria = $_SESSION['criteria']; } else { $criteria = new EMongoCriteria(); } $criteria->limit(200); $dataProvider = new EMongoDocumentDataProvider('Sample', array('criteria' => $criteria, 'pagination' => false)); $columns = array(); foreach (Sample::model()->attributeExportedLabels() as $key => $value) { if ($key == 'notes') { $columns[] = $this->addColumn($key, $value, '$data->getShortNotes()'); } elseif ($key == 'biobank_id') { $columns[] = $this->addColumn('biobank_id', $value, '$data->getBiobankName()'); } elseif ($key == 'collect_date') { $columns[] = $this->addColumn('collect_date', $value, '$data->collect_date'); //TODO normaliser les dates de collecte avant d activer cette feature // $columns [] = getArrayColumn('collect_date', $value, 'CommonTools::toShortDateFR($data->collect_date)'); } elseif ($key == 'storage_conditions') { $columns[] = $this->addColumn('storage_conditions', $value, '$data->getLiteralStorageCondition()'); } else { $columns[] = $this->addColumn($key, $value, '$data->' . $key); } } $this->render('print', array('dataProvider' => $dataProvider, 'columns' => $columns)); }
$visibility = 'display:none'; } if ($property == 'notes') { $columns[] = array('class' => 'DataColumn', 'name' => $property, 'id' => 'col_' . $property, 'header' => Sample::model()->getAttributeLabel($property), 'value' => '$data->getShortNotes()', 'htmlOptions' => array('class' => "col_{$property}", 'style' => $visibility), 'headerHtmlOptions' => array('class' => "col_{$property}", 'style' => $visibility)); } elseif ($property == 'biobank_id') { $columns[] = array('class' => 'DataColumn', 'name' => Yii::t('sample', 'biobank_id'), 'id' => 'col_' . $property, 'header' => Sample::model()->getAttributeLabel($property), 'value' => 'Biobank::model()->findByPk(new MongoId($data->biobank_id))->name', 'htmlOptions' => array('class' => "col_{$property}", 'style' => $visibility), 'headerHtmlOptions' => array('class' => "col_{$property}", 'style' => $visibility)); } elseif ($property == 'collect_date') { $columns[] = array('class' => 'DataColumn', 'name' => $property, 'id' => 'col_' . $property, 'header' => Sample::model()->getAttributeLabel($property), 'value' => 'CommonTools::toShortDateFR($data->collect_date)', 'htmlOptions' => array('class' => "col_{$property}", 'style' => $visibility), 'headerHtmlOptions' => array('class' => "col_{$property}", 'style' => $visibility)); } elseif ($property == 'storage_conditions') { $columns[] = array('class' => 'DataColumn', 'name' => $property, 'id' => 'col_' . $property, 'header' => Sample::model()->getAttributeLabel($property), 'value' => '$data->getLiteralStorageCondition()', 'htmlOptions' => array('class' => "col_{$property}", 'style' => $visibility), 'headerHtmlOptions' => array('class' => "col_{$property}", 'style' => $visibility)); } elseif ($property == 'collection_name') { $columns[] = addColumn('collection_name', Biobank::model()->getAttributeLabel('collection_name'), '$data->biobank->collection_name', $visibility); } elseif ($property == 'collection_id') { $columns[] = addColumn('collection_id', Biobank::model()->getAttributeLabel('collection_id'), '$data->biobank->collection_id', $visibility); } else { $columns[] = array('class' => 'DataColumn', 'name' => $property, 'id' => 'col_' . $property, 'value' => '$data->' . $property, 'header' => Sample::model()->getAttributeLabel($property), 'htmlOptions' => array('class' => "col_{$property}", 'style' => $visibility), 'headerHtmlOptions' => array('class' => "col_{$property}", 'style' => $visibility)); } } } // $columns[] = array('header' => Yii::t('demande', 'sampleDetail'), 'class' => 'CLinkColumn', 'labelExpression' => '$data->_id', 'urlExpression' => 'Yii::app()->createUrl("site/view",array("id"=>"$data->_id"))', 'linkHtmlOptions' => array('onclick' => 'window.open(this.href,"SampleDetail","left=100,top=100,width=760,height=650,toolbar=0,resizable=0, location=no");return false;'), 'htmlOptions' => array('style' => 'text-align:center'), 'imageUrl' => $imageSampleDetail); ?> <h1><?php echo Yii::t('common', 'demande') . ' ' . $model->titre; ?> </h1> <?php echo $this->renderPartial('_form', array('model' => $model)); ?>
public function actionDelete1($id) { if (isset($_SESSION['samples'])) { $info = $_SESSION['samples']; foreach ($info as $key => $value) { if ($value['id'] == $id) { unset($info[$key]); $_SESSION['samples'] = $info; $vars = array('samples'); //Dataset::storeSession($vars); $condition = 'id=' . $id; $sample_id = DatasetSample::model()->findByAttributes(array('id' => $id))->sample_id; DatasetSample::model()->deleteAll($condition); Sample::model()->deleteAll('id=' . $sample_id); $this->redirect("/adminDatasetSample/create1"); } } } }
public function testgetShortNotes() { $sample = Sample::model(); $this->assertNotNull($sample); //$sample=Sample::model()->search()); }
<?php echo CHtml::activeDropDownList($model, 'type_id', CHtml::listData(FileType::model()->findAll(), 'id', 'name')); ?> <?php echo $form->error($model, 'type_id'); ?> </div> </div> <div class="control-group"> <?php echo $form->labelEx($model, 'sample_name', array('class' => 'control-label')); ?> <div class="controls"> <?php echo CHtml::activeDropDownList($model, 'sample_name', CHtml::listData(Sample::model()->findAll(), 'id', 'name'), array('empty' => 'None')); ?> <?php echo $form->error($model, 'sample_name'); ?> </div> </div> <?php if (!$model->isNewRecord) { ?> <div class="control-group"> <a href="#" role="button" class="btn btn-attr">New Attribute </a> <br/> <div class="js-new-attr" style="display:none;"> <?php
if ($stats != null) { $complete = $stats->globalRate; } else { $complete = 0; } $roundcomplete = round($complete); $uncomplete = 100 - $roundcomplete; $data = array(array('Complet : ' . $roundcomplete . '%', $roundcomplete), array('Incomplet : ' . $uncomplete . "%", $uncomplete)); $this->beginWidget('zii.widgets.CPortlet', array('title' => "<i class = 'icon-adjust'></i> " . Yii::t('myBiobank', 'samplesCompletionRate') . " - {$model->identifier}")); // affichage du graphe de completude des echantillons $this->widget('application.widgets.charting.CPieChartWidget', array('id' => 'piechart-collab', 'theme' => 'WatersEdge', 'width' => 380, 'height' => 250, 'data' => $data, 'title' => '<a class="detail-button" href="#">détails</a>')); $this->endWidget(); ?> </div> <!-- affichage du tableau de stats detaillées --> <div style="float: left; width: 330px; padding-left: 10px; padding-top: 10px; display: none" class="detail_tab"> <h4><b>Détails des taux de complétude.</b></h4> <?php if ($stats != null) { foreach ($stats->values as $valueName => $value) { $attributes[] = array('label' => Sample::model()->getAttributeLabel($valueName), 'value' => $value . '%'); } $this->widget('zii.widgets.CDetailView', array('data' => $stats->values, 'attributes' => $attributes)); ?> </div> </div> <div style="clear: both;" /> <?php }
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); }
public function getSample() { $criteria = new CDbCriteria(); $criteria->join = "LEFT JOIN file_sample fs ON fs.sample_id = t.id"; $criteria->compare('fs.file_id', $this->id); return Sample::model()->find($criteria); }