Merge branch 'MDL-51603-fixes' of git://github.com/dmonllao/moodle

This commit is contained in:
Dan Poltawski 2016-04-21 09:24:28 +01:00
commit 2b311b2d3e
11 changed files with 69 additions and 41 deletions

View file

@ -46,5 +46,26 @@ class writer extends \core\dataformat\spout_base {
/** @var $spouttype */ /** @var $spouttype */
protected $spouttype = \Box\Spout\Common\Type::XLSX; 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;
}
} }

View file

@ -46,5 +46,26 @@ class writer extends \core\dataformat\spout_base {
/** @var $spouttype */ /** @var $spouttype */
protected $spouttype = \Box\Spout\Common\Type::ODS; 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;
}
} }

View file

@ -51,6 +51,10 @@ abstract class spout_base extends \core\dataformat\base {
$this->writer = \Box\Spout\Writer\WriterFactory::create($this->spouttype); $this->writer = \Box\Spout\Writer\WriterFactory::create($this->spouttype);
$filename = $this->filename . $this->get_extension(); $filename = $this->filename . $this->get_extension();
$this->writer->openToBrowser($filename); $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) { if (!$title) {
return; return;
} }
$title = preg_replace('/[\\\\\/\\?\\*\\[\\]]/', '', $title);
$title = substr($title, 0, 31);
$this->sheettitle = $title; $this->sheettitle = $title;
$sheet = $this->writer->getCurrentSheet();
$sheet->setName($title);
} }
/** /**

View file

@ -38,8 +38,8 @@
*/ */
function download_as_dataformat($filename, $dataformat, $columns, $iterator, $callback = null) { function download_as_dataformat($filename, $dataformat, $columns, $iterator, $callback = null) {
if (!NO_OUTPUT_BUFFERING) { if (ob_get_length()) {
throw new coding_exception("NO_OUTPUT_BUFFERING must be set to true before calling download_as_dataformat"); throw new coding_exception("Output can not be buffered before calling download_as_dataformat");
} }
$classname = 'dataformat_' . $dataformat . '\writer'; $classname = 'dataformat_' . $dataformat . '\writer';

View file

@ -1893,7 +1893,7 @@ class core_renderer extends renderer_base {
if ($format->is_enabled()) { if ($format->is_enabled()) {
$options[] = array( $options[] = array(
'value' => $format->name, 'value' => $format->name,
'label' => get_string('shortname', $format->component), 'label' => get_string('dataformat', $format->component),
); );
} }
} }

View file

@ -1704,10 +1704,8 @@ class table_dataformat_export_format extends table_default_export_format_parent
public function __construct(&$table, $dataformat) { public function __construct(&$table, $dataformat) {
parent::__construct($table); parent::__construct($table);
if (!NO_OUTPUT_BUFFERING) { if (ob_get_length()) {
// Ideally this would throw a coding exception but we are more forgiving here due throw new coding_exception("Output can not be buffered before instantiating table_dataformat_export_format");
// to the large amount of code already using table_sql.
debugging("NO_OUTPUT_BUFFERING should be set to true before downloading", DEBUG_DEVELOPER);
} }
$classname = 'dataformat_' . $dataformat . '\writer'; $classname = 'dataformat_' . $dataformat . '\writer';

View file

@ -30,15 +30,17 @@
* submit * submit
}} }}
<form method="get" action="{{base}}" class="dataformatselector"> <form method="get" action="{{base}}" class="dataformatselector">
<input type="hidden" name="sesskey" value="{{sesskey}}"> <div class="mdl-align">
<label for="downloadtype_{{name}}">{{label}}</label> <input type="hidden" name="sesskey" value="{{sesskey}}">
<select name="{{name}}" id="downloadtype_{{name}}"> <label for="downloadtype_{{name}}">{{label}}</label>
{{#options}} <select name="{{name}}" id="downloadtype_{{name}}">
<option value="{{value}}">{{label}}</option> {{#options}}
{{/options}} <option value="{{value}}">{{label}}</option>
</select> {{/options}}
<input type="submit" value="{{submit}}"> </select>
{{#params}} <input type="submit" value="{{submit}}">
<input type="hidden" name="{{name}}" value="{{value}}" /> {{#params}}
{{/params}} <input type="hidden" name="{{name}}" value="{{value}}" />
{{/params}}
</div>
</form> </form>

View 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_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 * 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.', 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 === === 3.0 ===

View 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['detailedanalysisforvariant'] = 'More detailed analysis of the responses to variant {$a} of this question';
$string['discrimination_index'] = 'Discrimination index'; $string['discrimination_index'] = 'Discrimination index';
$string['discriminative_efficiency'] = 'Discriminative efficiency'; $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['duration'] = 'Open for';
$string['effective_weight'] = 'Effective weight'; $string['effective_weight'] = 'Effective weight';
$string['errordeleting'] = 'Error deleting old {$a} records.'; $string['errordeleting'] = 'Error deleting old {$a} records.';

View file

@ -667,21 +667,10 @@ class quiz_statistics_report extends quiz_default_report {
* @return string HTML. * @return string HTML.
*/ */
protected function everything_download_options() { protected function everything_download_options() {
$downloadoptions = $this->table->get_download_menu(); global $OUTPUT;
$downloadelements = new stdClass(); return $OUTPUT->download_dataformat_selector(get_string('downloadeverything', 'quiz_statistics'),
$downloadelements->formatsmenu = html_writer::select($downloadoptions, 'download', $this->table->baseurl->out_omit_querystring(), 'download', $this->table->baseurl->params() + array('everything' => 1));
$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>';
return $output;
} }
/** /**

View file

@ -22,10 +22,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @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('../../config.php');
require_once($CFG->dirroot.'/course/lib.php'); require_once($CFG->dirroot.'/course/lib.php');
require_once($CFG->dirroot.'/report/log/locallib.php'); require_once($CFG->dirroot.'/report/log/locallib.php');