Example #1
0
 /**
  * @dataProvider dataProvider
  * @param SplFileInfo $file instance of sample file
  * @param array $data data to be exported
  * @param boolean $columnNames
  */
 public function testExport(SplFileInfo $file, array $data, $columnNames)
 {
     $exporter = new CsvExporter($data);
     $exportedData = $this->normalizeLineEndings($exporter->export($columnNames));
     $sampleData = $this->normalizeLineEndings(file_get_contents($file->getPathname()));
     $this->assertEquals($exportedData, $sampleData);
 }
 public function exportIrregularities()
 {
     if (!$this->hasRequestParameter('uri')) {
         $response = array('success' => false, 'message' => __('You must select a delivery in order to export its irregularities'));
         $this->returnJson($response, 200);
         return;
     }
     $delivery = new \core_kernel_classes_Resource(\tao_helpers_Uri::decode($this->getRequestParameter('uri')));
     $from = $this->hasRequestParameter('from') ? strtotime($this->getRequestParameter('from')) : '';
     $to = $this->hasRequestParameter('to') ? strtotime($this->getRequestParameter('to')) : '';
     try {
         $export = $this->getIrregularities($delivery, $from, $to);
     } catch (\common_Exception $e) {
         $response = array('success' => false, 'message' => __('Something went wrong during the export'));
         $this->returnJson($response, 200);
         return;
     }
     setcookie('fileDownload', 'true', 0, '/');
     $exporter = new CsvExporter($export);
     $exporter->export(false, true);
 }
 /**
  * Process action call
  *
  * @throws ResolutionException
  */
 private function process()
 {
     if (empty($this->params)) {
         throw new ResolutionException(__('Parameters were not given. Expected Syntax: ExportDeliveryResults <deliveryId> <filePath> [format]'));
     }
     $data = $this->getData();
     $format = $this->getFormat();
     $path = $this->getPath();
     switch ($format) {
         case 'csv':
             $exporter = new CsvExporter($data);
             break;
     }
     $result = $exporter->export(true, false, ';');
     file_put_contents($path, $result);
     $this->report = new Report(Report::TYPE_SUCCESS, 'Results successfully exported');
 }
 /**
  * Download csv file with all results of all delivery executions of given delivery.
  */
 public function getCsvFileByDelivery()
 {
     $filter = 'lastSubmitted';
     $delivery = new \core_kernel_classes_Resource(tao_helpers_Uri::decode($this->getRequestParameter('uri')));
     $columns = [];
     $cols = array_merge($this->getTestTakerColumn(), $this->service->getVariableColumns($delivery, CLASS_OUTCOME_VARIABLE, $filter), $this->service->getVariableColumns($delivery, CLASS_RESPONSE_VARIABLE, $filter));
     $dataProvider = new VariableDataProvider();
     foreach ($cols as $col) {
         $column = tao_models_classes_table_Column::buildColumnFromArray($col);
         if (!is_null($column)) {
             if ($column instanceof VariableColumn) {
                 $column->setDataProvider($dataProvider);
             }
             $columns[] = $column;
         }
     }
     $columns[0]->label = __("Test taker");
     $rows = $this->service->getResultsByDelivery($delivery, $columns, $filter);
     $columnNames = array_reduce($columns, function ($carry, $item) {
         $carry[] = $item->label;
         return $carry;
     });
     $result = [];
     foreach ($rows as $row) {
         $rowResult = [];
         foreach ($row['cell'] as $rowKey => $rowVal) {
             $rowResult[$columnNames[$rowKey]] = $rowVal[0];
         }
         $result[] = $rowResult;
     }
     //If there are no executions yet, the file is exported but contains only the header
     if (empty($result)) {
         $result = [array_fill_keys($columnNames, '')];
     }
     $exporter = new CsvExporter($result);
     $exporter->export(true, true, ";");
 }
 /**
  * Export log entries from database to csv file
  * dates should be in UTC
  */
 public function export()
 {
     $delimiter = $this->hasRequestParameter('field_delimiter') ? html_entity_decode($this->getRequestParameter('field_delimiter')) : ',';
     $enclosure = $this->hasRequestParameter('field_encloser') ? html_entity_decode($this->getRequestParameter('field_encloser')) : '"';
     $columnNames = $this->hasRequestParameter('first_row_column_names');
     if (!($exported = (new LogEntryCsvExporter())->export())) {
         return $this->returnJson(['message' => 'Not found exportable log entries. Please, check export configuration.'], 404);
     }
     $csvExporter = new CsvExporter($exported);
     setcookie('fileDownload', 'true', 0, '/');
     $csvExporter->export($columnNames, true, $delimiter, $enclosure);
 }