Added extra warning if no templates are available

This commit is contained in:
PMKuipers 2024-04-19 17:01:17 +02:00
parent 82838c57c5
commit 886a11d99e
3 changed files with 67 additions and 50 deletions

View File

@ -100,51 +100,62 @@ class studyplan_fromtemplateform extends formbase {
$templatelist[$s->id()] = implode(" / ",$c['path']) . " / " . $s->name();
}
$field = 'template_id';
$mform->addElement('autocomplete', $field,
get_string('studyplan_fromtemplate','local_treestudyplan'),
$templatelist);
$mform->addRule($field, null, 'required', null, 'client');
if (count($templatelist) > 0) {
$mform->addElement('hidden','hastemplates','yes');
$field = 'name';
$mform->addElement('text',$field,
get_string('studyplan_name','local_treestudyplan'),
[]);
$mform->addRule($field, null, 'required', null, 'client');
$field = 'template_id';
$mform->addElement('autocomplete', $field,
get_string('studyplan_fromtemplate','local_treestudyplan'),
$templatelist);
$mform->addRule($field, null, 'required', null, 'client');
$field = 'shortname';
$mform->addElement('text',$field,
get_string('studyplan_shortname','local_treestudyplan'),
[]);
$mform->addRule($field, null, 'required', null, 'client');
$field = 'idnumber';
$mform->addElement('text',$field,
get_string('studyplan_idnumber','local_treestudyplan'),
[]);
$contextlist = [];
foreach(courseservice::list_available_categories('edit') as $c){
$contextlist[$c['context_id']] = implode(" / ",$c['category']['path']);
}
$mform->addElement('autocomplete', 'context_id',
get_string('studyplan_context','local_treestudyplan'),
$contextlist);
$mform->addRule('context_id', null, 'required', null, 'client');
$timeless = \get_config("local_treestudyplan","timelessperiods");
if ( !$timeless) {
// Only add these fields if the studyplans are timed
$field = 'startdate';
$mform->addElement('date_selector',$field,
get_string('studyplan_startdate','local_treestudyplan'),
$field = 'name';
$mform->addElement('text',$field,
get_string('studyplan_name','local_treestudyplan'),
[]);
$mform->addRule($field, null, 'required', null, 'client');
}
$field = 'shortname';
$mform->addElement('text',$field,
get_string('studyplan_shortname','local_treestudyplan'),
[]);
$mform->addRule($field, null, 'required', null, 'client');
$field = 'idnumber';
$mform->addElement('text',$field,
get_string('studyplan_idnumber','local_treestudyplan'),
[]);
$contextlist = [];
foreach(courseservice::list_available_categories('edit') as $c){
$contextlist[$c['context_id']] = implode(" / ",$c['category']['path']);
}
$field = 'context_id';
$mform->addElement('autocomplete', $field,
get_string('studyplan_context','local_treestudyplan'),
$contextlist);
$mform->addRule($field, null, 'required', null, 'client');
$timeless = \get_config("local_treestudyplan","timelessperiods");
if ( !$timeless) {
// Only add these fields if the studyplans are timed
$field = 'startdate';
$mform->addElement('date_selector',$field,
get_string('studyplan_startdate','local_treestudyplan'),
[]);
$mform->addRule($field, null, 'required', null, 'client');
}
} else {
$mform->addElement('hidden','hastemplates','no');
$field = 'warning';
$mform->addElement('static', $field,
get_string('warning','core'),
get_string('no_templates','local_treestudyplan')
);
}
}
/**
@ -156,16 +167,20 @@ class studyplan_fromtemplateform extends formbase {
protected function process_submitted_data($entry) {
$customdata = (object)$this->_customdata;
// Find template study plan.
$template = studyplan::find_by_id($entry->template_id);
// Copy template plan.
$plan = $template->duplicate($entry->name,$entry->shortname,$entry->context_id,$entry->idnumber,$entry->startdate);
if($entry->hastemplates == "yes") {
// Find template study plan.
$template = studyplan::find_by_id($entry->template_id);
// Copy template plan.
$plan = $template->duplicate($entry->name,$entry->shortname,$entry->context_id,$entry->idnumber,$entry->startdate);
/* Return the simple model of the plan to make sure we can update stuff.
Parse it through the clean_returnvalue function of exernal api (of which studyplanservice is a subclass)
so we return it in a consistent way
*/
return studyplanservice::clean_returnvalue(studyplan::simple_structure(),$plan->simple_model());
/* Return the simple model of the plan to make sure we can update stuff.
Parse it through the clean_returnvalue function of exernal api (of which studyplanservice is a subclass)
so we return it in a consistent way
*/
return studyplanservice::clean_returnvalue(studyplan::simple_structure(),$plan->simple_model());
} else {
return null;
}
}

View File

@ -511,4 +511,5 @@ $string["line_can_enrol"] = 'You can register for this line';
$string["line_is_enrolled"] = 'You are registered for this line';
$string["line_enrolled_in"] = 'Registered in {$a}';
$string["switch_coach_editmode"] = "Edit studyplan";
$string["suspended"] = "Suspended";
$string["suspended"] = "Suspended";
$string["no_templates"] = "There are no templates available. Mark a study plan as template to enable template based creation.";

View File

@ -511,4 +511,5 @@ $string["line_can_enrol"] = 'Je kunt jezelf inschrijven voor deze leerlijn';
$string["line_is_enrolled"] = 'Je bent ingeschreven voor deze leerlijn';
$string["line_enrolled_in"] = 'Ingeschreven in {$a}';
$string["switch_coach_editmode"] = "Studieplan bewerken";
$string["suspended"] = "Tijdelijk uitgeschakeld";
$string["suspended"] = "Tijdelijk uitgeschakeld";
$string["no_templates"] = "Er zijn geen templates beschikbaar. Zet het vinkje 'Bruikbaar als template' aan bij een studieplan om deze als template te kunnen gebruiken.";