예제 #1
0
 public function toCsv()
 {
     $writer = \CsvWriter::create();
     $data = $this->toArray();
     $writer->writeLine(array_keys($data));
     $writer->writeLine($data);
     $out = $writer->flush();
     $writer->close();
     return $out;
 }
예제 #2
0
 /**
  * Export tabular data to CSV-file
  * @param array $data
  * @param string $filename
  */
 public static function export_table_csv_utf8($data, $filename = 'export')
 {
     if (empty($data)) {
         return false;
     }
     $path = Chamilo::temp_file();
     $converter = new Utf8Encoder(null, true);
     $file = FileWriter::create($path, $converter);
     $file = CsvWriter::create($file);
     foreach ($data as $row) {
         $file->put($row);
     }
     $file->close();
     DocumentManager::file_send_for_download($path, false, $filename . '.csv');
     unlink($path);
     exit;
 }
 public function export_csv()
 {
     $c_id = Request::get_c_id();
     $session_id = Request::get_session_id();
     $root = (object) array();
     $root->c_id = $c_id;
     $root->id = 0;
     $root->session_id = $session_id;
     $links = LinkRepository::instance()->find_by_category($root);
     $repo = LinkCategory::repository();
     $categories = $repo->find_by_course($c_id, $session_id);
     $temp = Chamilo::temp_file();
     $writer = \CsvWriter::create(new \FileWriter($temp));
     $headers = array();
     $headers[] = 'url';
     $headers[] = 'title';
     $headers[] = 'description';
     $headers[] = 'target';
     $headers[] = 'category_title';
     $headers[] = 'category_description';
     $writer->put($headers);
     foreach ($links as $link) {
         $data = array();
         $data[] = $link->url;
         $data[] = $link->title;
         $data[] = $link->description;
         $data[] = $link->target;
         $data[] = '';
         $data[] = '';
         $writer->put($data);
     }
     foreach ($categories as $category) {
         foreach ($category->links as $link) {
             $data = array();
             $data[] = $link->url;
             $data[] = $link->title;
             $data[] = $link->description;
             $data[] = $link->target;
             $data[] = $category->category_title;
             $data[] = $category->description;
             $writer->put($data);
         }
     }
     \DocumentManager::file_send_for_download($temp, true, get_lang('Links') . '.csv');
 }