-
Notifications
You must be signed in to change notification settings - Fork 4
/
renderer.php
executable file
·115 lines (99 loc) · 5.18 KB
/
renderer.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
<?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/>.
/**
* The renderer for qpractice module.
*
* @package mod_qpractice
* @copyright 2013 Jayesh Anandani
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
class mod_qpractice_renderer extends plugin_renderer_base {
public function summary_table($sessionid) {
global $DB;
$session = $DB->get_record('qpractice_session', array('id' => $sessionid));
$table = new html_table();
$table->attributes['class'] = 'generaltable qpracticesummaryofattempt boxaligncenter';
$table->caption = 'Hello';
$table->head = array(get_string('totalquestions', 'qpractice'), get_string('totalmarks', 'qpractice'));
$table->align = array('left', 'left');
$table->size = array('', '');
$table->data = array();
$table->data[] = array($session->totalnoofquestions, $session->marksobtained.'/'.$session->totalmarks);
echo html_writer::table($table);
}
public function summary_form($sessionid) {
$actionurl = new moodle_url('/mod/qpractice/summary.php', array('id'=>$sessionid));
$output='';
$output .= html_writer::start_tag('form', array('method' => 'post', 'action' => $actionurl,
'enctype' => 'multipart/form-data', 'id' => 'responseform'));
$output .= html_writer::start_tag('div', array('align'=> 'center'));
$output .= html_writer::empty_tag('input', array('type' => 'submit',
'name' => 'back', 'value' => get_string('backpractice', 'qpractice')));
$output .= html_writer::empty_tag('br');
$output .= html_writer::empty_tag('br');
$output .= html_writer::empty_tag('input', array('type' => 'submit',
'name' => 'finish', 'value' => get_string('submitandfinish', 'qpractice')));
$output .= html_writer::end_tag('div');
$output .= html_writer::end_tag('form');
echo $output;
}
public function report_table($cm, $context) {
global $DB, $USER;
$canviewallreports=has_capability('mod/qpractice:viewallreports', $context);
$canviewmyreports=has_capability('mod/qpractice:viewmyreport', $context);
if ($canviewmyreports) {
$session = $DB->get_records('qpractice_session', array('qpracticeid' => $cm->instance, 'userid' => $USER->id));
} if ($canviewallreports) {
$session = $DB->get_records('qpractice_session', array('qpracticeid' => $cm->instance));
}
if ($session!=null) {
$table = new html_table();
$table->attributes['class'] = 'generaltable qpracticesummaryofpractices boxaligncenter';
$table->caption = 'Hello';
$table->head = array(get_string('practicedate', 'qpractice'), get_string('category', 'qpractice'),
get_string('typeofpractice', 'qpractice'), get_string('score', 'qpractice'),
get_string('timegoalset', 'qpractice'), get_string('noofquestionsviewed', 'qpractice'),
get_string('noofquestionsright', 'qpractice'));
$table->align = array('left', 'left', 'left', 'left', 'left', 'left', 'left');
$table->size = array('', '', '', '', '', '', '', '');
$table->data = array();
foreach ($session as $qpractice) {
$date = $qpractice->practicedate;
$value = $qpractice->typeofpractice;
$categoryid = $qpractice->categoryid;
$category = $DB->get_records_menu('question_categories', array('id'=>$categoryid), 'name');
if ($value =='1') {
$value = 'Normal';
$timegoal = '-';
} else if ($value == '2') {
$value = 'Time Achiever';
$timegoal = $qpractice->time;
} else {
$value = 'Goal Achiever';
$timegoal = $qpractice->goalpercentage;
}
$table->data[] = array(userdate($date), $category[$categoryid], $value, $qpractice->marksobtained.'/'.$qpractice->totalmarks, $timegoal,
$qpractice->totalnoofquestions, $qpractice->totalnoofquestionsright);
}
echo html_writer::table($table);
} else {
$viewurl = new moodle_url('/mod/qpractice/view.php', array('id'=>$cm->id));
$viewtext = get_string('viewurl', 'qpractice');
redirect($viewurl, $viewtext);
}
}
}