2018-11-24 12:34:30 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
require_once($CFG->dirroot.'/blocks/gradelevel/lib.php');
|
|
|
|
|
|
|
|
class block_gradelevel_edit_form extends block_edit_form {
|
|
|
|
|
|
|
|
|
|
|
|
protected function specific_definition($mform) {
|
|
|
|
global $CFG;
|
|
|
|
// retrieve levelset
|
|
|
|
$levelset = $this->block->levelset;
|
|
|
|
|
|
|
|
// Section header title according to language file.
|
|
|
|
$mform->addElement('header', 'config_header', get_string('blocksettings', 'block'));
|
|
|
|
|
|
|
|
$skills = block_gradelevel_levelset::list_all();
|
|
|
|
// sort by name
|
|
|
|
usort( $skills, function( $a, $b) {
|
|
|
|
return ( $a->getName() < $b->getName()) ? -1 : 1;
|
|
|
|
} );
|
|
|
|
|
|
|
|
$options = array( '-1' => get_string('edit_noneskill', 'block_gradelevel'));
|
|
|
|
foreach($skills as $skill)
|
|
|
|
{
|
|
|
|
$options[$skill->getId()] = $skill->getName();
|
|
|
|
}
|
|
|
|
|
|
|
|
// A sample string variable with a default value.
|
|
|
|
$mform->addElement('select', 'attached_skill', get_string('edit_pickskill', 'block_gradelevel'), $options);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public function set_data($defaults)
|
|
|
|
{
|
|
|
|
global $COURSE;
|
|
|
|
|
|
|
|
$defaults->attached_skill = -1;
|
|
|
|
// retrieve levelset
|
|
|
|
$skill = block_gradelevel_levelset::find_by_course($COURSE->id);
|
|
|
|
if(isset($skill)){
|
|
|
|
$defaults->attached_skill = $skill->getId();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
parent::set_data($defaults);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function get_data()
|
|
|
|
{
|
|
|
|
$data = parent::get_data();
|
|
|
|
|
|
|
|
if(isset($data))
|
|
|
|
{
|
|
|
|
$this->save_data($data);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function save_data($data)
|
|
|
|
{
|
|
|
|
global $COURSE;
|
|
|
|
// retrieve levelset
|
|
|
|
|
|
|
|
if(isset($data->attached_skill))
|
|
|
|
{
|
|
|
|
$currentskill = block_gradelevel_levelset::find_by_course($COURSE->id);
|
|
|
|
if(isset($currentskill))
|
|
|
|
{
|
|
|
|
$currentskill->detach_course($COURSE->id);
|
|
|
|
}
|
|
|
|
|
|
|
|
$skill = block_gradelevel_levelset::find_by_id($data->attached_skill);
|
|
|
|
if(isset($skill)){
|
|
|
|
$skill->attach_course($COURSE->id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-17 13:12:56 +02:00
|
|
|
}
|