Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.

Differences Between: [Versions 310 and 400] [Versions 311 and 400] [Versions 39 and 400] [Versions 400 and 401] [Versions 400 and 402] [Versions 400 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: 1089 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.

return: assign
param: int|\assign $assignment

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.

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

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.

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

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

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

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

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

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

return: int number of pages
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.

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.

return: array(stored_file)
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

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.

return: array(stored_file)
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.

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

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

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.

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

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

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

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

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

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

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

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

return: array
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

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

return: \stored_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

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

return: null|\stored_file return rotated File
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.

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

return: \stored_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

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

return: \stored_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