Added extra warning if no templates are available
This commit is contained in:
parent
82838c57c5
commit
886a11d99e
|
@ -100,51 +100,62 @@ class studyplan_fromtemplateform extends formbase {
|
||||||
$templatelist[$s->id()] = implode(" / ",$c['path']) . " / " . $s->name();
|
$templatelist[$s->id()] = implode(" / ",$c['path']) . " / " . $s->name();
|
||||||
}
|
}
|
||||||
|
|
||||||
$field = 'template_id';
|
if (count($templatelist) > 0) {
|
||||||
$mform->addElement('autocomplete', $field,
|
$mform->addElement('hidden','hastemplates','yes');
|
||||||
get_string('studyplan_fromtemplate','local_treestudyplan'),
|
|
||||||
$templatelist);
|
|
||||||
$mform->addRule($field, null, 'required', null, 'client');
|
|
||||||
|
|
||||||
$field = 'name';
|
$field = 'template_id';
|
||||||
$mform->addElement('text',$field,
|
$mform->addElement('autocomplete', $field,
|
||||||
get_string('studyplan_name','local_treestudyplan'),
|
get_string('studyplan_fromtemplate','local_treestudyplan'),
|
||||||
[]);
|
$templatelist);
|
||||||
$mform->addRule($field, null, 'required', null, 'client');
|
$mform->addRule($field, null, 'required', null, 'client');
|
||||||
|
|
||||||
$field = 'shortname';
|
$field = 'name';
|
||||||
$mform->addElement('text',$field,
|
$mform->addElement('text',$field,
|
||||||
get_string('studyplan_shortname','local_treestudyplan'),
|
get_string('studyplan_name','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'),
|
|
||||||
[]);
|
[]);
|
||||||
$mform->addRule($field, null, 'required', null, 'client');
|
$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) {
|
protected function process_submitted_data($entry) {
|
||||||
$customdata = (object)$this->_customdata;
|
$customdata = (object)$this->_customdata;
|
||||||
|
|
||||||
// Find template study plan.
|
if($entry->hastemplates == "yes") {
|
||||||
$template = studyplan::find_by_id($entry->template_id);
|
// Find template study plan.
|
||||||
// Copy template plan.
|
$template = studyplan::find_by_id($entry->template_id);
|
||||||
$plan = $template->duplicate($entry->name,$entry->shortname,$entry->context_id,$entry->idnumber,$entry->startdate);
|
// 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.
|
/* 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)
|
Parse it through the clean_returnvalue function of exernal api (of which studyplanservice is a subclass)
|
||||||
so we return it in a consistent way
|
so we return it in a consistent way
|
||||||
*/
|
*/
|
||||||
return studyplanservice::clean_returnvalue(studyplan::simple_structure(),$plan->simple_model());
|
return studyplanservice::clean_returnvalue(studyplan::simple_structure(),$plan->simple_model());
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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_is_enrolled"] = 'You are registered for this line';
|
||||||
$string["line_enrolled_in"] = 'Registered in {$a}';
|
$string["line_enrolled_in"] = 'Registered in {$a}';
|
||||||
$string["switch_coach_editmode"] = "Edit studyplan";
|
$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.";
|
|
@ -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_is_enrolled"] = 'Je bent ingeschreven voor deze leerlijn';
|
||||||
$string["line_enrolled_in"] = 'Ingeschreven in {$a}';
|
$string["line_enrolled_in"] = 'Ingeschreven in {$a}';
|
||||||
$string["switch_coach_editmode"] = "Studieplan bewerken";
|
$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.";
|
Loading…
Reference in New Issue
Block a user