Skip to content

Commit

Permalink
MBS-8820: Add coversheet
Browse files Browse the repository at this point in the history
  • Loading branch information
PM84 committed Mar 10, 2024
1 parent afbdfbf commit 640cd4f
Show file tree
Hide file tree
Showing 11 changed files with 404 additions and 0 deletions.
1 change: 1 addition & 0 deletions classes/Report.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
58 changes: 58 additions & 0 deletions classes/coversheet/create_coversheet.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?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/>.

/**
* 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;

}
}
Empty file.
28 changes: 28 additions & 0 deletions classes/form/archive_quiz_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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',
'&nbsp;',
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);
Expand Down
87 changes: 87 additions & 0 deletions classes/local/admin/setting/setting_button.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?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/>.

/**
* 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);
}
}
12 changes: 12 additions & 0 deletions lang/de/quiz_archiver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <b>müssen</b> dem <code>${variablename}</code> Muster folgen. Die Dateiendung wird automatisch hinzugefügt.<br><br><b>Verfügbare Variablen</b>: <ul>{$a->variables}</ul><b>Verbotene Zeichen</b>: <code>{$a->forbiddenchars}</code>';
Expand Down
10 changes: 10 additions & 0 deletions lang/en/quiz_archiver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
25 changes: 25 additions & 0 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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'),
Expand Down
103 changes: 103 additions & 0 deletions settings_coversheet.php
Original file line number Diff line number Diff line change
@@ -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/>.

/**
* @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'] = '<html>
<head>
</head>
<body>
<h2>EXAMPLE</h2>
<p>This is an example, and will not be present in the PDF. As far as you do not save this page :-).</p>
</body>
</html>';
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();
Loading

0 comments on commit 640cd4f

Please sign in to comment.