[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/dataformat/json/classes/ -> writer.php (source)

   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.
  13  //
  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/>.
  16  
  17  /**
  18   * JSON data format writer
  19   *
  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
  23   */
  24  
  25  namespace dataformat_json;
  26  
  27  defined('MOODLE_INTERNAL') || die();
  28  
  29  /**
  30   * JSON data format writer
  31   *
  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
  35   */
  36  class writer extends \core\dataformat\base {
  37  
  38      /** @var $mimetype */
  39      public $mimetype = "application/json";
  40  
  41      /** @var $extension */
  42      public $extension = ".json";
  43  
  44      /**
  45       * Write the start of the format
  46       *
  47       * @param array $columns
  48       */
  49      public function write_header($columns) {
  50          echo "[";
  51      }
  52  
  53      /**
  54       * Write a single record
  55       *
  56       * @param array $record
  57       * @param int $rownum
  58       */
  59      public function write_record($record, $rownum) {
  60          if ($rownum) {
  61              echo ",";
  62          }
  63          echo json_encode($record);
  64      }
  65  
  66      /**
  67       * Write the end of the format
  68       *
  69       * @param array $columns
  70       */
  71      public function write_footer($columns) {
  72          echo "]";
  73      }
  74  
  75  }


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1