Repository navigation
Expand file tree
/
Copy pathextrasettings.php
More file actions
179 lines (167 loc) · 6.94 KB
/
Copy pathextrasettings.php
File metadata and controls
179 lines (167 loc) · 6.94 KB
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
<?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/>.
/**
* ILP Integration
*
* This program 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.
*
* This program 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 this program. If not, see http://opensource.org/licenses/gpl-3.0.html.
*
* @copyright Copyright (c) 2012 Moodlerooms Inc. (http://www.moodlerooms.com)
* @license http://opensource.org/licenses/gpl-3.0.html GNU Public License
* @package block_intelligent_learning
* @author Sam Chaffee
*/
/**
* ILP Integration block extra settings class definitions
*
* @author Sam Chaffee
* @version $Id$
* @package block_intelligent_learning
**/
/**
* Creates a setting where you can define
* dates related to categories and then manage
* those set dates (EG: update or delete)
*/
class admin_setting_intelligent_learning_catdate extends admin_setting {
/**
* Returns current value of this setting
* @return mixed array or string depending on instance, null means not set yet
*/
public function get_setting() {
$config = $this->config_read($this->name);
if (!empty($config)) {
$return = array();
parse_str($config, $return);
return $return;
}
return $config;
}
/**
* Store new setting
* @param mixed string or array, must not be null
* @return '' if ok, string error message otherwise
*/
public function write_setting($data) {
global $CFG, $DB;
if (!$config = $this->get_setting()) {
$config = array();
}
$categoryid = optional_param($this->get_full_name().'_categoryid', 0, PARAM_INT);
$date = optional_param($this->get_full_name().'_date', '', PARAM_TEXT);
$delete = optional_param($this->get_full_name().'_delete', 0, PARAM_INT);
if (!empty($delete)) {
foreach ($delete as $deletecatid => $value) {
unset($config[$deletecatid]);
}
}
if (!empty($categoryid) and !empty($date)) {
try {
$helper = new mr_helper('blocks/intelligent_learning');
$config[$categoryid] = $helper->date($date);
} catch (moodle_exception $e) {
return $e->getMessage();
}
}
if (!empty($config)) {
// Validate that all category IDs still exist.
foreach ($config as $catid => $date) {
if (!$DB->record_exists('course_categories', array('id' => $catid))) {
unset($config[$catid]);
}
}
$config = http_build_query($config, '', '&');
} else {
$config = '';
}
return ($this->config_write($this->name, $config) ? '' : get_string('errorsetting', 'admin'));
}
/**
* Return part of form with setting
* @param mixed data array or string depending on setting
* @return string
*/
public function output_html($data, $query='') {
global $CFG, $OUTPUT;
require_once($CFG->dirroot. '/course/lib.php');
$helper = new mr_helper('blocks/intelligent_learning');
$displaylist = core_course_category::make_categories_list();
$category = html_writer::select($displaylist, $this->get_full_name().'_categoryid');
$checkboxes = '';
if ($config = $this->get_setting($this->name)) {
$options = array();
foreach ($displaylist as $categoryid => $displayname) {
if (array_key_exists($categoryid, $config)) {
$options[] = $displayname.': '.$helper->date->format($config[$categoryid]).' '.
'<input type="checkbox" id="'.$this->get_id().'_'.$categoryid.'" name="'.$this->get_full_name().'_delete['.$categoryid.']" value="1" />'
.'<label for="'.$this->get_id().'_'.$categoryid.'">'.get_string('delete').'</label>';
}
}
if (!empty($options)) {
$checkboxes = '<div class="form-multicheckbox"><ul><li>'.implode('</li><li>', $options).'</li></ul></div><br />';
}
}
$helpbutton = $OUTPUT->help_icon('categorycutoff', 'block_intelligent_learning');
return format_admin_setting($this, $this->visiblename,
'<div class="form-text defaultsnext"><input type="hidden" id="'.$this->get_id().'" name="'.$this->get_full_name().'" value="1" />'.$checkboxes.$category.
'<input type="text" size="15" id="'.$this->get_id().'" name="'.$this->get_full_name().'_date" />
<input type="submit" value="'.s(get_string('addcutoff', 'block_intelligent_learning'))."\" /> $helpbutton</div>",
$this->description, false, '', null, $query);
}
}
/**
* Creates the extraletters config option.
*
* Config value is like: I,NC,WOW
* All caps, each less than or equal to three characters, separated by commas and no spaces.
*/
class admin_setting_intelligent_learning_extraletters extends admin_setting_configtext {
/**
* Constructor specific to extraletters config
*/
public function __construct() {
parent::__construct('extraletters', get_string('extraletters', 'block_intelligent_learning'), get_string('extralettersdesc', 'block_intelligent_learning'), '');
}
/**
* Specific validation and data manipulation
*/
public function validate($data) {
if ($data != '') {
$parts = explode(',', $data);
$newdata = array();
foreach ($parts as $part) {
$part = trim($part);
$part = strtoupper($part);
if (strlen($part) > 3) {
return get_string('lettergradetoolong', 'block_intelligent_learning', $part);
}
$newdata[] = $part;
}
$data = implode(',', $newdata);
}
return true;
}
}