[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 /** 18 * A scheduled task. 19 * 20 * @package assignfeedback_editpdf 21 * @copyright 2016 Damyon Wiese 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 namespace assignfeedback_editpdf\task; 25 26 use core\task\scheduled_task; 27 use assignfeedback_editpdf\document_services; 28 use context_module; 29 use assign; 30 31 /** 32 * Simple task to convert submissions to pdf in the background. 33 * @copyright 2016 Damyon Wiese 34 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 35 */ 36 class convert_submissions extends scheduled_task { 37 38 /** 39 * Get a descriptive name for this task (shown to admins). 40 * 41 * @return string 42 */ 43 public function get_name() { 44 return get_string('preparesubmissionsforannotation', 'assignfeedback_editpdf'); 45 } 46 47 /** 48 * Do the job. 49 * Throw exceptions on errors (the job will be retried). 50 */ 51 public function execute() { 52 global $CFG, $DB; 53 54 require_once($CFG->dirroot . '/mod/assign/locallib.php'); 55 56 $records = $DB->get_records('assignfeedback_editpdf_queue'); 57 58 $assignmentcache = array(); 59 60 foreach ($records as $record) { 61 $submissionid = $record->submissionid; 62 $submission = $DB->get_record('assign_submission', array('id' => $submissionid), '*', IGNORE_MISSING); 63 if (!$submission) { 64 // Submission no longer exists. 65 $DB->delete_records('assignfeedback_editpdf_queue', array('id' => $record->id)); 66 continue; 67 } 68 69 $assignmentid = $submission->assignment; 70 $attemptnumber = $record->submissionattempt; 71 72 if (empty($assignmentcache[$assignmentid])) { 73 $cm = get_coursemodule_from_instance('assign', $assignmentid, 0, false, MUST_EXIST); 74 $context = context_module::instance($cm->id); 75 76 $assignment = new assign($context, null, null); 77 $assignmentcache[$assignmentid] = $assignment; 78 } else { 79 $assignment = $assignmentcache[$assignmentid]; 80 } 81 82 $users = array(); 83 if ($submission->userid) { 84 array_push($users, $submission->userid); 85 } else { 86 $members = $assignment->get_submission_group_members($submission->groupid, true); 87 88 foreach ($members as $member) { 89 array_push($users, $member->id); 90 } 91 } 92 93 mtrace('Convert ' . count($users) . ' submission attempt(s) for assignment ' . $assignmentid); 94 foreach ($users as $userid) { 95 document_services::get_page_images_for_attempt($assignment, 96 $userid, 97 $attemptnumber, 98 true); 99 document_services::get_page_images_for_attempt($assignment, 100 $userid, 101 $attemptnumber, 102 false); 103 } 104 105 $DB->delete_records('assignfeedback_editpdf_queue', array('id' => $record->id)); 106 } 107 } 108 109 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |