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 * Synchronise plans from template cohorts. 19 * 20 * @package core_competency 21 * @copyright 2015 Issam Taboubi <issam.taboubi@umontreal.ca> 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 25 namespace core\task; 26 defined('MOODLE_INTERNAL') || die(); 27 28 use core_competency\api; 29 use core_competency\template_cohort; 30 31 /** 32 * Synchronise plans from template cohorts. 33 * 34 * 35 * @package core_competency 36 * @copyright 2015 Issam Taboubi <issam.taboubi@umontreal.ca> 37 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 38 */ 39 class sync_plans_from_template_cohorts_task extends \core\task\scheduled_task { 40 41 /** 42 * Get a descriptive name for this task. 43 * 44 * @return string 45 */ 46 public function get_name() { 47 return get_string('syncplanscohorts', 'core_competency'); 48 } 49 50 /** 51 * Do the job. 52 */ 53 public function execute() { 54 if (!api::is_enabled()) { 55 return; 56 } 57 58 $missingplans = template_cohort::get_all_missing_plans(self::get_last_run_time()); 59 60 foreach ($missingplans as $missingplan) { 61 foreach ($missingplan['userids'] as $userid) { 62 try { 63 api::create_plan_from_template($missingplan['template'], $userid); 64 } catch (\Exception $e) { 65 debugging(sprintf('Exception caught while creating plan for user %d from template %d. Message: %s', 66 $userid, $missingplan['template']->get_id(), $e->getMessage()), DEBUG_DEVELOPER); 67 } 68 } 69 } 70 } 71 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body