diff --git a/classes/courseinfo.php b/classes/courseinfo.php
index 26d8834..732ef18 100644
--- a/classes/courseinfo.php
+++ b/classes/courseinfo.php
@@ -75,7 +75,7 @@ class courseinfo {
/**
* Return course record
- * @return stdClass
+ * @return \stdClass
*/
public function course() {
return $this->course;
@@ -292,6 +292,7 @@ class courseinfo {
"canselectgradables" => new \external_value(PARAM_BOOL, 'Requesting user can change selected gradables'),
"numenrolled" => new \external_value(PARAM_INT, 'number of students from this studyplan enrolled in the course'),
"tag" => new \external_value(PARAM_TEXT, 'Tag'),
+ "extrafields" => self::extrafields_structure();
], 'referenced course information', $value);
}
@@ -324,8 +325,10 @@ class courseinfo {
'canupdatecourse' => \has_capability("moodle/course:update", $this->coursecontext),
'canselectgradables' => $this->i_can_select_gradables(),
'tag' => "Editormodel",
+ 'extrafields' => $this->extrafields_model(),
'grades' => [],
'numenrolled' => $numenrolled,
+
];
if (isset($this->studyitem)) {
@@ -370,6 +373,7 @@ class courseinfo {
"startdate" => new \external_value(PARAM_TEXT, 'Course start date'),
"enddate" => new \external_value(PARAM_TEXT, 'Course end date'),
"enrolled" => new \external_value(PARAM_BOOL, 'True if student is enrolled as student in this course'),
+ "extrafields" => self::extrafields_structure();
], 'course information', $value);
}
@@ -445,6 +449,7 @@ class courseinfo {
'enddate' => date("Y-m-d", $this->course->enddate),
'grades' => [],
'enrolled' => $this->is_enrolled_student($userid),
+ 'extrafields' => $this->extrafields_model(),
];
@@ -469,4 +474,102 @@ class courseinfo {
return $info;
}
+
+ /**
+ * Webservice structure for extra fields
+ * @param int $value Webservice requirement constant
+ */
+ public static function extrafields_structure($value = VALUE_REQUIRED) : \external_description {
+ return new \external_multiple_structure(new \external_single_structure([
+ "title" => new \external_value(PARAM_RAW, 'title'),
+ "value" => new \external_value(PARAM_RAW, 'value'),
+ "position" => new \external_value(PARAM_TEXT, 'position'),
+ "type" => new \external_value(PARAM_TEXT, 'value type'),
+ ], 'referenced course information'), $value);
+ }
+
+ /**
+ * Webservice model for basic info
+ * @return array Webservice data model
+ */
+ public function extrafields_model() {
+ $list = [];
+ for ($i=1; $i <= 5; $i++) {
+ $field = get_config('local_treestudyplan','courseinfo'.$i.'_field');
+ $title = self::extrafields_localize_title(get_config('local_treestudyplan','courseinfo'.$i.'_title'));
+ $pos = get_config('local_treestudyplan','courseinfo'.$i.'_position');
+ [$value,$type] = $this->extrafields_value($field);
+ $list[] = [
+ "title" => $title,
+ "value" => $value,
+ "position" => $pos,
+ "type" => $type,
+ ];
+
+ }
+ return $list;
+ }
+
+ protected static function extrafields_localize_title($field) {
+ $lang = trim(current_language());
+ $lines = explode("\n",$field);
+ $title = "";
+ foreach ($lines as $l) {
+ $parts = explode("|",$l,2);
+ if (count($parts) > 0) {
+ if (count($parts) == 1 && empty($title)) {
+ $title = trim($parts[0]);
+ }
+ else if (trim($parts[1]) == $lang) {
+ return trim($parts[0]);
+ }
+ }
+ }
+
+ return $title;
+ }
+
+ /**
+ * Determine value and type of an extra field for this course
+ * @return array [value,type] of the field for this
+ */
+ protected function extrafields_value($fieldname) {
+ $fieldname = get_config("local_treestudyplan", "display_field");
+
+ if ($fieldname == "description") {
+ return [$this->course()->description, "textarea"];
+ } else if ($fieldname == "idnumber") {
+ $idnumber = trim(preg_replace("/\s+/u", " ", $this->course->idnumber));
+ return [$idnumber, "text"];
+ } else if ($fieldname == "contacts") {
+ $cle = new \core_course_list_element($this->course());
+ $contacts = $cle->get_course_contacts();
+ $value = "";
+ foreach ($contacts as $uid => $contact) {
+ if(strlen($value) > 0) {
+ $value .= ", ";
+ }
+ $value .= $contact["username"] . "(".$contact["role"]["name"].")";
+ }
+
+ return [$value, "text"];
+ } else if (strpos( $fieldname , "customfield_") === 0) {
+ $fieldname = substr($fieldname, strlen("customfield_"));
+
+ $handler = \core_customfield\handler::get_handler('core_course', 'course');
+ $datas = $handler->get_instance_data($this->course->id);
+ foreach ($datas as $data) {
+ $field = $data->get_field();
+ if ($field->get('shortname') == $fieldname) {
+ $value = trim(preg_replace("/\s+/u", " ", $data->get_value()));
+ $type = $field->get('type');
+ if (strlen($value) > 0) {
+ return [$value,$type];
+ }
+ }
+ }
+ }
+ // Fallback to shortname when the specified display field fails, since shortname is never empty.
+ return ["",""];
+ }
}
diff --git a/lang/en/local_treestudyplan.php b/lang/en/local_treestudyplan.php
index 81350a5..653cb67 100644
--- a/lang/en/local_treestudyplan.php
+++ b/lang/en/local_treestudyplan.php
@@ -78,11 +78,6 @@ $string["view_plan"] = 'View study plans';
$string["edit_plan"] = 'Edit study plan';
$string["settingspage"] = 'Study plan settings';
-$string["setting_display_heading"] = 'Display';
-$string["settingdesc_display_heading"] = 'Study plan display settings';
-$string["setting_display_field"] = 'Course display name';
-$string["settingdesc_display_field"] = 'Select the field to use for the display name of a course in the study plan';
-
$string["setting_navigation_heading"] = 'Navigation';
$string["settingdesc_navigation_heading"] = 'Navigation menu configuration';
$string["setting_primary_nav_autofill"] = 'Automatically fill custom menu items';
@@ -90,7 +85,6 @@ $string["settingdesc_primary_nav_autofill"] = 'To show the studyplan links in th
$string["setting_defaulticon"] = 'Default studyplan image';
$string["settingdesc_defaulticon"] = 'Configure default image to show for a study plans if no specific image is set';
-
$string["settingspage_csync"] = 'Synchronize linked cohorts and users to courses';
$string["setting_csync_heading"] = 'Automatically create a cohort sync in all courses linked to a study plan for all cohorts linked to a study plan';
$string["settingdesc_csync_heading"] = '';
@@ -107,10 +101,34 @@ $string["settingdesc_csync_remember_manual_csync_field"] = 'Mark cohort syncs th
$string["setting_csync_users_field"] = 'Enroll linked users';
$string["settingdesc_csync_users_field"] = 'Also enrol all users that are explicitly linked to a study plan in that study plan\'s courses.';
+$string["setting_display_heading"] = 'Display';
+$string["settingdesc_display_heading"] = 'Study plan display settings';
+$string["setting_display_field"] = 'Course display name';
+$string["settingdesc_display_field"] = 'Select the field to use for the display name of a course in the study plan';
+
+$string["setting_courseprogressbar"] = 'Show progress bar in course';
+$string["settingdesc_courseprogressbar"] = 'Show a progress bar in the course popup';
+
+$string["setting_infofields_heading"] = 'Extra course information fields';
+$string["settingdesc_infofields_heading"] = 'Select up to 5 fields or custom fields to add to the course popup';
+
+$string["infofield_position_above"] = 'Above course results';
+$string["infofield_position_below"] = 'Below course results';
+$string["infofield_position_header"] = 'Header ';
+$string["infofield_position_footer"] = 'Footer';
+
+for ($i=1;$i<=5;$i++) {
+ $string["setting_infofield".$i."_field"] = 'Add course details from field ('.$i.')';
+ $string["settingdesc_infofield".$i."_field"] = 'Information field to show';
+ $string["setting_infofield".$i."_title"] = 'Title for course details from field ('.$i.').';
+ $string["settingdesc_infofield".$i."_title"] = 'Title for course info field. One line per language. End with "|" to localize'.$i.'. Leave empty to set no title';
+ $string["setting_infofield".$i."_position"] = 'Position of course info field ('.$i.')';
+ $string["settingdesc_infofield".$i."_position"] = 'Where to place this info field in the course popup screen';
+}
+
$string["autocohortsync_name"] = 'Study plan automatic cohort sync cascading';
$string["refreshteacherlist_name"] = "Refresh teacher's study plan list";
-
$string["studyplan_add"] = 'Add study plan';
$string["studyplan_edit"] = 'Edit study plan';
$string["studyplan_remove"] = 'Remove study plan';
diff --git a/lang/nl/local_treestudyplan.php b/lang/nl/local_treestudyplan.php
index 0b88857..6a51b4e 100644
--- a/lang/nl/local_treestudyplan.php
+++ b/lang/nl/local_treestudyplan.php
@@ -85,11 +85,6 @@ $string["settingdesc_primary_nav_autofill"] = 'Om in het primaire navigatiemenu
$string["setting_defaulticon"] = 'Standaard afbeelding foor studieplan';
$string["settingdesc_defaulticon"] = 'Stel standaard afbeelding in om weer te geven als een studieplan geen eigen afbeelding heeft ingesteld';
-$string["setting_display_heading"] = 'Weergave';
-$string["settingdesc_display_heading"] = 'Configuratie voor de weergave van de studieplannen';
-$string["setting_display_field"] = 'Weergavenaam cursus';
-$string["settingdesc_display_field"] = 'Kies welk veld gebruikt moet worden als weergavenaam van een cursus';
-
$string["settingspage_csync"] = 'Site-groepen en gebruikerskoppelingen doorzetten naar cursussen';
$string["setting_csync_heading"] = 'Site-groepen die aan een studieplan gekoppeld zijn automatisch als site-groep synchronisatie koppelen aan alle cursussen in het studieplan.';
$string["settingdesc_csync_heading"] = '';
@@ -105,6 +100,32 @@ $string["setting_csync_remember_manual_csync_field"] = 'Bewaar bestaande site-gr
$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["setting_csync_users_field"] = 'Gekoppelde gebruikers automatisch inchrijven';
$string["settingdesc_csync_users_field"] = 'Ook alle gebruikers die expliciet aan een studieplan gekoppeld zijn inschrijven in de cursussen van dat studieplan.';
+
+$string["setting_display_heading"] = 'Weergave';
+$string["settingdesc_display_heading"] = 'Configuratie voor de weergave van de studieplannen';
+$string["setting_display_field"] = 'Weergavenaam cursus';
+$string["settingdesc_display_field"] = 'Kies welk veld gebruikt moet worden als weergavenaam van een cursus';
+
+$string["setting_courseprogressbar"] = 'Toon voortgangsbalk in cursus';
+$string["settingdesc_courseprogressbar"] = 'Laat een voortgangsbalk zien in de cursuspopup';
+
+$string["setting_infofields_heading"] = 'Extra cursusinformatie in popup';
+$string["settingdesc_infofields_heading"] = 'Kies tot 5 extra velden om in het cursuspopupvenster te laten zien';
+
+$string["infofield_position_above"] = 'Boven cursusresultaten';
+$string["infofield_position_below"] = 'Onder cursusresultaten';
+$string["infofield_position_header"] = 'Header ';
+$string["infofield_position_footer"] = 'Footer';
+
+for ($i=1;$i<=5;$i++) {
+ $string["setting_infofield".$i."_field"] = 'Laat gegevens zien uit cursusveld ('.$i.')';
+ $string["settingdesc_infofield".$i."_field"] = 'Kies cursusveld om informatie uit te tonen';
+ $string["setting_infofield".$i."_title"] = 'Titel voor gegevens uit cursusveld ('.$i.')';
+ $string["settingdesc_infofield".$i."_title"] = 'Titel for cursusveld. Een regel per taal. Eindig met "|" om taal aan te geven';
+ $string["setting_infofield".$i."_position"] = 'Plaats van cursusveld ('.$i.')';
+ $string["settingdesc_infofield".$i."_position"] = 'Waar de gegevens komen te staan in het cursusvenster';
+}
+
$string["autocohortsync_name"] = 'Studyplan automatisch site-group synchronisatie doorzetten';
$string["refreshteacherlist_name"] = "Ververs lijst van studieplannen voor leraar";
diff --git a/settings.php b/settings.php
index bb5d0ef..1664b77 100644
--- a/settings.php
+++ b/settings.php
@@ -89,6 +89,7 @@ if ($hassiteconfig) {
));
$displayfields = ["shortname" => get_string("shortname"), "idnumber" => get_string("idnumber")];
+ $infofields = ["" => get_string('none'), "description" => get_string("description"), "contacts" => get_string("teachers"), "idnumber" => get_string("idnumber")];
$handler = \core_customfield\handler::get_handler('core_course', 'course');
foreach ($handler->get_categories_with_fields() as $cat) {
@@ -97,6 +98,7 @@ if ($hassiteconfig) {
$fieldname = $field->get_formatted_name();
$fieldid = $field->get("shortname");
$displayfields["customfield_".$fieldid] = $catname.": ".$fieldname;
+ $infofields["customfield_".$fieldid] = $catname.": ".$fieldname;
}
}
@@ -107,8 +109,44 @@ if ($hassiteconfig) {
$displayfields
));
- // COMPETENCY AGGREGATON DEFAULTS.
+ $page->add(new admin_setting_configcheckbox('local_treestudyplan/courseprogressbar',
+ get_string('setting_courseprogressbar', 'local_treestudyplan'),
+ get_string('settingdesc_courseprogressbar', 'local_treestudyplan'),
+ false,
+ ));
+ $page->add(new admin_setting_heading('local_treestudyplan/infofields_heading',
+ get_string('setting_infofields_heading', 'local_treestudyplan'),
+ get_string('settingdesc_infofields_heading', 'local_treestudyplan')
+ ));
+
+ $positions = [ "above" => get_string('infofield_position_above', 'local_treestudyplan'),
+ "below" => get_string("infofield_position_below", 'local_treestudyplan'),
+ "header" => get_string("infofield_position_header", 'local_treestudyplan'),
+ "footer" => get_string("infofield_position_footer", 'local_treestudyplan')
+ ];
+
+ for ($i=1;$i<=5;$i++) {
+ $page->add(new admin_setting_configselect('local_treestudyplan/courseinfo'.$i.'_field',
+ get_string('setting_infofield'.$i.'_field', 'local_treestudyplan'),
+ get_string('settingdesc_infofield'.$i.'_field', 'local_treestudyplan'),
+ "",
+ $infofields
+ ));
+ $page->add(new admin_setting_configselect('local_treestudyplan/courseinfo'.$i.'_position',
+ get_string('setting_infofield'.$i.'_position', 'local_treestudyplan'),
+ get_string('settingdesc_infofield'.$i.'_position', 'local_treestudyplan'),
+ "below",
+ $positions
+ ));
+ $page->add(new admin_setting_configtextarea('local_treestudyplan/courseinfo'.$i.'_title',
+ get_string('setting_infofield'.$i.'_title', 'local_treestudyplan'),
+ get_string('settingdesc_infofield'.$i.'_title', 'local_treestudyplan'),
+ "Information $i|en\nInformatie $i|nl"
+ ));
+ }
+
+ // COMPETENCY AGGREGATON DEFAULTS.
$page->add(new admin_setting_configselect('local_treestudyplan/competency_displayname',
get_string('setting_competency_displayname', 'local_treestudyplan'),
get_string('settingdesc_competency_displayname', 'local_treestudyplan'),
diff --git a/version.php b/version.php
index cd1fb76..284771f 100644
--- a/version.php
+++ b/version.php
@@ -22,7 +22,7 @@
defined('MOODLE_INTERNAL') || die();
$plugin->component = 'local_treestudyplan'; // Recommended since 2.0.2 (MDL-26035). Required since 3.0 (MDL-48494).
-$plugin->version = 2023120100; // YYYYMMDDHH (year, month, day, iteration).
+$plugin->version = 2023121002; // YYYYMMDDHH (year, month, day, iteration).
$plugin->requires = 2021051700; // YYYYMMDDHH (This is the release version for Moodle 3.11).
$plugin->release = "1.1.0";