Skip to content

Commit

Permalink
Merge pull request #5853 from christianbeeznest/matra-22096
Browse files Browse the repository at this point in the history
Session: Add batch session export to CSV - refs BT#22096
  • Loading branch information
NicoDucou authored Dec 4, 2024
2 parents 88c7bb9 + 248d6fd commit bd524b1
Show file tree
Hide file tree
Showing 24 changed files with 1,885 additions and 1,349 deletions.
Binary file added public/img/copy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/img/icons/32/attendance_list.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/img/icons/32/scorms.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/img/icons/32/scorms_na.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/img/icons/32/security.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/img/icons/32/security_na.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/img/icons/32/tools.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/img/icons/32/tools_na.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/img/icons/32/user.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/img/icons/32/user_na.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/img/save_pack.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1,318 changes: 1,318 additions & 0 deletions public/main/inc/lib/TrackingCourseLog.php

Large diffs are not rendered by default.

44 changes: 3 additions & 41 deletions public/main/inc/lib/exercise.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -3000,47 +3000,9 @@ public static function get_all_exercises(

$repo = Container::getQuizRepository();

return $repo->findAllByCourse($course, $session, (string) $search, $active);

// Show courses by active status
/*if (true == $search_all_sessions) {
$conditions = [
'where' => [
$active_sql.' c_id = ? '.$needle_where.$timeConditions => [
$course_id,
$needle,
],
],
'order' => 'title',
];
} else {
if (empty($session_id)) {
$conditions = [
'where' => [
$active_sql.' (session_id = 0 OR session_id IS NULL) AND c_id = ? '.$needle_where.$timeConditions => [
$course_id,
$needle,
],
],
'order' => 'title',
];
} else {
$conditions = [
'where' => [
$active_sql.' (session_id = 0 OR session_id IS NULL OR session_id = ? ) AND c_id = ? '.$needle_where.$timeConditions => [
$session_id,
$course_id,
$needle,
],
],
'order' => 'title',
];
}
}
$table = Database::get_course_table(TABLE_QUIZ_TEST);
return Database::select('*', $table, $conditions);*/
return $repo->findAllByCourse($course, $session, (string) $search, $active)
->getQuery()
->getResult();
}

/**
Expand Down
45 changes: 39 additions & 6 deletions public/main/inc/lib/export.lib.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,9 @@ public function __construct()
/**
* Export tabular data to CSV-file.
*
* @param array $data
* @param string $filename
* @param bool $writeOnly Whether to only write on disk or also send for download
* @param string $enclosure
*
* @return mixed csv raw data | false if no data to export | string file path if success in $writeOnly mode
*/
public static function arrayToCsv($data, $filename = 'export', $writeOnly = false, $enclosure = '"')
public static function arrayToCsv(array $data, string $filename = 'export', bool $writeOnly = false, string $enclosure = '"')
{
if (empty($data)) {
return false;
Expand All @@ -55,6 +50,44 @@ public static function arrayToCsv($data, $filename = 'export', $writeOnly = fals
return $filePath;
}

/**
* Converts an array of data into a CSV file and optionally sends it for download.
*
* @return string|void Returns the file path if $writeOnly is true, otherwise sends the file for download and exits.
*/
public static function arrayToCsvSimple(array $data, string $filename = 'export', bool $writeOnly = false)
{
$file = api_get_path(SYS_ARCHIVE_PATH) . uniqid('') . '.csv';

$handle = fopen($file, 'w');

if ($handle === false) {
throw new \RuntimeException("Unable to create or open the file: $file");
}

if (is_array($data)) {
foreach ($data as $row) {
$line = '';
if (is_array($row)) {
foreach ($row as $value) {
$line .= '"' . str_replace('"', '""', (string)$value) . '";';
}
}
fwrite($handle, rtrim($line, ';') . "\n");
}
}

fclose($handle);

if (!$writeOnly) {
DocumentManager::file_send_for_download($file, true, $filename . '.csv');
unlink($file);
exit;
}

return $file;
}

/**
* Export tabular data to XLS-file.
*/
Expand Down
34 changes: 24 additions & 10 deletions public/main/inc/lib/extra_field_value.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,10 @@ public function saveFieldValues(

$tags = [];
foreach ($tagValues as $tagValue) {
if (is_array($tagValue)) {
$tagValue = reset($tagValue);
}

if (empty($tagValue)) {
continue;
}
Expand Down Expand Up @@ -338,16 +342,26 @@ public function saveFieldValues(

break;
case ExtraField::FIELD_TYPE_DATE:
$d = DateTime::createFromFormat('Y-m-d', $value);
$valid = $d && $d->format('Y-m-d') === $value;
if ($valid) {
$newParams = [
'item_id' => $params['item_id'],
'field_id' => $extraFieldInfo['id'],
'field_value' => $value,
'comment' => $comment,
];
$this->save($newParams, $showQuery);
if (is_array($value)) {
if (empty($value)) {
break;
}
$value = reset($value);
}

if (is_string($value) && !empty($value)) {
$d = DateTime::createFromFormat('Y-m-d', $value);
$valid = $d && $d->format('Y-m-d') === $value;

if ($valid) {
$newParams = [
'item_id' => $params['item_id'],
'field_id' => $extraFieldInfo['id'],
'field_value' => $value,
'comment' => $comment,
];
$this->save($newParams, $showQuery);
}
}
break;
case ExtraField::FIELD_TYPE_DATETIME:
Expand Down
Loading

0 comments on commit bd524b1

Please sign in to comment.