mirror of
https://github.com/moodle/moodle.git
synced 2025-08-10 11:26:41 +02:00
Merge branch 'MDL-71685' of https://github.com/paulholden/moodle
This commit is contained in:
commit
d078fe1197
1 changed files with 10 additions and 1 deletions
|
@ -24,7 +24,7 @@
|
||||||
|
|
||||||
namespace dataformat_json;
|
namespace dataformat_json;
|
||||||
|
|
||||||
defined('MOODLE_INTERNAL') || die();
|
use core_text;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* JSON data format writer
|
* JSON data format writer
|
||||||
|
@ -47,6 +47,9 @@ class writer extends \core\dataformat\base {
|
||||||
/** @var $sheetdatadded */
|
/** @var $sheetdatadded */
|
||||||
public $sheetdatadded = false;
|
public $sheetdatadded = false;
|
||||||
|
|
||||||
|
/** @var string[] $columns */
|
||||||
|
protected $columns = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write the start of the file.
|
* Write the start of the file.
|
||||||
*/
|
*/
|
||||||
|
@ -60,6 +63,10 @@ class writer extends \core\dataformat\base {
|
||||||
* @param array $columns
|
* @param array $columns
|
||||||
*/
|
*/
|
||||||
public function start_sheet($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) {
|
if ($this->sheetstarted) {
|
||||||
echo ",";
|
echo ",";
|
||||||
} else {
|
} else {
|
||||||
|
@ -80,6 +87,8 @@ class writer extends \core\dataformat\base {
|
||||||
echo ",";
|
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);
|
echo json_encode($this->format_record($record), JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
|
||||||
|
|
||||||
$this->sheetdatadded = true;
|
$this->sheetdatadded = true;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue