Studyplan marking for csync cascade
This commit is contained in:
parent
4994f8a63e
commit
13e862de9a
11 changed files with 68 additions and 10 deletions
|
@ -201,6 +201,7 @@ class associationservice extends \external_api
|
||||||
'cohort_id' => $cohort_id,
|
'cohort_id' => $cohort_id,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
$studyplan->mark_csync_changed();
|
||||||
return ['success' => true, 'msg'=>'Cohort connected'];
|
return ['success' => true, 'msg'=>'Cohort connected'];
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
@ -240,6 +241,8 @@ class associationservice extends \external_api
|
||||||
'cohort_id' => $cohort_id,
|
'cohort_id' => $cohort_id,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
$studyplan->mark_csync_changed();
|
||||||
|
|
||||||
return ['success' => true, 'msg'=>'Cohort Disconnected'];
|
return ['success' => true, 'msg'=>'Cohort Disconnected'];
|
||||||
} else {
|
} else {
|
||||||
return ['success' => true, 'msg'=>'Connection does not exist'];
|
return ['success' => true, 'msg'=>'Connection does not exist'];
|
||||||
|
@ -314,8 +317,7 @@ class associationservice extends \external_api
|
||||||
'studyplan_id' => $studyplan_id,
|
'studyplan_id' => $studyplan_id,
|
||||||
'user_id' => $user_id,
|
'user_id' => $user_id,
|
||||||
]);
|
]);
|
||||||
|
return ['success' => true, 'msg'=>'User Disconnected'];
|
||||||
return ['success' => true, 'msg'=>'USer Disconnected'];
|
|
||||||
} else {
|
} else {
|
||||||
return ['success' => true, 'msg'=>'Connection does not exist'];
|
return ['success' => true, 'msg'=>'Connection does not exist'];
|
||||||
}
|
}
|
||||||
|
|
|
@ -198,7 +198,12 @@ class studyitem {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$id = $DB->insert_record(self::TABLE, $info);
|
$id = $DB->insert_record(self::TABLE, $info);
|
||||||
return self::findById($id);
|
$item = self::findById($id);
|
||||||
|
if($item->type() == self::COURSE){
|
||||||
|
// Signal the studyplan that a course has been added so it can be marked for csync cascading
|
||||||
|
$item->getStudyline()->getStudyplan()->mark_csync_changed();
|
||||||
|
}
|
||||||
|
return $item;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function edit($fields)
|
public function edit($fields)
|
||||||
|
|
|
@ -729,6 +729,28 @@ class studyplan {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mark the studyplan as changed regarding courses and associated cohorts
|
||||||
|
*/
|
||||||
|
public function mark_csync_changed(){
|
||||||
|
global $DB;
|
||||||
|
$DB->update_record(self::TABLE, ['id' => $this->id,"csync_flag" => 1]);
|
||||||
|
$this->r->csync_flag = 1; //manually set it in the cache, if something unexpected happened, an exception has already been thrown anyway
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clear the csync mark
|
||||||
|
*/
|
||||||
|
public function clear_csync_changed(){
|
||||||
|
global $DB;
|
||||||
|
$DB->update_record(self::TABLE, ['id' => $this->id,"csync_flag" => 0]);
|
||||||
|
$this->r->csync_flag = 0; //manually set it in the cache, if something unexpected happened, an exception has already been thrown anyway
|
||||||
|
}
|
||||||
|
|
||||||
|
public function has_csync_changed(){
|
||||||
|
return ($this->r->csync_flag > 0)?true:false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* See if the specified course id is linked in this studyplan
|
* See if the specified course id is linked in this studyplan
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -20,12 +20,22 @@ class autocohortsync extends \core\task\scheduled_task {
|
||||||
*/
|
*/
|
||||||
public function execute() {
|
public function execute() {
|
||||||
if(get_config("local_treestudyplan","csync_enable")){
|
if(get_config("local_treestudyplan","csync_enable")){
|
||||||
|
\mtrace("Automatic csync cascading enabled");
|
||||||
$studyplans = studyplan::find_all();
|
$studyplans = studyplan::find_all();
|
||||||
|
|
||||||
foreach($studyplans as $studyplan) {
|
foreach($studyplans as $studyplan) {
|
||||||
|
// Only process studyplans that have been marked for change because
|
||||||
|
// a cohort change has occurred or a course has been added....
|
||||||
|
if($studyplan->has_csync_changed()){
|
||||||
|
\mtrace("Studyplan {$studyplan->shortname()} needs processing");
|
||||||
$enroller = new cascadecohortsync($studyplan);
|
$enroller = new cascadecohortsync($studyplan);
|
||||||
$enroller->sync();
|
$enroller->sync();
|
||||||
|
$studyplan->clear_csync_changed();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
\mtrace("Task done");
|
||||||
|
} else {
|
||||||
|
\mtrace("Automatic csync cascading disabled");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
<XMLDB PATH="local/treestudyplan/db" VERSION="20210827" COMMENT="XMLDB file for Moodle local/treestudyplan"
|
<XMLDB PATH="local/treestudyplan/db" VERSION="20230626" COMMENT="XMLDB file for Moodle local/treestudyplan"
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd"
|
xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd"
|
||||||
>
|
>
|
||||||
|
@ -33,6 +33,7 @@
|
||||||
<FIELD NAME="aggregation" TYPE="char" LENGTH="30" NOTNULL="true" DEFAULT="bistate" SEQUENCE="false"/>
|
<FIELD NAME="aggregation" TYPE="char" LENGTH="30" NOTNULL="true" DEFAULT="bistate" SEQUENCE="false"/>
|
||||||
<FIELD NAME="aggregation_config" TYPE="text" NOTNULL="false" SEQUENCE="false"/>
|
<FIELD NAME="aggregation_config" TYPE="text" NOTNULL="false" SEQUENCE="false"/>
|
||||||
<FIELD NAME="context_id" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false"/>
|
<FIELD NAME="context_id" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false"/>
|
||||||
|
<FIELD NAME="csync_flag" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="1" SEQUENCE="false" COMMENT="Flags the studyplan as needing a csync update"/>
|
||||||
</FIELDS>
|
</FIELDS>
|
||||||
<KEYS>
|
<KEYS>
|
||||||
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
|
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
|
||||||
|
|
|
@ -3,7 +3,7 @@ $tasks = [
|
||||||
[
|
[
|
||||||
'classname' => 'local_treestudyplan\task\autocohortsync',
|
'classname' => 'local_treestudyplan\task\autocohortsync',
|
||||||
'blocking' => 0,
|
'blocking' => 0,
|
||||||
'minute' => '*/10',
|
'minute' => '*',
|
||||||
'hour' => '*',
|
'hour' => '*',
|
||||||
'day' => '*',
|
'day' => '*',
|
||||||
'month' => '*',
|
'month' => '*',
|
||||||
|
|
|
@ -183,7 +183,20 @@ function xmldb_local_treestudyplan_upgrade($oldversion) {
|
||||||
upgrade_plugin_savepoint(true, 2023051700, 'local', 'treestudyplan');
|
upgrade_plugin_savepoint(true, 2023051700, 'local', 'treestudyplan');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($oldversion < 2023062603) {
|
||||||
|
|
||||||
|
// Define field csync_flag to be added to local_treestudyplan.
|
||||||
|
$table = new xmldb_table('local_treestudyplan');
|
||||||
|
$field = new xmldb_field('csync_flag', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '1', 'context_id');
|
||||||
|
|
||||||
|
// Conditionally launch add field csync_flag.
|
||||||
|
if (!$dbman->field_exists($table, $field)) {
|
||||||
|
$dbman->add_field($table, $field);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Treestudyplan savepoint reached.
|
||||||
|
upgrade_plugin_savepoint(true, 2023062603, 'local', 'treestudyplan');
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
|
@ -69,6 +69,8 @@ $string['setting_csync_role_field'] = 'Role';
|
||||||
$string['settingdesc_csync_role_field'] = 'The role to use for automatic cohort sync enrolment created in courses';
|
$string['settingdesc_csync_role_field'] = 'The role to use for automatic cohort sync enrolment created in courses';
|
||||||
$string['setting_csync_remember_manual_csync_field'] = 'Remember existing cohort-syncs';
|
$string['setting_csync_remember_manual_csync_field'] = 'Remember existing cohort-syncs';
|
||||||
$string['settingdesc_csync_remember_manual_csync_field'] = 'Mark cohort syncs that were manually created earlier, so they won\'t be removed during autosync if cohorts are removed from the studyplan';
|
$string['settingdesc_csync_remember_manual_csync_field'] = 'Mark cohort syncs that were manually created earlier, so they won\'t be removed during autosync if cohorts are removed from the studyplan';
|
||||||
|
$string['autocohortsync_name'] = 'Studyplan automatic cohort sync cascading';
|
||||||
|
|
||||||
|
|
||||||
$string['studyplan_add'] = 'Add study plan';
|
$string['studyplan_add'] = 'Add study plan';
|
||||||
$string['studyplan_edit'] = 'Edit study plan';
|
$string['studyplan_edit'] = 'Edit study plan';
|
||||||
|
|
|
@ -71,6 +71,7 @@ $string['setting_csync_role_field'] = 'Synchronisatierol';
|
||||||
$string['settingdesc_csync_role_field'] = 'Welke rol te gebruiken voor automatische site-groep sync koppelingen';
|
$string['settingdesc_csync_role_field'] = 'Welke rol te gebruiken voor automatische site-groep sync koppelingen';
|
||||||
$string['setting_csync_remember_manual_csync_field'] = 'Bewaar bestaande site-group syncs';
|
$string['setting_csync_remember_manual_csync_field'] = 'Bewaar bestaande site-group syncs';
|
||||||
$string['settingdesc_csync_remember_manual_csync_field'] = 'Markeer site-group synchronisaties die eerder handmatig zijn aangemaakt, zodat deze niet worden verwijderd als ze uit het studieplan worden gehaald.';
|
$string['settingdesc_csync_remember_manual_csync_field'] = 'Markeer site-group synchronisaties die eerder handmatig zijn aangemaakt, zodat deze niet worden verwijderd als ze uit het studieplan worden gehaald.';
|
||||||
|
$string['autocohortsync_name'] = 'Studyplan automatisch site-group synchronisatie doorzetten';
|
||||||
|
|
||||||
$string['studyplan_add'] = 'Nieuw studieplan';
|
$string['studyplan_add'] = 'Nieuw studieplan';
|
||||||
$string['studyplan_edit'] = 'Studieplan bewerken';
|
$string['studyplan_edit'] = 'Studieplan bewerken';
|
||||||
|
|
|
@ -198,7 +198,9 @@ if ($hassiteconfig) {
|
||||||
$student = get_archetype_roles('student');
|
$student = get_archetype_roles('student');
|
||||||
$student = reset($student);
|
$student = reset($student);
|
||||||
$page_csync->add(new admin_setting_configselect('local_treestudyplan/csync_roleid',
|
$page_csync->add(new admin_setting_configselect('local_treestudyplan/csync_roleid',
|
||||||
get_string('defaultrole', 'role'), '', $student->id ?? null, $options));
|
get_string('setting_csync_role_field', 'local_treestudyplan'),
|
||||||
|
get_string('settingdesc_csync_role_field', 'local_treestudyplan'),
|
||||||
|
$student->id ?? null, $options));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add settings page2 to the admin settings category.
|
// Add settings page2 to the admin settings category.
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
$plugin->component = 'local_treestudyplan'; // Recommended since 2.0.2 (MDL-26035). Required since 3.0 (MDL-48494)
|
$plugin->component = 'local_treestudyplan'; // Recommended since 2.0.2 (MDL-26035). Required since 3.0 (MDL-48494)
|
||||||
$plugin->version = 2023062602; // YYYYMMDDHH (year, month, day, iteration)
|
$plugin->version = 2023062604; // YYYYMMDDHH (year, month, day, iteration)
|
||||||
$plugin->requires = 2021051700; // YYYYMMDDHH (This is the release version for Moodle 3.11)
|
$plugin->requires = 2021051700; // YYYYMMDDHH (This is the release version for Moodle 3.11)
|
||||||
|
|
||||||
$plugin->dependencies = [
|
$plugin->dependencies = [
|
||||||
|
|
Loading…
Reference in a new issue