MDL-51603 dataformat: Implement streaming dataformat plugin

This commit is contained in:
Brendan Heywood
2016-04-20 12:39:25 +10:00
parent b4772a41d1
commit bff1edbe44
34 changed files with 1461 additions and 5 deletions
+82
View File
@@ -0,0 +1,82 @@
<?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/>.
/**
* Lets users manage data formats
*
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
* @copyright 2016 Brendan Heywood ([email protected])
* @package core
* @subpackage dataformat
*/
require_once('../config.php');
require_once($CFG->libdir.'/adminlib.php');
$action = required_param('action', PARAM_ALPHANUMEXT);
$name = required_param('name', PARAM_PLUGIN);
$syscontext = context_system::instance();
$PAGE->set_url('/admin/dataformats.php');
$PAGE->set_context($syscontext);
require_login();
require_capability('moodle/site:config', $syscontext);
require_sesskey();
$return = new moodle_url('/admin/settings.php', array('section' => 'managedataformats'));
$plugins = core_plugin_manager::instance()->get_plugins_of_type('dataformat');
$sortorder = array_flip(array_keys($plugins));
if (!isset($plugins[$name])) {
print_error('courseformatnotfound', 'error', $return, $name);
}
switch ($action) {
case 'disable':
if ($plugins[$name]->is_enabled()) {
set_config('disabled', 1, 'dataformat_'. $name);
core_plugin_manager::reset_caches();
}
break;
case 'enable':
if (!$plugins[$name]->is_enabled()) {
unset_config('disabled', 'dataformat_'. $name);
core_plugin_manager::reset_caches();
}
break;
case 'up':
if ($sortorder[$name]) {
$currentindex = $sortorder[$name];
$seq = array_keys($plugins);
$seq[$currentindex] = $seq[$currentindex - 1];
$seq[$currentindex - 1] = $name;
set_config('dataformat_plugins_sortorder', implode(',', $seq));
}
break;
case 'down':
if ($sortorder[$name] < count($sortorder) - 1) {
$currentindex = $sortorder[$name];
$seq = array_keys($plugins);
$seq[$currentindex] = $seq[$currentindex + 1];
$seq[$currentindex + 1] = $name;
set_config('dataformat_plugins_sortorder', implode(',', $seq));
}
break;
}
redirect($return);
+2
View File
@@ -1647,6 +1647,8 @@
</PHP_EXTENSION>
<PHP_EXTENSION name="xml" level="required">
</PHP_EXTENSION>
<PHP_EXTENSION name="xmlreader" level="required">
</PHP_EXTENSION>
<PHP_EXTENSION name="intl" level="optional">
<FEEDBACK>
<ON_CHECK message="intlrecommended" />
+5
View File
@@ -187,6 +187,11 @@ if ($hassiteconfig) {
$plugin->load_settings($ADMIN, 'filtersettings', $hassiteconfig);
}
// Data format settings.
$ADMIN->add('modules', new admin_category('dataformatsettings', new lang_string('dataformats')));
$temp = new admin_settingpage('managedataformats', new lang_string('managedataformats'));
$temp->add(new admin_setting_managedataformats());
$ADMIN->add('dataformatsettings', $temp);
//== Portfolio settings ==
require_once($CFG->libdir. '/portfoliolib.php');
+50
View File
@@ -0,0 +1,50 @@
<?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/>.
/**
* CSV data format writer
*
* @package dataformat_csv
* @copyright 2016 Brendan Heywood ([email protected])
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace dataformat_csv;
require_once("$CFG->libdir/spout/src/Spout/Autoloader/autoload.php");
defined('MOODLE_INTERNAL') || die();
/**
* CSV data format writer
*
* @package dataformat_csv
* @copyright 2016 Brendan Heywood ([email protected])
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class writer extends \core\dataformat\spout_base {
/** @var $mimetype */
protected $mimetype = "text/csv";
/** @var $extension */
protected $extension = ".csv";
/** @var $spouttype */
protected $spouttype = \Box\Spout\Common\Type::CSV;
}
+27
View File
@@ -0,0 +1,27 @@
<?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/>.
/**
* CSV dataformat lang strings.
*
* @package dataformat_csv
* @copyright 2016 Brendan Heywood ([email protected])
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string['dataformat'] = 'Comma separated values (.csv)';
$string['shortname'] = 'CSV';
+30
View File
@@ -0,0 +1,30 @@
<?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/>.
/**
* Data activity filter version information
*
* @package dataformat_csv
* @copyright 2016 Brendan Heywood ([email protected])
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2016031700;
$plugin->requires = 2016031700; // Requires this Moodle version.
$plugin->component = 'dataformat_csv';
+50
View File
@@ -0,0 +1,50 @@
<?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/>.
/**
* Excel data format writer
*
* @package dataformat_excel
* @copyright 2016 Brendan Heywood ([email protected])
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace dataformat_excel;
require_once("$CFG->libdir/spout/src/Spout/Autoloader/autoload.php");
defined('MOODLE_INTERNAL') || die();
/**
* Excel data format writer
*
* @package dataformat_excel
* @copyright 2016 Brendan Heywood ([email protected])
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class writer extends \core\dataformat\spout_base {
/** @var $mimetype */
protected $mimetype = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
/** @var $extension */
protected $extension = ".xlsx";
/** @var $spouttype */
protected $spouttype = \Box\Spout\Common\Type::XLSX;
}
@@ -0,0 +1,27 @@
<?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/>.
/**
* Excel dataformat lang strings.
*
* @package dataformat_excel
* @copyright 2016 Brendan Heywood ([email protected])
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string['dataformat'] = 'Microsoft Excel (.xlsx)';
$string['shortname'] = 'Excel';
+30
View File
@@ -0,0 +1,30 @@
<?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/>.
/**
* Data activity filter version information
*
* @package dataformat_excel
* @copyright 2016 Brendan Heywood ([email protected])
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2016031700;
$plugin->requires = 2016031700; // Requires this Moodle version.
$plugin->component = 'dataformat_excel';
+111
View File
@@ -0,0 +1,111 @@
<?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/>.
/**
* html data format writer
*
* @package dataformat_html
* @copyright 2016 Brendan Heywood ([email protected])
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace dataformat_html;
defined('MOODLE_INTERNAL') || die();
/**
* html data format writer
*
* @package dataformat_html
* @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 = "text/html";
/** @var $extension */
public $extension = ".html";
/**
* Write the start of the format
*
* @param array $columns
*/
public function write_header($columns) {
echo "<!DOCTYPE html><html>";
echo \html_writer::tag('title', $this->filename);
echo "<style>
html, body {
margin: 0;
padding: 0;
font-family: sans-serif;
font-size: 13px;
background: #eee;
}
th {
border: solid 1px #999;
background: #eee;
}
td {
border: solid 1px #999;
background: #fff;
}
tr:hover td {
background: #eef;
}
table {
border-collapse: collapse;
border-spacing: 0pt;
width: 80%;
margin: auto;
}
</style>
<body>
<table border=1 cellspacing=0 cellpadding=3>
";
echo \html_writer::start_tag('tr');
foreach ($columns as $k => $v) {
echo \html_writer::tag('th', $v);
}
echo \html_writer::end_tag('tr');
}
/**
* Write a single record
*
* @param array $record
* @param int $rownum
*/
public function write_record($record, $rownum) {
echo \html_writer::start_tag('tr');
foreach ($record as $cell) {
echo \html_writer::tag('td', $cell);
}
echo \html_writer::end_tag('tr');
}
/**
* Write the end of the format
*
* @param array $columns
*/
public function write_footer($columns) {
echo "</table></body></html>";
}
}
@@ -0,0 +1,27 @@
<?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/>.
/**
* html dataformat lang strings.
*
* @package dataformat_html
* @copyright 2016 Brendan Heywood ([email protected])
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string['dataformat'] = 'HTML table';
$string['shortname'] = 'HTML';
+29
View File
@@ -0,0 +1,29 @@
<?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/>.
/**
* Data activity filter version information
*
* @package dataformat_html
* @copyright 2016 Brendan Heywood ([email protected])
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2016031700;
$plugin->requires = 2016031700; // Requires this Moodle version.
$plugin->component = 'dataformat_html';
+75
View File
@@ -0,0 +1,75 @@
<?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";
/**
* Write the start of the format
*
* @param array $columns
*/
public function write_header($columns) {
echo "[";
}
/**
* Write a single record
*
* @param array $record
* @param int $rownum
*/
public function write_record($record, $rownum) {
if ($rownum) {
echo ",";
}
echo json_encode($record);
}
/**
* Write the end of the format
*
* @param array $columns
*/
public function write_footer($columns) {
echo "]";
}
}
@@ -0,0 +1,27 @@
<?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 dataformat lang strings.
*
* @package dataformat_json
* @copyright 2016 Brendan Heywood ([email protected])
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string['dataformat'] = 'Javascript Object Notation (.json)';
$string['shortname'] = 'JSON';
+29
View File
@@ -0,0 +1,29 @@
<?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/>.
/**
* Data activity filter version information
*
* @package dataformat_json
* @copyright 2016 Brendan Heywood ([email protected])
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2016031700;
$plugin->requires = 2016031700; // Requires this Moodle version.
$plugin->component = 'dataformat_json';
+50
View File
@@ -0,0 +1,50 @@
<?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/>.
/**
* ODS data format writer
*
* @package dataformat_ods
* @copyright 2016 Brendan Heywood ([email protected])
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace dataformat_ods;
require_once("$CFG->libdir/spout/src/Spout/Autoloader/autoload.php");
defined('MOODLE_INTERNAL') || die();
/**
* ODS data format writer
*
* @package dataformat_ods
* @copyright 2016 Brendan Heywood ([email protected])
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class writer extends \core\dataformat\spout_base {
/** @var $mimetype */
protected $mimetype = "application/vnd.oasis.opendocument.spreadsheet";
/** @var $extension */
protected $extension = ".ods";
/** @var $spouttype */
protected $spouttype = \Box\Spout\Common\Type::ODS;
}
+27
View File
@@ -0,0 +1,27 @@
<?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/>.
/**
* ODS dataformat lang strings.
*
* @package dataformat_ods
* @copyright 2016 Brendan Heywood ([email protected])
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string['dataformat'] = 'OpenDocument (.ods)';
$string['shortname'] = 'OpenDoc';
+30
View File
@@ -0,0 +1,30 @@
<?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/>.
/**
* Data activity filter version information
*
* @package dataformat_ods
* @copyright 2016 Brendan Heywood ([email protected])
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2016031700;
$plugin->requires = 2016031700; // Requires this Moodle version.
$plugin->component = 'dataformat_ods';
+7
View File
@@ -0,0 +1,7 @@
This files describes API changes in /dataformat/ download system,
information provided here is intended especially for developers.
=== 3.1 ===
* Added new plugin system with low memory support for csv, ods, xls and json
+2
View File
@@ -431,6 +431,7 @@ $string['databaseupgradeblocks'] = 'Blocks version is now {$a}';
$string['databaseupgradegroups'] = 'Groups version is now {$a}';
$string['databaseupgradelocal'] = 'Local database customisations version is now {$a}';
$string['databaseupgrades'] = 'Upgrading database';
$string['dataformats'] = 'Data formats';
$string['date'] = 'Date';
$string['datechanged'] = 'Date changed';
$string['datemostrecentfirst'] = 'Date - most recent first';
@@ -1088,6 +1089,7 @@ $string['makethismyhome'] = 'Make this my default home page';
$string['manageblocks'] = 'Blocks';
$string['managecategorythis'] = 'Manage this category';
$string['managecourses'] = 'Manage courses';
$string['managedataformats'] = 'Manage data formats';
$string['managedatabase'] = 'Database';
$string['manageeditorfiles'] = 'Manage files used by editor';
$string['managefilters'] = 'Filters';
+2
View File
@@ -121,6 +121,8 @@ $string['type_calendartype'] = 'Calendar type';
$string['type_calendartype_plural'] = 'Calendar types';
$string['type_coursereport'] = 'Course report';
$string['type_coursereport_plural'] = 'Course reports';
$string['type_dataformat'] = 'Data format';
$string['type_dataformat_plural'] = 'Data formats';
$string['type_editor'] = 'Editor';
$string['type_editor_plural'] = 'Editors';
$string['type_enrol'] = 'Enrolment method';
+159
View File
@@ -6916,6 +6916,165 @@ class admin_setting_manageformats extends admin_setting {
}
}
/**
* Data formats manager. Allow reorder and to enable/disable data formats and jump to settings
*
* @copyright 2016 Brendan Heywood (brendan@catalyst-au.net)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class admin_setting_managedataformats extends admin_setting {
/**
* Calls parent::__construct with specific arguments
*/
public function __construct() {
$this->nosave = true;
parent::__construct('managedataformats', new lang_string('managedataformats'), '', '');
}
/**
* Always returns true
*
* @return true
*/
public function get_setting() {
return true;
}
/**
* Always returns true
*
* @return true
*/
public function get_defaultsetting() {
return true;
}
/**
* Always returns '' and doesn't write anything
*
* @param mixed $data string or array, must not be NULL
* @return string Always returns ''
*/
public function write_setting($data) {
// Do not write any setting.
return '';
}
/**
* Search to find if Query is related to format plugin
*
* @param string $query The string to search for
* @return bool true for related false for not
*/
public function is_related($query) {
if (parent::is_related($query)) {
return true;
}
$formats = core_plugin_manager::instance()->get_plugins_of_type('dataformat');
foreach ($formats as $format) {
if (strpos($format->component, $query) !== false ||
strpos(core_text::strtolower($format->displayname), $query) !== false) {
return true;
}
}
return false;
}
/**
* Return XHTML to display control
*
* @param mixed $data Unused
* @param string $query
* @return string highlight
*/
public function output_html($data, $query='') {
global $CFG, $OUTPUT;
$return = '';
$formats = core_plugin_manager::instance()->get_plugins_of_type('dataformat');
$txt = get_strings(array('settings', 'name', 'enable', 'disable', 'up', 'down', 'default'));
$txt->uninstall = get_string('uninstallplugin', 'core_admin');
$txt->updown = "$txt->up/$txt->down";
$table = new html_table();
$table->head = array($txt->name, $txt->enable, $txt->updown, $txt->uninstall, $txt->settings);
$table->align = array('left', 'center', 'center', 'center', 'center');
$table->attributes['class'] = 'manageformattable generaltable admintable';
$table->data = array();
$cnt = 0;
$spacer = $OUTPUT->pix_icon('spacer', '', 'moodle', array('class' => 'iconsmall'));
$totalenabled = 0;
foreach ($formats as $format) {
if ($format->is_enabled() && $format->is_installed_and_upgraded()) {
$totalenabled++;
}
}
foreach ($formats as $format) {
$status = $format->get_status();
$url = new moodle_url('/admin/dataformats.php',
array('sesskey' => sesskey(), 'name' => $format->name));
$class = '';
if ($format->is_enabled()) {
$strformatname = $format->displayname;
if ($totalenabled == 1&& $format->is_enabled()) {
$hideshow = '';
} else {
$hideshow = html_writer::link($url->out(false, array('action' => 'disable')),
$OUTPUT->pix_icon('t/hide', $txt->disable, 'moodle', array('class' => 'iconsmall')));
}
} else {
$class = 'dimmed_text';
$strformatname = $format->displayname;
$hideshow = html_writer::link($url->out(false, array('action' => 'enable')),
$OUTPUT->pix_icon('t/show', $txt->enable, 'moodle', array('class' => 'iconsmall')));
}
$updown = '';
if ($cnt) {
$updown .= html_writer::link($url->out(false, array('action' => 'up')),
$OUTPUT->pix_icon('t/up', $txt->up, 'moodle', array('class' => 'iconsmall'))). '';
} else {
$updown .= $spacer;
}
if ($cnt < count($formats) - 1) {
$updown .= '&nbsp;'.html_writer::link($url->out(false, array('action' => 'down')),
$OUTPUT->pix_icon('t/down', $txt->down, 'moodle', array('class' => 'iconsmall')));
} else {
$updown .= $spacer;
}
$uninstall = '';
if ($status === core_plugin_manager::PLUGIN_STATUS_MISSING) {
$uninstall = get_string('status_missing', 'core_plugin');
} else if ($status === core_plugin_manager::PLUGIN_STATUS_NEW) {
$uninstall = get_string('status_new', 'core_plugin');
} else if ($uninstallurl = core_plugin_manager::instance()->get_uninstall_url('dataformat_'.$format->name, 'manage')) {
if ($totalenabled != 1 || !$format->is_enabled()) {
$uninstall = html_writer::link($uninstallurl, $txt->uninstall);
}
}
$settings = '';
if ($format->get_settings_url()) {
$settings = html_writer::link($format->get_settings_url(), $txt->settings);
}
$row = new html_table_row(array($strformatname, $hideshow, $updown, $uninstall, $settings));
if ($class) {
$row->attributes['class'] = $class;
}
$table->data[] = $row;
$cnt++;
}
$return .= html_writer::table($table);
return highlight($query, $return);
}
}
/**
* Special class for filter administration.
*
+2
View File
@@ -357,6 +357,7 @@ $cache = '.var_export($cache, true).';
'countries' => null,
'course' => $CFG->dirroot.'/course',
'currencies' => null,
'dataformat' => $CFG->dirroot.'/dataformat',
'dbtransfer' => null,
'debug' => null,
'editor' => $CFG->dirroot.'/lib/editor',
@@ -430,6 +431,7 @@ $cache = '.var_export($cache, true).';
'filter' => $CFG->dirroot.'/filter',
'editor' => $CFG->dirroot.'/lib/editor',
'format' => $CFG->dirroot.'/course/format',
'dataformat' => $CFG->dirroot.'/dataformat',
'profilefield' => $CFG->dirroot.'/user/profile/field',
'report' => $CFG->dirroot.'/report',
'coursereport' => $CFG->dirroot.'/course/report', // Must be after system reports.
+126
View File
@@ -0,0 +1,126 @@
<?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/>.
/**
* Base class for dataformat.
*
* @package core
* @subpackage dataformat
* @copyright 2016 Brendan Heywood ([email protected])
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core\dataformat;
/**
* Base class for dataformat.
*
* @package core
* @subpackage dataformat
* @copyright 2016 Brendan Heywood ([email protected])
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
abstract class base {
/** @var $mimetype */
protected $mimetype = "text/plain";
/** @var $extension */
protected $extension = ".txt";
/** @var $filename */
protected $filename = '';
/**
* Get the file extension
*
* @return string file extension
*/
public function get_extension() {
return $this->extension;
}
/**
* Set download filename base
*
* @param string $filename
*/
public function set_filename($filename) {
$this->filename = $filename;
}
/**
* Set the title of the worksheet inside a spreadsheet
*
* For some formats this will be ignored.
*
* @param string $title
*/
public function set_sheettitle($title) {
}
/**
* Output file headers to initialise the download of the file.
*/
public function send_http_headers() {
global $CFG;
if (defined('BEHAT_SITE_RUNNING')) {
// For text based formats - we cannot test the output with behat if we force a file download.
return;
}
if (is_https()) {
// HTTPS sites - watch out for IE! KB812935 and KB316431.
header('Cache-Control: max-age=10');
header('Pragma: ');
} else {
// Normal http - prevent caching at all cost.
header('Cache-Control: private, must-revalidate, pre-check=0, post-check=0, max-age=0');
header('Pragma: no-cache');
}
header('Expires: '. gmdate('D, d M Y H:i:s', 0) .' GMT');
header("Content-Type: $this->mimetype\n");
$filename = $this->filename . $this->get_extension();
header("Content-Disposition: attachment; filename=\"$filename\"");
}
/**
* Write the start of the format
*
* @param array $columns
*/
public function write_header($columns) {
// Override me if needed.
}
/**
* Write a single record
*
* @param array $record
* @param int $rownum
*/
abstract public function write_record($record, $rownum);
/**
* Write the end of the format
*
* @param array $columns
*/
public function write_footer($columns) {
// Override me if needed.
}
}
+103
View File
@@ -0,0 +1,103 @@
<?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/>.
/**
* Common Spout class for dataformat.
*
* @package core
* @subpackage dataformat
* @copyright 2016 Brendan Heywood ([email protected])
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core\dataformat;
/**
* Common Spout class for dataformat.
*
* @package core
* @subpackage dataformat
* @copyright 2016 Brendan Heywood ([email protected])
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
abstract class spout_base extends \core\dataformat\base {
/** @var $spouttype */
protected $spouttype = '';
/** @var $writer */
protected $writer;
/** @var $sheettitle */
protected $sheettitle;
/**
* Output file headers to initialise the download of the file.
*/
public function send_http_headers() {
$this->writer = \Box\Spout\Writer\WriterFactory::create($this->spouttype);
$filename = $this->filename . $this->get_extension();
$this->writer->openToBrowser($filename);
}
/**
* 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;
}
$title = preg_replace('/[\\\\\/\\?\\*\\[\\]]/', '', $title);
$title = substr($title, 0, 31);
$this->sheettitle = $title;
$sheet = $this->writer->getCurrentSheet();
$sheet->setName($title);
}
/**
* Write the start of the format
*
* @param array $columns
*/
public function write_header($columns) {
$this->writer->addRow(array_values((array)$columns));
}
/**
* Write a single record
*
* @param object $record
* @param int $rownum
*/
public function write_record($record, $rownum) {
$this->writer->addRow(array_values((array)$record));
}
/**
* Write the end of the format
*
* @param array $columns
*/
public function write_footer($columns) {
$this->writer->close();
$this->writer = null;
}
}
+4
View File
@@ -1758,6 +1758,10 @@ class core_plugin_manager {
'number', 'picture', 'radiobutton', 'text', 'textarea', 'url'
),
'dataformat' => array(
'html', 'csv', 'json', 'excel', 'ods',
),
'datapreset' => array(
'imagegallery'
),
+166
View File
@@ -0,0 +1,166 @@
<?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/>.
/**
* Defines classes used for plugin info.
*
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
* @copyright 2016 Brendan Heywood ([email protected])
* @package core
*/
namespace core\plugininfo;
use moodle_url, part_of_admin_tree, admin_settingpage, admin_externalpage, core_plugin_manager;
defined('MOODLE_INTERNAL') || die();
/**
* Class for dataformats
*
* @package core
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
* @copyright 2016 Brendan Heywood ([email protected])
*/
class dataformat extends base {
/**
* Display name
*/
public function init_display_name() {
if (!get_string_manager()->string_exists('dataformat', $this->component)) {
$this->displayname = '[dataformat,' . $this->component . ']';
} else {
$this->displayname = get_string('dataformat', $this->component);
}
}
/**
* Gathers and returns the information about all plugins of the given type
*
* @param string $type the name of the plugintype, eg. mod, auth or workshopform
* @param string $typerootdir full path to the location of the plugin dir
* @param string $typeclass the name of the actually called class
* @param core_plugin_manager $pluginman the plugin manager calling this method
* @return array of plugintype classes, indexed by the plugin name
*/
public static function get_plugins($type, $typerootdir, $typeclass, $pluginman) {
global $CFG;
$formats = parent::get_plugins($type, $typerootdir, $typeclass, $pluginman);
if (!empty($CFG->dataformat_plugins_sortorder)) {
$order = explode(',', $CFG->dataformat_plugins_sortorder);
$order = array_merge(array_intersect($order, array_keys($formats)),
array_diff(array_keys($formats), $order));
} else {
$order = array_keys($formats);
}
$sortedformats = array();
foreach ($order as $formatname) {
$sortedformats[$formatname] = $formats[$formatname];
}
return $sortedformats;
}
/**
* Finds all enabled plugins, the result may include missing plugins.
* @return array|null of enabled plugins $pluginname=>$pluginname, null means unknown
*/
public static function get_enabled_plugins() {
$enabled = array();
$plugins = core_plugin_manager::instance()->get_installed_plugins('dataformat');
if (!$plugins) {
return array();
}
$enabled = array();
foreach ($plugins as $plugin => $version) {
$disabled = get_config('dataformat_' . $plugin, 'disabled');
if (empty($disabled)) {
$enabled[$plugin] = $plugin;
}
}
return $enabled;
}
/**
* Returns the node name used in admin settings menu for this plugin settings (if applicable)
*
* @return null|string node name or null if plugin does not create settings node (default)
*/
public function get_settings_section_name() {
return 'dataformatsetting' . $this->name;
}
/**
* Loads plugin settings to the settings tree
*
* This function usually includes settings.php file in plugins folder.
* Alternatively it can create a link to some settings page (instance of admin_externalpage)
*
* @param \part_of_admin_tree $adminroot
* @param string $parentnodename
* @param bool $hassiteconfig whether the current user has moodle/site:config capability
*/
public function load_settings(part_of_admin_tree $adminroot, $parentnodename, $hassiteconfig) {
global $CFG, $USER, $DB, $OUTPUT, $PAGE; // In case settings.php wants to refer to them.
$ADMIN = $adminroot; // May be used in settings.php.
$plugininfo = $this; // Also can be used inside settings.php.
$dataformat = $this; // Also can be used inside settings.php.
if (!$this->is_installed_and_upgraded()) {
return;
}
if (!$hassiteconfig) {
return;
}
if (file_exists($this->full_path('settings.php'))) {
$fullpath = $this->full_path('settings.php');
} else if (file_exists($this->full_path('dataformatsettings.php'))) {
$fullpath = $this->full_path('dataformatsettings.php');
} else {
return;
}
$section = $this->get_settings_section_name();
$settings = new admin_settingpage($section, $this->displayname, 'moodle/site:config', $this->is_enabled() === false);
include($fullpath); // This may also set $settings to null.
if ($settings) {
$ADMIN->add($parentnodename, $settings);
}
}
/**
* dataformats can be uninstalled
*
* @return bool
*/
public function is_uninstall_allowed() {
return true;
}
/**
* Return URL used for management of plugins of this type.
* @return moodle_url
*/
public static function get_manage_url() {
return new moodle_url('/admin/settings.php?section=managedataformats');
}
}
+72
View File
@@ -0,0 +1,72 @@
<?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/>.
/**
* dataformatlib.php - Contains core dataformat related functions.
*
* @package core
* @subpackage dataformat
* @copyright 2016 Brendan Heywood ([email protected])
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* Sends a formated data file to the browser
*
* @package core
* @subpackage dataformat
*
* @param string $filename The base filename without an extension
* @param string $dataformat A dataformat name
* @param array $columns An ordered map of column keys and labels
* @param Iterator $iterator An iterator over the records, usually a RecordSet
* @param function $callback An option function applied to each record before writing
* @param mixed $extra An optional value which is passed into the callback function
*/
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");
}
$classname = 'dataformat_' . $dataformat . '\writer';
if (!class_exists($classname)) {
throw new coding_exception("Unable to locate dataformat/$type/classes/writer.php");
}
$format = new $classname;
// The data format export could take a while to generate...
set_time_limit(0);
// Close the session so that the users other tabs in the same session are not blocked.
\core\session\manager::write_close();
$format->set_filename($filename);
$format->send_http_headers();
$format->write_header($columns);
$c = 0;
foreach ($iterator as $row) {
if ($callback) {
$row = $callback($row);
}
if ($row === null) {
continue;
}
$format->write_record($row, $c++);
}
$format->write_footer($columns);
}
+42
View File
@@ -1876,6 +1876,48 @@ class core_renderer extends renderer_base {
return $this->render($select);
}
/**
* Returns a dataformat selection and download form
*
* @param string $label A text label
* @param moodle_url|string $base The download page url
* @param string $name The query param which will hold the type of the download
* @param array $params Extra params sent to the download page
* @return string HTML fragment
*/
public function download_dataformat_selector($label, $base, $name = 'dataformat', $params = array()) {
$formats = core_plugin_manager::instance()->get_plugins_of_type('dataformat');
$options = array();
foreach ($formats as $format) {
if ($format->is_enabled()) {
$options[] = array(
'value' => $format->name,
'label' => get_string('shortname', $format->component),
);
}
}
$hiddenparams = array();
foreach ($params as $key => $value) {
$hiddenparams[] = array(
'name' => $key,
'value' => $value,
);
}
$data = array(
'label' => $label,
'base' => $base,
'name' => $name,
'params' => $hiddenparams,
'options' => $options,
'sesskey' => sesskey(),
'submit' => get_string('download'),
);
return $this->render_from_template('core/dataformat_selector', $data);
}
/**
* Internal implementation of single_select rendering
*
@@ -0,0 +1,44 @@
{{!
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/>.
}}
{{!
@template core/dataformat_selector
Template for all html emails. Note that it may wrap content formatted
elsewhere in another a module template.
Context variables required for this template:
* label
* base
* name
* params
* options
* sesskey
* 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}}
</form>
+6 -4
View File
@@ -31,10 +31,12 @@ defined('MOODLE_INTERNAL') || die();
*/
class core_component_testcase extends advanced_testcase {
// To be changed if number of subsystems increases/decreases,
// this is defined here to annoy devs that try to add more without any thinking,
// always verify that it does not collide with any existing add-on modules and subplugins!!!
const SUBSYSTEMCOUNT = 64;
/**
* To be changed if number of subsystems increases/decreases,
* this is defined here to annoy devs that try to add more without any thinking,
* always verify that it does not collide with any existing add-on modules and subplugins!!!
*/
const SUBSYSTEMCOUNT = 65;
public function test_get_core_subsystems() {
global $CFG;
+6
View File
@@ -269,4 +269,10 @@
<license>GPL</license>
<version>1.6.3</version>
</library>
<library>
<location>spout</location>
<name>Spout</name>
<license>GPL</license>
<version>2.3.0</version>
</library>
</libraries>
+11
View File
@@ -501,6 +501,17 @@ a.skip:active {
.groupselector label {
display: inline-block;
}
// Data format selector
.dataformatselector {
margin: 1em 0;
}
.dataformatselector label {
display: inline-block;
margin: 0 5px 10px 0;
line-height: 30px;
vertical-align: top;
}
// Login
.loginbox {
margin: 15px;
File diff suppressed because one or more lines are too long