Add PDF export to exercise result only for teachers see BT#13394

pull/2487/head
jmontoyaa 8 years ago
parent eb997ff5d2
commit ec72f195e4
  1. 60
      main/exercise/exercise_show.php
  2. 33
      main/inc/lib/pdf.lib.php
  3. 2
      main/template/default/export/table_pdf.tpl

@ -57,11 +57,6 @@ $TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION);
$TBL_TRACK_EXERCISES = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES);
$TBL_TRACK_ATTEMPT = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
// General parameters passed via POST/GET
if ($debug) {
error_log('Entered exercise_result.php: '.print_r($_POST, 1));
}
if (empty($formSent)) {
$formSent = isset($_REQUEST['formSent']) ? $_REQUEST['formSent'] : null;
}
@ -171,15 +166,24 @@ if ($allowRecordAudio && $allowTeacherCommentAudio) {
$scoreJsCode = ExerciseLib::getJsCode();
if ($origin != 'learnpath') {
Display::display_header('');
} else {
$htmlHeadXtra[] = "
if ($action != 'export') {
if ($origin != 'learnpath') {
Display::display_header('');
} else {
$htmlHeadXtra[] = "
<style>
body { background: none;}
</style>
";
Display::display_reduced_header();
Display::display_reduced_header();
}
echo Display::toolbarAction('toolbar', [
Display::url(
Display::return_icon('pdf.png', get_lang('Export')),
api_get_self().'?'.api_get_cidreq().'&id='.$id.'&action=export&'
)
]);
}
?>
<script>
@ -285,9 +289,13 @@ if ($is_allowedToEdit && in_array($action, ['qualify', 'edit'])) {
$show_results = true;
}
if ($action == 'export') {
ob_start();
}
$user_info = api_get_user_info($student_id);
if ($show_results || $show_only_total_score || $showTotalScoreAndUserChoicesInLastAttempt) {
$user_info = api_get_user_info($student_id);
//Shows exercise header
// Shows exercise header
echo $objExercise->show_exercise_result_header(
$user_info,
api_convert_and_format_date($exercise_date),
@ -702,7 +710,7 @@ foreach ($questionList as $questionId) {
}
$marksname = '';
if ($isFeedbackAllowed) {
if ($isFeedbackAllowed && $action != 'export') {
$name = "fckdiv".$questionId;
$marksname = "marksName".$questionId;
if (in_array($answerType, array(FREE_ANSWER, ORAL_EXPRESSION, ANNOTATION))) {
@ -763,6 +771,7 @@ foreach ($questionList as $questionId) {
$feedback_form->setDefaults($default);
$feedback_form->display();
echo '</div>';
if ($allowRecordAudio && $allowTeacherCommentAudio) {
@ -783,7 +792,7 @@ foreach ($questionList as $questionId) {
}
}
if ($is_allowedToEdit && $isFeedbackAllowed) {
if ($is_allowedToEdit && $isFeedbackAllowed && $action != 'export') {
if (in_array($answerType, array(FREE_ANSWER, ORAL_EXPRESSION, ANNOTATION))) {
$marksname = "marksName".$questionId;
$arrmarks[] = $questionId;
@ -926,7 +935,7 @@ foreach ($questionList as $questionId) {
$exercise_content .= Display::panel($question_content);
} // end of large foreach on questions
$total_score_text = null;
$total_score_text = '';
//Total score
if ($origin != 'learnpath' || ($origin == 'learnpath' && isset($_GET['fb_type']))) {
@ -963,6 +972,27 @@ echo $total_score_text;
echo $exercise_content;
echo $total_score_text;
if ($action == 'export') {
$content = ob_get_clean();
$params = array(
'filename' => api_replace_dangerous_char(
$objExercise->name.' '.
$user_info['complete_name'].' '.
api_get_local_time()
),
'course_code' => api_get_course_id(),
'session_info' => api_get_session_info(api_get_session_id()),
'course_info' => '',
'pdf_date' => '',
'show_real_course_teachers' => false,
'show_teacher_as_myself' => false,
'orientation' => 'P'
);
$pdf = new PDF('A4', $params['orientation'], $params);
$pdf->html_to_pdf_with_template($content, false, false, true);
exit;
}
if ($isFeedbackAllowed) {
if (is_array($arrid) && is_array($arrmarks)) {
$strids = implode(",", $arrid);

@ -45,7 +45,7 @@ class PDF
$params['bottom'] = isset($params['bottom']) ? $params['bottom'] : 30;
$this->params['filename'] = isset($params['filename']) ? $params['filename'] : api_get_local_time();
$this->params['pdf_title'] = isset($params['pdf_title']) ? $params['pdf_title'] : get_lang('Untitled');
$this->params['pdf_title'] = isset($params['pdf_title']) ? $params['pdf_title'] : '';
$this->params['course_info'] = isset($params['course_info']) ? $params['course_info'] : api_get_course_info();
$this->params['session_info'] = isset($params['session_info']) ? $params['session_info'] : api_get_session_info(api_get_session_id());
$this->params['course_code'] = isset($params['course_code']) ? $params['course_code'] : api_get_course_id();
@ -88,13 +88,15 @@ class PDF
* @param $content
* @param bool|false $saveToFile
* @param bool|false $returnHtml
* @param bool $addDefaultCss
*
* @return string
*/
public function html_to_pdf_with_template(
$content,
$saveToFile = false,
$returnHtml = false
$returnHtml = false,
$addDefaultCss = false
) {
if (empty($this->template)) {
$tpl = new Template('', false, false, false);
@ -151,7 +153,6 @@ class PDF
$css_file = api_get_path(SYS_CSS_PATH).'print.css';
}
$css = file_get_contents($css_file);
$html = self::content_to_pdf(
$html,
$css,
@ -160,7 +161,8 @@ class PDF
'D',
$saveToFile,
null,
$returnHtml
$returnHtml,
$addDefaultCss
);
if ($returnHtml) {
@ -399,6 +401,11 @@ class PDF
* @param string $course_code course code
* (if you are using html that are located in the document tool you must provide this)
* @param string $outputMode the MPDF output mode can be:
* @param bool $saveInFile
* @param string $fileToSave
* @param bool $returnHtml
* @param bool $addDefaultCss
*
* 'I' (print on standard output),
* 'D' (download file) (this is the default value),
* 'F' (save to local file) or
@ -413,7 +420,8 @@ class PDF
$outputMode = 'D',
$saveInFile = false,
$fileToSave = null,
$returnHtml = false
$returnHtml = false,
$addDefaultCss = false
) {
$urlAppend = api_get_configuration_value('url_append');
@ -450,7 +458,7 @@ class PDF
$document_path = api_get_path(SYS_COURSE_PATH).$course_data['path'].'/document/';
$doc = new DOMDocument();
$result = @$doc->loadHTML($document_html);
@$doc->loadHTML($document_html);
//Fixing only images @todo do the same thing with other elements
$elements = $doc->getElementsByTagName('img');
@ -495,6 +503,19 @@ class PDF
if (!empty($css)) {
$this->pdf->WriteHTML($css, 1);
}
if ($addDefaultCss) {
$basicStyles = [
api_get_path(WEB_PUBLIC_PATH).'assets/bootstrap/dist/css/bootstrap.min.css',
api_get_path(WEB_CSS_PATH).'base.css',
api_get_path(WEB_CSS_PATH).api_get_visual_theme().'/default.css'
];
foreach ($basicStyles as $style) {
$cssContent = file_get_contents($style);
$this->pdf->WriteHTML("<style>$cssContent</style>", 1);
}
}
$this->pdf->WriteHTML($document_html);
if (empty($pdf_name)) {

@ -1,4 +1,6 @@
{% if pdf_title %}
<h2 align="center"> {{ pdf_title }} </h2>
{% endif %}
{% if pdf_description %}
{{ pdf_description }}

Loading…
Cancel
Save