| Server IP : 172.67.187.206 / Your IP : 162.159.115.42 Web Server : Apache/2.4.25 (Win32) OpenSSL/1.0.2j PHP/5.6.30 System : Windows NT WIN-ECQAAA40806 6.2 build 9200 (Windows Server 2012 Standard Edition) i586 User : SYSTEM ( 0) PHP Version : 5.6.30 Disable Function : NONE MySQL : ON | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : E:/Inetpub/www/myschool/triamudom/tuprblearn/dataformat/json/classes/ |
Upload File : |
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* JSON data format writer
*
* @package dataformat_json
* @copyright 2016 Brendan Heywood ([email protected])
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace dataformat_json;
defined('MOODLE_INTERNAL') || die();
/**
* JSON data format writer
*
* @package dataformat_json
* @copyright 2016 Brendan Heywood ([email protected])
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class writer extends \core\dataformat\base {
/** @var $mimetype */
public $mimetype = "application/json";
/** @var $extension */
public $extension = ".json";
/** @var $sheetstarted */
public $sheetstarted = false;
/** @var $sheetdatadded */
public $sheetdatadded = false;
/**
* Write the start of the file.
*/
public function start_output() {
echo "[";
}
/**
* Write the start of the sheet we will be adding data to.
*
* @param array $columns
*/
public function start_sheet($columns) {
if ($this->sheetstarted) {
echo ",";
} else {
$this->sheetstarted = true;
}
$this->sheetdatadded = false;
echo "[";
}
/**
* Write a single record
*
* @param array $record
* @param int $rownum
*/
public function write_record($record, $rownum) {
if ($this->sheetdatadded) {
echo ",";
}
echo json_encode($record, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
$this->sheetdatadded = true;
}
/**
* Write the end of the sheet containing the data.
*
* @param array $columns
*/
public function close_sheet($columns) {
echo "]";
}
/**
* Write the end of the file.
*/
public function close_output() {
echo "]";
}
}