/** * display catalog of biobanks with contacts and agregated infos */ public function actionSearch() { $model = new Biobank('search'); $model->unsetAttributes(); // clear any default values if (isset($_GET['Biobank'])) { $model->attributes = $_GET['Biobank']; } //make the search //render the biobanks $this->render('catalog', array('model' => $model)); }
public function actionExportCsv() { $model = new Biobank('search'); $model->unsetAttributes(); if (isset($_GET['Biobank'])) { $model->attributes = $_GET['Biobank']; } if (isset($_SESSION['criteria']) && $_SESSION['criteria'] != null && $_SESSION['criteria'] instanceof EMongoCriteria) { $criteria = $_SESSION['criteria']; } else { $criteria = new EMongoCriteria(); } $models = Biobank::model()->findAll($criteria); $dataProvider = array(); $listAttributes = array(); foreach ($models as $model) { //récuperation de la liste totale des attributs foreach ($model->attributes as $attributeName => $attributeValue) { $listAttributes[$attributeName] = $attributeName; } } foreach ($models as $model) { $datas = array(); foreach ($listAttributes as $attribute) { if (isset($model->{$attribute})) { if (!is_object($model->{$attribute})) { $datas[$attribute] = $model->{$attribute}; } } else { $datas[$attribute] = ""; } } $dataProvider[] = $datas; } $filename = 'biobanks_list.csv'; $csv = new ECSVExport($dataProvider); $toExclude = array(); $toExport = $model->attributeExportedLabels(); foreach ($listAttributes as $attribute) { if (!isset($toExport[$attribute])) { $toExclude[] = $attribute; } } $csv->setExclude($toExclude); // $csv->exportCurrentPageOnly(); Yii::app()->getRequest()->sendFile($filename, $csv->toCSV(), "text/csv", false); }
/** * export xls des biobanques */ public function actionExportXls() { $model = new Biobank('search'); $model->unsetAttributes(); if (isset($_GET['Biobank'])) { $model->attributes = $_GET['Biobank']; } if (isset($_SESSION['criteria']) && $_SESSION['criteria'] != null && $_SESSION['criteria'] instanceof EMongoCriteria) { $criteria = $_SESSION['criteria']; } else { $criteria = new EMongoCriteria(); } $biobanks = Biobank::model()->findAll($criteria); $data = array(1 => array_keys(Biobank::model()->attributeExportedLabels())); setlocale(LC_ALL, 'fr_FR.UTF-8'); foreach ($biobanks as $biobank) { $line = array(); foreach (array_keys($biobank->attributeExportedLabels()) as $attribute) { if (isset($biobank->{$attribute}) && $biobank->{$attribute} != null && !empty($biobank->{$attribute})) { $line[] = iconv("UTF-8", "ASCII//TRANSLIT", $biobank->{$attribute}); //solution la moins pire qui ne fait pas bugge les accents mais les convertit en caractere generique } else { $line[] = "-"; } } $line[] = iconv("UTF-8", "ASCII//TRANSLIT", $biobank->getShortContact()); $line[] = iconv("UTF-8", "ASCII//TRANSLIT", $biobank->getEmailContact()); $contact = $biobank->getContact(); if ($contact != null) { $line[] = iconv("UTF-8", "ASCII//TRANSLIT", $contact->getFullAddress()); } else { $line[] = "No address"; } $data[] = $line; } Yii::import('application.extensions.phpexcel.JPhpExcel'); $xls = new JPhpExcel('UTF-8', true, 'Biobank list'); $xls->addArray($data); $xls->generateXML('Biobank list'); }