Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 310 and 401] [Versions 311 and 401] [Versions 39 and 401] [Versions 400 and 401] [Versions 401 and 402] [Versions 401 and 403]

This file contains the ingest manager for the assignfeedback_editpdf plugin

Copyright: 2012 Davo Smith
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 1093 lines (47 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class


Class: document_services  - X-Ref

Functions for generating the annotated pdf.

This class controls the ingest of student submission files to a normalised
PDF 1.4 document with all submission files concatinated together. It also
provides the functions to generate a downloadable pdf with all comments and
annotations embedded.
get_assignment_from_param($assignment)   X-Ref
This function will take an int or an assignment instance and
return an assignment instance. It is just for convenience.

param: int|\assign $assignment
return: assign

hash($assignment, $userid, $attemptnumber)   X-Ref
Get a hash that will be unique and can be used in a path name.

param: int|\assign $assignment
param: int $userid
param: int $attemptnumber (-1 means latest attempt)

strip_images($html)   X-Ref
Use a DOM parser to accurately replace images with their alt text.

param: string $html
return: string New html with no image tags.

list_compatible_submission_files_for_attempt($assignment, $userid, $attemptnumber)   X-Ref
This function will search for all files that can be converted
and concatinated into a PDF (1.4) - for any submission plugin
for this students attempt.

param: int|\assign $assignment
param: int $userid
param: int $attemptnumber (-1 means latest attempt)
return: combined_document

get_combined_document_for_attempt($assignment, $userid, $attemptnumber)   X-Ref
Fetch the current combined document ready for state checking.

param: int|\assign $assignment
param: int $userid
param: int $attemptnumber (-1 means latest attempt)
return: combined_document

get_combined_pdf_for_attempt($assignment, $userid, $attemptnumber)   X-Ref
This function return the combined pdf for all valid submission files.

param: int|\assign $assignment
param: int $userid
param: int $attemptnumber (-1 means latest attempt)
return: combined_document

page_number_for_attempt($assignment, $userid, $attemptnumber, $readonly = false)   X-Ref
This function will return the number of pages of a pdf.

param: int|\assign $assignment
param: int $userid
param: int $attemptnumber (-1 means latest attempt)
param: bool $readonly When true we get the number of pages for the readonly version.
return: int number of pages

generate_page_images_for_attempt($assignment, $userid, $attemptnumber, $resetrotation = true)   X-Ref
This function will generate and return a list of the page images from a pdf.

param: int|\assign $assignment
param: int $userid
param: int $attemptnumber (-1 means latest attempt)
param: bool $resetrotation check if need to reset page rotation information
return: array(stored_file)

get_page_images_for_attempt($assignment, $userid, $attemptnumber, $readonly = false)   X-Ref
This function returns a list of the page images from a pdf.

The readonly version is different than the normal one. The readonly version contains a copy
of the pages in the state they were when the PDF was annotated, by doing so we prevent the
the pages that are displayed to change as soon as the submission changes.

Though there is an edge case, if the PDF was annotated before MDL-45580, then it is possible
that we do not find any readonly version of the pages. In that case, we will get the normal
pages and copy them to the readonly area. This ensures that the pages will remain in that
state until the submission is updated. When the normal files do not exist, we throw an exception
because the readonly pages should only ever be displayed after a teacher has annotated the PDF,
they would not exist until they do.

param: int|\assign $assignment
param: int $userid
param: int $attemptnumber (-1 means latest attempt)
param: bool $readonly If true, then we are requesting the readonly version.
return: array(stored_file)

get_downloadable_feedback_filename($assignment, $userid, $attemptnumber)   X-Ref
This function returns sensible filename for a feedback file.

param: int|\assign $assignment
param: int $userid
param: int $attemptnumber (-1 means latest attempt)
return: string

generate_feedback_document($assignment, $userid, $attemptnumber)   X-Ref
This function takes the combined pdf and embeds all the comments and annotations.

This also moves the annotations and comments from drafts to not drafts. And it will
copy all the images stored to the readonly area, so that they can be viewed online, and
not be overwritten when a new submission is sent.

param: int|\assign $assignment
param: int $userid
param: int $attemptnumber (-1 means latest attempt)
return: stored_file

copy_pages_to_readonly_area($assignment, $grade)   X-Ref
Copy the pages image to the readonly area.

param: int|\assign $assignment The assignment.
param: \stdClass $grade The grade record.
return: void

get_feedback_document($assignment, $userid, $attemptnumber)   X-Ref
This function returns the generated pdf (if it exists).

param: int|\assign $assignment
param: int $userid
param: int $attemptnumber (-1 means latest attempt)
return: stored_file

delete_feedback_document($assignment, $userid, $attemptnumber)   X-Ref
This function deletes the generated pdf for a student.

param: int|\assign $assignment
param: int $userid
param: int $attemptnumber (-1 means latest attempt)
return: bool

get_files($assignment, $userid, $attemptnumber, $filearea, $filepath = '/')   X-Ref
Get All files in a File area

param: int|\assign $assignment Assignment
param: int $userid User ID
param: int $attemptnumber Attempt Number
param: string $filearea File Area
param: string $filepath File Path
return: array

save_file($assignment, $userid, $attemptnumber, $filearea, $newfilepath, $storedfilepath = '/')   X-Ref
Save file.

param: int|\assign $assignment Assignment
param: int $userid User ID
param: int $attemptnumber Attempt Number
param: string $filearea File Area
param: string $newfilepath File Path
param: string $storedfilepath stored file path
return: \stored_file

rotate_page($assignment, $userid, $attemptnumber, $index, $rotateleft)   X-Ref
This function rotate a page, and mark the page as rotated.

param: int|\assign $assignment Assignment
param: int $userid User ID
param: int $attemptnumber Attempt Number
param: int $index Index of Current Page
param: bool $rotateleft To determine whether the page is rotated left or right.
return: null|\stored_file return rotated File

save_jpg_to_pdf($assignment, $userid, $attemptnumber, $file, $size=null)   X-Ref
Convert jpg file to pdf file

param: int|\assign $assignment Assignment
param: int $userid User ID
param: int $attemptnumber Attempt Number
param: \stored_file $file file to save
param: null|array $size size of image
return: \stored_file

save_rotated_image_file($assignment, $userid, $attemptnumber, $rotateddata, $filename)   X-Ref
Save rotated image data to file.

param: int|\assign $assignment Assignment
param: int $userid User ID
param: int $attemptnumber Attempt Number
param: resource $rotateddata image data to save
param: string $filename name of the image file
return: \stored_file