Esempio n. 1
0
 /**
  * Check to see if the grade feedback for the pdf has been modified.
  *
  * @param stdClass $grade Grade object.
  * @param stdClass $data Data from the form submission (not used).
  * @return boolean True if the pdf has been modified, else false.
  */
 public function is_feedback_modified(stdClass $grade, stdClass $data)
 {
     global $USER;
     $pagenumbercount = document_services::page_number_for_attempt($this->assignment, $grade->userid, $grade->attemptnumber);
     for ($i = 0; $i < $pagenumbercount; $i++) {
         // Select all annotations.
         $draftannotations = page_editor::get_annotations($grade->id, $i, true);
         $nondraftannotations = page_editor::get_annotations($grade->id, $i, false);
         // Check to see if the count is the same.
         if (count($draftannotations) != count($nondraftannotations)) {
             // The count is different so we have a modification.
             return true;
         } else {
             $matches = 0;
             // Have a closer look and see if the draft files match all the non draft files.
             foreach ($nondraftannotations as $ndannotation) {
                 foreach ($draftannotations as $dannotation) {
                     foreach ($ndannotation as $key => $value) {
                         if ($key != 'id' && $value != $dannotation->{$key}) {
                             continue 2;
                         }
                     }
                     $matches++;
                 }
             }
             if ($matches !== count($nondraftannotations)) {
                 return true;
             }
         }
         // Select all comments.
         $draftcomments = page_editor::get_comments($grade->id, $i, true);
         $nondraftcomments = page_editor::get_comments($grade->id, $i, false);
         if (count($draftcomments) != count($nondraftcomments)) {
             return true;
         } else {
             // Go for a closer inspection.
             $matches = 0;
             foreach ($nondraftcomments as $ndcomment) {
                 foreach ($draftcomments as $dcomment) {
                     foreach ($ndcomment as $key => $value) {
                         if ($key != 'id' && $value != $dcomment->{$key}) {
                             continue 2;
                         }
                     }
                     $matches++;
                 }
             }
             if ($matches !== count($nondraftcomments)) {
                 return true;
             }
         }
     }
     return false;
 }
Esempio n. 2
0
 /**
  * Create a widget for rendering the editor.
  *
  * @param int $userid
  * @param stdClass $grade
  * @param bool $readonly
  * @return assignfeedback_editpdf_widget
  */
 public function get_widget($userid, $grade, $readonly)
 {
     $attempt = -1;
     if ($grade && $grade->attemptnumber) {
         $attempt = $grade->attemptnumber;
     } else {
         $grade = $this->assignment->get_user_grade($userid, true);
     }
     $feedbackfile = document_services::get_feedback_document($this->assignment->get_instance()->id, $userid, $attempt);
     $stampfiles = array();
     $fs = get_file_storage();
     $syscontext = context_system::instance();
     // Copy any new stamps to this instance.
     if ($files = $fs->get_area_files($syscontext->id, 'assignfeedback_editpdf', 'stamps', 0, "filename", false)) {
         foreach ($files as $file) {
             $filename = $file->get_filename();
             if ($filename !== '.') {
                 $existingfile = $fs->get_file($this->assignment->get_context()->id, 'assignfeedback_editpdf', 'stamps', $grade->id, '/', $file->get_filename());
                 if (!$existingfile) {
                     $newrecord = new stdClass();
                     $newrecord->contextid = $this->assignment->get_context()->id;
                     $newrecord->itemid = $grade->id;
                     $fs->create_file_from_storedfile($newrecord, $file);
                 }
             }
         }
     }
     // Now get the full list of stamp files for this instance.
     if ($files = $fs->get_area_files($this->assignment->get_context()->id, 'assignfeedback_editpdf', 'stamps', $grade->id, "filename", false)) {
         foreach ($files as $file) {
             $filename = $file->get_filename();
             if ($filename !== '.') {
                 $url = moodle_url::make_pluginfile_url($this->assignment->get_context()->id, 'assignfeedback_editpdf', 'stamps', $grade->id, '/', $file->get_filename(), false);
                 array_push($stampfiles, $url->out());
             }
         }
     }
     $url = false;
     $filename = '';
     if ($feedbackfile) {
         $url = moodle_url::make_pluginfile_url($this->assignment->get_context()->id, 'assignfeedback_editpdf', document_services::FINAL_PDF_FILEAREA, $grade->id, '/', $feedbackfile->get_filename(), false);
         $filename = $feedbackfile->get_filename();
     }
     // Retrieve total number of pages.
     $pagetotal = document_services::page_number_for_attempt($this->assignment->get_instance()->id, $userid, $attempt, $readonly);
     $widget = new assignfeedback_editpdf_widget($this->assignment->get_instance()->id, $userid, $attempt, $url, $filename, $stampfiles, $readonly, $pagetotal);
     return $widget;
 }
Esempio n. 3
0
 /**
  * Check to see if the grade feedback for the pdf has been modified.
  *
  * @param stdClass $grade Grade object.
  * @param stdClass $data Data from the form submission (not used).
  * @return boolean True if the pdf has been modified, else false.
  */
 public function is_feedback_modified(stdClass $grade, stdClass $data)
 {
     // We only need to know if the source user's PDF has changed. If so then all
     // following users will have the same status. If it's only an individual annotation
     // then only one user will come through this method.
     // Source user id is only added to the form if there was a pdf.
     if (!empty($data->editpdf_source_userid)) {
         $sourceuserid = $data->editpdf_source_userid;
         // Retrieve the grade information for the source user.
         $sourcegrade = $this->assignment->get_user_grade($sourceuserid, true, $grade->attemptnumber);
         $pagenumbercount = document_services::page_number_for_attempt($this->assignment, $sourceuserid, $sourcegrade->attemptnumber);
         for ($i = 0; $i < $pagenumbercount; $i++) {
             // Select all annotations.
             $draftannotations = page_editor::get_annotations($sourcegrade->id, $i, true);
             $nondraftannotations = page_editor::get_annotations($grade->id, $i, false);
             // Check to see if the count is the same.
             if (count($draftannotations) != count($nondraftannotations)) {
                 // The count is different so we have a modification.
                 return true;
             } else {
                 $matches = 0;
                 // Have a closer look and see if the draft files match all the non draft files.
                 foreach ($nondraftannotations as $ndannotation) {
                     foreach ($draftannotations as $dannotation) {
                         foreach ($ndannotation as $key => $value) {
                             if ($key != 'id' && $value != $dannotation->{$key}) {
                                 continue 2;
                             }
                         }
                         $matches++;
                     }
                 }
                 if ($matches !== count($nondraftannotations)) {
                     return true;
                 }
             }
             // Select all comments.
             $draftcomments = page_editor::get_comments($sourcegrade->id, $i, true);
             $nondraftcomments = page_editor::get_comments($grade->id, $i, false);
             if (count($draftcomments) != count($nondraftcomments)) {
                 return true;
             } else {
                 // Go for a closer inspection.
                 $matches = 0;
                 foreach ($nondraftcomments as $ndcomment) {
                     foreach ($draftcomments as $dcomment) {
                         foreach ($ndcomment as $key => $value) {
                             if ($key != 'id' && $value != $dcomment->{$key}) {
                                 continue 2;
                             }
                         }
                         $matches++;
                     }
                 }
                 if ($matches !== count($nondraftcomments)) {
                     return true;
                 }
             }
         }
     }
     return false;
 }