Change function names and implementation.

1.10.x
Julio Montoya 11 years ago
parent fd3d8c90d1
commit c8ef4daf90
  1. 3
      composer.json
  2. 2
      main/admin/add_users_to_usergroup.php
  3. 4
      main/admin/user_export.php
  4. 2
      main/admin/user_information.php
  5. 2
      main/admin/usergroup_export.php
  6. 2
      main/course_progress/thematic_controller.php
  7. 2
      main/glossary/index.php
  8. 4
      main/gradebook/gradebook_view_result.php
  9. 6
      main/group/group_overview.php
  10. 2
      main/inc/ajax/model.ajax.php
  11. 91
      main/inc/lib/export.lib.inc.php
  12. 2
      main/mySpace/index.php
  13. 2
      main/mySpace/myStudents.php
  14. 2
      main/mySpace/student.php
  15. 2
      main/mySpace/teachers.php
  16. 2
      main/mySpace/users.php
  17. 2
      main/tracking/courseLog.php
  18. 2
      main/tracking/course_log_tools.php
  19. 2
      main/tracking/lp_results_by_user.php
  20. 4
      main/user/user.php
  21. 2
      plugin/ticket/src/myticket.php
  22. 2
      plugin/ticket/src/tutor.php
  23. 6
      tests/main/inc/lib/export.lib.inc.test.php

@ -68,7 +68,8 @@
"bower-asset/jqueryui-timepicker-addon": "1.5.*",
"ramsey/array_column": "~1.1",
"patchwork/utf8": "~1.2",
"ddeboer/data-import": "@stable"
"ddeboer/data-import": "@stable",
"phpoffice/phpexcel": "~1.8"
},
"require-dev": {
"behat/behat": "2.5.*@stable",

@ -132,7 +132,7 @@ if (isset($_GET['action']) && $_GET['action'] == 'export') {
$data[] = array($user['username'], $groupInfo['name']);
}
$filename = 'export_user_class_' . api_get_local_time();
Export::export_table_csv($data, $filename);
Export::arrayToCsv($data, $filename);
exit;
}
}

@ -126,11 +126,11 @@ if ($form->validate()) {
switch($file_type) {
case 'xml':
Export::export_table_xml($data,$filename,'Contact','Contacts');
Export::arrayToXml($data, $filename, 'Contact', 'Contacts');
exit;
break;
case 'csv':
Export::export_table_csv($data,$filename);
Export::arrayToCsv($data,$filename);
exit;
break;
}

@ -394,7 +394,7 @@ if (isset($_GET['action'])) {
}
break;
case 'export':
Export :: export_table_csv_utf8($csvContent, 'user_information_'.$user);
Export :: arrayToCsv($csvContent, 'user_information_'.$user);
exit;
break;
}

@ -28,7 +28,7 @@ if ($form->validate()) {
$data = $userGroup->getDataToExport();
$data = array_merge($header, $data);
$filename = 'export_classes_'.api_get_local_time();
Export::export_table_csv($data, $filename);
Export::arrayToCsv($data, $filename);
exit;
}

@ -178,7 +178,7 @@ class ThematicController
}
}
}
Export::export_table_csv($csv);
Export::arrayToCsv($csv);
exit;
// Don't continue building a normal page.
return;

