/** * display the current logo into simple image format. * @return simple img */ public function toSimpleImage() { $splitStringArray = split(".", $this->filename); $extension = end($splitStringArray); $result = CommonTools::data_uri($this->getBytes(), "image/" . $extension); return $result; }
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); }
<link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->request->baseUrl; ?> /css/form.css" /> <script src="//ajax.googleapis.com/ajax/libs/dojo/1.9.3/dojo/dojo.js"></script> </head> <?php CommonTools::getBiobankInfo(); $splitStringArray = split(".", $_SESSION['vitrine']['biobankLogo']->filename); $extention = end($splitStringArray); ?> <body class="container" id="page" > <div style="float:left;"> <a href="http://www.biobanques.eu" target="_blank"><img src="<?php echo CommonTools::data_uri($_SESSION['vitrine']['biobankLogo']->getBytes(), "image/{$extention}"); ?> " alt="1 photo" style="height:120px;"/></a> </div> <div style="float:left;"> <h1><?php echo $_SESSION['vitrine']['biobank']->identifier; ?> </h1> </div> <div style="float:right;padding-right:20px;padding-top:20px;"> <div > <?php