Differences Between: [Versions 310 and 311] [Versions 310 and 400] [Versions 310 and 401] [Versions 310 and 402] [Versions 310 and 403]
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 for workshop cron. 19 * 20 * @package mod_workshop 21 * @copyright 2019 Simey Lameze <simey@moodle.com> 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 namespace mod_workshop\task; 25 26 defined('MOODLE_INTERNAL') || die(); 27 28 /** 29 * The main scheduled task for the workshop. 30 * 31 * @package mod_workshop 32 * @copyright 2019 Simey Lameze <simey@moodle.com> 33 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 34 */ 35 class cron_task extends \core\task\scheduled_task { 36 37 /** 38 * Get a descriptive name for this task (shown to admins). 39 * 40 * @return string 41 */ 42 public function get_name() { 43 return get_string('crontask', 'mod_workshop'); 44 } 45 46 /** 47 * Run workshop cron. 48 */ 49 public function execute() { 50 global $CFG, $DB; 51 52 $now = time(); 53 54 mtrace(' processing workshop subplugins ...'); 55 56 // Now when the scheduled allocator had a chance to do its job. 57 // Check if there are some workshops to switch into the assessment phase. 58 $workshops = $DB->get_records_select("workshop", 59 "phase = 20 AND phaseswitchassessment = 1 AND submissionend > 0 AND submissionend < ?", [$now]); 60 61 if (!empty($workshops)) { 62 mtrace('Processing automatic assessment phase switch in ' . count($workshops) . ' workshop(s) ... ', ''); 63 require_once($CFG->dirroot . '/mod/workshop/locallib.php'); 64 foreach ($workshops as $workshop) { 65 $cm = get_coursemodule_from_instance('workshop', $workshop->id, $workshop->course, false, MUST_EXIST); 66 $course = $DB->get_record('course', ['id' => $cm->course], '*', MUST_EXIST); 67 $workshop = new \workshop($workshop, $cm, $course); 68 $workshop->switch_phase(\workshop::PHASE_ASSESSMENT); 69 70 $params = [ 71 'objectid' => $workshop->id, 72 'context' => $workshop->context, 73 'courseid' => $workshop->course->id, 74 'other' => [ 75 'workshopphase' => $workshop->phase 76 ] 77 ]; 78 $event = \mod_workshop\event\phase_switched::create($params); 79 $event->trigger(); 80 81 // Disable the automatic switching now so that it is not executed again by accident. 82 // That can happen if the teacher changes the phase back to the submission one. 83 $DB->set_field('workshop', 'phaseswitchassessment', 0, ['id' => $workshop->id]); 84 } 85 mtrace('done'); 86 } 87 } 88 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body