2023-06-26 11:40:49 +02:00
|
|
|
<?php
|
2023-08-24 23:02:41 +02:00
|
|
|
// This file is part of the Studyplan plugin for Moodle
|
|
|
|
//
|
|
|
|
// Moodle is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// Moodle is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @package local_treestudyplan
|
|
|
|
* @copyright 2023 P.M. Kuipers
|
|
|
|
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
|
*/
|
|
|
|
|
2023-06-26 11:40:49 +02:00
|
|
|
namespace local_treestudyplan\task;
|
2023-08-25 12:04:27 +02:00
|
|
|
defined('MOODLE_INTERNAL') || die();
|
|
|
|
|
2023-06-26 11:40:49 +02:00
|
|
|
require_once($CFG->dirroot.'/course/externallib.php');
|
|
|
|
use local_treestudyplan\studyplan;
|
2023-06-26 21:44:31 +02:00
|
|
|
use local_treestudyplan\cascadecohortsync;
|
2023-06-30 12:14:11 +02:00
|
|
|
use local_treestudyplan\cascadeusersync;
|
2023-06-26 11:40:49 +02:00
|
|
|
|
|
|
|
class autocohortsync extends \core\task\scheduled_task {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the task's name as shown in admin screens.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function get_name() {
|
|
|
|
return get_string('autocohortsync_name', 'local_treestudyplan');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Execute the task.
|
|
|
|
*/
|
|
|
|
public function execute() {
|
2023-08-24 23:02:41 +02:00
|
|
|
if (get_config("local_treestudyplan", "csync_enable")) {
|
2023-06-27 07:33:27 +02:00
|
|
|
\mtrace("Automatic csync cascading enabled");
|
2023-06-26 11:40:49 +02:00
|
|
|
$studyplans = studyplan::find_all();
|
|
|
|
|
2023-08-24 23:02:41 +02:00
|
|
|
foreach ($studyplans as $studyplan) {
|
|
|
|
// Only process studyplans that have been marked for change because .
|
2023-08-25 09:44:34 +02:00
|
|
|
// A cohort change has occurred or a course has been added....
|
2023-08-24 23:02:41 +02:00
|
|
|
if ($studyplan->has_csync_changed()) {
|
2023-06-27 07:33:27 +02:00
|
|
|
\mtrace("Studyplan {$studyplan->shortname()} needs processing");
|
|
|
|
$enroller = new cascadecohortsync($studyplan);
|
|
|
|
$enroller->sync();
|
2023-08-24 23:02:41 +02:00
|
|
|
if (get_config("local_treestudyplan", "csync_users")) {
|
2023-06-30 12:14:11 +02:00
|
|
|
$userenroller = new cascadeusersync($studyplan);
|
|
|
|
$userenroller->sync();
|
|
|
|
}
|
2023-06-27 07:33:27 +02:00
|
|
|
$studyplan->clear_csync_changed();
|
2023-06-30 12:14:11 +02:00
|
|
|
|
2023-08-24 23:02:41 +02:00
|
|
|
}
|
2023-06-26 11:40:49 +02:00
|
|
|
}
|
2023-06-27 07:33:27 +02:00
|
|
|
\mtrace("Task done");
|
|
|
|
} else {
|
|
|
|
\mtrace("Automatic csync cascading disabled");
|
2023-06-26 11:40:49 +02:00
|
|
|
}
|
|
|
|
}
|
2023-08-25 11:52:05 +02:00
|
|
|
}
|