2 // This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
18 * Synchronise plans from template cohorts.
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
26 defined('MOODLE_INTERNAL') ||
die();
28 use core_competency\api
;
29 use core_competency\template_cohort
;
32 * Synchronise plans from template cohorts.
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
39 class sync_plans_from_template_cohorts_task
extends \core\task\scheduled_task
{
42 * Get a descriptive name for this task.
46 public function get_name() {
47 return get_string('syncplanscohorts', 'core_competency');
53 public function execute() {
54 if (!api
::is_enabled()) {
58 $missingplans = template_cohort
::get_all_missing_plans(self
::get_last_run_time());
60 foreach ($missingplans as $missingplan) {
61 foreach ($missingplan['userids'] as $userid) {
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
);