diff --git a/classes/Report.php b/classes/Report.php index aee069c..c1753d2 100644 --- a/classes/Report.php +++ b/classes/Report.php @@ -565,6 +565,7 @@ public function generate_full_page(int $attemptid, array $sections, bool $fix_re // Build HTML tree $html = ""; $html .= $OUTPUT->header(); + // $html .= \quiz_archiver\local\coversheet\create_coversheet::get_coversheet($attemptid); $html .= self::generate($attemptid, $sections); $html .= $OUTPUT->footer(); diff --git a/classes/coversheet/create_coversheet.php b/classes/coversheet/create_coversheet.php new file mode 100644 index 0000000..71cbf1d --- /dev/null +++ b/classes/coversheet/create_coversheet.php @@ -0,0 +1,58 @@ +. + +/** + * Handles everything that is needed for coversheet creation. + * + * @package quiz_archiver + * @copyright ISB Bayern, 2024 + * @author Dr. Peter Mayer + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace quiz_archiver\local\coversheet; + +use admin_setting_heading; + +defined('MOODLE_INTERNAL') || die(); + +/** + * Handles everything that is needed for coversheet creation. + * + * @package quiz_archiver + * @copyright ISB Bayern, 2024 + * @author Dr. Peter Mayer + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class create_coversheet { + + /** + * Create the coversheet. Only this method should be called from outside. + * @param int $attemptid + * @return string + */ + public static function get_coversheet(int $attemptid): string { + + $config = get_config('quiz_archiver'); + + if(empty($config->enable_pdf_coversheet)) { + return ''; + } + + return $config->dynamic_pdf_content; + + } +} diff --git a/classes/coversheet/placeholder/profile.php b/classes/coversheet/placeholder/profile.php new file mode 100644 index 0000000..e69de29 diff --git a/classes/form/archive_quiz_form.php b/classes/form/archive_quiz_form.php index 13c6ba4..4f7ec67 100644 --- a/classes/form/archive_quiz_form.php +++ b/classes/form/archive_quiz_form.php @@ -76,6 +76,7 @@ public function definition() { // Options $mform->addElement('header', 'header_settings', get_string('settings')); + $mform->setExpanded('header_settings', false); // Options: Test $mform->addElement('static', 'quiz_name', get_string('modulename', 'mod_quiz'), $this->quiz_name); @@ -130,6 +131,33 @@ public function definition() { $mform->addHelpButton('export_course_backup', 'export_course_backup', 'quiz_archiver'); $mform->setDefault('export_course_backup', $config->job_preset_export_course_backup); + // PDF cover sheet. + $mform->addElement('header', 'header_pdfcoversheet_settings', get_string('pdfcoversheet_settings', 'quiz_archiver')); + $mform->setExpanded('header_pdfcoversheet_settings', true); + + $mform->addElement( + 'advcheckbox', + 'enable_pdf_coversheet', + ' ', + get_string('enable_pdf_coversheet', 'quiz_archiver'), + $config->{'job_preset_export_report_section_' . $section . '_locked'} ? 'disabled' : null + ); + $mform->addHelpButton('enable_pdf_coversheet', 'enable_pdf_coversheet', 'quiz_archiver'); + + $mform->addElement( + 'filepicker', + 'pdf_coversheet_background', + get_string('pdf_coversheet_backgroundimage', 'quiz_archiver'), + null, + [ + 'accepted_types' => 'png, jpg', + ] + ); + $mform->addHelpButton('pdf_coversheet_background', 'pdf_coversheet_backgroundimage', 'quiz_archiver'); + + $mform->addElement('textarea', 'pdf_coversheet_html_area', get_string("pdf_coversheet_html_area", "quiz_archiver"), 'wrap="virtual" rows="20" cols="50"'); + $mform->addHelpButton('pdf_coversheet_html_area', 'pdf_coversheet_html_area', 'quiz_archiver'); + // Advanced options $mform->addElement('header', 'header_advanced_settings', get_string('advancedsettings')); $mform->setExpanded('header_advanced_settings', false); diff --git a/classes/local/admin/setting/setting_button.php b/classes/local/admin/setting/setting_button.php new file mode 100644 index 0000000..d225417 --- /dev/null +++ b/classes/local/admin/setting/setting_button.php @@ -0,0 +1,87 @@ +. + +/** + * Admin config settings page + * + * @package quiz_archiver + * @copyright ISB Bayern, 2024 + * @author Dr. Peter Mayer + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace quiz_archiver\local\setting\admin; + +use admin_setting_heading; + +defined('MOODLE_INTERNAL') || die(); + +require_once($CFG->libdir . '/moodlelib.php'); + +/** + * Settings for label type admin setting. + * + * @package quiz_archiver + * @copyright ISB Bayern, 2024 + * @author Dr. Peter Mayer + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class setting_button extends admin_setting_heading { + /** @var string Button label */ + protected $label; + /** @var string Button href */ + protected $href; + /** @var string Button css */ + protected $additionalcssclasses; + + /** + * A button element + * + * @param string $name unique ascii name. + * @param string $visiblename heading + * @param string $description description of what the button does + * @param string $label what is written on the button + * @param string $href the URL directed to on click + * @param string $additionalcssclasses additional css classes + */ + public function __construct(string $name, string $visiblename, string $description, string $label, string $href, string $additionalcssclasses) { + $this->nosave = true; + $this->label = $label; + $this->href = $href; + $this->additionalcssclasses = $additionalcssclasses; + parent::__construct($name, $visiblename, $description, ''); + } + + /** + * Returns an HTML string + * @param mixed $data + * @param string $query + * @return string Returns an HTML string + */ + public function output_html($data, $query = '') { + global $OUTPUT; + $context = (object)[ + 'label' => $this->label, + 'href' => $this->href, + 'additionalcssclasses' => $this->additionalcssclasses, + 'forceltr' => $this->get_force_ltr(), + ]; + + $element = $OUTPUT->render_from_template('quiz_archiver/setting_configbutton', $context); + + return format_admin_setting($this, $this->visiblename, $element, $this->description); + } +} diff --git a/lang/de/quiz_archiver.php b/lang/de/quiz_archiver.php index bf9d518..2f629d3 100644 --- a/lang/de/quiz_archiver.php +++ b/lang/de/quiz_archiver.php @@ -84,6 +84,18 @@ $string['job_overview'] = 'Testarchive'; $string['num_attempts'] = 'Anzahl Testversuche'; +// Language strings for pdf cover sheet. +$string['pdfcoversheet_settings'] = 'PDF-Deckblatt'; +$string['pdfcoversheet_settings_desc'] = 'Ein Standard-Deckblatt festlegen'; +$string['enable_pdf_coversheet'] = 'PDF-Deckblatt anzeigen'; +$string['enable_pdf_coversheet_help'] = 'Ein Deckblatt zu den PDF-Versuchen hinzufügen'; +$string['pdf_coversheet_backgroundimage'] = 'Deckblatt-Hintergrundbild'; +$string['pdf_coversheet_backgroundimage_help'] = 'Das Hintergrundbild sollte das gewünschte Seitenformat haben.'; +$string['pdf_coversheet_html_area'] = 'Dynamischer Inhalt des Deckblatts'; +$string['pdf_coversheet_html_area_help'] = 'Platzhalter für dynamische Deckblattinhalte verwenden'; +$string['pdfcoversheet_heading'] = 'PDF-Deckblatt'; +$string['define_pdfcoversheet'] = 'Deckblatt definieren'; + // Job creation form: Filename pattern $string['archive_filename_pattern'] = 'Archivname'; $string['archive_filename_pattern_help'] = 'Name des erzeugten Archivs. Variablen müssen dem ${variablename} Muster folgen. Die Dateiendung wird automatisch hinzugefügt.

Verfügbare Variablen: Verbotene Zeichen: {$a->forbiddenchars}'; diff --git a/lang/en/quiz_archiver.php b/lang/en/quiz_archiver.php index 7385834..8622ed5 100644 --- a/lang/en/quiz_archiver.php +++ b/lang/en/quiz_archiver.php @@ -83,6 +83,16 @@ $string['export_report_section_attachments_help'] = 'Include all file attachments (e.g., essay file submissions) inside the archive. Warning: This can significantly increase the archive size.'; $string['job_overview'] = 'Archives'; $string['num_attempts'] = 'Number of attempts'; +$string['pdfcoversheet_settings'] = 'PDF Cover Sheet'; +$string['pdfcoversheet_settings_desc'] = 'Define a default cover sheet'; +$string['enable_pdf_coversheet'] = 'Ad PDF cover sheet'; +$string['enable_pdf_coversheet_help'] = 'Add a cover sheet to the attempts pdf'; +$string['pdf_coversheet_backgroundimage'] = 'Cover Sheet Background Image'; +$string['pdf_coversheet_backgroundimage_help'] = 'The background image should have the desired page format.'; +$string['pdf_coversheet_html_area'] = 'Coversheet dynamic content'; +$string['pdf_coversheet_html_area_help'] = 'Use placeholders for dynamic cover sheet contents'; +$string['pdfcoversheet_heading'] = 'PDF Cover Sheet'; +$string['define_pdfcoversheet'] = 'Define Cover Sheet'; // Job creation form: Filename pattern $string['archive_filename_pattern'] = 'Archive name'; diff --git a/settings.php b/settings.php index fd03c01..780ea26 100644 --- a/settings.php +++ b/settings.php @@ -28,6 +28,7 @@ use quiz_archiver\local\admin\setting\admin_setting_attempt_filename_pattern; use quiz_archiver\local\admin\setting\admin_setting_configcheckbox_alwaystrue; use quiz_archiver\Report; +use quiz_archiver\local\admin\setting\setting_button; defined('MOODLE_INTERNAL') || die(); @@ -195,6 +196,30 @@ $set->add_dependent_on('quiz_archiver/job_preset_archive_autodelete'); $settings->add($set); + $settings->add(new admin_setting_heading( + 'quit_archiver/pdfcoversheet_settings', + get_string('pdfcoversheet_settings', 'quiz_archiver'), + get_string('pdfcoversheet_settings_desc', 'quiz_archiver') + )); + + $settings->add(new admin_setting_configcheckbox( + 'quiz_archiver/enable_pdf_coversheet', + get_string('enable_pdf_coversheet', 'quiz_archiver'), + get_string('enable_pdf_coversheet_help', 'quiz_archiver'), + '0', + )); + + $settings->add( + new setting_button( + 'quiz_archiver/pdfcoversheet_settings', + get_string('pdfcoversheet_settings', 'quiz_archiver'), + '', + get_string('define_pdfcoversheet', 'quiz_archiver'), + $CFG->wwwroot . '/mod/quiz/report/archiver/settings_coversheet.php', + "btn btn-primary" + ), + ); + // Time-Stamp Protocol settings $settings->add(new admin_setting_heading('quit_archiver/header_tsp', get_string('setting_header_tsp', 'quiz_archiver'), diff --git a/settings_coversheet.php b/settings_coversheet.php new file mode 100644 index 0000000..03e7e69 --- /dev/null +++ b/settings_coversheet.php @@ -0,0 +1,103 @@ +. + +/** + * @package quiz_archiver + * @copyright ISB Bayern, 2024 + * @author Dr. Peter Mayer + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +require_once(dirname(dirname(dirname(dirname(dirname(__FILE__))))) . '/config.php'); + + +global $PAGE, $USER, $DB, $OUTPUT; + +// $courseid = required_param('courseid', PARAM_INT); + +$thisurl = new moodle_url('/mod/quiz/report/archiver/settings_coversheet.php'); +$PAGE->set_url($thisurl); +// $PAGE->set_pagelayout('incourse'); + +$action = optional_param('action', '', PARAM_RAW); + +if (!empty($action)) { + switch ($action) { + case 'storecoversheet': + set_config('dynamic_pdf_content', required_param('dynamic_pdf_content', PARAM_RAW), 'quiz_archiver'); + break; + } +} + +// $category = $DB->get_record('course_categories', array('id' => $ccatid), '*', MUST_EXIST); +// $courseurl = new moodle_url('/course/view.php', array('id' => $courseid)); + +// require_login($courseid, false); +// $coursecontext = context_course::instance($courseid); + +// $template = $DB->get_record('block_mbsteachshare_template', array('courseid' => $courseid), '*', MUST_EXIST); + +$PAGE->set_context(\context_system::instance()); +$pagetitle = get_string('define_pdfcoversheet', 'quiz_archiver'); +$PAGE->set_title($pagetitle); +$PAGE->set_heading($pagetitle); + +// No secondary navigation. +$PAGE->set_secondary_navigation(false); + +$templatecontext = []; + +// $helper = new quiz_archiver\helper(); +// $plugininfo = new quiz_archiver\plugininfo\aitool(); +// $enabledtools = $plugininfo->get_enabled_plugins(); + +// // $options = ['' => get_string('pleaseselect', 'quiz_archiver')]; +// $options = []; +// foreach ($enabledtools as $tool) { +// $options[] = ['tool' => $tool, 'toolname' => get_string('pluginname', 'aitool_' . $tool), 'apikey' => "testkey"]; +// } + +// $purposes = $helper->get_all_purposes(); +// foreach ($purposes as $purpose) { + +// $templatecontext['matching']['purposes'][] = [ +// 'purpose' => $purpose, +// 'purposename' => get_string('purpose_' . $purpose, 'quiz_archiver'), +// 'selectoptions' => $options, +// ]; +// } + +$templatecontext['storedhtml'] = ' + + + +

EXAMPLE

+

This is an example, and will not be present in the PDF. As far as you do not save this page :-).

