-
Notifications
You must be signed in to change notification settings - Fork 0
/
edit_form.php
195 lines (166 loc) · 6.65 KB
/
edit_form.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
<?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/>.
/**
* This block generates a simple list of links based on the users profile.
*
* @package block_links
* @copyright 2013 Stephen Bourget
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
require_once($CFG->libdir . '/formslib.php');
require_once($CFG->dirroot.'/blocks/links/lib.php');
/**
* This defines the edit form for managing the links.
*
* @package block_links
* @copyright 2010 Stephen Bourget
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class link_edit_form extends moodleform {
/**
* Link ID.
* @var int
*/
protected $id;
/**
* Link text to display.
* @var string
*/
protected $linktext = '';
/**
* URL of web-link.
* @var string
*/
protected $url = '';
/**
* Additional notes to display.
* @var string
*/
protected $notes = '';
/**
* Default display setting
* @var boolean
*/
protected $defaultshow = BLOCK_LINKS_SHOWLINK;
/**
* Profile setting to match when displaying the link.
* @var string
*/
protected $department = BLOCK_LINKS_SHOW_EVERYONE;
/**
* Constructor.
* @param string $actionurl
* @param int $id
*/
public function __construct($actionurl, $id) {
$this->id = $id;
parent::__construct($actionurl);
}
/**
* Form definition.
*/
public function definition() {
global $DB;
$blockconfig = get_config('block_links');
$mform =& $this->_form;
// Then show the fields about where this block appears.
$mform->addElement('header', 'editlinkheader', get_string('managelinks', 'block_links'));
$mform->addElement('text', 'linktext', get_string('linktext', 'block_links'), array('size' => 60));
$mform->setType('linktext', PARAM_TEXT);
$mform->addRule('linktext', null, 'required');
$mform->addRule('linktext', null, 'maxlength', 250);
$mform->addElement('text', 'url', get_string('url', 'block_links'), array('size' => 60));
$mform->setType('url', PARAM_URL);
$mform->addRule('url', null, 'required');
$mform->addRule('url', null, 'maxlength', 250);
$mform->addElement('header', 'additionalsettings', get_string('additionalsettings', 'block_links'));
$mform->addElement('text', 'notes', get_string('notes', 'block_links'), array('size' => 60));
$mform->setType('notes', PARAM_TEXT);
$mform->addRule('notes', null, 'maxlength', 250);
$mform->addElement('select', 'defaultshow', get_string('defaultshow', 'block_links'),
array(BLOCK_LINKS_SHOWLINK => get_string('yes'), BLOCK_LINKS_HIDELINK => get_string('no')));
$mform->setType('defaultshow', PARAM_INT);
$mform->setDefault('defaultshow', $this->defaultshow);
$options = array();
$options['All'] = get_string('all', 'block_links');
switch($blockconfig->profile_field) {
case BLOCK_LINKS_INSTITUTION:
$sql = "SELECT DISTINCT institution FROM {user} ORDER BY institution";
$categories = $DB->get_records_sql($sql);
foreach ($categories as $category) {
if (!empty($category->institution)) {
$options[$category->institution] = $category->institution;
}
}
break;
case BLOCK_LINKS_DEPARTMENT:
$sql = "SELECT DISTINCT department FROM {user} ORDER BY department";
$categories = $DB->get_records_sql($sql);
foreach ($categories as $category) {
if (!empty($category->department)) {
$options[$category->department] = $category->department;
}
}
break;
case BLOCK_LINKS_CITY:
$sql = "SELECT DISTINCT city FROM {user} ORDER BY city";
$categories = $DB->get_records_sql($sql);
foreach ($categories as $category) {
if (!empty($category->city)) {
$options[$category->city] = $category->city;
}
}
break;
case BLOCK_LINKS_COUNTRY:
$sql = "SELECT DISTINCT country FROM {user} ORDER BY country";
$categories = $DB->get_records_sql($sql);
foreach ($categories as $category) {
if (!empty($category->country)) {
$options[$category->country] = $category->country;
}
}
break;
case BLOCK_LINKS_DESCRIPTION:
$sql = "SELECT DISTINCT description FROM {user} ORDER BY description";
$categories = $DB->get_records_sql($sql);
foreach ($categories as $category) {
$item = "";
if (!empty($category->description)) {
// Strip tags etc before display.
$item = clean_param($category->description, PARAM_NOTAGS);
$options[$item] = $item;
}
}
break;
default:
$sql = "SELECT DISTINCT institution FROM {user} ORDER BY institution";
$categories = $DB->get_records_sql($sql);
foreach ($categories as $category) {
if (!empty($category->institution)) {
$options[$category->institution] = $category->institution;
}
}
}
$mform->addElement('select', 'department', get_string('category', 'block_links'), $options);
$mform->setType('department', PARAM_TEXT);
$mform->setDefault('department', 'All');
// Hidden.
$mform->addElement('hidden', 'id');
$mform->setType('id', PARAM_INT);
$this->add_action_buttons(true);
}
}