mirror of
https://github.com/moodle/moodle.git
synced 2025-03-14 04:30:15 +01:00
Merge branch 'MDL-71685' of https://github.com/paulholden/moodle
This commit is contained in:
commit
d078fe1197
@ -24,7 +24,7 @@
|
||||
|
||||
namespace dataformat_json;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
use core_text;
|
||||
|
||||
/**
|
||||
* JSON data format writer
|
||||
@ -47,6 +47,9 @@ class writer extends \core\dataformat\base {
|
||||
/** @var $sheetdatadded */
|
||||
public $sheetdatadded = false;
|
||||
|
||||
/** @var string[] $columns */
|
||||
protected $columns = [];
|
||||
|
||||
/**
|
||||
* Write the start of the file.
|
||||
*/
|
||||
@ -60,6 +63,10 @@ class writer extends \core\dataformat\base {
|
||||
* @param array $columns
|
||||
*/
|
||||
public function start_sheet($columns) {
|
||||
$this->columns = array_map(function($column) {
|
||||
return core_text::strtolower(clean_param($column, PARAM_ALPHA));
|
||||
}, $columns);
|
||||
|
||||
if ($this->sheetstarted) {
|
||||
echo ",";
|
||||
} else {
|
||||
@ -80,6 +87,8 @@ class writer extends \core\dataformat\base {
|
||||
echo ",";
|
||||
}
|
||||
|
||||
// Ensure our record is keyed by column names, rather than numerically.
|
||||
$record = array_combine($this->columns, (array) $record);
|
||||
echo json_encode($this->format_record($record), JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
|
||||
|
||||
$this->sheetdatadded = true;
|
||||
|
Loading…
x
Reference in New Issue
Block a user