Skip to content

Commit

Permalink
remove some debugging points
Browse files Browse the repository at this point in the history
  • Loading branch information
PM84 committed Mar 12, 2024
1 parent 62ffba7 commit 73113ea
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 65 deletions.
4 changes: 1 addition & 3 deletions classes/Report.php
Original file line number Diff line number Diff line change
Expand Up @@ -568,8 +568,6 @@ 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 All @@ -589,7 +587,7 @@ public function generate_full_page(int $attemptid, array $sections, bool $fix_re
// We need to inject custom CSS to hide elements since the DOM generated by
// Moodle can be corrupt which causes the PHP DOMDocument parser to die...
$cssHacksNode = $dom->createElement("style", "
nav.navbar {
nav.navbar, bycs-topbar {
display: none !important;
}
Expand Down
29 changes: 10 additions & 19 deletions classes/coversheet/create_coversheet.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class create_coversheet {
* @return string
*/
public static function get_coversheet(int $attemptid): string {
global $OUTPUT;

$config = get_config('quiz_archiver');

Expand All @@ -68,34 +69,24 @@ 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;'];
\local_debugger\performance\debugger::print_debug('test', 'html', $html);

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

$templatecontext = [];

$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';
$imgdata64 = base64_encode($backgroundimage->get_content());
$templatecontext['backgroundimage64'] = 'data:image/png;base64,' . $imgdata64;
}
$templatecontext['html'] = $html;
$templatecontext['styles'] = 'page-break-after: always; width: 100%; height: 100vh;';

$html = '<div style="' . join(' ', $styles) . '">' . $html . '</div>';
\local_debugger\performance\debugger::print_debug('test', 'get_coversheet', $html);
$html = $OUTPUT->render_from_template('quiz_archiver/pdfcoversheet_html_sceleton', $templatecontext);
// $html = '<div style="' . join(' ', $styles) . '">' . $html . '</div>';
return $html;
}

Expand Down
20 changes: 20 additions & 0 deletions classes/coversheet/placeholder/profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,24 @@ public static function language( object $params): string {
$user = \core_user::get_user($params->userid);
return $user->lang;
}

/**
* Get user idnumber.
* @param object $params
* @return string
*/
public static function idnumber(object $params): string {
$user = \core_user::get_user($params->userid);
return $user->idnumber;
}

/**
* Get user matricel number.
* @param object $params
* @return string
*/
public static function matricelnumber(object $params): string {
return self::idnumber($params);
}

}
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
40 changes: 0 additions & 40 deletions settings_coversheet.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,10 @@
*/
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);

Expand All @@ -41,14 +37,6 @@
}
}

// $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);
Expand All @@ -59,26 +47,6 @@

$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>
Expand All @@ -92,14 +60,6 @@
}

$templatecontext['placeholderdata'] = \quiz_archiver\coversheet\create_coversheet::get_possible_placeholders();
// 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();
7 changes: 7 additions & 0 deletions templates/pdfcoversheet_html_sceleton.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<div style="{{styles}}">

<img src='{{backgroundimage64}}' style="width: 100%; position:relative; top:0; left:0; z-index=-1">

{{{html}}}

</div>

0 comments on commit 73113ea

Please sign in to comment.