first commit

This commit is contained in:
CHIEFSOFT\ameye
2024-09-30 18:11:26 -04:00
commit e592ca6823
27270 changed files with 5002257 additions and 0 deletions
@@ -0,0 +1,46 @@
<?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/>.
/**
* Privacy provider implementation for dataformat_csv.
*
* @package dataformat_csv
* @copyright 2018 Mihail Geshoski <mihail@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace dataformat_csv\privacy;
defined('MOODLE_INTERNAL') || die();
/**
* Privacy provider implementation for dataformat_csv.
*
* @copyright 2018 Mihail Geshoski <mihail@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements \core_privacy\local\metadata\null_provider {
/**
* Get the language string identifier with the component's language
* file to explain why this plugin stores no data.
*
* @return string
*/
public static function get_reason(): string {
return 'privacy:metadata';
}
}
+46
View File
@@ -0,0 +1,46 @@
<?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 (brendan@catalyst-au.net)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace dataformat_csv;
defined('MOODLE_INTERNAL') || die();
/**
* CSV data format writer
*
* @package dataformat_csv
* @copyright 2016 Brendan Heywood (brendan@catalyst-au.net)
* @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";
}
+28
View File
@@ -0,0 +1,28 @@
<?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 (brendan@catalyst-au.net)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string['dataformat'] = 'Comma separated values (.csv)';
$string['privacy:metadata'] = 'The CSV data format plugin does not store any personal data.';
$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 (brendan@catalyst-au.net)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2024042200;
$plugin->requires = 2024041600; // Requires this Moodle version.
$plugin->component = 'dataformat_csv';
@@ -0,0 +1,46 @@
<?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/>.
/**
* Privacy provider implementation for dataformat_excel.
*
* @package dataformat_excel
* @copyright 2018 Mihail Geshoski <mihail@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace dataformat_excel\privacy;
defined('MOODLE_INTERNAL') || die();
/**
* Privacy provider implementation for dataformat_excel.
*
* @copyright 2018 Mihail Geshoski <mihail@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements \core_privacy\local\metadata\null_provider {
/**
* Get the language string identifier with the component's language
* file to explain why this plugin stores no data.
*
* @return string
*/
public static function get_reason(): string {
return 'privacy:metadata';
}
}
+67
View File
@@ -0,0 +1,67 @@
<?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 (brendan@catalyst-au.net)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace dataformat_excel;
defined('MOODLE_INTERNAL') || die();
/**
* Excel data format writer
*
* @package dataformat_excel
* @copyright 2016 Brendan Heywood (brendan@catalyst-au.net)
* @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";
/**
* 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;
}
}
@@ -0,0 +1,28 @@
<?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 (brendan@catalyst-au.net)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string['dataformat'] = 'Microsoft Excel (.xlsx)';
$string['privacy:metadata'] = 'The Excel data format plugin does not store any personal data.';
$string['shortname'] = 'Excel';
+81
View File
@@ -0,0 +1,81 @@
<?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/>.
namespace dataformat_excel;
use core\dataformat;
/**
* Tests for the dataformat_excel writer
*
* @package dataformat_excel
* @copyright 2022 Marina Glancy
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class writer_test extends \advanced_testcase {
/**
* Test writing data whose content contains an image with pluginfile.php source
*/
public function test_write_data(): void {
$columns = ['fruit', 'colour', 'animal'];
$rows = [
['banana', 'yellow', 'monkey'],
['apple', 'red', 'wolf'],
['melon', 'green', 'aardvark'],
];
// Export to file.
$exportfile = dataformat::write_data('My export', 'excel', $columns, $rows);
// Read the file.
$excelcells = $this->get_excel(file_get_contents($exportfile));
$this->assertEquals(array_merge([$columns], $rows), $excelcells);
}
/**
* Get an Excel object to check the content
*
* @param string $content
* @return array two-dimensional array with cell values
*/
private function get_excel(string $content) {
$file = tempnam(sys_get_temp_dir(), 'excel_');
$handle = fopen($file, "w");
fwrite($handle, $content);
/** @var \OpenSpout\Reader\XLSX\Reader $reader */
$reader = \OpenSpout\Reader\Common\Creator\ReaderFactory::createFromFileByMimeType($file);
$reader->open($file);
/** @var \OpenSpout\Reader\XLSX\Sheet[] $sheets */
$sheets = $reader->getSheetIterator();
$rowscellsvalues = [];
foreach ($sheets as $sheet) {
/** @var \OpenSpout\Common\Entity\Row[] $rows */
$rows = $sheet->getRowIterator();
foreach ($rows as $row) {
$thisvalues = [];
foreach ($row->getCells() as $cell) {
$thisvalues[] = $cell->getValue();
}
$rowscellsvalues[] = $thisvalues;
}
}
return $rowscellsvalues;
}
}
+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 (brendan@catalyst-au.net)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2024042200;
$plugin->requires = 2024041600; // Requires this Moodle version.
$plugin->component = 'dataformat_excel';
@@ -0,0 +1,46 @@
<?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/>.
/**
* Privacy provider implementation for dataformat_html.
*
* @package dataformat_html
* @copyright 2018 Mihail Geshoski <mihail@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace dataformat_html\privacy;
defined('MOODLE_INTERNAL') || die();
/**
* Privacy provider implementation for dataformat_html.
*
* @copyright 2018 Mihail Geshoski <mihail@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements \core_privacy\local\metadata\null_provider {
/**
* Get the language string identifier with the component's language
* file to explain why this plugin stores no data.
*
* @return string
*/
public static function get_reason(): string {
return 'privacy:metadata';
}
}
+135
View File
@@ -0,0 +1,135 @@
<?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 (brendan@catalyst-au.net)
* @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 (brendan@catalyst-au.net)
* @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 output
*/
public function start_output() {
echo "<!DOCTYPE html><html><head>";
echo \html_writer::empty_tag('meta', ['charset' => 'UTF-8']);
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>
</head>
<body>";
}
/**
* Write the start of the sheet we will be adding data to.
*
* @param array $columns
*/
public function start_sheet($columns) {
echo "<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');
}
/**
* Method to define whether the dataformat supports export of HTML
*
* @return bool
*/
public function supports_html(): bool {
return true;
}
/**
* Write a single record
*
* @param array $record
* @param int $rownum
*/
public function write_record($record, $rownum) {
$record = $this->format_record($record);
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 sheet containing the data.
*
* @param array $columns
*/
public function close_sheet($columns) {
echo "</table>";
}
/**
* Write the end of the sheet containing the data.
*/
public function close_output() {
echo "</body></html>";
}
}
@@ -0,0 +1,28 @@
<?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 (brendan@catalyst-au.net)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string['dataformat'] = 'HTML table';
$string['privacy:metadata'] = 'The HTML table data format plugin does not store any personal data.';
$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 (brendan@catalyst-au.net)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2024042200;
$plugin->requires = 2024041600; // Requires this Moodle version.
$plugin->component = 'dataformat_html';
@@ -0,0 +1,46 @@
<?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/>.
/**
* Privacy provider implementation for dataformat_json.
*
* @package dataformat_json
* @copyright 2018 Mihail Geshoski <mihail@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace dataformat_json\privacy;
defined('MOODLE_INTERNAL') || die();
/**
* Privacy provider implementation for dataformat_json.
*
* @copyright 2018 Mihail Geshoski <mihail@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements \core_privacy\local\metadata\null_provider {
/**
* Get the language string identifier with the component's language
* file to explain why this plugin stores no data.
*
* @return string
*/
public static function get_reason(): string {
return 'privacy:metadata';
}
}
+112
View File
@@ -0,0 +1,112 @@
<?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 (brendan@catalyst-au.net)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace dataformat_json;
use core_text;
/**
* JSON data format writer
*
* @package dataformat_json
* @copyright 2016 Brendan Heywood (brendan@catalyst-au.net)
* @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";
/** @var $sheetstarted */
public $sheetstarted = false;
/** @var $sheetdatadded */
public $sheetdatadded = false;
/** @var string[] $columns */
protected $columns = [];
/**
* Write the start of the file.
*/
public function start_output() {
echo "[";
}
/**
* Write the start of the sheet we will be adding data to.
*
* @param array $columns
*/
public function start_sheet($columns) {
$this->columns = array_map(function($column) {
return core_text::strtolower(clean_param($column, PARAM_ALPHANUMEXT));
}, $columns);
if ($this->sheetstarted) {
echo ",";
} else {
$this->sheetstarted = true;
}
$this->sheetdatadded = false;
echo "[";
}
/**
* Write a single record
*
* @param array $record
* @param int $rownum
*/
public function write_record($record, $rownum) {
if ($this->sheetdatadded) {
echo ",";
}
// Ensure our record is keyed by column names, rather than numerically.
$record = array_combine($this->columns, (array) $record);
echo json_encode($this->format_record($record), JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
$this->sheetdatadded = true;
}
/**
* Write the end of the sheet containing the data.
*
* @param array $columns
*/
public function close_sheet($columns) {
echo "]";
}
/**
* Write the end of the file.
*/
public function close_output() {
echo "]";
}
}
@@ -0,0 +1,28 @@
<?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 (brendan@catalyst-au.net)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string['dataformat'] = 'Javascript Object Notation (.json)';
$string['privacy:metadata'] = 'The JavaScript Object Notation (JSON) data format plugin does not store any personal data.';
$string['shortname'] = 'JavaScript Object Notation (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 (brendan@catalyst-au.net)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2024042200;
$plugin->requires = 2024041600; // Requires this Moodle version.
$plugin->component = 'dataformat_json';
@@ -0,0 +1,46 @@
<?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/>.
/**
* Privacy provider implementation for dataformat_ods.
*
* @package dataformat_ods
* @copyright 2018 Mihail Geshoski <mihail@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace dataformat_ods\privacy;
defined('MOODLE_INTERNAL') || die();
/**
* Privacy provider implementation for dataformat_ods.
*
* @copyright 2018 Mihail Geshoski <mihail@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements \core_privacy\local\metadata\null_provider {
/**
* Get the language string identifier with the component's language
* file to explain why this plugin stores no data.
*
* @return string
*/
public static function get_reason(): string {
return 'privacy:metadata';
}
}
+66
View File
@@ -0,0 +1,66 @@
<?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 (brendan@catalyst-au.net)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace dataformat_ods;
defined('MOODLE_INTERNAL') || die();
/**
* ODS data format writer
*
* @package dataformat_ods
* @copyright 2016 Brendan Heywood (brendan@catalyst-au.net)
* @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";
/**
* 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;
}
}
+28
View File
@@ -0,0 +1,28 @@
<?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 (brendan@catalyst-au.net)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string['dataformat'] = 'OpenDocument (.ods)';
$string['privacy:metadata'] = 'The OpenDocument data format plugin does not store any personal data.';
$string['shortname'] = 'OpenDocument';
+81
View File
@@ -0,0 +1,81 @@
<?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/>.
namespace dataformat_ods;
use core\dataformat;
/**
* Tests for the dataformat_ods writer
*
* @package dataformat_ods
* @copyright 2022 Marina Glancy
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class writer_test extends \advanced_testcase {
/**
* Test writing data whose content contains an image with pluginfile.php source
*/
public function test_write_data(): void {
$columns = ['fruit', 'colour', 'animal'];
$rows = [
['banana', 'yellow', 'monkey'],
['apple', 'red', 'wolf'],
['melon', 'green', 'aardvark'],
];
// Export to file.
$exportfile = dataformat::write_data('My export', 'ods', $columns, $rows);
// Read the file.
$odscells = $this->get_ods_rows_content(file_get_contents($exportfile));
$this->assertEquals(array_merge([$columns], $rows), $odscells);
}
/**
* Get ods rows from binary content
* @param string $content
* @return array
* @throws \OpenSpout\Common\Exception\IOException
* @throws \OpenSpout\Reader\Exception\ReaderNotOpenedException
*/
private function get_ods_rows_content($content) {
$file = tempnam(sys_get_temp_dir(), 'ods_');
$handle = fopen($file, "w");
fwrite($handle, $content);
/** @var \OpenSpout\Reader\ODS\Reader $reader */
$reader = \OpenSpout\Reader\Common\Creator\ReaderFactory::createFromFileByMimeType($file);
$reader->open($file);
/** @var \OpenSpout\Reader\ODS\Sheet[] $sheets */
$sheets = $reader->getSheetIterator();
$rowscellsvalues = [];
foreach ($sheets as $sheet) {
/** @var \OpenSpout\Common\Entity\Row[] $rows */
$rows = $sheet->getRowIterator();
foreach ($rows as $row) {
$thisvalues = [];
foreach ($row->getCells() as $cell) {
$thisvalues[] = $cell->getValue();
}
$rowscellsvalues[] = $thisvalues;
}
}
return $rowscellsvalues;
}
}
+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 (brendan@catalyst-au.net)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2024042200;
$plugin->requires = 2024041600; // Requires this Moodle version.
$plugin->component = 'dataformat_ods';
@@ -0,0 +1,46 @@
<?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/>.
/**
* Privacy provider implementation for dataformat_pdf.
*
* @package dataformat_pdf
* @copyright 2019 Shamim Rezaie <shamim@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace dataformat_pdf\privacy;
defined('MOODLE_INTERNAL') || die();
/**
* Privacy provider implementation for dataformat_pdf.
*
* @copyright 2019 Shamim Rezaie <shamim@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements \core_privacy\local\metadata\null_provider {
/**
* Get the language string identifier with the component's language
* file to explain why this plugin stores no data.
*
* @return string
*/
public static function get_reason(): string {
return 'privacy:metadata';
}
}
+223
View File
@@ -0,0 +1,223 @@
<?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/>.
/**
* pdf data format writer
*
* @package dataformat_pdf
* @copyright 2019 Shamim Rezaie <shamim@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace dataformat_pdf;
defined('MOODLE_INTERNAL') || die();
/**
* pdf data format writer
*
* @package dataformat_pdf
* @copyright 2019 Shamim Rezaie <shamim@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class writer extends \core\dataformat\base {
public $mimetype = "application/pdf";
public $extension = ".pdf";
/**
* @var \pdf The pdf object that is used to generate the pdf file.
*/
protected $pdf;
/**
* @var float Each column's width in the current sheet.
*/
protected $colwidth;
/**
* @var string[] Title of columns in the current sheet.
*/
protected $columns;
/**
* writer constructor.
*/
public function __construct() {
global $CFG;
require_once($CFG->libdir . '/pdflib.php');
$this->pdf = new \pdf();
$this->pdf->setPrintHeader(false);
$this->pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
// Set background color for headings.
$this->pdf->SetFillColor(238, 238, 238);
}
public function send_http_headers() {
}
/**
* Start output to file, note that the actual writing of the file is done in {@see close_output_to_file()}
*/
public function start_output_to_file(): void {
$this->start_output();
}
public function start_output() {
$this->pdf->AddPage('L');
}
public function start_sheet($columns) {
$margins = $this->pdf->getMargins();
$pagewidth = $this->pdf->getPageWidth() - $margins['left'] - $margins['right'];
$this->colwidth = $pagewidth / count($columns);
$this->columns = $columns;
$this->print_heading($this->pdf);
}
/**
* Method to define whether the dataformat supports export of HTML
*
* @return bool
*/
public function supports_html(): bool {
return true;
}
/**
* When exporting images, we need to return their Base64 encoded content. Otherwise TCPDF will create a HTTP
* request for them, which will lead to the login page (i.e. not the image it expects) and throw an exception
*
* Note: ideally we would copy the file to a temp location and return it's path, but a bug in TCPDF currently
* prevents that
*
* @param \stored_file $file
* @return string|null
*/
protected function export_html_image_source(\stored_file $file): ?string {
// Set upper dimensions for embedded images.
$resizedimage = $file->resize_image(400, 300);
return '@' . base64_encode($resizedimage);
}
/**
* Write a single record
*
* @param array $record
* @param int $rownum
*/
public function write_record($record, $rownum) {
$rowheight = 0;
$record = $this->format_record($record);
foreach ($record as $cell) {
// We need to calculate the row height (accounting for any content). Unfortunately TCPDF doesn't provide an easy
// method to do that, so we create a second PDF inside a transaction, add cell content and use the largest cell by
// height. Solution similar to that at https://stackoverflow.com/a/1943096.
$pdf2 = clone $this->pdf;
$pdf2->startTransaction();
$numpages = $pdf2->getNumPages();
$pdf2->AddPage('L');
$this->print_heading($pdf2);
$pdf2->writeHTMLCell($this->colwidth, 0, '', '', $cell, 1, 1, false, true, 'L');
$pagesadded = $pdf2->getNumPages() - $numpages;
$margins = $pdf2->getMargins();
$pageheight = $pdf2->getPageHeight() - $margins['top'] - $margins['bottom'];
$cellheight = ($pagesadded - 1) * $pageheight + $pdf2->getY() - $margins['top'] - $this->get_heading_height();
$rowheight = max($rowheight, $cellheight);
$pdf2->rollbackTransaction();
}
$margins = $this->pdf->getMargins();
if ($this->pdf->getNumPages() > 1 &&
($this->pdf->GetY() + $rowheight + $margins['bottom'] > $this->pdf->getPageHeight())) {
$this->pdf->AddPage('L');
$this->print_heading($this->pdf);
}
// Get the last key for this record.
end($record);
$lastkey = key($record);
// Reset the record pointer.
reset($record);
// Loop through each element.
foreach ($record as $key => $cell) {
// Determine whether we're at the last element of the record.
$nextposition = ($lastkey === $key) ? 1 : 0;
// Write the element.
$this->pdf->writeHTMLCell($this->colwidth, $rowheight, '', '', $cell, 1, $nextposition, false, true, 'L');
}
}
public function close_output() {
$filename = $this->filename . $this->get_extension();
$this->pdf->Output($filename, 'D');
}
/**
* Write data to disk
*
* @return bool
*/
public function close_output_to_file(): bool {
$this->pdf->Output($this->filepath, 'F');
return true;
}
/**
* Prints the heading row for a given PDF.
*
* @param \pdf $pdf A pdf to print headings in
*/
private function print_heading(\pdf $pdf) {
$fontfamily = $pdf->getFontFamily();
$fontstyle = $pdf->getFontStyle();
$pdf->SetFont($fontfamily, 'B');
$total = count($this->columns);
$counter = 1;
foreach ($this->columns as $columns) {
$nextposition = ($counter == $total) ? 1 : 0;
$pdf->Multicell($this->colwidth, $this->get_heading_height(), $columns, 1, 'C', true, $nextposition);
$counter++;
}
$pdf->SetFont($fontfamily, $fontstyle);
}
/**
* Returns the heading height.
*
* @return int
*/
private function get_heading_height() {
$height = 0;
foreach ($this->columns as $columns) {
$height = max($height, $this->pdf->getStringHeight($this->colwidth, $columns, false, true, '', 1));
}
return $height;
}
}
+28
View File
@@ -0,0 +1,28 @@
<?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/>.
/**
* pdf dataformat lang strings.
*
* @package dataformat_pdf
* @copyright 2019 Shamim Rezaie <shamim@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string['dataformat'] = 'Portable Document Format (.pdf)';
$string['privacy:metadata'] = 'The PDF data format plugin does not store any personal data.';
$string['shortname'] = 'PDF';
+74
View File
@@ -0,0 +1,74 @@
<?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/>.
/**
* Tests for the dataformat_pdf writer
*
* @package dataformat_pdf
* @copyright 2020 Paul Holden <paulh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace dataformat_pdf;
use core\dataformat;
use context_system;
use html_writer;
use moodle_url;
/**
* Writer tests
*
* @package dataformat_pdf
* @copyright 2020 Paul Holden <paulh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class writer_test extends \advanced_testcase {
/**
* Test writing data whose content contains an image with pluginfile.php source
*/
public function test_write_data_with_pluginfile_image(): void {
global $CFG;
$this->resetAfterTest(true);
$imagefixture = "{$CFG->dirroot}/lib/filestorage/tests/fixtures/testimage.jpg";
$image = get_file_storage()->create_file_from_pathname([
'contextid' => context_system::instance()->id,
'component' => 'dataformat_pdf',
'filearea' => 'test',
'itemid' => 0,
'filepath' => '/',
'filename' => basename($imagefixture),
], $imagefixture);
$imageurl = moodle_url::make_pluginfile_url($image->get_contextid(), $image->get_component(), $image->get_filearea(),
$image->get_itemid(), $image->get_filepath(), $image->get_filename());
// Insert out test image into the data so it is exported.
$columns = ['animal', 'image'];
$row = ['cat', html_writer::img($imageurl->out(), 'My image')];
// Export to file. Assert that the exported file exists.
$exportfile = dataformat::write_data('My export', 'pdf', $columns, [$row]);
$this->assertFileExists($exportfile);
// The exported file should be a reasonable size (~275kb).
$this->assertGreaterThan(270000, filesize($exportfile));
}
}
+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_pdf
* @copyright 2019 Shamim Rezaie <shamim@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2024042200;
$plugin->requires = 2024041600; // Requires this Moodle version.
$plugin->component = 'dataformat_pdf';
+36
View File
@@ -0,0 +1,36 @@
This files describes API changes in /dataformat/ download system,
information provided here is intended especially for developers.
=== 3.11.1 ===
* Optional $callback for the following \core\dataformat methods now receive a second argument to define
whether the current format writer supports HTML:
- download_data()
- write_data()
- write_data_to_filearea()
=== 3.9 ===
* The following methods have been added to the base dataformat class to allow instances to export to a local
file. They can be overridden in extending classes to define how files should be created:
- start_output_to_file()
- close_output_to_file()
* Calls to the following dataformat plugin methods have been removed:
- write_header()
- write_footer()
* The following methods have been added to the base class to allow instances to define support for exporting
HTML content, with additional support for defining how images should be embedded:
- supports_html()
- export_html_image_source()
* Dataformat writers should also call the following method to ensure data is properly formatted before being
written, which takes into account prior methods defining support for HTML:
- format_record()
=== 3.4 ===
* In order to allow multiple sheets in an exported file the functions write_header() and write_footer() have
been removed from core dataformat plugins and have been replaced.
- write_header() has been replaced with the two functions start_output() and start_sheet().
- write_footer() has been replaced with the two functions close_output() and close_sheet().
For backwards compatibility write_header() and write_footer() will continue to work but if used will
trigger the function error_log().
=== 3.1 ===
* Added new plugin system with low memory support for csv, ods, xls and json