-
Notifications
You must be signed in to change notification settings - Fork 9
/
playview.controller.php
74 lines (71 loc) · 2.68 KB
/
playview.controller.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
<?php
/**
* a controller for the play view
*
* @package mod-flashcard
* @category mod
* @author Valery Fremaux
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
* @version Moodle 2.0
*
* @usecase initialize
* @usecase reset
* @usecase igotit
* @usecase ifailed
*/
// security
if (!defined('MOODLE_INTERNAL')){
die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page.
}
/*---------------------------------- initialize a deck ---------------------------------*/
if ($action == 'initialize'){
if ($initials = $DB->get_records_select('flashcard_card', "flashcardid = ? AND userid = ? AND deck = ? ", array($flashcard->id, $USER->id, $deck))){
$_SESSION['flashcard_initials'] = implode("','", array_keys($initials));
}
unset($_SESSION['flashcard_consumed']);
}
/*---------------------------------- reset a deck ---------------------------------*/
if ($action == 'reset'){
$initials = explode("','", $_SESSION['flashcard_initials']);
list($usql, $params) = $DB->get_in_or_equal(array_keys($initials));
$DB->set_field_select('flashcard_card', 'deck', $deck, "id $usql ", $params);
unset($_SESSION['flashcard_consumed']);
}
/*---------------------------------- a card was declared right --------------------*/
if ($action == 'igotit'){
$card = new StdClass();
$card->id = required_param('cardid', PARAM_INT);
$card = $DB->get_record('flashcard_card', array('id' => $card->id));
if ($card->deck < $flashcard->decks){
$card->deck = $deck + 1;
} else {
// if in last deck, consume it !!
if (array_key_exists('flashcard_consumed', $_SESSION)){
$_SESSION['flashcard_consumed'] .= ','.$card->id;
} else {
$_SESSION['flashcard_consumed'] = $card->id;
}
}
$card->lastaccessed = time();
$card->accesscount++ ;
if (!$DB->update_record('flashcard_card', $card)){
print_error('dbcouldnotupdate', 'flashcard', '', get_string('cardinfo', 'flashcard'));
}
}
/*------------------------------ a card was declared wrong -----------------------*/
if ($action == 'ifailed'){
$card = new StdClass();
$card->id = required_param('cardid', PARAM_INT);
$card = $DB->get_record('flashcard_card', array('id' => $card->id));
$card->lastaccessed = time();
$card->accesscount++ ;
if (!$DB->update_record('flashcard_card', $card)){
print_error('dbcouldnotupdate', 'flashcard', '', get_string('cardinfo', 'flashcard'));
}
if (array_key_exists('flashcard_consumed', $_SESSION)){
$_SESSION['flashcard_consumed'] .= ','.$card->id;
} else {
$_SESSION['flashcard_consumed'] = $card->id;
}
}
?>