forked from vfremaux/moodle-mod_flashcard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayview.php
194 lines (171 loc) · 8.45 KB
/
playview.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
<?php
/**
* This view allows playing with a deck
*
* @package mod-flashcard
* @category mod
* @author Gustav Delius
* @contributors Valery Fremaux
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
* @version Moodle 2.0
*/
/// Security
if (!defined('MOODLE_INTERNAL')){
die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page.
}
/// Invoke controller
// we need it in controller
$deck = required_param('deck', PARAM_INT);
$subquestions = $DB->get_records('flashcard_deckdata', array('flashcardid' => $flashcard->id));
if ($action != ''){
include $CFG->dirroot.'/mod/flashcard/playview.controller.php';
}
// unmark state for this deck
$DB->delete_records('flashcard_userdeck_state', array('userid' => $USER->id, 'flashcardid' => $flashcard->id, 'deck' => $deck));
if (empty($subquestions)) {
echo $out;
echo $OUTPUT->box_start();
echo print_string('undefinedquestionset', 'flashcard');
echo $OUTPUT->box_end();
echo $OUTPUT->footer($course);
return;
}
$consumed = explode(',', @$_SESSION['flashcard_consumed']);
$subquestions = array();
list($usql, $params) = $DB->get_in_or_equal($consumed, SQL_PARAMS_QM, 'param0000', false); // negative IN
$select = "
flashcardid = {$flashcard->id} AND
userid = {$USER->id} AND
deck = {$deck} AND
id $usql
";
if ($cards = $DB->get_records_select('flashcard_card', $select, $params)){
foreach($cards as $card){
$obj = new stdClass();
$obj->entryid = $card->entryid;
$obj->cardid = $card->id;
$subquestions[] = $obj;
}
} else {
echo $out;
echo $OUTPUT->box(get_string('nomorecards', 'flashcard'), 'notify');
echo $OUTPUT->continue_button($thisurl."?view=checkdecks&id={$cm->id}");
echo $OUTPUT->footer($course);
die;
// redirect($thisurl."?view=checkdecks&id={$cm->id}");
}
/// print deferred header
echo $out;
/// randomize and get a question (obviously it is not a consumed question).
$random = rand(0, count($subquestions) - 1);
$subquestion = $DB->get_record('flashcard_deckdata', array('id' => $subquestions[$random]->entryid));
$back = 'question';
$front = 'answer';
if ($flashcard->flipdeck){
// flip card side values
$tmp = $subquestion->answertext;
$subquestion->answertext = $subquestion->questiontext;
$subquestion->questiontext = $tmp;
$back = 'answer';
$front = 'question';
// flip media types
$tmp = $flashcard->answersmediatype;
$flashcard->answersmediatype = $flashcard->questionsmediatype;
$flashcard->questionsmediatype = $tmp;
}
$autoplay = ($flashcard->audiostart) ? 'true' : 'false';
?>
<script type="text/javascript">
var qtype = "<?php echo $flashcard->questionsmediatype ?>";
var atype = "<?php echo $flashcard->answersmediatype ?>";
var maxitems = <?php echo count($cards) ?>;
</script>
<style>
<?php echo $flashcard->extracss ?>
</style>
<div id="flashcard_board">
<div id="flashcard_header">
<?php echo $OUTPUT->heading($flashcard->name); ?>
<p> <?php print_string('instructions', 'flashcard'); ?></p>
</div>
<center>
<div id="questiondiv" style=";background-repeat:no-repeat;background-image:url(<?php echo flashcard_print_custom_url($flashcard, 'customback', 0) ?>)" class="flashcard-question" onclick="javascript:togglecard()">
<?php
if ($flashcard->questionsmediatype == FLASHCARD_MEDIA_IMAGE) {
// flashcard_print_image($flashcard, $subquestion->questiontext);
flashcard_print_image($flashcard, "{$back}imagefile/{$subquestion->id}");
} elseif ($flashcard->questionsmediatype == FLASHCARD_MEDIA_SOUND){
// flashcard_play_sound($flashcard, $subquestion->questiontext, $autoplay, false, 'bell_q');
flashcard_play_sound($flashcard, "{$back}soundfile/{$subquestion->id}", $autoplay, false, 'bell_q');
} elseif ($flashcard->questionsmediatype == FLASHCARD_MEDIA_VIDEO){
// flashcard_play_video($flashcard, $subquestion->questiontext, $autoplay, false, 'bell_q');
flashcard_play_video($flashcard, "{$back}videofile/{$subquestion->id}", $autoplay, false, 'bell_q');
} elseif ($flashcard->questionsmediatype == FLASHCARD_MEDIA_IMAGE_AND_SOUND){
// list($image, $sound) = split('@', $subquestion->questiontext);
// flashcard_print_image($flashcard, $image);
flashcard_print_image($flashcard, "{$back}imagefile/{$subquestion->id}");
echo "<br/>";
// flashcard_play_sound($flashcard, $sound, $autoplay, false, 'bell_q');
flashcard_play_sound($flashcard, "{$back}soundfile/{$subquestion->id}", $autoplay, false, 'bell_q');
} else {
echo format_text($subquestion->questiontext, FORMAT_HTML);
}
?>
</div>
<div id="answerdiv" style="display:none;background-repeat:no-repeat;background-image:url(<?php echo flashcard_print_custom_url($flashcard, 'customfront', 0) ?>)" class="flashcard-answer" onclick="javascript:togglecard()">
<?php
if ($flashcard->answersmediatype == FLASHCARD_MEDIA_IMAGE) {
// flashcard_print_image($flashcard, $subquestion->answertext);
flashcard_print_image($flashcard, "{$front}imagefile/{$subquestion->id}");
} elseif ($flashcard->answersmediatype == FLASHCARD_MEDIA_SOUND){
// flashcard_play_sound($flashcard, $subquestion->answertext, $autoplay, false, 'bell_a');
flashcard_play_sound($flashcard, "{$front}soundfile/{$subquestion->id}", $autoplay, false, 'bell_a');
} elseif ($flashcard->answersmediatype == FLASHCARD_MEDIA_VIDEO){
// flashcard_play_video($flashcard, $subquestion->answertext, $autoplay, false, 'bell_a');
flashcard_play_video($flashcard, "{$front}videofile/{$subquestion->id}", $autoplay, false, 'bell_a');
} elseif ($flashcard->answersmediatype == FLASHCARD_MEDIA_IMAGE_AND_SOUND){
// list($image, $sound) = split('@', $subquestion->answertext);
// flashcard_print_image($flashcard, $image);
flashcard_print_image($flashcard, "{$front}imagefile/{$subquestion->id}");
echo "<br/>";
// flashcard_play_sound($flashcard, $sound, $autoplay, false, 'bell_a');
flashcard_play_sound($flashcard, "{$front}soundfile/{$subquestion->id}", $autoplay, false, 'bell_a');
} else {
echo format_text($subquestion->answertext,FORMAT_HTML);
}
?>
</div>
<div id="flashcard_controls">
<p><?php print_string('cardsremaining', 'flashcard'); ?>: <span id="remain"><?php echo count($subquestions);?></span></p>
<?php
$options['id'] = $cm->id;
$options['what'] = 'igotit';
$options['view'] = 'play';
$options['deck'] = $deck;
$options['cardid'] = $subquestions[$random]->cardid;
echo $OUTPUT->single_button(new moodle_url('view.php',$options), get_string('igotit', 'flashcard'), 'post', array('class'=>'flashcard_playbutton'));
?>
<?php
$options['id'] = $cm->id;
$options['what'] = 'ifailed';
$options['view'] = 'play';
$options['deck'] = $deck;
$options['cardid'] = $subquestions[$random]->cardid;
echo $OUTPUT->single_button(new moodle_url('view.php', $options), get_string('ifailed', 'flashcard'), 'post', array('class'=>'flashcard_playbutton'));
?>
<br />
<?php
/*
$options['id'] = $cm->id;
$options['what'] = 'reset';
$options['view'] = 'play';
$options['deck'] = $deck;
echo $OUTPUT->single_button(new moodle_url('view.php', $options), get_string('reset', 'flashcard'), 'post');
*/
?>
<br/>
<a href="<?php echo $thisurl ?>?id=<?php echo $cm->id ?>&view=checkdecks"><?php print_string('backtodecks', 'flashcard') ?></a>
- <a href="<?php echo $CFG->wwwroot ?>/course/view.php?id=<?php echo $course->id ?>"><?php print_string('backtocourse', 'flashcard') ?></a>
</div>
</center>
</div>