[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/lib/classes/dataformat/ -> base.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   * Base class for dataformat.
  19   *
  20   * @package    core
  21   * @subpackage dataformat
  22   * @copyright  2016 Brendan Heywood (brendan@catalyst-au.net)
  23   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   */
  25  
  26  namespace core\dataformat;
  27  
  28  /**
  29   * Base class for dataformat.
  30   *
  31   * @package    core
  32   * @subpackage dataformat
  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  abstract class base {
  37  
  38      /** @var $mimetype */
  39      protected $mimetype = "text/plain";
  40  
  41      /** @var $extension */
  42      protected $extension = ".txt";
  43  
  44      /** @var $filename */
  45      protected $filename = '';
  46  
  47      /**
  48       * Get the file extension
  49       *
  50       * @return string file extension
  51       */
  52      public function get_extension() {
  53          return $this->extension;
  54      }
  55  
  56      /**
  57       * Set download filename base
  58       *
  59       * @param string $filename
  60       */
  61      public function set_filename($filename) {
  62          $this->filename = $filename;
  63      }
  64  
  65      /**
  66       * Set the title of the worksheet inside a spreadsheet
  67       *
  68       * For some formats this will be ignored.
  69       *
  70       * @param string $title
  71       */
  72      public function set_sheettitle($title) {
  73      }
  74  
  75      /**
  76       * Output file headers to initialise the download of the file.
  77       */
  78      public function send_http_headers() {
  79          global $CFG;
  80  
  81          if (defined('BEHAT_SITE_RUNNING')) {
  82              // For text based formats - we cannot test the output with behat if we force a file download.
  83              return;
  84          }
  85          if (is_https()) {
  86              // HTTPS sites - watch out for IE! KB812935 and KB316431.
  87              header('Cache-Control: max-age=10');
  88              header('Pragma: ');
  89          } else {
  90              // Normal http - prevent caching at all cost.
  91              header('Cache-Control: private, must-revalidate, pre-check=0, post-check=0, max-age=0');
  92              header('Pragma: no-cache');
  93          }
  94          header('Expires: '. gmdate('D, d M Y H:i:s', 0) .' GMT');
  95          header("Content-Type: $this->mimetype\n");
  96          $filename = $this->filename . $this->get_extension();
  97          header("Content-Disposition: attachment; filename=\"$filename\"");
  98      }
  99  
 100      /**
 101       * Write the start of the format
 102       *
 103       * @param array $columns
 104       */
 105      public function write_header($columns) {
 106          // Override me if needed.
 107      }
 108  
 109      /**
 110       * Write a single record
 111       *
 112       * @param array $record
 113       * @param int $rownum
 114       */
 115      abstract public function write_record($record, $rownum);
 116  
 117      /**
 118       * Write the end of the format
 119       *
 120       * @param array $columns
 121       */
 122      public function write_footer($columns) {
 123          // Override me if needed.
 124      }
 125  
 126  }


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