Browse Source

Fix phpdocs problems

MOODLE_20_STABLE
bdaloukas 8 years ago
parent
commit
526fdd2377
  1. 3
      CHANGES.md
  2. 19
      attempt.php
  3. 20
      db/upgrade.php
  4. 33
      export.php
  5. 28
      export/html/snakes/css/game.css
  6. 12
      export/html/snakes/css/modal.css
  7. 72
      export/html/snakes/css/snakes.css
  8. 6
      export/html/snakes/css/style.css
  9. 4
      export/html/snakes/css/subModal.css
  10. 45
      export/html/snakes/js/snakes-mod.js
  11. 96
      lib.php
  12. 106
      locallib.php
  13. 90
      pagelib.php
  14. 14
      print.php
  15. 14
      version.php
  16. 8
      view.php

3
CHANGES.md

@ -1,3 +1,6 @@
Changes in version 2017-06-10 (20170610)
- Fix phpdocs problems
Changes in version 2017-06-09 (20170609) Changes in version 2017-06-09 (20170609)
- Fix Moodle 3.4 compatibility problems - Fix Moodle 3.4 compatibility problems
- Fix stylings problems - Fix stylings problems

19
attempt.php

@ -40,6 +40,11 @@ game_do_attempt( $id, $game, $action, $course, $context);
/** /**
* Do the required checks and print header. * Do the required checks and print header.
*
* @param int $id
* @param stdClass $game
* @param stdClass $course
* @param stdClass $context
*/ */
function game_show_header( &$id, &$game, &$course, &$context) { function game_show_header( &$id, &$game, &$course, &$context) {
global $DB, $USER, $PAGE, $OUTPUT; global $DB, $USER, $PAGE, $OUTPUT;
@ -118,8 +123,12 @@ function game_show_header( &$id, &$game, &$course, &$context) {
/** /**
* Do one attempt. * Do one attempt.
*
* @param int $id
* @param stdClass $game
* @param stdClass $course
* @param stdClass $context
*/ */
function game_do_attempt( $id, $game, $action, $course, $context) { function game_do_attempt( $id, $game, $action, $course, $context) {
global $OUTPUT; global $OUTPUT;
@ -194,6 +203,12 @@ function game_do_attempt( $id, $game, $action, $course, $context) {
/** /**
* Creates one game. * Creates one game.
*
* @param stdClass $game
* @param int $id
* @param int $forcenew
* @param stdClass $course
* @param stdClass $context
*/ */
function game_create( $game, $id, $forcenew, $course, $context) { function game_create( $game, $id, $forcenew, $course, $context) {
global $USER, $CFG, $DB; global $USER, $CFG, $DB;
@ -236,6 +251,8 @@ function game_create( $game, $id, $forcenew, $course, $context) {
/** /**
* Unpacks the cross. * Unpacks the cross.
*
* @param string $g
*/ */
function game_cross_unpackpuzzle( $g) { function game_cross_unpackpuzzle( $g) {
$ret = ""; $ret = "";

20
db/upgrade.php

@ -853,6 +853,16 @@ function xmldb_game_upgrade($oldversion) {
upgrade_mod_savepoint(true, 2007111310, 'game'); upgrade_mod_savepoint(true, 2007111310, 'game');
} }
if ($oldversion < 2007111303) {
$table = new xmldb_table('game');
$field = new xmldb_field('bottomtext', XMLDB_TYPE_TEXT);
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
upgrade_mod_savepoint(true, 2007111303, 'game');
}
if ($oldversion < 2007111842) { if ($oldversion < 2007111842) {
$table = new xmldb_table( 'game_queries'); $table = new xmldb_table( 'game_queries');
$field = new xmldb_field( 'gameinstanceid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, '0'); $field = new xmldb_field( 'gameinstanceid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, '0');
@ -872,16 +882,6 @@ function xmldb_game_upgrade($oldversion) {
upgrade_mod_savepoint(true, 2007111843, 'game'); upgrade_mod_savepoint(true, 2007111843, 'game');
} }
if ($oldversion < 2007111303) {
$table = new xmldb_table('game');
$field = new xmldb_field('bottomtext', XMLDB_TYPE_TEXT);
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
upgrade_mod_savepoint(true, 2007111303, 'game');
}
if ($oldversion < 2007111844) { if ($oldversion < 2007111844) {
$table = new xmldb_table('game_queries'); $table = new xmldb_table('game_queries');
$field = new xmldb_field('questiontext', XMLDB_TYPE_TEXT, null, null, null, null, '', 'glossaryentryid'); $field = new xmldb_field('questiontext', XMLDB_TYPE_TEXT, null, null, null, null, '', 'glossaryentryid');

33
export.php

@ -41,6 +41,9 @@ $target = optional_param('target', "", PARAM_ALPHANUM); // The target is HTML or
class mod_game_exporthtml_form extends moodleform { class mod_game_exporthtml_form extends moodleform {
/**
* Definition of form.
*/
public function definition() { public function definition() {
global $CFG, $game; global $CFG, $game;
@ -98,6 +101,14 @@ class mod_game_exporthtml_form extends moodleform {
$mform->closeHeaderBefore('submitbutton'); $mform->closeHeaderBefore('submitbutton');
} }
/**
* Validation of form.
*
* @param stdClass $data
* @param stdClass $files
*
* @return errors
*/
public function validation($data, $files) { public function validation($data, $files) {
global $CFG, $USER, $DB; global $CFG, $USER, $DB;
$errors = parent::validation($data, $files); $errors = parent::validation($data, $files);
@ -105,6 +116,9 @@ class mod_game_exporthtml_form extends moodleform {
return $errors; return $errors;
} }
/**
* Do the exporting.
*/
public function export() { public function export() {
global $game, $DB; global $game, $DB;
@ -140,6 +154,9 @@ class mod_game_exporthtml_form extends moodleform {
class mod_game_exportjavame_form extends moodleform { class mod_game_exportjavame_form extends moodleform {
/**
* Definition of form.
*/
public function definition() { public function definition() {
global $CFG, $DB, $game; global $CFG, $DB, $game;
@ -192,6 +209,14 @@ class mod_game_exportjavame_form extends moodleform {
$mform->closeHeaderBefore('submitbutton'); $mform->closeHeaderBefore('submitbutton');
} }
/**
* Validation of form.
*
* @param stdClass $data
* @param stdClass $files
*
* @return errors
*/
public function validation($data, $files) { public function validation($data, $files) {
global $CFG, $USER, $DB; global $CFG, $USER, $DB;
$errors = parent::validation($data, $files); $errors = parent::validation($data, $files);
@ -199,6 +224,9 @@ class mod_game_exportjavame_form extends moodleform {
return $errors; return $errors;
} }
/**
* Do the exporting.
*/
public function export() { public function export() {
global $game, $DB; global $game, $DB;
@ -271,6 +299,11 @@ if ($mform->is_cancelled()) {
} }
echo $OUTPUT->footer(); echo $OUTPUT->footer();
/**
* Sends via html a file.
*
* @param string file
*/
function game_send_stored_file($file) { function game_send_stored_file($file) {
if (file_exists($file)) { if (file_exists($file)) {
header('Content-Description: File Transfer'); header('Content-Description: File Transfer');

28
export/html/snakes/css/game.css

@ -1,29 +1,25 @@
.nodis .nodis {
{ list-style-type: none;
list-style-type:none;
} }
#cont #cont {
{ position: relative;
position:relative; display: none;
display:none;
} }
.img1 .img1 {
{ position: absolute;
position:absolute; display: none;
display:none;
} }
#dicecont #dicecont {
{ float: right;
float:right; width: 250px;
width:250px;
background-image: url(../images/meter.png); background-image: url(../images/meter.png);
background-repeat: repeat; background-repeat: repeat;
font-family: Arial, Helvetica, sans-serif; font-family: Arial, Helvetica, sans-serif;
font-weight: normal; font-weight: normal;
color: #FFFFFF; color: #ffffff;
border: 0.5em solid #333333; border: 0.5em solid #333333;
top: 30px; top: 30px;
position: absolute; position: absolute;

12
export/html/snakes/css/modal.css

@ -7,7 +7,8 @@
opacity: .80; opacity: .80;
z-index: 9999; z-index: 9999;
} }
.popup_block{
.popup_block {
display: none; /*--hidden by default--*/ display: none; /*--hidden by default--*/
background: #fff; background: #fff;
padding: 20px; padding: 20px;
@ -18,22 +19,25 @@
top: 50%; left: 50%; top: 50%; left: 50%;
z-index: 99999; z-index: 99999;
/*--CSS3 Box Shadows--*/ /*--CSS3 Box Shadows--*/
-webkit-box-shadow: 0px 0px 20px #000; -webkit-box-shadow: 0 0 20px #000;
-moz-box-shadow: 0px 0px 20px #000; -moz-box-shadow: 0 0 20px #000;
box-shadow: 0px 0px 20px #000; box-shadow: 0 0 20px #000;
/*--CSS3 Rounded Corners--*/ /*--CSS3 Rounded Corners--*/
-webkit-border-radius: 10px; -webkit-border-radius: 10px;
-moz-border-radius: 10px; -moz-border-radius: 10px;
border-radius: 10px; border-radius: 10px;
} }
img.btn_close { img.btn_close {
float: right; float: right;
margin: -55px -55px 0 0; margin: -55px -55px 0 0;
} }
/*--Making IE6 Understand Fixed Positioning--*/ /*--Making IE6 Understand Fixed Positioning--*/
*html #fade { *html #fade {
position: absolute; position: absolute;
} }
*html .popup_block { *html .popup_block {
position: absolute; position: absolute;
} }

72
export/html/snakes/css/snakes.css

@ -2,81 +2,71 @@
Husain Limdiyawala(MSc IT DA-IICT) Husain Limdiyawala(MSc IT DA-IICT)
Any Duplication of this code should be avoided*/ Any Duplication of this code should be avoided*/
.blocks .blocks {
{
font-family: Arial, Helvetica, sans-serif; font-family: Arial, Helvetica, sans-serif;
margin-left: 5px; margin-left: 5px;
margin-top:2px; margin-top: 2px;
margin-bottom:2px; margin-bottom: 2px;
padding: 0px; padding: 0px;
float:left; float: left;
height: 52px; height: 52px;
width: 52px; width: 52px;
display:block; display: block;
position:relative; position: relative;
background-image: url(../square52.png); background-image: url(../square52.png);
} }
.nodis .nodis {
{ list-style-type: none;
list-style-type:none;
} }
#cont #cont {
{ position: relative;
position:relative; display: none;
display:none;
} }
#diceimg #diceimg {
{ display: none;
display:none; width: 45px;
width:45px; height: 44px;
height:44px;
} }
.img1 .img1 {
{
position:absolute; position:absolute;
display:none; display:none;
} }
body body {
{ background:#cccccc;
background:#CCCCCC;
} }
#player #player {
{ display: none;
display:none; z-index: 5;
z-index:5; position: absolute;
position:absolute;
} }
#players #players {
{
margin-top: 0.3em; margin-top: 0.3em;
margin-bottom: 1em; margin-bottom: 1em;
} }
#dicecont #dicecont {
{ float: right;
float:right; width: 170px;
width:170px;
background-image: url(../images/meter.png); background-image: url(../images/meter.png);
background-repeat: repeat; background-repeat: repeat;
font-family: Arial, Helvetica, sans-serif; font-family: Arial, Helvetica, sans-serif;
font-weight: bold; font-weight: bold;
color: #FFFFFF; color: #ffffff;
border: 0.5em solid #333333; border: 0.5em solid #333333;
top: 30px; top: 30px;
position: absolute; position: absolute;
right: 880px; right: 880px;
} }
#playbtn #playbtn {
{ margin-left: 0.5em;
margin-left:0.5em;
font-family: Arial, Helvetica, sans-serif; font-family: Arial, Helvetica, sans-serif;
font-weight: bold; font-weight: bold;
color: #000000; color: #000000;
@ -94,6 +84,7 @@ body
opacity: .80; opacity: .80;
z-index: 9999; z-index: 9999;
} }
.popup_block{ .popup_block{
display: none; /*--hidden by default--*/ display: none; /*--hidden by default--*/
background: #fff; background: #fff;
@ -113,15 +104,18 @@ body
-moz-border-radius: 10px; -moz-border-radius: 10px;
border-radius: 10px; border-radius: 10px;
} }
img.btn_close { img.btn_close {
float: right; float: right;
margin: -55px -55px 0 0; margin: -55px -55px 0 0;
border: 0; border: 0;
} }
/*--Making IE6 Understand Fixed Positioning--*/ /*--Making IE6 Understand Fixed Positioning--*/
*html #fade { *html #fade {
position: absolute; position: absolute;
} }
*html .popup_block { *html .popup_block {
position: absolute; position: absolute;
} }

6
export/html/snakes/css/style.css

@ -3,13 +3,13 @@ body {
} }
body, html, input { body, html, input {
font-family:Verdana, Arial, Helvetica, sans-serif; font-family: Verdana, Arial, Helvetica, sans-serif;
font-size:11px; font-size: 11px;
color: #333333; color: #333333;
} }
.info { .info {
font-style:italic; font-style: italic;
font-size: 0.9em; font-size: 0.9em;
color: #666666; color: #666666;
} }

4
export/html/snakes/css/subModal.css

@ -53,8 +53,8 @@
height: 1.3em; height: 1.3em;
padding: 5px; padding: 5px;
border-bottom: 2px solid #000000; border-bottom: 2px solid #000000;
border-top: 1px solid #78A3F2; border-top: 1px solid #7878a3f2;
border-left: 1px solid #78A3F2; border-left: 1px solid #7878a3f2;
border-right: 1px solid #204095; border-right: 1px solid #204095;
position: relative; position: relative;
z-index: 203; z-index: 203;

45
export/html/snakes/js/snakes-mod.js

@ -1,10 +1,5 @@
/*This code was originally based on code by /* This code was originally based on code by
Husain Limdiyawala(MSc IT DA-IICT)*/ Husain Limdiyawala(MSc IT DA-IICT) */
$(document).ready(function () {
});
// Global Variables. // Global Variables.
var totblocks = 0; var totblocks = 0;
@ -21,8 +16,8 @@ var destsnake = new Array(4);
var ladsrc = new Array(3); var ladsrc = new Array(3);
var laddest = new Array(3); var laddest = new Array(3);
var quest = new Array(); // Available questions along with multiple answers. var quest = new Array(); // Available questions along with multiple answers.
var COR_answered = new Array(); // Record all questions (along with answers) the user responded CORRECTLY. var cor_answered = new Array(); // Record all questions (along with answers) the user responded CORRECTLY.
var WRO_answered = new Array(); // Record all questions (along with answers) the user responded WRONGLY. var wro_answered = new Array(); // Record all questions (along with answers) the user responded WRONGLY.
var user = new Array(); var user = new Array();
// Constract table with questions and answers and pick question to display. // Constract table with questions and answers and pick question to display.
@ -156,7 +151,7 @@ function throwDice(i) {
// The below Function Checks The Snake Biting for a user. // The below Function Checks The Snake Biting for a user.
function snakescheck(k) { function snakescheck(k) {
i = 0; var i;
for(i = 0; i <= srcsnake.length; i++) { for(i = 0; i <= srcsnake.length; i++) {
if (srcsnake[i] == tots[k]) { if (srcsnake[i] == tots[k]) {
@ -176,7 +171,7 @@ function snakescheck(k) {
// The below function checks the ladders for a user. // The below function checks the ladders for a user.
function laddercheck(k) { function laddercheck(k) {
i = 0; var i;
for(i = 0; i <= ladsrc.length; i++) { for(i = 0; i <= ladsrc.length; i++) {
if (ladsrc[i] == tots[k]) { if (ladsrc[i] == tots[k]) {
@ -254,11 +249,17 @@ function selectPlayer() {
// The below function starts the play. // The below function starts the play.
function play() { function play() {
if (tots[l] != null) { if (tots[l] != null) {
var s;
s = "<ul class='nodis'><li>O Paiktis " + (l + 1);
s = s + " </li><li>brisketai sto tetragwno " + tots[l] + "</li><li></li></ul>";
disableField(); disableField();
document.getElementById("status").innerHTML = "<ul class='nodis'><li>O Paiktis " + (l + 1) + " </li><li>brisketai sto tetragwno " + tots[l] + "</li><li></li></ul>"; document.getElementById("status").innerHTML = s;
Question(); question();
document.getElementById("status").innerHTML = "<ul class='nodis'><li>O Paiktis " + (l + 1) + " </li><li>vrisketai sto tetragwno " + tots[l] + "</li></ul>"; s = "<ul class='nodis'><li>O Paiktis " + (l + 1);
s = s + " </li><li>vrisketai sto tetragwno " + tots[l] + "</li></ul>";
document.getElementById("status").innerHTML = s;
} else { } else {
document.getElementById("status").innerHTML = "<ul class='nodis'><li>Molis exases...</li></ul>"; document.getElementById("status").innerHTML = "<ul class='nodis'><li>Molis exases...</li></ul>";
} }
@ -277,13 +278,13 @@ function doit(i) {
snakescheck(i); snakescheck(i);
laddercheck(i); laddercheck(i);
} else { } else {
alert("ÏëïêëÞñùóåò ôçí ðßóôá, óõã÷áñçôÞñéá!!!"); alert("Congatulations!!!");
} }
} }
// The below function checks whether the player has won or not. // The below function checks whether the player has won or not.
function checkWin(i) { function checkWin(i) {
if( tots[i] == totblocks) { if (tots[i] == totblocks) {
return false; return false;
} else { } else {
return true; return true;
@ -296,18 +297,20 @@ function disableField() {
document.getElementById("boardtype").disabled = "disabled"; document.getElementById("boardtype").disabled = "disabled";
} }
function Question() { function question() {
var picked, q1;
picked = selectQuest(allQuest); picked = selectQuest(allQuest);
alert("Randomly selected number:" + picked); alert("Randomly selected number:" + picked);
Q1 = prompt(quest[picked * 4], "Απάντηση"); q1 = prompt(quest[picked * 4], "Απάντηση");
if (Q1 == quest[picked * 4 + 1]) { if (q1 == quest[picked * 4 + 1]) {
alert("Σωστά!") alert("Σωστά!")
doit(l); doit(l);
COR_answered.concat(quest.splice(picked * 4, 4)); cor_answered.concat(quest.splice(picked * 4, 4));
} else { } else {
alert("Η απάντηση δεν ήταν σωστή. Χάνεις τη σειρά σου για αυτό το γύρο!") alert("Η απάντηση δεν ήταν σωστή. Χάνεις τη σειρά σου για αυτό το γύρο!")
WRO_answered.concat(quest.splice(picked * 4, 4)); wro_answered.concat(quest.splice(picked * 4, 4));
} }
// Remove question and answers from available questions - (thus not allowing to have a Repeated question). // Remove question and answers from available questions - (thus not allowing to have a Repeated question).

96
lib.php

@ -61,7 +61,6 @@ define('GAME_REVIEW_GENERALFEEDBACK', 32 * 0x1041); // Show general feedback.
* @param object $instance An object from the form in mod.html * @param object $instance An object from the form in mod.html
* @return int The id of the newly inserted game record * @return int The id of the newly inserted game record
**/ **/
function game_add_instance($game) { function game_add_instance($game) {
global $DB; global $DB;
@ -138,6 +137,11 @@ function game_update_instance($game) {
return true; return true;
} }
/**
* Updates some fields before writing to database.
*
* @param stdClass $game
*/
function game_before_add_or_update(&$game) { function game_before_add_or_update(&$game) {
if (isset( $game->questioncategoryid)) { if (isset( $game->questioncategoryid)) {
$pos = strpos( $game->questioncategoryid, ','); $pos = strpos( $game->questioncategoryid, ',');
@ -264,7 +268,12 @@ function game_user_outline($course, $user, $mod, $game) {
/** /**
* Print a detailed representation of what a user has done with * Print a detailed representation of what a user has done with
* a given particular instance of this module, for user activity reports. * a given particular instance of this module, for user activity reports.
**/
* @param stdClass $course
* @param stdClass $user
* @param string $mod
* @param stdClass $game
*/
function game_user_complete($course, $user, $mod, $game) { function game_user_complete($course, $user, $mod, $game) {
global $DB; global $DB;
@ -296,11 +305,17 @@ function game_user_complete($course, $user, $mod, $game) {
* @uses $CFG * @uses $CFG
* @return boolean * @return boolean
* @todo Finish documenting this function * @todo Finish documenting this function
**/ *
* @param stdClass $course
* @param int $isteacher
* @param int $timestart
*
* @return True if anything was printed, otherwise false.
*/
function game_print_recent_activity($course, $isteacher, $timestart) { function game_print_recent_activity($course, $isteacher, $timestart) {
global $CFG; global $CFG;
return false; // True if anything was printed, otherwise false. return false;
} }
/** /**
@ -308,7 +323,6 @@ function game_print_recent_activity($course, $isteacher, $timestart) {
* This function searches for things that need to be done, such * This function searches for things that need to be done, such
* as sending out mail, toggling flags etc ... * as sending out mail, toggling flags etc ...
* *
* @uses $CFG * @uses $CFG
* @return boolean * @return boolean
* @todo Finish documenting this function * @todo Finish documenting this function
@ -512,6 +526,13 @@ function game_grade_item_delete( $game) {
/** /**
* Returns all game graded users since a given time for specified game * Returns all game graded users since a given time for specified game
* @param stdClass $activities
* @param int $index
* @param int $timestart
* @param int courseid
* @param int cmid
* @param int userid
* @param int groupid
*/ */
function game_get_recent_mod_activity(&$activities, &$index, $timestart, $courseid, $cmid, $userid=0, $groupid=0) { function game_get_recent_mod_activity(&$activities, &$index, $timestart, $courseid, $cmid, $userid=0, $groupid=0) {
global $DB, $COURSE, $USER; global $DB, $COURSE, $USER;
@ -607,6 +628,14 @@ function game_get_recent_mod_activity(&$activities, &$index, $timestart, $course
} }
} }
/**
* Prints recent activity.
*
* @param stdClass $activity
* @param int $courseid
* @param stdClass $detail
* @param array $modgames
*/
function game_print_recent_mod_activity($activity, $courseid, $detail, $modnames) { function game_print_recent_mod_activity($activity, $courseid, $detail, $modnames) {
global $CFG, $OUTPUT; global $CFG, $OUTPUT;
@ -755,10 +784,26 @@ function game_num_attempt_summary($game, $cm, $returnzero = false, $currentgroup
return ''; return '';
} }
/**
* Converts score of game to grade.
*
* @param stdClass $game
* @param float $score
*
* @return float the score
*/
function game_format_score($game, $score) { function game_format_score($game, $score) {
return format_float($game->grade * $score / 100, $game->decimalpoints); return format_float($game->grade * $score / 100, $game->decimalpoints);
} }
/**
* Converts grade to score.
*
* @param stdClass $game
* @param float $grade
*
* @return foat score
*/
function game_format_grade($game, $grade) { function game_format_grade($game, $grade) {
return format_float($grade, $game->decimalpoints); return format_float($grade, $game->decimalpoints);
} }
@ -1103,6 +1148,18 @@ if (defined('USE_GET_SHORTCUTS')) {
} }
} }
/**
* Serves the game attachents.
*
* @param stdClass $course
* @param stdClass $cm
* @param stdClass $context
* @param string filearea
* @param array args
* @param boolean forcedownload
*
* @return boolean false if not exists file
*/
function mod_game_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload) { function mod_game_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload) {
global $CFG, $DB; global $CFG, $DB;
@ -1176,6 +1233,8 @@ function game_reset_course_form_definition(&$mform) {
/** /**
* Course reset form defaults. * Course reset form defaults.
* @param stdClass $course
*
* @return array * @return array
*/ */
function game_reset_course_form_defaults($course) { function game_reset_course_form_defaults($course) {
@ -1188,6 +1247,7 @@ function game_reset_course_form_defaults($course) {
* *
* @global object * @global object
* @param $data the data submitted from the reset course. * @param $data the data submitted from the reset course.
*
* @return array status array * @return array status array
*/ */
function game_reset_userdata($data) { function game_reset_userdata($data) {
@ -1295,6 +1355,7 @@ function game_reset_userdata($data) {
* @param object $cm Course-module * @param object $cm Course-module
* @param int $userid User ID * @param int $userid User ID
* @param bool $type Type of comparison (or/and; can be used as return value if no conditions) * @param bool $type Type of comparison (or/and; can be used as return value if no conditions)
*
* @return bool True if completed, false if not, $type if conditions not set. * @return bool True if completed, false if not, $type if conditions not set.
*/ */
function game_get_completion_state($course, $cm, $userid, $type) { function game_get_completion_state($course, $cm, $userid, $type) {
@ -1340,6 +1401,14 @@ function game_scale_used_anywhere($scaleid) {
} }
} }
/**
* Returns the context instance of a Module. Is the same for all version of Moodle.
*
* This is used to find out if scale used anywhere
*
* @param int $moduleid
* @return stdClass context
*/
function game_get_context_module_instance( $moduleid) { function game_get_context_module_instance( $moduleid) {
if (class_exists( 'context_module')) { if (class_exists( 'context_module')) {
return context_module::instance( $moduleid); return context_module::instance( $moduleid);
@ -1348,6 +1417,14 @@ function game_get_context_module_instance( $moduleid) {
return get_context_instance( CONTEXT_MODULE, $moduleid); return get_context_instance( CONTEXT_MODULE, $moduleid);
} }
/**
* Returns the context instance of a course. Is the same for all version of Moodle.
*
* This is used to find out if scale used anywhere
*
* @param int $moduleid
* @return stdClass context
*/
function game_get_context_course_instance( $courseid) { function game_get_context_course_instance( $courseid) {
if (class_exists( 'context_course')) { if (class_exists( 'context_course')) {
return context_course::instance( $courseid); return context_course::instance( $courseid);
@ -1356,11 +1433,18 @@ function game_get_context_course_instance( $courseid) {
return get_context_instance( CONTEXT_COURSE, $courseid); return get_context_instance( CONTEXT_COURSE, $courseid);
} }
/**
* Returns the url of a pix file. Is the same for all versions of Moodle.
*
* @param string $filename
* @param string module
* @return stdClass url
*/
function game_pix_url( $filename, $module='') { function game_pix_url( $filename, $module='') {
global $OUTPUT; global $OUTPUT;
if (game_get_moodle_version() >= '03.03') { if (game_get_moodle_version() >= '03.03') {
return $OUTPUT->image_url($filename, 'mod_game'); return $OUTPUT->image_url($filename, $module);
} else { } else {
return $OUTPUT->pix_url($filename, $module); return $OUTPUT->pix_url($filename, $module);
} }

106
locallib.php

@ -38,6 +38,11 @@ $gamegrademethod = array ( GAME_GRADEMETHOD_HIGHEST => get_string("gradehighest"
define( "CONST_GAME_TRIES_REPETITION", "3"); define( "CONST_GAME_TRIES_REPETITION", "3");
/**
* Returns the version of Moodle.
*
* @return string version
*/
function game_get_moodle_version() { function game_get_moodle_version() {
global $DB; global $DB;
@ -56,6 +61,13 @@ function game_get_moodle_version() {
} }
} }
/**
* Convert a string to upper.
*
* @param string $str
* @param string $lang
* @return string the uppercase of $str
*/
function game_upper( $str, $lang='') { function game_upper( $str, $lang='') {
if ($lang == 'user') { if ($lang == 'user') {
return $str; return $str;
@ -80,6 +92,15 @@ function game_upper( $str, $lang='') {
return $str; return $str;
} }
/**
* Returns the HTML of a select control.
*
* @param string $name
* @param array a
* @param string $input
* @param array $events
* @return string the HTML
*/
function game_showselectcontrol( $name, $a, $input, $events='') { function game_showselectcontrol( $name, $a, $input, $events='') {
$ret = "<select id=\"$name\" name=\"$name\" $events>"; $ret = "<select id=\"$name\" name=\"$name\" $events>";
@ -95,6 +116,13 @@ function game_showselectcontrol( $name, $a, $input, $events='') {
return $ret; return $ret;
} }
/**
* Returns the HTML of a checkbox control.
*
* @param string $name
* @param string $value
* @return string the HTML
*/
function game_showcheckbox( $name, $value) { function game_showcheckbox( $name, $value) {
$a = array(); $a = array();
$a[ 0] = get_string( 'no'); $a[ 0] = get_string( 'no');
@ -103,7 +131,15 @@ function game_showcheckbox( $name, $value) {
return game_showselectcontrol( $name, $a, $value); return game_showselectcontrol( $name, $a, $value);
} }
// Used by hangman. /**
* Used by hangman. Returns a short answer.
*
* @param string $name
* @param array a
* @param string $input
* @param array $events
* @return string the HTML
*/
function game_question_shortanswer( $game, $allowspaces=false, $userepetitions=true) { function game_question_shortanswer( $game, $allowspaces=false, $userepetitions=true) {
switch( $game->sourcemodule) switch( $game->sourcemodule)
{ {
@ -118,7 +154,15 @@ function game_question_shortanswer( $game, $allowspaces=false, $userepetitions=t
return false; return false;
} }
// Used by hangman. /**
* Used by hangman. Returns a short answer from glossary.
*
* @param string $name
* @param array a
* @param string $input
* @param array $events
* @return string the HTML
*/
function game_question_shortanswer_glossary( $game, $allowspaces, $userepetitions) { function game_question_shortanswer_glossary( $game, $allowspaces, $userepetitions) {
global $DB; global $DB;
@ -160,7 +204,15 @@ function game_question_shortanswer_glossary( $game, $allowspaces, $userepetition
return $rec; return $rec;
} }
// Used by hangman. /**
* Used by hangman. Returns a short answer from quiz.
*
* @param string $name
* @param array a
* @param string $input
* @param array $events
* @return string the HTML
*/
function game_question_shortanswer_quiz( $game, $allowspaces, $userepetitions) { function game_question_shortanswer_quiz( $game, $allowspaces, $userepetitions) {
global $DB; global $DB;
@ -200,7 +252,15 @@ function game_question_shortanswer_quiz( $game, $allowspaces, $userepetitions) {
} }
} }
// Used by hangman. /**
* Used by hangman. Returns a short answer from question.
*
* @param string $name
* @param stdClass $game
* @param boolean $allowspaces
* @param boolean $userepetitions
* @return the short answer record
*/
function game_question_shortanswer_question( $game, $allowspaces, $userepetitions) { function game_question_shortanswer_question( $game, $allowspaces, $userepetitions) {
global $DB; global $DB;
@ -242,7 +302,16 @@ function game_question_shortanswer_question( $game, $allowspaces, $userepetition
} }
} }
// Used by millionaire, game_question_shortanswer_quiz, hidden picture. /**
* Select a random question. Used by millionaire, game_question_shortanswer_quiz, hidden picture.
*
* @param stdClass $game
* @param string $table
* @param string $select
* @param string $idfields
* @param boolean userepetitions
* @return stdClass the random question
*/
function game_question_selectrandom( $game, $table, $select, $idfields='id', $userepetitions=true) { function game_question_selectrandom( $game, $table, $select, $idfields='id', $userepetitions=true) {
global $DB, $USER; global $DB, $USER;
@ -307,6 +376,15 @@ function game_question_selectrandom( $game, $table, $select, $idfields='id', $us
return $minid; return $minid;
} }
/**
* Updates the repetition table.
*
* @param int $gameid
* @param int $userid
* @param int $questionid
* @param int $glossaryentryid
*/
function game_update_repetitions( $gameid, $userid, $questionid, $glossaryentryid) { function game_update_repetitions( $gameid, $userid, $questionid, $glossaryentryid) {
global $DB; global $DB;
@ -338,7 +416,13 @@ function game_update_repetitions( $gameid, $userid, $questionid, $glossaryentryi
} }
} }
// Used by sudoku. /**
* Select random questions for Sudoku.
*
* @param stdClass $game
* @param int count
* @param stdClass the random record(s)
*/
function game_questions_selectrandom( $game, $count=1) { function game_questions_selectrandom( $game, $count=1) {
global $DB; global $DB;
@ -431,7 +515,15 @@ function game_questions_selectrandom( $game, $count=1) {
return $ret; return $ret;
} }
// Used by game_questions_selectrandom. /**
* Select random questions. Used by game_questions_selectrandom.
*
* @param string $table
* @param string $select
@param int $idfield
@param int $count
* @return stdClass the random record(s)
*/
function game_questions_selectrandom_detail( $table, $select, $idfield="id", $count=1) { function game_questions_selectrandom_detail( $table, $select, $idfield="id", $count=1) {
global $DB; global $DB;

90
pagelib.php

@ -1,90 +0,0 @@
<?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/>.
defined('MOODLE_INTERNAL') || die();
require_once( $CFG->libdir.'/pagelib.php');
require_once( $CFG->dirroot.'/course/lib.php'); // Needed for some blocks.
define('PAGE_GAME_VIEW', 'mod-game-view');
page_map_class( PAGE_GAME_VIEW, 'page_game');
/**
* Class that models the behavior of a game
*
* @author Jon Papaioannou
* @package pages
*/
class page_game extends page_generic_activity {
public function init_quick($data) {
if (empty($data->pageid)) {
print_error('Cannot quickly initialize page: empty course id');
}
$this->activityname = 'game';
parent::init_quick($data);
}
public function print_header($title, $morebreadcrumbs = null, $navigation ='') {
global $USER, $CFG;
$this->init_full();
$replacements = array(
'%fullname%' => format_string($this->activityrecord->name)
);
foreach ($replacements as $search => $replace) {
$title = str_replace($search, $replace, $title);
}
if ($this->courserecord->id == SITEID) {
$breadcrumbs = array();
} else {
$breadcrumbs = array($this->courserecord->shortname => $CFG->wwwroot.'/course/view.php?id='.$this->courserecord->id);
}
$breadcrumbs[get_string('modulenameplural', 'game')] = $CFG->wwwroot.'/mod/game/index.php?id='.$this->courserecord->id;
$breadcrumbs[format_string($this->activityrecord->name)]
= $CFG->wwwroot.'/mod/game/view.php?id='.$this->modulerecord->id;
if (!empty($morebreadcrumbs)) {
$breadcrumbs = array_merge($breadcrumbs, $morebreadcrumbs);
}
if (empty($morebreadcrumbs) && $this->user_allowed_editing()) {
$buttons = '<table><tr><td>'.
update_module_button($this->modulerecord->id, $this->courserecord->id, get_string('modulename', 'game')).'</td>';
if (!empty($CFG->showblocksonmodpages)) {
$buttons .= '<td><form '.$CFG->frametarget.' method="get" action="view.php">'.
'<div>'.
'<input type="hidden" name="id" value="'.$this->modulerecord->id.'" />'.
'<input type="hidden" name="edit" value="'.($this->user_is_editing() ? 'off' : 'on').'" />'.
'<input type="submit" value="'.get_string($this->user_is_editing() ? 'blockseditoff' : 'blocksediton').'" />'.
'</div></form></td>';
}
$buttons .= '</tr></table>';
} else {
$buttons = '&nbsp;';
}
print_header($title, $this->courserecord->fullname, $navigation);
}
public function get_type() {
return PAGE_GAME_VIEW;
}
}

14
print.php

@ -44,6 +44,13 @@ function game_print( $game, $update, $context) {
} }
} }
/**
* Prints a cross.
*
* @param stdClass $game
@param boolean $update
* @param stdClass $context
*/
function game_print_cross( $game, $update, $context) { function game_print_cross( $game, $update, $context) {
require( "cross/play.php"); require( "cross/play.php");
@ -70,6 +77,13 @@ function game_print_cross( $game, $update, $context) {
$showstudentguess, $context); $showstudentguess, $context);
} }
/**
* Prints a cryptex.
*
* @param stdClass $game
@param boolean $update
* @param stdClass $context
*/
function game_print_cryptex( $game, $update, $context) { function game_print_cryptex( $game, $update, $context) {
global $DB; global $DB;

14
version.php

@ -15,12 +15,12 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/** /**
* Code fragment to define the version of game * Version information
* This fragment is called by moodle_needs_upgrading() and /admin/index.php
* *
* @author * @package mod_game
* @package game * @copyright 2007 Vasilis Daloukas
**/ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die(); defined('MOODLE_INTERNAL') || die();
@ -35,10 +35,10 @@ if (!isset( $plugin)) {
} }
$plugin->component = 'mod_game'; // Full name of the plugin (used for diagnostics). $plugin->component = 'mod_game'; // Full name of the plugin (used for diagnostics).
$plugin->version = 2017060901; // The current module version (Date: YYYYMMDDXX). $plugin->version = 2017061001; // The current module version (Date: YYYYMMDDXX).
$plugin->requires = 2010112400; // Requires Moodle 2.0. $plugin->requires = 2010112400; // Requires Moodle 2.0.
$plugin->cron = 0; // Period for cron to check this module (secs). $plugin->cron = 0; // Period for cron to check this module (secs).
$plugin->release = '2017-06-09'; $plugin->release = '2017-06-10';
if ($useplugin != 2) { if ($useplugin != 2) {
$module = $plugin; $module = $plugin;

8
view.php

@ -14,7 +14,13 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
// This page prints a particular instance of game. /**
* This file is the entry point to the game module. All pages are rendered from here
*
* @package mod_game
* @copyright 2007 Vasilis Daloukas
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or late
*/
require_once(dirname(__FILE__) . '/../../config.php'); require_once(dirname(__FILE__) . '/../../config.php');
require_once($CFG->libdir.'/gradelib.php'); require_once($CFG->libdir.'/gradelib.php');

Loading…
Cancel
Save