Skip to content

Commit

Permalink
add background image handling
Browse files Browse the repository at this point in the history
  • Loading branch information
PM84 committed Mar 11, 2024
1 parent 1d47929 commit 62ffba7
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 5 deletions.
2 changes: 2 additions & 0 deletions classes/Report.php
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,8 @@ public function generate_full_page(int $attemptid, array $sections, bool $fix_re
$html .= \quiz_archiver\coversheet\create_coversheet::get_coversheet($attemptid);
$html .= self::generate($attemptid, $sections);
$html .= $OUTPUT->footer();
\local_debugger\performance\debugger::print_debug('archiver', 'HTML output', $html);


// Parse HTML as DOMDocument but supress consistency check warnings
libxml_use_internal_errors(true);
Expand Down
28 changes: 27 additions & 1 deletion classes/coversheet/create_coversheet.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,35 @@ public static function get_coversheet(int $attemptid): string {
$replacement = self::check_class_and_method($classpath, $method, $attemptmetadata);
$html = preg_replace('/' . $placeholder . '/', $replacement, $html);
}
$styles = ['page-break-after: always;'];

$filename = !empty($config->pdfcoversheetbackgroundimage) ? $config->pdfcoversheetbackgroundimage : null;
$fs = get_file_storage();
$context = \context_system::instance();

$backgroundimage = $fs->get_file($context->id, 'quiz_archiver', 'pdfcoversheetbackgroundimage', 0, '/', $filename);
\local_debugger\performance\debugger::print_debug('test', 'backgroundimage', $backgroundimage);
if (!empty($backgroundimage)) {
$url = \moodle_url::make_pluginfile_url(
$backgroundimage->get_contextid(),
$backgroundimage->get_component(),
$backgroundimage->get_filearea(),
$backgroundimage->get_itemid(),
$backgroundimage->get_filepath(),
$backgroundimage->get_filename()
)->out();

$styles[] = 'background-image: url(\'' . $url . '\');';
$styles[] = 'width: 100%;';
$styles[] = 'height: 100vh;';
$styles[] = 'background-position: center;';
$styles[] = 'background-repeat: no-repeat;';
$styles[] = 'background-size: cover';
}

$html = '<div style="' . join(' ', $styles) . '">' . $html . '</div>';
\local_debugger\performance\debugger::print_debug('test', 'get_coversheet', $html);
return '<div style="page-break-after: always;">' . $config->dynamic_pdf_content . '</div>';
return $html;
}

/**
Expand Down
1 change: 1 addition & 0 deletions classes/output/job_overview_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public function __construct(string $uniqueid, int $courseid, int $cmid, int $qui
$this->sortable(true, 'timecreated', SORT_DESC);
$this->no_sorting('jobid');
$this->no_sorting('actions');
$this->no_sorting('user');
$this->collapsible(false);
}

Expand Down
2 changes: 1 addition & 1 deletion lang/en/quiz_archiver.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
$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_backgroundimage_desc'] = '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';
Expand Down
6 changes: 3 additions & 3 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ function quiz_archiver_pluginfile($course, $cm, $context, $filearea, $args, $for
}

// Validate course
if ($args[1] !== $course->id) {
send_file_not_found();
}
// if ($args[1] !== $course->id) {
// send_file_not_found();
// }

// Try to serve file
$fs = get_file_storage();
Expand Down
10 changes: 10 additions & 0 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,16 @@
'0',
));

// PDF cover sheet backround image.
$settings->add(new admin_setting_configstoredfile(
'quiz_archiver/pdfcoversheetbackgroundimage',
get_string('pdf_coversheet_backgroundimage', 'quiz_archiver'),
get_string('pdf_coversheet_backgroundimage_desc', 'quiz_archiver'),
'pdfcoversheetbackgroundimage',
0,
['maxfiles' => 1, 'accepted_types' => ['.png', '.jpg']]
));

$settings->add(
new setting_button(
'quiz_archiver/pdfcoversheet_settings',
Expand Down

0 comments on commit 62ffba7

Please sign in to comment.