2018-09-17 13:12:56 +02: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'));
|
|
|
|
|
2018-09-23 22:06:52 +02:00
|
|
|
$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)
|
2018-09-17 13:12:56 +02:00
|
|
|
{
|
2018-09-23 22:06:52 +02:00
|
|
|
$options[$skill->getId()] = $skill->getName();
|
2018-09-17 13:12:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// A sample string variable with a default value.
|
2018-09-23 22:06:52 +02:00
|
|
|
$mform->addElement('select', 'attached_skill', get_string('edit_pickskill', 'block_gradelevel'), $options);
|
|
|
|
|
2018-09-21 22:30:09 +02:00
|
|
|
|
2018-09-17 13:12:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function set_data($defaults)
|
|
|
|
{
|
2018-09-23 22:06:52 +02:00
|
|
|
global $COURSE;
|
2018-09-17 13:12:56 +02:00
|
|
|
|
2018-09-23 22:06:52 +02:00
|
|
|
$defaults->attached_skill = -1;
|
|
|
|
// retrieve levelset
|
|
|
|
$skill = block_gradelevel_levelset::find_by_course($COURSE->id);
|
|
|
|
if(isset($skill)){
|
|
|
|
$defaults->attached_skill = $skill->getId();
|
|
|
|
}
|
2018-09-17 13:12:56 +02:00
|
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2018-09-23 22:06:52 +02:00
|
|
|
global $COURSE;
|
2018-09-17 13:12:56 +02:00
|
|
|
// retrieve levelset
|
|
|
|
|
2018-09-23 22:06:52 +02:00
|
|
|
if(isset($data->attached_skill))
|
2018-09-17 13:12:56 +02:00
|
|
|
{
|
2018-09-23 22:06:52 +02:00
|
|
|
$currentskill = block_gradelevel_levelset::find_by_course($COURSE->id);
|
|
|
|
if(isset($currentskill))
|
2018-09-17 13:12:56 +02:00
|
|
|
{
|
2018-09-23 22:06:52 +02:00
|
|
|
$this->debug("deetaching...");
|
|
|
|
$currentskill->detach_course($COURSE->id);
|
2018-09-17 13:12:56 +02:00
|
|
|
}
|
|
|
|
|
2018-09-23 22:06:52 +02:00
|
|
|
$skill = block_gradelevel_levelset::find_by_id($data->attached_skill);
|
|
|
|
if(isset($skill)){
|
|
|
|
$this->debug("attaching...");
|
|
|
|
$skill->attach_course($COURSE->id);
|
|
|
|
}
|
2018-09-17 13:12:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private function debug($msg)
|
|
|
|
{
|
|
|
|
error_log($msg, 3, '/tmp/moodledevlog.log');
|
|
|
|
}
|
|
|
|
}
|