/
award_criteria_overall.php
158 lines (142 loc) · 5.13 KB
/
award_criteria_overall.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
<?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 file contains the overall badge award criteria type
*
* @package core
* @subpackage badges
* @copyright 2012 onwards Totara Learning Solutions Ltd {@link http://www.totaralms.com/}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @author Yuliya Bozhko <yuliya.bozhko@totaralms.com>
*/
defined('MOODLE_INTERNAL') || die();
/**
* Overall badge award criteria
*
*/
class award_criteria_overall extends award_criteria {
/* @var int Criteria [BADGE_CRITERIA_TYPE_OVERALL] */
public $criteriatype = BADGE_CRITERIA_TYPE_OVERALL;
/**
* Add appropriate form elements to the criteria form
*
* @param stdClass $data details of overall criterion
*/
public function config_form_criteria($data) {
global $OUTPUT;
$prefix = 'criteria-' . $this->id;
if (count($data->criteria) > 2) {
echo $OUTPUT->box_start();
echo $OUTPUT->heading($this->get_title(), 2);
$agg = $data->get_aggregation_methods();
if (!$data->is_locked() && !$data->is_active()) {
$url = new moodle_url('criteria.php', array('id' => $data->id, 'sesskey' => sesskey()));
$table = new html_table();
$table->attributes = array('class' => 'clearfix');
$table->colclasses = array('', 'activatebadge');
$table->data[] = array(
$OUTPUT->single_select($url, 'update', $agg, $data->get_aggregation_method($this->criteriatype), null),
get_string('overallcrit', 'badges')
);
echo html_writer::table($table);
} else {
echo $OUTPUT->box(get_string('criteria_descr_' . $this->criteriatype, 'badges',
core_text::strtoupper($agg[$data->get_aggregation_method()])), 'clearfix');
}
echo $OUTPUT->box_end();
}
}
/**
* Add appropriate parameter elements to the criteria form
*
*/
public function config_options(&$mform, $param) {
}
/**
* Get criteria details for displaying to users
*
* @return string
*/
public function get_details($short = '') {
}
/**
* Review this criteria and decide if it has been completed
* Overall criteria review should be called only from other criteria handlers.
*
* @param int $userid User whose criteria completion needs to be reviewed.
* @param bool $filtered An additional parameter indicating that user list
* has been reduced and some expensive checks can be skipped.
*
* @return bool Whether criteria is complete
*/
public function review($userid, $filtered = false) {
global $DB;
$sql = "SELECT bc.*, bcm.critid, bcm.userid, bcm.datemet
FROM {badge_criteria} bc
LEFT JOIN {badge_criteria_met} bcm
ON bc.id = bcm.critid AND bcm.userid = :userid
WHERE bc.badgeid = :badgeid
AND bc.criteriatype != :criteriatype ";
$params = array(
'userid' => $userid,
'badgeid' => $this->badgeid,
'criteriatype' => BADGE_CRITERIA_TYPE_OVERALL
);
$criteria = $DB->get_records_sql($sql, $params);
$overall = false;
foreach ($criteria as $crit) {
if ($this->method == BADGE_CRITERIA_AGGREGATION_ALL) {
if ($crit->datemet === null) {
return false;
} else {
$overall = true;
continue;
}
} else {
if ($crit->datemet === null) {
$overall = false;
continue;
} else {
return true;
}
}
}
return $overall;
}
/**
* Returns array with sql code and parameters returning all ids
* of users who meet this particular criterion.
*
* @return array list($join, $where, $params)
*/
public function get_completed_criteria_sql() {
return array('', '', array());
}
/**
* Add appropriate criteria elements to the form
*
*/
public function get_options(&$mform) {
}
/**
* Return criteria parameters
*
* @param int $critid Criterion ID
* @return array
*/
public function get_params($cid) {
}
}