Merge branch 'MDL-51603-fixes' of git://github.com/dmonllao/moodle
authorDan Poltawski <dan@moodle.com>
Thu, 21 Apr 2016 08:24:28 +0000 (09:24 +0100)
committerDan Poltawski <dan@moodle.com>
Thu, 21 Apr 2016 08:24:28 +0000 (09:24 +0100)
dataformat/excel/classes/writer.php
dataformat/ods/classes/writer.php
lib/classes/dataformat/spout_base.php
lib/dataformatlib.php
lib/outputrenderers.php
lib/tablelib.php
lib/templates/dataformat_selector.mustache
lib/upgrade.txt
mod/quiz/report/statistics/lang/en/quiz_statistics.php
mod/quiz/report/statistics/report.php
report/log/index.php

index e6454a3..0783e9e 100644 (file)
@@ -46,5 +46,26 @@ class writer extends \core\dataformat\spout_base {
     /** @var $spouttype */
     protected $spouttype = \Box\Spout\Common\Type::XLSX;
 
+    /**
+     * Set the title of the worksheet inside a spreadsheet
+     *
+     * For some formats this will be ignored.
+     *
+     * @param string $title
+     */
+    public function set_sheettitle($title) {
+        if (!$title) {
+            return;
+        }
+
+        // Replace any characters in the name that Excel cannot cope with.
+        $title = strtr(trim($title, "'"), '[]*/\?:', '       ');
+        // Shorten the title if necessary.
+        $title = \core_text::substr($title, 0, 31);
+        // After the substr, we might now have a single quote on the end.
+        $title = trim($title, "'");
+
+        $this->sheettitle = $title;
+    }
 }
 
index 359aaf3..8f28228 100644 (file)
@@ -46,5 +46,26 @@ class writer extends \core\dataformat\spout_base {
     /** @var $spouttype */
     protected $spouttype = \Box\Spout\Common\Type::ODS;
 
+    /**
+     * Set the title of the worksheet inside a spreadsheet
+     *
+     * For some formats this will be ignored.
+     *
+     * @param string $title
+     */
+    public function set_sheettitle($title) {
+        if (!$title) {
+            return;
+        }
+
+        // Replace any characters in the name that ODS cannot cope with.
+        $title = strtr(trim($title, "'"), '[]*/\?:', '       ');
+        // Shorten the title if necessary.
+        $title = \core_text::substr($title, 0, 31);
+        // After the substr, we might now have a single quote on the end.
+        $title = trim($title, "'");
+
+        $this->sheettitle = $title;
+    }
 }
 
