-
Notifications
You must be signed in to change notification settings - Fork 0
/
field.class.php
81 lines (68 loc) · 2.71 KB
/
field.class.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* @package datafield
* @subpackage linkedradiobutton
* @copyright 2015 onwards Andrew Hancox (andrewdchancox@googlemail.com)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once($CFG->dirroot . '/mod/data/field/radiobutton/field.class.php');
class data_field_linkedradiobutton extends data_field_radiobutton {
public $type = 'linkedradiobutton';
public function display_browse_field($recordid, $template) {
global $DB, $CFG;
if ($content = $DB->get_record('data_content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))) {
if (empty($content->content)) {
return false;
}
$options = explode("\n", $this->field->param1);
$options = array_map('trim', $options);
$contentarray = explode('##', $content->content);
$str = '';
foreach ($contentarray as $line) {
if (!in_array($line, $options)) {
// Somebody edited the field definition.
continue;
}
$params = array(
"f_{$this->field->id}" => $line,
'd' => $this->data->id,
'advanced' => 1
);
$url = new moodle_url('/mod/data/view.php', $params);
$link = html_writer::link($url, $line);
$str .= $link . "<br />\n";
}
return $str;
}
return false;
}
/**
* Prints the respective type icon
*
* @global object
* @return string
*/
function image() {
global $OUTPUT;
$params = array('d' => $this->data->id, 'fid' => $this->field->id, 'mode' => 'display', 'sesskey' => sesskey());
$link = new moodle_url('/mod/data/field.php', $params);
$str = '<a href="' . $link->out() . '">';
$str .= $OUTPUT->pix_icon('linkedradiobutton', 'linkedradiobutton', 'datafield_linkedradiobutton');
$str .= '</a>';
return $str;
}
}