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'));
|
|
|
|
|
|
|
|
// A sample string variable with a default value.
|
|
|
|
$mform->addElement('text', 'levelset_name', get_string('levelset_name', 'block_gradelevel'));
|
|
|
|
|
|
|
|
$icon = $levelset->getIcon();
|
|
|
|
if(strncmp($icon,"data: ",6) != 0)
|
|
|
|
{
|
|
|
|
$icon = $CFG->wwwroot.$icon;
|
|
|
|
}
|
|
|
|
|
|
|
|
$icon_title = get_string('levelset_icon_cur', 'block_gradelevel');
|
|
|
|
$mform->addElement('html',"<div class='form-group row fitem'><div class='col-md-3'>{$icon_title}</div><div class='col-md-9'><figure class='levelset_icon'><img src='{$icon}' /></figure></div></div>");
|
|
|
|
|
|
|
|
// A sample string variable with a default value.
|
|
|
|
$mform->addElement('filepicker', 'levelset_icon', get_string('levelset_icon_new', 'block_gradelevel'), null,
|
|
|
|
array('maxbytes' => $maxbytes, 'accepted_types' => array('.png', '.svg')));
|
|
|
|
|
2018-09-21 22:30:09 +02:00
|
|
|
$mform->addElement('header', 'config_header', get_string('levelset_levels', 'block_gradelevel'));
|
|
|
|
$mform->addElement('html',print block_gradelevel_managelevelservice::render_leveltable(0));
|
|
|
|
|
2018-09-17 13:12:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function set_data($defaults)
|
|
|
|
{
|
|
|
|
// retrieve levelset
|
|
|
|
$levelset = $this->block->levelset;
|
|
|
|
|
|
|
|
$defaults->levelset_name = $levelset->getName();
|
|
|
|
|
|
|
|
$defaults->levelset_icon = $levelset->getIcon();
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
// retrieve levelset
|
|
|
|
$levelset = $this->block->levelset;
|
|
|
|
|
|
|
|
$this->debug("data: ".print_r($data,true));
|
|
|
|
|
|
|
|
|
|
|
|
if(isset($data->levelset_name)){
|
|
|
|
$levelset->setName($data->levelset_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(isset($data->levelset_icon))
|
|
|
|
{
|
|
|
|
$filename = $this->get_new_filename('levelset_icon');
|
|
|
|
$contents = $this->get_file_content('levelset_icon');
|
|
|
|
|
|
|
|
$imageData = base64_encode($contents);
|
|
|
|
|
|
|
|
$pi = pathinfo($filename);
|
|
|
|
if($pi['extension'] == 'svg')
|
|
|
|
{
|
|
|
|
$mime = "image/svg+xml";
|
|
|
|
}
|
|
|
|
else if($pi['extension'] == 'png')
|
|
|
|
{
|
|
|
|
$mime = "image/png";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$mime = "binary/octet-stream"; // no idea what it is
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$dataSrc = 'data: '.$mime.';base64,'.$imageData;
|
|
|
|
|
|
|
|
$levelset->setIcon($dataSrc);
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->debug("levelset: ".print_r($levelset,true));
|
|
|
|
|
|
|
|
$levelset->save_data();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private function debug($msg)
|
|
|
|
{
|
|
|
|
error_log($msg, 3, '/tmp/moodledevlog.log');
|
|
|
|
}
|
|
|
|
}
|