-
Notifications
You must be signed in to change notification settings - Fork 1
/
block_game_content_unlock_conditionadd_form.php
159 lines (129 loc) · 6.08 KB
/
block_game_content_unlock_conditionadd_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
<?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/>.
/**
* Content unlock block add condition form definition.
*
* @package block_game_content_unlock
* @copyright 2016 Loys Henrique Saccomano Gibertoni
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once("{$CFG->libdir}/formslib.php");
class block_game_content_unlock_conditionadd_form extends moodleform
{
function __construct($unlocksystemid)
{
$this->unlocksystemid = $unlocksystemid;
parent::__construct();
}
function definition()
{
global $DB, $COURSE;
$mform =& $this->_form;
$mform->addElement('header','displayinfo', get_string('conditionadd_header', 'block_game_content_unlock'));
$condition_types = array();
$game_points_installed = $DB->record_exists('block', array('name' => 'game_points'));
if($game_points_installed)
{
$condition_types[0] = get_string('conditionadd_typebypointstext', 'block_game_content_unlock');
}
$condition_types[1] = get_string('conditionadd_typebyunlocktext', 'block_game_content_unlock');
$game_achievements_installed = $DB->record_exists('block', array('name' => 'game_content_unlock'));
if($game_achievements_installed)
{
$condition_types[2] = get_string('conditionadd_typebyachievementtext', 'block_game_content_unlock');
}
$mform->addElement('select', 'condition_type', get_string('conditionadd_typetext', 'block_game_content_unlock'), $condition_types, null);
$mform->addRule('condition_type', null, 'required', null, 'client');
// Points system condition
if($game_points_installed)
{
$mform->addElement('html', '<hr></hr>');
$points_systems_list = array();
$blocks_info = $DB->get_records('block_instances', array('blockname' => 'game_points'));
foreach($blocks_info as $info)
{
$instance = block_instance('game_points', $info);
$points_systems_list['block::' . $instance->instance->id] = '- Bloco ' . $instance->title;
$points_systems = $DB->get_records('points_system', array('blockinstanceid' => $instance->instance->id, 'deleted' => 0));
foreach($points_systems as $points_system)
{
$points_systems_list['pointsystem::' . $points_system->id] = ' Sistema de pontos ' . (isset($points_system->name) ? $points_system->name . ' (' . $points_system->id . ')' : $points_system->id);
}
}
$mform->addElement('select', 'points_condition_blockorpointsystemid', 'Os pontos do bloco', $points_systems_list, null);
$mform->disabledIf('points_condition_blockorpointsystemid', 'condition_type', 'neq', 0);
$mform->addElement('text', 'points_condition_points', 'Maiores ou iguais a');
$mform->disabledIf('points_condition_points', 'condition_type', 'neq', 0);
$mform->addElement('advcheckbox', 'points_condition_grupal', 'Grupal', null, null, array(0, 1));
}
// Content unlock system condition
$mform->addElement('html', '<hr></hr>');
$unlock_systems = array();
$blocks_info = $DB->get_records('block_instances', array('blockname' => 'game_content_unlock'));
foreach($blocks_info as $info)
{
$instance = block_instance('game_content_unlock', $info);
$sql = "SELECT *
FROM
{content_unlock_system} u
WHERE u.deleted = 0
AND u.blockinstanceid = :blockinstanceid";
$params['blockinstanceid'] = $instance->instance->id;
$us = $DB->get_records_sql($sql, $params);
foreach($us as $unlock_system)
{
$course = $DB->get_record('course', array('id' => $COURSE->id));
$info = get_fast_modinfo($course);
$cm = $info->get_cm($unlock_system->coursemoduleid);
$unlock_systems[$unlock_system->id] = ($unlock_system->coursemodulevisibility ? 'Desbloqueado' : 'Bloqueado') . ' o recurso/atividade ' . $cm->name . ' (bloco ' . $instance->title . ')';
}
}
$mform->addElement('select', 'unlock_condition_must', 'O aluno', array(0 => 'Não deve', 1 => 'Deve'), null);
$mform->setDefault('unlock_condition_must', 1);
$mform->disabledIf('unlock_condition_must', 'condition_type', 'neq', 1);
$mform->addElement('select', 'unlock_condition_unlocksystemid', 'Ter', $unlock_systems, null);
$mform->disabledIf('unlock_condition_unlocksystemid', 'condition_type', 'neq', 1);
// Achievement condition
if($game_achievements_installed)
{
$mform->addElement('html', '<hr></hr>');
$achievements = array();
$blocks_info = $DB->get_records('block_instances', array('blockname' => 'game_achievements'));
foreach($blocks_info as $info)
{
$instance = block_instance('game_achievements', $info);
$sql = 'SELECT id
FROM {achievements}
WHERE blockinstanceid = :blockinstanceid
AND deleted = :deleted';
$params['blockinstanceid'] = $instance->instance->id;
$params['deleted'] = 0;
$achievement_ids = $DB->get_fieldset_sql($sql, $params);
foreach($achievement_ids as $achievement_id)
{
$achievement = $DB->get_record('achievements', array('id' => $achievement_id));
$achievements[$achievement_id] = 'Conquista ' . (isset($achievement->name) ? $achievement->name . ' (' . $achievement_id . ')' : $achievement_id) . ' (bloco ' . $instance->title . ')';
}
}
$mform->addElement('select', 'achievements_condition_achievementid', 'Ter alcançado a', $achievements, null);
$mform->disabledIf('achievements_condition_achievementid', 'condition_type', 'neq', 2);
}
$mform->addElement('hidden', 'unlocksystemid');
$mform->addElement('hidden', 'courseid');
$this->add_action_buttons();
}
}
?>