MDL-61135 core_tag: add function get_tags_by_area_in_contexts
[moodle.git] / dataformat / json / classes / writer.php
blob8e3cfbad1dfb65cc533d9ea7be574f1ba96e65cf
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17 /**
18 * JSON data format writer
20 * @package dataformat_json
21 * @copyright 2016 Brendan Heywood (brendan@catalyst-au.net)
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 namespace dataformat_json;
27 defined('MOODLE_INTERNAL') || die();
29 /**
30 * JSON data format writer
32 * @package dataformat_json
33 * @copyright 2016 Brendan Heywood (brendan@catalyst-au.net)
34 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
36 class writer extends \core\dataformat\base {
38 /** @var $mimetype */
39 public $mimetype = "application/json";
41 /** @var $extension */
42 public $extension = ".json";
44 /** @var $sheetstarted */
45 public $sheetstarted = false;
47 /** @var $sheetdatadded */
48 public $sheetdatadded = false;
50 /**
51 * Write the start of the file.
53 public function start_output() {
54 echo "[";
57 /**
58 * Write the start of the sheet we will be adding data to.
60 * @param array $columns
62 public function start_sheet($columns) {
63 if ($this->sheetstarted) {
64 echo ",";
65 } else {
66 $this->sheetstarted = true;
68 $this->sheetdatadded = false;
69 echo "[";
72 /**
73 * Write a single record
75 * @param array $record
76 * @param int $rownum
78 public function write_record($record, $rownum) {
79 if ($this->sheetdatadded) {
80 echo ",";
83 echo json_encode($record);
85 $this->sheetdatadded = true;
88 /**
89 * Write the end of the sheet containing the data.
91 * @param array $columns
93 public function close_sheet($columns) {
94 echo "]";
97 /**
98 * Write the end of the file.
100 public function close_output() {
101 echo "]";