-
Notifications
You must be signed in to change notification settings - Fork 0
/
reportentry_mform_groups.php
244 lines (158 loc) · 7.27 KB
/
reportentry_mform_groups.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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
<?php
/**
* This class provides a mform that previews the entry form
*
* @copyright © 2011 University of London Computer Centre
* @author http://www.ulcc.ac.uk, http://moodle.ulcc.ac.uk
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
* @package ILP
* @version 2.0
*/
class report_entry_mform extends ilp_moodleform {
public $course_id;
public $report_id;
public $user_id;
public $dbc;
/**
* TODO comment this
*/
function __construct($report_id,$user_id,$entry_id=null,$course_id=null, $students) {
global $CFG;
$this->course_id = $course_id;
$this->report_id = $report_id;
$this->user_id = $user_id;
$this->entry_id = $entry_id;
$this->dbc = new ilp_db();
// print_r($this);
// echo ' dbc ';
// print_r($this->dbc);
$query_string = "?report_id={$report_id}&user_id={$user_id}";
// echo 'query string is: ' . $query_string;
if (!empty($entry_id)) $query_string .= "&entry_id={$entry_id}";
if (!empty($course_id)) $query_string .= "&course_id={$course_id}";
// echo 'students ' . $students;
// call the parent constructor and pass it the report id variable to get latter
parent::__construct("{$CFG->wwwroot}/blocks/group_targets/reports_forms.php?report_id=" . $report_id . "&students=" . $students);
}
/**
* TODO comment this
*/
function definition() {
global $USER, $CFG;
// include the assmgr db
require_once($CFG->dirroot.'/blocks/ilp/db/ilp_db.php');
$dbc = new ilp_db;
$mform =& $this->_form;
//get all of the fields in the current report, they will be returned in order as
//no position has been specified
$reportfields = $this->dbc->get_report_fields_by_position($this->report_id);
$report = $this->dbc->get_report_by_id($this->report_id);
$user = $this->dbc->get_user_by_id($this->user_id);
//create a new fieldset
// $mform->addElement('html', '<fieldset id="reportfieldset" class="clearfix ilpfieldset">');
// $mform->addElement('html', '<legend class="ftoggler">'.$title.'</legend>');
$desc = html_entity_decode($report->description);
$mform->addElement('html', '<div class="descritivetext">'.$desc.'</div>');
$mform->addElement('hidden', 'entry_id',$this->entry_id);
$mform->setType('entry_id', PARAM_INT);
$mform->addElement('hidden', 'report_id',$this->report_id);
$mform->setType('report_id', PARAM_INT);
$mform->addElement('hidden', 'user_id',$this->user_id);
$mform->setType('user_id', PARAM_INT);
$mform->addElement('hidden', 'course_id',$this->course_id);
$mform->setType('course_id', PARAM_INT);
if (!empty($reportfields)) {
foreach ($reportfields as $field) {
//get the plugin record that for the plugin
$pluginrecord = $dbc->get_plugin_by_id($field->plugin_id);
//take the name field from the plugin as it will be used to call the instantiate the plugin class
$classname = $pluginrecord->name;
// include the class for the plugin
include_once("{$CFG->dirroot}/blocks/ilp/classes/form_elements/plugins/{$classname}.php");
if(!class_exists($classname)) {
print_error('noclassforplugin', 'block_ilp', '', $pluginrecord->name);
}
//instantiate the plugin class
$pluginclass = new $classname();
$pluginclass->load($field->id);
//call the plugins entry_form function which will add an instance of the plugin
//to the form
$pluginclass->entry_form($mform);
}
}
$buttonarray[] = &$mform->createElement('submit', 'submitbutton', get_string('submit'));
// $buttonarray[] = &$mform->createElement('cancel');
$mform->addGroup($buttonarray, 'buttonar', '', array(' '), false);
//close the fieldset
$mform->addElement('html', '</fieldset>');
}
/**
* TODO comment this
*/
function process_data($data, $students) {
$studentArray = unserialize($students);
echo 'student array: ';
print_r($students);
// add the loop here for multiple users from the session?
foreach ($studentArray as $student) {
echo 'processing';
global $CFG,$USER;
//no need to process data as this is just a preview of the final form
//get the id of the report
$report_id = $data->report_id;
//get the id of the entry if known
$entry_id = $data->entry_id;
//get the id of the user
$user_id = $data->user_id;
//get the id of the course
$course_id = $data->course_id;
$result = true;
if (empty($entry_id)) {
//create the entry
$entry = new stdClass();
$entry->report_id = $report_id;
$entry->creator_id = $USER->id;
$entry->user_id = $student;
//TODO: do we need to save course ?
//$entry->course
$entry_id = $this->dbc->create_entry($entry);
} else {
//update the entry
//as there is nothing to update but we want the entries timemodifed
//to be updated we will just re-add the report_id
$entry = new stdClass();
$entry->id = $entry_id;
$entry->report_id = $report_id;
if (!$this->dbc->update_entry($entry)) $result = false;
}
//get all of the fields in the current report, they will be returned in order as
//no position has been specified
$reportfields = $this->dbc->get_report_fields_by_position($report_id);
foreach ($reportfields as $field) {
//get the plugin record that for the plugin
$pluginrecord = $this->dbc->get_plugin_by_id($field->plugin_id);
//take the name field from the plugin as it will be used to call the instantiate the plugin class
$classname = $pluginrecord->name;
// include the class for the plugin
include_once("{$CFG->dirroot}/blocks/ilp/classes/form_elements/plugins/{$classname}.php");
if(!class_exists($classname)) {
print_error('noclassforplugin', 'block_ilp', '', $pluginrecord->name);
}
//instantiate the plugin class
$pluginclass = new $classname();
$pluginclass->load($field->id);
//call the plugins entry_form function which will add an instance of the plugin
//to the form
if ($pluginclass->is_processable()) {
if (!$pluginclass->entry_process_data($field->id,$entry_id,$data)) $result = false;
}
}
}
return $result;
}
/**
* TODO comment this
*/
function definition_after_data() {
}
}