+ +'; +if(!empty($dynamicpdfcontent = get_config('quiz_archiver', 'dynamic_pdf_content'))) { + $templatecontext['storedhtml'] = get_config('quiz_archiver', 'dynamic_pdf_content'); +} +// print_r(get_config('quiz_archiver', 'dynamic_pdf_content'));die; +echo $OUTPUT->header(); + +// $renderer = $PAGE->get_renderer('block_mbsteachshare'); +// template::add_template_management_info($template); + +echo $OUTPUT->render_from_template('quiz_archiver/define_pdfcoversheet', $templatecontext); +// $logdata = log::get_template_history($template->id); +// echo $renderer->render_template_history($template, $logdata); + +echo $OUTPUT->footer(); diff --git a/templates/define_pdfcoversheet.mustache b/templates/define_pdfcoversheet.mustache new file mode 100644 index 0000000..b142b8c --- /dev/null +++ b/templates/define_pdfcoversheet.mustache @@ -0,0 +1,43 @@ +{{! + 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 . +}} +{{! + @template quiz_archiver/define_pdfcoversheet + + Admin text setting template to define a dynamic pdf cover sheet. + + Context variables required for this template: + * label - form element name + * href - element id + * forceltr - always display as ltr + + Example context (json): + { + "storedhtml": HTML Code, + } +}} + +
+
+ +
+ + +
+ + +
+
diff --git a/templates/setting_configbutton.mustache b/templates/setting_configbutton.mustache new file mode 100644 index 0000000..425a2fc --- /dev/null +++ b/templates/setting_configbutton.mustache @@ -0,0 +1,37 @@ +{{! + 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 . +}} +{{! + @template quiz_archiver/setting_configbutton + + Admin text setting template. + + Context variables required for this template: + * label - form element name + * href - element id + * forceltr - always display as ltr + + Example context (json): + { + "label": "button label", + "href": "http://google.com", + "forceltr": false + } +}} +
+ +