Skip to content

Commit

Permalink
MDL-56046 dataformat_*: convert core plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
mdjnelson committed Jun 26, 2017
1 parent f72bc10 commit 4ba0709
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 15 deletions.
31 changes: 21 additions & 10 deletions dataformat/html/classes/writer.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,9 @@ class writer extends \core\dataformat\base {
public $extension = ".html";

/**
* Write the start of the format
*
* @param array $columns
* Write the start of the output
*/
public function write_header($columns) {
public function start_output() {
echo "<!DOCTYPE html><html>";
echo \html_writer::tag('title', $this->filename);
echo "<style>
Expand Down Expand Up @@ -75,9 +73,16 @@ public function write_header($columns) {
margin: auto;
}
</style>
<body>
<table border=1 cellspacing=0 cellpadding=3>
";
<body>";
}

/**
* Write the start of the sheet we will be adding data to.
*
* @param array $columns
*/
public function start_sheet($columns) {
echo "<table border=1 cellspacing=0 cellpadding=3>";
echo \html_writer::start_tag('tr');
foreach ($columns as $k => $v) {
echo \html_writer::tag('th', $v);
Expand All @@ -100,12 +105,18 @@ public function write_record($record, $rownum) {
}

/**
* Write the end of the format
* Write the end of the sheet containing the data.
*
* @param array $columns
*/
public function write_footer($columns) {
echo "</table></body></html>";
public function close_sheet($columns) {
echo "</table>";
}

/**
* Write the end of the sheet containing the data.
*/
public function close_output() {
echo "</body></html>";
}
}
38 changes: 33 additions & 5 deletions dataformat/json/classes/writer.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,31 @@ class writer extends \core\dataformat\base {
/** @var $extension */
public $extension = ".json";

/** @var $hasstarted */
public $sheetstarted = false;

/** @var $sheetdatadded */
public $sheetdatadded = false;

/**
* Write the start of the file.
*/
public function start_output() {
echo "[";
}

/**
* Write the start of the format
* Write the start of the sheet we will be adding data to.
*
* @param array $columns
*/
public function write_header($columns) {
public function start_sheet($columns) {
if ($this->sheetstarted) {
echo ",";
} else {
$this->sheetstarted = true;
}
$this->sheetdatadded = false;
echo "[";
}

Expand All @@ -57,19 +76,28 @@ public function write_header($columns) {
* @param int $rownum
*/
public function write_record($record, $rownum) {
if ($rownum) {
if ($this->sheetdatadded) {
echo ",";
}

echo json_encode($record);

$this->sheetdatadded = true;
}

/**
* Write the end of the format
* Write the end of the sheet containing the data.
*
* @param array $columns
*/
public function write_footer($columns) {
public function close_sheet($columns) {
echo "]";
}

/**
* Write the end of the file.
*/
public function close_output() {
echo "]";
}
}

0 comments on commit 4ba0709

Please sign in to comment.