index ef085f7..29c8ed4 100644 (file)
@@ -51,6 +51,10 @@ abstract class spout_base extends \core\dataformat\base {
         $this->writer = \Box\Spout\Writer\WriterFactory::create($this->spouttype);
         $filename = $this->filename . $this->get_extension();
         $this->writer->openToBrowser($filename);
+        if ($this->sheettitle) {
+            $sheet = $this->writer->getCurrentSheet();
+            $sheet->setName($this->sheettitle);
+        }
     }
 
     /**
@@ -64,11 +68,7 @@ abstract class spout_base extends \core\dataformat\base {
         if (!$title) {
             return;
         }
-        $title = preg_replace('/[\\\\\/\\?\\*\\[\\]]/', '', $title);
-        $title = substr($title, 0, 31);
         $this->sheettitle = $title;
-        $sheet = $this->writer->getCurrentSheet();
-        $sheet->setName($title);
     }
 
     /**
index f192ef8..36b5173 100644 (file)
@@ -38,8 +38,8 @@
  */
 function download_as_dataformat($filename, $dataformat, $columns, $iterator, $callback = null) {
 
-    if (!NO_OUTPUT_BUFFERING) {
-        throw new coding_exception("NO_OUTPUT_BUFFERING must be set to true before calling download_as_dataformat");
+    if (ob_get_length()) {
+        throw new coding_exception("Output can not be buffered before calling download_as_dataformat");
     }
 
     $classname = 'dataformat_' . $dataformat . '\writer';
index 7495155..845ff1b 100644 (file)
@@ -1893,7 +1893,7 @@ class core_renderer extends renderer_base {
             if ($format->is_enabled()) {
                 $options[] = array(
                     'value' => $format->name,
-                    'label' => get_string('shortname', $format->component),
+                    'label' => get_string('dataformat', $format->component),
                 );
             }
         }
index d33942c..ce3ff20 100644 (file)
@@ -1704,10 +1704,8 @@ class table_dataformat_export_format extends table_default_export_format_parent
     public function __construct(&$table, $dataformat) {
         parent::__construct($table);
 
-        if (!NO_OUTPUT_BUFFERING) {
-            // Ideally this would throw a coding exception but we are more forgiving here due
-            // to the large amount of code already using table_sql.
-            debugging("NO_OUTPUT_BUFFERING should be set to true before downloading", DEBUG_DEVELOPER);
+        if (ob_get_length()) {
+            throw new coding_exception("Output can not be buffered before instantiating table_dataformat_export_format");
         }
 
         $classname = 'dataformat_' . $dataformat . '\writer';
index 96c713a..e961ae1 100644 (file)
     * submit
 }}
 <form method="get" action="{{base}}" class="dataformatselector">
-    <input type="hidden" name="sesskey" value="{{sesskey}}">
-    <label for="downloadtype_{{name}}">{{label}}</label>
-    <select name="{{name}}" id="downloadtype_{{name}}">
-    {{#options}}
-        <option value="{{value}}">{{label}}</option>
-    {{/options}}
-    </select>
-    <input type="submit" value="{{submit}}">
-    {{#params}}
-    <input type="hidden" name="{{name}}" value="{{value}}" />
-    {{/params}}
+    <div class="mdl-align">
+        <input type="hidden" name="sesskey" value="{{sesskey}}">
+        <label for="downloadtype_{{name}}">{{label}}</label>
+        <select name="{{name}}" id="downloadtype_{{name}}">
+        {{#options}}
+            <option value="{{value}}">{{label}}</option>
+        {{/options}}
+        </select>
+        <input type="submit" value="{{submit}}">
+        {{#params}}
+        <input type="hidden" name="{{name}}" value="{{value}}" />
+        {{/params}}
+    </div>
 </form>
index 172d9c2..c912959 100644 (file)
@@ -116,6 +116,7 @@ information provided here is intended especially for developers.
 * behat_util::is_server_running() is removed, please use behat_util::check_server_status() instead.
 * Behat\Mink\Selector\SelectorsHandler::xpathLiteral() method is deprecated use behat_context_helper::escape instead
   when building Xpath, or pass the unescaped value when using the named selector.',
+* table_sql download process is using the new data formats plugin which you can't use if you are buffering any output
 
 === 3.0 ===
 
index dd257ae..ae3928c 100644 (file)
@@ -47,7 +47,7 @@ $string['detailedanalysis'] = 'More detailed analysis of the responses to this q
 $string['detailedanalysisforvariant'] = 'More detailed analysis of the responses to variant {$a} of this question';
 $string['discrimination_index'] = 'Discrimination index';
 $string['discriminative_efficiency'] = 'Discriminative efficiency';
-$string['downloadeverything'] = 'Download full report as {$a->formatsmenu} {$a->downloadbutton}';
+$string['downloadeverything'] = 'Download full report as';
 $string['duration'] = 'Open for';
 $string['effective_weight'] = 'Effective weight';
 $string['errordeleting'] = 'Error deleting old {$a} records.';
index bc194c4..0b8b155 100644 (file)
@@ -667,21 +667,10 @@ class quiz_statistics_report extends quiz_default_report {
      * @return string HTML.
      */
     protected function everything_download_options() {
-        $downloadoptions = $this->table->get_download_menu();
-
-        $downloadelements = new stdClass();
-        $downloadelements->formatsmenu = html_writer::select($downloadoptions, 'download',
-                $this->table->defaultdownloadformat, false);
-        $downloadelements->downloadbutton = '<input type="submit" value="' .
-                get_string('download') . '"/>';
-
-        $output = '<form action="'. $this->table->baseurl .'" method="post">';
-        $output .= '<div class="mdl-align">';
-        $output .= '<input type="hidden" name="everything" value="1"/>';
-        $output .= html_writer::tag('label', get_string('downloadeverything', 'quiz_statistics', $downloadelements));
-        $output .= '</div></form>';
+        global $OUTPUT;
 
-        return $output;
+        return $OUTPUT->download_dataformat_selector(get_string('downloadeverything', 'quiz_statistics'),
+            $this->table->baseurl->out_omit_querystring(), 'download', $this->table->baseurl->params() + array('everything' => 1));
     }
 
     /**
index 79bcff1..d5e00ee 100644 (file)
  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
 
-if (!empty($_GET['download'])) {
-    define('NO_OUTPUT_BUFFERING', true);
-}
-
 require('../../config.php');
 require_once($CFG->dirroot.'/course/lib.php');
 require_once($CFG->dirroot.'/report/log/locallib.php');