@ -75,7 +75,7 @@ if (isset($_GET['action']) && $_GET['action'] == 'export') {
$list[] = array ($line[0], $line[1]);
}
$filename = 'glossary_course_'.api_get_course_id();
Export::export_table_csv_utf8($list, $filename);
Export::arrayToCsv($list, $filename);
}
if (isset($_GET['action']) && $_GET['action'] == 'export_to_pdf') {
GlossaryManager::export_to_pdf();

@ -328,11 +328,11 @@ if (isset($_GET['export'])) {
switch ($file_type) {
case 'xml' :
Export :: export_table_xml($alldata, $filename, 'Result', 'XMLResults');
Export :: arrayToXml($alldata, $filename, 'Result', 'XMLResults');
exit;
break;
case 'csv' :
Export :: export_table_csv($alldata, $filename);
Export :: arrayToCsv($alldata, $filename);
exit;
break;
}

@ -34,7 +34,7 @@ if (isset($_GET['action'])) {
switch ($_GET['action']) {
case 'export_all':
$data = GroupManager::exportCategoriesAndGroupsToArray(null, true);
Export::export_table_csv($data);
Export::arrayToCsv($data);
exit;
break;
case 'export_pdf':
@ -53,12 +53,12 @@ if (isset($_GET['action'])) {
switch ($_GET['type']) {
case 'csv':
Export::export_table_csv($data);
Export::arrayToCsv($data);
exit;
break;
case 'xls':
if (!empty($data)) {
Export::export_table_xls($data);
Export::arrayToXls($data);
exit;
}
break;

@ -1509,7 +1509,7 @@ if (in_array($action, $allowed_actions)) {
default:
//TODO add date if exists
$file_name = (!empty($action)) ? $action : 'company_report';
Export::export_table_csv($array, $file_name);
Export::arrayToCsv($array, $file_name);
break;
}
exit;

@ -1,6 +1,13 @@
<?php
/* See license terms in /license.txt */
use Ddeboer\DataImport\Writer\ExcelWriter;
use Ddeboer\DataImport\Writer\CsvWriter;
use Ddeboer\DataImport\Workflow;
use Ddeboer\DataImport\Reader\CsvReader;
use Ddeboer\DataImport\Reader\ArrayReader;
use Ddeboer\DataImport\Writer\ArrayWriter;
/**
* This is the export library for Chamilo.
* Include/require it in your code to use its functionality.
@ -14,53 +21,32 @@ class Export
{
}
/**
*
* @deprecated use export_table_csv_utf8 instead
*/
public static function export_table_csv ($data, $filename = 'export')
{
$file = api_get_path(SYS_ARCHIVE_PATH).uniqid('').'.csv';
$handle = @fopen($file, 'a+');
if (is_array($data)) {
foreach ($data as $index => $row) {
$line = '';
if (is_array($row)) {
foreach ($row as $value) {
$line .= '"'.str_replace('"', '""', $value).'";';
}
}
@fwrite($handle, $line."\n");
}
}
@fclose($handle);
DocumentManager :: file_send_for_download($file, true, $filename.'.csv');
return false;
}
/**
* Export tabular data to CSV-file
* @param array $data
* @param string $filename
*/
public static function export_table_csv_utf8($data, $filename = 'export')
public static function arrayToCsv($data, $filename = 'export')
{
if(empty($data)) {
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);
$reader = new ArrayReader($data);
// Create the workflow from the reader
$workflow = new Workflow($reader);
$filePath = api_get_path(SYS_ARCHIVE_PATH).uniqid('').'.csv';
$file = new \SplFileObject($filePath, 'w');
$writer = new CsvWriter($file);
$workflow->addWriter($writer);
$workflow->process();
exit;
DocumentManager::file_send_for_download($filePath, false, $filename.'.csv');
exit;
}
/**
@ -68,20 +54,22 @@ class Export
* @param array $data
* @param string $filename
*/
public static function export_table_xls($data, $filename = 'export', $encoding = 'utf-8')
public static function arrayToXls($data, $filename = 'export', $encoding = 'utf-8')
{
$file = api_get_path(SYS_ARCHIVE_PATH).uniqid('').'.xls';
$handle = fopen($file, 'a+');
$systemEncoding = api_get_system_encoding();
foreach ($data as $row) {
$string = implode("\t", $row);
if ($encoding != 'utf-8') {
$string = api_convert_encoding($string, $encoding, $systemEncoding);
}
fwrite($handle, $string."\n");
$filePath = api_get_path(SYS_ARCHIVE_PATH).uniqid('').'.xls';
$file = new \SplFileObject($filePath, 'w');
$writer = new ExcelWriter($file);
$writer->prepare();
foreach ($data as $index => $row) {
$writer->writeItem($row);
}
fclose($handle);
DocumentManager::file_send_for_download($file, false, $filename.'.xls');
$writer->finish();
DocumentManager::file_send_for_download($filePath, false, $filename.'.xls');
exit;
}
/**
@ -112,6 +100,7 @@ class Export
fclose($handle);
DocumentManager::file_send_for_download($file, false, $filename.'.xls');
}
/**
* Export tabular data to XML-file
* @param array Simple array of data to put in XML
@ -120,7 +109,7 @@ class Export
* @param string Name of the root element. A root element should always be given.
* @param string Encoding in which the data is provided
*/
public static function export_table_xml($data, $filename = 'export', $item_tagname = 'item', $wrapper_tagname = null, $encoding = null)
public static function arrayToXml($data, $filename = 'export', $item_tagname = 'item', $wrapper_tagname = null, $encoding = null)
{
if (empty($encoding)) {
$encoding = api_get_system_encoding();

@ -397,7 +397,7 @@ if ($export_csv) {
// Send the csv file if asked
if ($export_csv) {
ob_end_clean();
Export :: export_table_csv($csv_content, 'reporting_index');
Export :: arrayToCsv($csv_content, 'reporting_index');
exit;
}

@ -1158,7 +1158,7 @@ if (!empty($student_id)) {
}
if ($export_csv) {
ob_end_clean();
Export :: export_table_csv($csv_content, 'reporting_student');
Export :: arrayToCsv($csv_content, 'reporting_student');
exit;
}

@ -283,7 +283,7 @@ if ($export_csv) {
}
$csv_content = array_merge($csv_header, $content);
ob_end_clean();
Export :: export_table_csv($csv_content, 'reporting_student_list');
Export :: arrayToCsv($csv_content, 'reporting_student_list');
exit;
} else {
Display::display_header($nameTools);

@ -260,7 +260,7 @@ if ($export_csv) {
}
$csv_content = array_merge($csv_header, $content);
ob_end_clean();
Export :: export_table_csv($csv_content, 'reporting_teacher_list');
Export :: arrayToCsv($csv_content, 'reporting_teacher_list');
exit;
} else {
Display::display_header($nameTools);

@ -271,7 +271,7 @@ if ($export_csv) {
}
$csv_content = array_merge($csv_header, $content);
ob_end_clean();
Export :: export_table_csv($csv_content, 'reporting_student_list');
Export :: arrayToCsv($csv_content, 'reporting_student_list');
exit;
} else {
Display::display_header($nameTools);

@ -517,7 +517,7 @@ if ($export_csv) {
ob_end_clean();
array_unshift($csv_content, $csv_headers); // Adding headers before the content.
Export::export_table_csv($csv_content, 'reporting_student_list');
Export::arrayToCsv($csv_content, 'reporting_student_list');
exit;
}
Display::display_footer();

@ -335,7 +335,7 @@ echo '<div class="clear"></div>';
// send the csv file if asked
if ($export_csv) {
ob_end_clean();
Export :: export_table_csv($csv_content, 'reporting_course_tools');
Export :: arrayToCsv($csv_content, 'reporting_course_tools');
exit;
}

@ -222,7 +222,7 @@ function export_complete_report_csv($filename, $array) {
$header[] = array(get_lang('Course'),get_lang('LearningPath'), get_lang('Exercise'), get_lang('User'),get_lang('Attempt'), get_lang('Date'),get_lang('Results'));
if (!empty($array)) {
$array = array_merge($header, $array);
Export :: export_table_csv($array, $filename);
Export :: arrayToCsv($array, $filename);
}
exit;
/*

@ -347,10 +347,10 @@ if (api_is_allowed_to_edit(null, true)) {
switch ($_GET['type']) {
case 'csv' :
Export::export_table_csv($a_users);
Export::arrayToCsv($a_users);
exit;
case 'xls' :
Export::export_table_xls($a_users);
Export::arrayToXls($a_users);
exit;
case 'pdf' :
$header_attributes = array(

@ -183,7 +183,7 @@ if (isset($_GET['action'])) {
);
$data[] = $ticket_rem;
}
Export::export_table_xls($data, $plugin->get_lang('Tickets'));
Export::arrayToXls($data, $plugin->get_lang('Tickets'));
exit;
break;
case 'close_tickets':

@ -95,7 +95,7 @@ function save() {
$course_code = api_get_course_id();
$results = initializeReport($course_code);
if (isset($_GET['action'])) {
Export::export_table_xls($results['export'], "COURSE_USER_REPORT" . $course_code);
Export::arrayToXls($results['export'], "COURSE_USER_REPORT" . $course_code);
} else {
Display::display_header();
api_protect_course_script();

@ -22,7 +22,7 @@ class TestExport extends UnitTestCase {
$data = array();
// can only be tested if headers were not sent
ob_start();
$res = Export::export_table_csv($data, $filename = 'export');
$res = Export::arrayToCsv($data, $filename = 'export');
$this->assertFalse($res);
ob_end_clean();
}
@ -32,7 +32,7 @@ class TestExport extends UnitTestCase {
$data = array();
$filename = 'export';
ob_start();
$res=Export::export_table_xls($data,$filename);
$res=Export::arrayToXls($data,$filename);
$this->assertFalse($res);
ob_end_clean();
}
@ -44,7 +44,7 @@ class TestExport extends UnitTestCase {
$wrapper_tagname = null;
$encoding=null;
ob_start();
$res=Export::export_table_xml($data,$filename,$item_tagname,
$res=Export::arrayToXml($data,$filename,$item_tagname,
$wrapper_tagname,$encoding);
$this->assertFalse($res);
ob_end_clean();

Loading…
Cancel
Save