Browse Source

Fix:Coding style

MOODLE_20_STABLE
Vasilis Daloukas 9 years ago
parent
commit
7b957611bd
  1. 44
      headergame.php
  2. 243
      mod_form.php
  3. 54
      pagelib.php
  4. 24
      preview.php
  5. 41
      print.php
  6. 51
      report.php
  7. 126
      review.php
  8. 19
      settings.php
  9. 144
      showanswers.php
  10. 78
      showattempts.php
  11. 30
      tabs.php
  12. 309
      translate.php
  13. 39
      version.php
  14. 103
      view.php

44
headergame.php

@ -1,12 +1,26 @@
<?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/>.
require_once(dirname(__FILE__) . '/../../config.php');
require_once($CFG->libdir.'/gradelib.php');
require_once($CFG->dirroot.'/mod/game/locallib.php');
require_once($CFG->libdir . '/completionlib.php');
$id = optional_param('id', 0, PARAM_INT); // Course Module ID, or
$q = optional_param('q', 0, PARAM_INT); // game ID
$id = optional_param('id', 0, PARAM_INT); // Course Module ID.
$q = optional_param('q', 0, PARAM_INT); // Game ID.
if ($id) {
if (!$cm = get_coursemodule_from_id('game', $id)) {
@ -30,33 +44,27 @@
}
}
/// Check login and get context.
// Check login and get context.
require_login($course->id, false, $cm);
$context = game_get_context_module_instance( $cm->id);
require_capability('mod/game:view', $context);
/// Cache some other capabilites we use several times.
// Cache some other capabilites we use several times.
$canattempt = has_capability('mod/game:attempt', $context);
$canreviewmine = has_capability('mod/game:reviewmyattempts', $context);
/// Create an object to manage all the other (non-roles) access rules.
// Create an object to manage all the other (non-roles) access rules.
$timenow = time();
//$accessmanager = new game_access_manager(game::create($game->id, $USER->id), $timenow);
/// If no questions have been set up yet redirect to edit.php
//if (!$game->questions && has_capability('mod/game:manage', $context)) {
// redirect($CFG->wwwroot . '/mod/game/edit.php?cmid=' . $cm->id);
//}
/// Log this request.
if( game_use_events())
{
// Log this request.
if (game_use_events()) {
require( 'classes/event/course_module_viewed.php');
\mod_game\event\course_module_viewed::viewed($game, $context)->trigger();
}else
} else {
add_to_log($course->id, 'game', 'view', "view.php?id=$cm->id", $game->id, $cm->id);
}
/// Initialize $PAGE, compute blocks
// Initialize $PAGE, compute blocks.
$PAGE->set_url('/mod/game/view.php', array('id' => $cm->id));
$edit = optional_param('edit', -1, PARAM_BOOL);
@ -72,7 +80,9 @@
$buttons = '<table><tr><td><form method="get" action="view.php"><div>'.
'<input type="hidden" name="id" value="'.$cm->id.'" />'.
'<input type="hidden" name="edit" value="'.($PAGE->user_is_editing() ? 'off' : 'on').'" />'.
'<input type="submit" value="'.get_string($PAGE->user_is_editing()?'blockseditoff':'blocksediton').'" /></div></form></td></tr></table>';
'<input type="submit" value="'.
get_string($PAGE->user_is_editing() ? 'blockseditoff' : 'blocksediton').
'" /></div></form></td></tr></table>';
$PAGE->set_button($buttons);
}

243
mod_form.php

@ -1,4 +1,19 @@
<?php // $Id: mod_form.php,v 1.28 2012/07/26 05:38:58 bdaloukas Exp $
<?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/>.
/**
* Form for creating and modifying a game
*
@ -12,29 +27,25 @@ require( 'locallib.php');
class mod_game_mod_form extends moodleform_mod {
function definition() {
public function definition() {
global $CFG, $DB, $COURSE;
$config = get_config('game');
$mform =& $this->_form;
$id = $this->_instance;
if (!empty($this->_instance)) {
if ($g = $DB->get_record('game', array('id' => $id))) {
$gamekind = $g->gamekind;
}
else{
} else {
print_error('incorrect game');
}
}
else {
} else {
$gamekind = required_param('type', PARAM_ALPHA);
}
//Hidden elements
// Hidden elements.
$mform->addElement('hidden', 'gamekind', $gamekind);
$mform->setDefault('gamekind', $gamekind);
$mform->setType('gamekind', PARAM_ALPHA);
@ -50,25 +61,26 @@ class mod_game_mod_form extends moodleform_mod {
$mform->addElement('text', 'name', 'Name', array('size' => '64'));
if (!empty($CFG->formatstringstriptags)) {
$mform->setType('name', PARAM_TEXT);
}
else{
} else {
$mform->setType('name', PARAM_CLEAN);
}
if( !isset( $g))
if (!isset( $g)) {
$mform->setDefault('name', get_string( 'game_'.$gamekind, 'game'));
}
$mform->addRule('name', null, 'required', null, 'client');
$hasglossary = ($gamekind == 'hangman' || $gamekind == 'cross' || $gamekind == 'cryptex' || $gamekind == 'sudoku' || $gamekind == 'hiddenpicture' || $gamekind == 'snakes');
$hasglossary = ($gamekind == 'hangman' || $gamekind == 'cross' ||
$gamekind == 'cryptex' || $gamekind == 'sudoku' ||
$gamekind == 'hiddenpicture' || $gamekind == 'snakes');
$questionsourceoptions = array();
if($hasglossary)
if ($hasglossary) {
$questionsourceoptions['glossary'] = get_string('modulename', 'glossary');
//if( $gamekind != 'snakes' && $gamekind != 'sudoku' &&
// $gamekind != 'hiddenpicture') {
}
$questionsourceoptions['question'] = get_string('sourcemodule_question', 'game');
//}
if( $gamekind != 'bookquiz')
if ($gamekind != 'bookquiz') {
$questionsourceoptions['quiz'] = get_string('modulename', 'quiz');
}
$mform->addElement('select', 'sourcemodule', get_string('sourcemodule', 'game'), $questionsourceoptions);
if ($hasglossary) {
@ -81,12 +93,11 @@ class mod_game_mod_form extends moodleform_mod {
$mform->addElement('select', 'glossaryid', get_string('sourcemodule_glossary', 'game'), $a);
$mform->disabledIf('glossaryid', 'sourcemodule', 'neq', 'glossary');
if( count( $a) == 0)
if (count( $a) == 0) {
$select = 'glossaryid=-1';
else if( count( $a) == 1)
} else if (count( $a) == 1) {
$select = 'glossaryid='.$rec->id;
else
{
} else {
$select = '';
foreach ($recs as $rec) {
$select .= ','.$rec->id;
@ -107,10 +118,7 @@ class mod_game_mod_form extends moodleform_mod {
$mform->disabledIf('glossarycategoryid', 'sourcemodule', 'neq', 'glossary');
}
//*********************
// Question Category - Short Answer
// Question Category - Short Answer.
if ($gamekind != 'bookquiz') {
$context = game_get_context_course_instance( $COURSE->id);
$select = " contextid in ($context->id)";
@ -129,15 +137,12 @@ class mod_game_mod_form extends moodleform_mod {
$mform->addElement('select', 'questioncategoryid', get_string('sourcemodule_questioncategory', 'game'), $a);
$mform->disabledIf('questioncategoryid', 'sourcemodule', 'neq', 'question');
//subcategories
// Subcategories.
$mform->addElement('selectyesno', 'subcategories', get_string('sourcemodule_include_subcategories', 'game'));
$mform->disabledIf('subcategories', 'sourcemodule', 'neq', 'question');
}
//***********************
// Quiz Category
// Quiz Category.
if ($gamekind != 'bookquiz') {
$a = array();
if ($recs = $DB->get_records('quiz', array( 'course' => $COURSE->id), 'id,name')) {
@ -149,9 +154,7 @@ class mod_game_mod_form extends moodleform_mod {
$mform->disabledIf('quizid', 'sourcemodule', 'neq', 'quiz');
}
//***********************
// Book
// Book.
if ( $gamekind == 'bookquiz') {
$a = array();
if ($recs = $DB->get_records('book', array( 'course' => $COURSE->id), 'id,name')) {
@ -162,13 +165,11 @@ class mod_game_mod_form extends moodleform_mod {
$mform->addElement('select', 'bookid', get_string('sourcemodule_book', 'game'), $a);
}
//Common settings to all games
// Common settings to all games.
$mform->addElement('text', 'maxattempts', get_string('cross_max_attempts', 'game'));
$mform->setType('maxattempts', PARAM_INT);
//---------------------------------------------------------------------------
// Grade options
// Grade options.
$mform->addElement('header', 'gradeoptions', get_string('grades', 'grades'));
$mform->addElement('text', 'grade', get_string( 'grademax', 'grades'), array('size' => 4));
$mform->setType('grade', PARAM_INT);
@ -187,20 +188,17 @@ class mod_game_mod_form extends moodleform_mod {
$mform->addElement('date_time_selector', 'timeclose', get_string('gameclose', 'game'),
array('optional' => true, 'step' => 1));
//---------------------------------------------------------------------------
// Bookquiz options
// Bookquiz options.
if ($gamekind == 'bookquiz') {
$mform->addElement('header', 'bookquiz', get_string( 'bookquiz_options', 'game'));
$bookquizlayoutoptions = array();
$bookquizlayoutoptions[0] = get_string('bookquiz_layout0', 'game');
$bookquizlayoutoptions[1] = get_string('bookquiz_layout1', 'game');
$mform->addElement('select','param3', get_string('bookquiz_layout', 'game'), $bookquizlayoutoptions);
$mform->addElement('select', 'param3',
get_string('bookquiz_layout', 'game'), $bookquizlayoutoptions);
}
//---------------------------------------------------------------------------
// Hangman options
// Hangman options.
if ($gamekind == 'hangman') {
$mform->addElement('header', 'hangman', get_string( 'hangman_options', 'game'));
$mform->addElement('text', 'param4', get_string('hangman_maxtries', 'game'), array('size' => 4));
@ -213,15 +211,16 @@ class mod_game_mod_form extends moodleform_mod {
$mform->addElement('text', 'param10', get_string( 'hangman_maximum_number_of_errors', 'game'), array('size' => 4));
$mform->setType('param10', PARAM_INT);
if( !isset( $config->hangmanimagesets))
if (!isset( $config->hangmanimagesets)) {
$number = 1;
else
} else {
$number = $config->hangmanimagesets;
if( $number > 1)
{
}
if ($number > 1) {
$a = array();
for( $i=1; $i <= $number; $i++)
for ($i = 1; $i <= $number; $i++) {
$a[ $i] = $i;
}
$mform->addElement('select', 'param3', get_string('hangman_imageset', 'game'), $a);
}
@ -241,9 +240,7 @@ class mod_game_mod_form extends moodleform_mod {
$mform->disabledIf('userlanguage', 'language', 'neq', 'user');
}
//---------------------------------------------------------------------------
// Crossword options
// Crossword options.
if ($gamekind == 'cross') {
$mform->addElement('header', 'cross', get_string( 'cross_options', 'game'));
$mform->addElement('text', 'param1', get_string('cross_maxcols', 'game'));
@ -261,9 +258,7 @@ class mod_game_mod_form extends moodleform_mod {
$mform->addElement('selectyesno', 'param6', get_string('cross_disabletransformuppercase', 'game'));
}
//---------------------------------------------------------------------------
// Cryptex options
// Cryptex options.
if ($gamekind == 'cryptex') {
$mform->addElement('header', 'cryptex', get_string( 'cryptex_options', 'game'));
$mform->addElement('text', 'param1', get_string('cross_maxcols', 'game'));
@ -277,9 +272,7 @@ class mod_game_mod_form extends moodleform_mod {
$mform->setType('param8', PARAM_INT);
}
//---------------------------------------------------------------------------
// Millionaire options
// Millionaire options.
if ($gamekind == 'millionaire') {
global $OUTPUT, $PAGE;
@ -288,25 +281,17 @@ class mod_game_mod_form extends moodleform_mod {
$mform->setDefault('param8', '#408080');
$mform->setType('param8', PARAM_TEXT);
//$mform->addElement('colorpicker', 'param8', get_string('millionaire_background', 'game'));
//$mform->registerRule('color','regex','/^#([a-fA-F0-9]{6})$/');
//$mform->addRule('config_bgcolor','Enter a valid RGB color - # and then 6 characters','color');
$mform->addElement('selectyesno', 'shuffle', get_string('millionaire_shuffle', 'game'));
}
//---------------------------------------------------------------------------
// Sudoku options
// Sudoku options.
if ($gamekind == 'sudoku') {
$mform->addElement('header', 'sudoku', get_string( 'sudoku_options', 'game'));
$mform->addElement('text', 'param2', get_string('sudoku_maxquestions', 'game'));
$mform->setType('param2', PARAM_INT);
}
//---------------------------------------------------------------------------
// Snakes and Ladders options
// Snakes and Ladders options.
if ($gamekind == 'snakes') {
$mform->addElement('header', 'snakes', get_string( 'snakes_options', 'game'));
$snakesandladdersbackground = array();
@ -334,12 +319,12 @@ class mod_game_mod_form extends moodleform_mod {
ksort( $snakesandladdersbackground);
$mform->addElement('select', 'param3', get_string('snakes_background', 'game'), $snakesandladdersbackground);
//param3 = background
//param4 = itemid for file_storage
//param5 (=1 means dirty file and and have to be computed again)
//param6 = width of autogenerated picture
//param7 = height of autogenerated picture
//param8 = layout
// Param3 = background.
// Param4 = itemid for file_storage.
// Param5 (=1 means dirty file and and have to be computed again).
// Param6 = width of autogenerated picture.
// Param7 = height of autogenerated picture.
// Param8 = layout.
$attachmentoptions = array('subdirs' => false, 'maxfiles' => 1);
$mform->addElement('filepicker', 'param4', get_string('snakes_file', 'game'), $attachmentoptions);
@ -379,9 +364,7 @@ class mod_game_mod_form extends moodleform_mod {
$mform->setType('snakes_height', PARAM_INT);
}
//---------------------------------------------------------------------------
// Hidden Picture options
// Hidden Picture options.
if ($gamekind == 'hiddenpicture') {
$mform->addElement('header', 'hiddenpicture', get_string( 'hiddenpicture_options', 'game'));
$mform->addElement('text', 'param1', get_string('hiddenpicture_across', 'game'));
@ -410,24 +393,19 @@ class mod_game_mod_form extends moodleform_mod {
$mform->addElement('selectyesno', 'param7', get_string('hangman_allowspaces', 'game'));
}
//---------------------------------------------------------------------------
// Header/Footer options
// Header/Footer options.
$mform->addElement('header', 'headerfooteroptions', 'Header/Footer Options');
$mform->addElement('htmleditor', 'toptext', get_string('toptext', 'game'));
$mform->addElement('htmleditor', 'bottomtext', get_string('bottomtext', 'game'));
//---------------------------------------------------------------------------
$features = new stdClass;
$this->standard_coursemodule_elements($features);
//---------------------------------------------------------------------------
// buttons
// Buttons.
$this->add_action_buttons();
}
function validation($data, $files){
public function validation($data, $files) {
$errors = parent::validation($data, $files);
// Check open and close times are consistent.
@ -440,71 +418,70 @@ class mod_game_mod_form extends moodleform_mod {
}
function set_data($default_values) {
public function set_data($defaultvalues) {
global $DB;
if( isset( $default_values->type))
{
if (isset( $defaultvalues->type)) {
// Default values for every game.
if( $default_values->type == 'hangman')
{
$default_values->param10 = 6; //maximum number of wrongs
}else if( $default_values->type == 'snakes')
{
$default_values->gamekind = $default_values->type;
$default_values->param3 = 1;
$default_values->questioncategoryid = 0;
}else if( $default_values->type == 'millionaire')
{
$default_values->shuffle = 1;
}
}
if( isset( $default_values->gamekind)){
if( $default_values->gamekind == 'hangman'){
if( $default_values->param10 == 0)
$default_values->param10 = 6;
}else if( $default_values->gamekind == 'millionaire'){
if( isset( $default_values->param8))
$default_values->param8 = '#'.substr( '000000'.strtoupper( dechex( $default_values->param8)),-6);
}else if( $default_values->gamekind == 'cross')
{
if( $default_values->param5 == NULL)
$default_values->param5 = 1;
}
if( $default_values->gamekind == 'snakes'){
if( isset( $default_values->param9)){
$a = explode( '#',$default_values->param9);
if ($defaultvalues->type == 'hangman') {
$defaultvalues->param10 = 6; // Maximum number of wrongs.
} else if ($defaultvalues->type == 'snakes') {
$defaultvalues->gamekind = $defaultvalues->type;
$defaultvalues->param3 = 1;
$defaultvalues->questioncategoryid = 0;
} else if ($defaultvalues->type == 'millionaire') {
$defaultvalues->shuffle = 1;
}
}
if (isset( $defaultvalues->gamekind)) {
if ($defaultvalues->gamekind == 'hangman') {
if ($defaultvalues->param10 == 0) {
$defaultvalues->param10 = 6;
}
} else if ($defaultvalues->gamekind == 'millionaire') {
if (isset( $defaultvalues->param8)) {
$defaultvalues->param8 = '#'.substr( '000000'.strtoupper( dechex( $defaultvalues->param8)), -6);
}
} else if ($defaultvalues->gamekind == 'cross') {
if ($defaultvalues->param5 == null) {
$defaultvalues->param5 = 1;
}
}
if ($defaultvalues->gamekind == 'snakes') {
if (isset( $defaultvalues->param9)) {
$a = explode( '#', $defaultvalues->param9);
foreach ($a as $s) {
$pos = strpos( $s, ':');
if ($pos) {
$name = substr( $s, 0, $pos);
$default_values->$name = substr( $s, $pos+1);
$defaultvalues->$name = substr( $s, $pos + 1);
}
}
}
}
}
if( !isset( $default_values->gamekind))
$default_values->gamekind = $default_values->type;
if( $default_values->gamekind == 'snakes'){
if( isset( $default_values->param3)){
$board = $default_values->param3;
if (!isset( $defaultvalues->gamekind)) {
$defaultvalues->gamekind = $defaultvalues->type;
}
if ($defaultvalues->gamekind == 'snakes') {
if (isset( $defaultvalues->param3)) {
$board = $defaultvalues->param3;
if ($board != 0) {
$rec = $DB->get_record( 'game_snakes_database', array( 'id' => $board));
$default_values->snakes_data = $rec->data;
$default_values->snakes_cols = $rec->cols;
$default_values->snakes_rows = $rec->rows;
$default_values->snakes_headerx = $rec->headerx;
$default_values->snakes_headery = $rec->headery;
$default_values->snakes_footerx = $rec->footerx;
$default_values->snakes_footery = $rec->footery;
$defaultvalues->snakes_data = $rec->data;
$defaultvalues->snakes_cols = $rec->cols;
$defaultvalues->snakes_rows = $rec->rows;
$defaultvalues->snakes_headerx = $rec->headerx;
$defaultvalues->snakes_headery = $rec->headery;
$defaultvalues->snakes_footerx = $rec->footerx;
$defaultvalues->snakes_footery = $rec->footery;
}
}
}
parent::set_data($default_values);
parent::set_data($defaultvalues);
}
}

54
pagelib.php

@ -1,7 +1,21 @@
<?php // $Id: pagelib.php,v 1.5 2012/07/25 11:16:04 bdaloukas Exp $
<?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/>.
require_once( $CFG->libdir.'/pagelib.php');
require_once($CFG->dirroot.'/course/lib.php'); // needed for some blocks
require_once( $CFG->dirroot.'/course/lib.php'); // Needed for some blocks.
define('PAGE_GAME_VIEW', 'mod-game-view');
@ -18,7 +32,7 @@ $DEFINEDPAGES = array( PAGE_GAME_VIEW);
class page_game extends page_generic_activity {
function init_quick($data) {
public function init_quick($data) {
if (empty($data->pageid)) {
print_error('Cannot quickly initialize page: empty course id');
}
@ -26,43 +40,31 @@ class page_game extends page_generic_activity {
parent::init_quick($data);
}
function print_header($title, $morebreadcrumbs = NULL, $navigation ='') {
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 {
} 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;
$breadcrumbs[format_string($this->activityrecord->name)]
= $CFG->wwwroot.'/mod/game/view.php?id='.$this->modulerecord->id;
if (!empty($morebreadcrumbs)) {
$breadcrumbs = array_merge($breadcrumbs, $morebreadcrumbs);
}
/*
$total = count($breadcrumbs);
$current = 1;
$crumbtext = '';
foreach($breadcrumbs as $text => $href) {
if($current++ == $total) {
$crumbtext .= ' '.$text;
}
else {
$crumbtext .= ' <a href="'.$href.'">'.$text.'</a> ->';
}
}
*/
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>';
@ -75,18 +77,14 @@ class page_game extends page_generic_activity {
'</div></form></td>';
}
$buttons .= '</tr></table>';
}
else {
} else {
$buttons = '&nbsp;';
}
//print_header($title, $this->courserecord->fullname, $crumbtext, '', '', true, $buttons, navmenu($this->courserecord, $this->modulerecord),false,$bodytags);
print_header($title, $this->courserecord->fullname, $navigation);
print_header($title, $this->courserecord->fullname, $navigation);
}
function get_type() {
public function get_type() {
return PAGE_GAME_VIEW;
}
}
?>

24
preview.php

@ -1,4 +1,19 @@
<?php // $Id: preview.php,v 1.10 2012/07/25 11:16:04 bdaloukas Exp $
<?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 page prints a particular attempt of game
*
@ -38,8 +53,7 @@
$PAGE->navbar->add(get_string('preview', 'game'));
switch( $gamekind)
{
switch( $gamekind) {
case 'cross':
$g = '';
$onlyshow = true;
@ -49,7 +63,9 @@
$showhtmlsolutions = false;
$showhtmlprintbutton = true;
$showstudentguess = false;
game_cross_play( $update, $game, $attempt, $detail, $g, $onlyshow, $solution, $endofgame, $print, $checkbutton, $showhtmlsolutions, $showhtmlprintbutton, $showstudentguess, $context);
game_cross_play( $update, $game, $attempt, $detail, $g, $onlyshow, $solution,
$endofgame, $print, $checkbutton, $showhtmlsolutions, $showhtmlprintbutton,
$showstudentguess, $context);
break;
case 'sudoku':
game_sudoku_play( $update, $game, $attempt, $detail, true, $solution, $context);

41
print.php

@ -1,4 +1,19 @@
<?php // $Id: print.php,v 1.7 2012/07/25 11:16:04 bdaloukas Exp $
<?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 page export the game to html
*
@ -10,7 +25,7 @@
require_once("lib.php");
require_once("locallib.php");
$id = required_param('id', PARAM_INT); // Course Module ID, or
$id = required_param('id', PARAM_INT); // Course Module ID.
$gameid = required_param('gameid', PARAM_INT);
$game = $DB->get_record( 'game', array( 'id' => $gameid));
@ -23,15 +38,14 @@
game_print( $game, $id, $context);
function game_print( $game, $update, $context) {
if( $game->gamekind == 'cross')
if ( $game->gamekind == 'cross') {
game_print_cross( $game, $update, $context);
else if( $game->gamekind == 'cryptex')
} else if ($game->gamekind == 'cryptex') {
game_print_cryptex( $game, $update, $context);
}
}
function game_print_cross( $game, $update, $context)
{
function game_print_cross( $game, $update, $context) {
require( "cross/play.php");
$attempt = game_getattempt( $game, $crossrec);
@ -52,12 +66,12 @@
<title>Print</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php
game_cross_play( $update, $game, $attempt, $crossrec, $g, $onlyshow, $showsolution, $endofgame, $print, $checkbutton, $showhtmlsolutions, $showhtmlprintbutton,$showstudentguess, $context);
game_cross_play( $update, $game, $attempt, $crossrec, $g, $onlyshow, $showsolution,
$endofgame, $print, $checkbutton, $showhtmlsolutions, $showhtmlprintbutton,
$showstudentguess, $context);
}
function game_print_cryptex( $game, $update, $context)
{
function game_print_cryptex( $game, $update, $context) {
global $DB;
require( 'cross/cross_class.php');
@ -79,7 +93,6 @@
<title>Print</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php
game_cryptex_play( $update, $game, $attempt, $crossrec, $crossm, $updateattempt, $onlyshow, $showsolution, $context, $print, $showhtmlprintbutton);
game_cryptex_play( $update, $game, $attempt, $crossrec, $crossm, $updateattempt,
$onlyshow, $showsolution, $context, $print, $showhtmlprintbutton);
}

51
report.php

@ -1,15 +1,29 @@
<?php // $Id: report.php,v 1.5 2012/07/25 11:16:04 bdaloukas Exp $
// This script uses installed report plugins to print game reports
<?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 script uses installed report plugins to print game reports.
require_once("../../config.php");
require_once($CFG->dirroot.'/mod/game/locallib.php');
require_once($CFG->dirroot.'/mod/game/report/reportlib.php');
$id = optional_param('id',0,PARAM_INT); // Course Module ID, or
$q = optional_param('q',0,PARAM_INT); // game ID
$id = optional_param('id', 0, PARAM_INT); // Course Module ID.
$q = optional_param('q', 0, PARAM_INT); // Game ID.
$mode = optional_param('mode', 'overview', PARAM_ALPHA); // Report mode
$mode = optional_param('mode', 'overview', PARAM_ALPHA); // Report mode.
if ($id) {
if (! $cm = get_coursemodule_from_id('game', $id)) {
@ -23,7 +37,6 @@
if (! $game = $DB->get_record( 'game', array( 'id' => $cm->instance))) {
print_error( "The game with id $cm->instance corresponding to this coursemodule $id is missing");
}
} else {
if (! $game = $DB->get_record( 'game', array( 'id' => $q))) {
print_error( "There is no game with id $q");
@ -40,24 +53,9 @@
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
require_capability('mod/game:viewreports', $context);
// if no questions have been set up yet redirect to edit.php
//if (!$game->questions and has_capability('mod/game:manage', $context)) {
// redirect('edit.php?gameid='.$game->id);
//}
// Upgrade any attempts that have not yet been upgraded to the
// Moodle 1.5 model (they will not yet have the timestamp set)
//if ($attempts = get_records_sql("SELECT a.*".
// " FROM {$CFG->prefix}game_attempts a, {$CFG->prefix}question_states s".
// " WHERE a.game = '$game->id' AND s.attempt = a.uniqueid AND s.timestamp = 0")) {
// foreach ($attempts as $attempt) {
// game_upgrade_states($attempt);
// }
//}
add_to_log($course->id, "game", "report", "report.php?id=$cm->id", "$game->id", "$cm->id");
/// Open the selected game report and display it
// Open the selected game report and display it.
$mode = clean_param( $mode, PARAM_SAFEDIR);
@ -65,8 +63,8 @@
print_error("Report not known ($mode)");
}
include("report/default.php"); // Parent class
include("report/$mode/report.php");
require("report/default.php"); // Parent class.
require("report/$mode/report.php");
$report = new game_overview_report();
@ -74,6 +72,5 @@
print_error( 'Error occurred during pre-processing!');
}
/// Print footer
// Print footer.
echo $OUTPUT->footer($course);

126
review.php

@ -1,18 +1,27 @@
<?php // $Id: review.php,v 1.12 2012/07/25 23:07:43 bdaloukas Exp $
/**
* This page prints a review of a particular game attempt
*
* @version $Id: review.php,v 1.12 2012/07/25 23:07:43 bdaloukas Exp $
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
* @package game
*/
<?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 page prints a review of a particular game attempt.
require_once("../../config.php");
require_once("locallib.php");
require_once("../../lib/questionlib.php");
$attempt = required_param('attempt', PARAM_INT); // A particular attempt ID for review
$page = optional_param('page', 0, PARAM_INT); // The required page
$attempt = required_param('attempt', PARAM_INT); // A particular attempt ID for review.
$page = optional_param('page', 0, PARAM_INT); // The required page.
$showall = optional_param('showall', 0, PARAM_BOOL);
if (! $attempt = $DB->get_record('game_attempts', array( 'id' => $attempt))) {
@ -43,7 +52,7 @@
add_to_log($course->id, "game", "review", "review.php?id=$cm->id&amp;attempt=$attempt->id", "$game->id", "$cm->id");
/// Print the page header
// Print the page header.
$strgames = get_string('modulenameplural', 'game');
$strreview = get_string('review', 'game');
@ -53,10 +62,8 @@
$strtimetaken = get_string('timetaken', 'game');
$strtimecompleted = get_string('completedon', 'game');
$strupdatemodule = has_capability('moodle/course:manageactivities', $coursecontext)
? update_module_button($cm->id, $course->id, get_string('modulename', 'game'))
: "";
$strupdatemodule = has_capability('moodle/course:manageactivities',
$coursecontext) ? update_module_button($cm->id, $course->id, get_string('modulename', 'game')) : '';
$strgames = get_string("modulenameplural", "game");
$strgame = get_string("modulename", "game");
@ -72,30 +79,28 @@
} else {
$navigation = '';
}
echo $OUTPUT->heading("$course->shortname: $game->name", "$course->fullname",
"$navigation <a href=index.php?id=$course->id>$strgames</a> -> $game->name",
"", "", true, update_module_button($cm->id, $course->id, $strgame),
navmenu($course, $cm));
}
echo '<div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div>'; // For overlib.
echo '<div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div>'; // for overlib
/// Print heading and tabs if this is part of a preview
//if (has_capability('mod/game:preview', $context)) {
if ($attempt->userid == $USER->id) { // this is the report on a preview
// Print heading and tabs if this is part of a preview.
if ($attempt->userid == $USER->id) {
// This is the report on a preview.
$currenttab = 'preview';
} else {
$currenttab = 'reports';
$mode = '';
}
include('tabs.php');
//} else {
// print_heading(format_string($game->name));
//}
/// Load all the questions and states needed by this script
require('tabs.php');
// load the questions needed by page
// Load all the questions and states needed by this script.
// Load the questions needed by page.
$pagelist = $showall ? game_questions_in_game( $attempt->layout) : game_questions_on_page( $attempt->layout, $page);
$a = explode( ',', $pagelist);
$pagelist = '';
@ -106,6 +111,7 @@
}
}
}
$pagelist = substr( $pagelist, 1);
if ($pagelist != '') {
@ -119,20 +125,18 @@
if (!$questions = $DB->get_records_sql( $sql)) {
print_error('No questions found');
}
}else
{
} else {
$questions = array();
}
// Load the question type specific information
// Load the question type specific information.
if (!get_question_options( $questions)) {
print_error('Could not load question options');
}
$states = game_compute_states( $game, $questions);
/// Print infobox
// Print infobox.
//$timelimit = (int)$game->timelimit * 60;
$timelimit = 0;
$overtime = 0;
@ -154,27 +158,29 @@
if ($attempt->userid <> $USER->id) {
$student = $DB->get_record('user', array( 'id' => $attempt->userid));
$picture = print_user_picture($student->id, $course->id, $student->picture, false, true);
$table->data[] = array($picture, '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$student->id.'&amp;course='.$course->id.'">'.fullname($student, true).'</a>');
$table->data[] = array($picture,
'<a href="'.$CFG->wwwroot.'/user/view.php?id='.$student->id.'&amp;course='.
$course->id.'">'.fullname($student, true).'</a>');
}
//if (has_capability('mod/game:grade', $context)){
if( count($attempts = $DB->get_records('game_attempts', array( 'gameid' => $game->id, 'userid' => $attempt->userid), 'attempt ASC')) > 1) {
// print list of attempts
if (count($attempts = $DB->get_records('game_attempts', array( 'gameid' => $game->id,
'userid' => $attempt->userid), 'attempt ASC')) > 1) {
// Print list of attempts.
$attemptlist = '';
foreach ($attempts as $at) {
$attemptlist .= ($at->id == $attempt->id)
? '<strong>'.$at->attempt.'</strong>, '
: '<a href="review.php?attempt='.$at->id.($showall?'&amp;showall=true':'').'">'.$at->attempt.'</a>, ';
$attemptlist .= ($at->id == $attempt->id) ? '<strong>'.$at->attempt.'</strong>, ' : '<a href="review.php?attempt='.
$at->id.($showall ? '&amp;showall=true' : '').'">'.$at->attempt.'</a>, ';
}
$table->data[] = array(get_string('attempts', 'game').':', trim($attemptlist, ' ,'));
}
//}
$table->data[] = array(get_string('startedon', 'game').':', userdate($attempt->timestart));
if ($attempt->timefinish) {
$table->data[] = array("$strtimecompleted:", userdate($attempt->timefinish));
$table->data[] = array("$strtimetaken:", $timetaken);
}
//if the student is allowed to see their score
// If the student is allowed to see their score.
if ($options->scores) {
if ($game->grade) {
if ($overtime) {
@ -187,31 +193,33 @@
$a->grade = game_score_to_grade( $attempt->score, $game);
$a->maxgrade = $game->grade;
$table->data[] = array("$strscore:", "{$a->grade}/{$game->grade} ($percentage %)");
//$table->data[] = array("$strgrade:", get_string('outof', 'game', $a));
}
}
if ($options->overallfeedback && $feedback) {
$table->data[] = array(get_string('feedback', 'game'), $feedback);
}
if ($isteacher and $attempt->userid == $USER->id) {
// the teacher is at the end of a preview. Print button to start new preview
// The teacher is at the end of a preview. Print button to start new preview.
unset($buttonoptions);
$buttonoptions['q'] = $game->id;
$buttonoptions['forcenew'] = true;
echo '<div class="controls">';
print_single_button($CFG->wwwroot.'/mod/game/attempt.php', $buttonoptions, get_string('startagain', 'game'));
echo '</div>';
} else { // print number of the attempt
} else {
// Print number of the attempt.
print_heading(get_string('reviewofattempt', 'game', $attempt->attempt));
}
print_table($table);
// print javascript button to close the window, if necessary
// Print javascript button to close the window, if necessary.
if (!$isteacher) {
include('attempt_close_js.php');
}
/// Print the navigation panel if required
// Print the navigation panel if required.
$numpages = game_number_of_pages( $attempt->layout);
if ($numpages > 1 and !$showall) {
print_paging_bar($numpages, $page, 1, 'review.php?attempt='.$attempt->id.'&amp;');
@ -220,32 +228,29 @@
echo '</a></div>';
}
/// Print all the questions
// Print all the questions.
if ($pagelist) {
game_print_questions( $pagelist, $attempt, $questions, $options, $states, $game);
}
// Print the navigation panel if required
// Print the navigation panel if required.
if ($numpages > 1 and !$showall) {
print_paging_bar($numpages, $page, 1, 'review.php?attempt='.$attempt->id.'&amp;');
}
// print javascript button to close the window, if necessary
// Print javascript button to close the window, if necessary.
if (!$isteacher) {
include('attempt_close_js.php');
require('attempt_close_js.php');
}
if (empty($popup)) {
echo $OUTPUT->footer($course);
}
function game_compute_states( $game, $questions)
{
function game_compute_states( $game, $questions) {
global $QTYPES;
// Restore the question sessions to their most recent states
// creating new sessions where required
// Restore the question sessions to their most recent states creating new sessions where required.
$states = array();
foreach ($questions as $question) {
$state = new StdClass;
@ -266,7 +271,6 @@
}
$state->event = QUESTION_EVENTOPEN;
//$question->maxgrade = 100;
$state->manualcomment = '';
$state->responses = array( '' => $question->studentanswer);
@ -277,10 +281,7 @@
return $states;
}
function game_print_questions( $pagelist, $attempt, $questions, $options, $states, $game)
{
function game_print_questions( $pagelist, $attempt, $questions, $options, $states, $game) {
$pagequestions = explode(',', $pagelist);
$number = game_first_questionnumber( $attempt->layout, $pagelist);
foreach ($pagequestions as $i) {
@ -289,17 +290,18 @@
echo '<strong><font size="+1">' . $number . '</font></strong><br />';
notify(get_string('errormissingquestion', 'quiz', $i));
echo $OUTPUT->box_end();
$number++; // Just guessing that the missing question would have lenght 1
$number++; // Just guessing that the missing question would have lenght 1.
continue;
}
$options->validation = QUESTION_EVENTVALIDATE === $states[$i]->event;
//$options->history = ($isteacher and !$attempt->preview) ? 'all' : 'graded';
$options->history = false;
unset( $options->questioncommentlink);
// Print the question
// Print the question.
if ($i > 0) {
echo "<br />\n";
}
$questions[$i]->maxgrade = 0;
$options->correct_responses = 0;
@ -323,5 +325,3 @@
$number += $questions[$i]->length;
}
}
?>

19
settings.php

@ -1,4 +1,19 @@
<?php // $Id: settings.php
<?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/>.
/**
* Form for creating and modifying a game
*
@ -12,7 +27,7 @@ defined('MOODLE_INTERNAL') || die;
if ($ADMIN->fulltree) {
require_once(dirname(__FILE__).'/lib.php');
// General settings
// General settings.
$settings->add(new admin_setting_configcheckbox('game/hidebookquiz',
get_string('hidebookquiz', 'game'), get_string('confighidebookquiz', 'game'), 0));

144
showanswers.php

@ -1,4 +1,19 @@
<?php // $Id: showanswers.php,v 1.7 2012/07/25 22:46:42 bdaloukas Exp $
<?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 page shows the answers of the current game
*
@ -16,17 +31,21 @@
$PAGE->navbar->add(get_string('showanswers', 'game'));
$action = optional_param('action', "", PARAM_ALPHANUM); // action
if( $action == 'delstats')
$action = optional_param('action', "", PARAM_ALPHANUM); // Action.
if ($action == 'delstats') {
$DB->delete_records('game_repetitions', array('gameid' => $game->id, 'userid' => $USER->id));
if( $action == 'computestats')
}
if ($action == 'computestats') {
game_compute_repetitions($game);
}
echo '<b>'.get_string('repetitions', 'game').': &nbsp;&nbsp;</b>';
echo get_string('user').': ';
game_showusers($game);
echo " &nbsp;<a href=\"{$CFG->wwwroot}/mod/game/showanswers.php?q=$q&action=delstats\">".get_string('clearrepetitions','game').'</a>';
echo " &nbsp;&nbsp;<a href=\"{$CFG->wwwroot}/mod/game/showanswers.php?q=$q&action=computestats\">".get_string('computerepetitions','game').'</a>';
echo " &nbsp;<a href=\"{$CFG->wwwroot}/mod/game/showanswers.php?q=$q&action=delstats\">".
get_string('clearrepetitions', 'game').'</a>';
echo " &nbsp;&nbsp;<a href=\"{$CFG->wwwroot}/mod/game/showanswers.php?q=$q&action=computestats\">".
get_string('computerepetitions', 'game').'</a>';
echo '<br><br>';
$existsbook = ($DB->get_record( 'modules', array( 'name' => 'book'), 'id,id'));
@ -43,12 +62,12 @@ function game_compute_repetitions($game){
"SELECT $game->id,$USER->id,questionid,glossaryentryid,COUNT(*) ".
"FROM {game_queries} WHERE gameid=$game->id AND userid=$USER->id GROUP BY questionid,glossaryentryid";
if( !$DB->execute( $sql))
if (!$DB->execute( $sql)) {
print_error('Problem on computing statistics for repetitions');
}
}
function game_showusers($game)
{
function game_showusers($game) {
global $CFG, $USER;
$users = array();
@ -63,11 +82,13 @@ function game_showusers($game)
if ($guest = guest_user()) {
$users[$guest->id] = fullname($guest);
}
$href = $CFG->wwwroot.'/mod/game/showanswers.php?q='.$game->id.'&userid=';
?>
<script type="text/javascript">
function onselectuser()
{
window.location.href = "<?php echo $CFG->wwwroot.'/mod/game/showanswers.php?q='.$game->id.'&userid=';?>" + document.getElementById('menuuser').value;
window.location.href =
"<?php echo $href;?>" + document.getElementById('menuuser').value;
}
</script>
<?php
@ -76,7 +97,7 @@ function game_showusers($game)
$name = 'user';
$id = 'menu'.$name;
$class = 'menu'.$name;
$class = 'select ' . $class; /// Add 'select' selector always
$class = 'select ' . $class; // Add 'select' selector always.
$nothing = get_string("allparticipants");
$nothingvalue = '0';
$options = $users;
@ -106,8 +127,7 @@ function game_showusers($game)
echo $output . '</select>' . "\n";
}
function game_showanswers( $game, $existsbook, $context)
{
function game_showanswers( $game, $existsbook, $context) {
if ($game->gamekind == 'bookquiz' and $existsbook) {
game_showanswers_bookquiz( $game, $context);
return;
@ -126,8 +146,7 @@ function game_showanswers( $game, $existsbook, $context)
}
}
function game_showanswers_appendselect( $game)
{
function game_showanswers_appendselect( $game) {
switch ($game->gamekind) {
case 'hangman':
case 'cross':
@ -144,8 +163,7 @@ function game_showanswers_appendselect( $game)
return '';
}
function game_showanswers_question( $game, $context)
{
function game_showanswers_question( $game, $context) {
global $DB;
if ($game->gamekind != 'bookquiz') {
@ -157,8 +175,7 @@ function game_showanswers_question( $game, $context)
$select = ' category in ('.$cats.')';
}
}
}else
{
} else {
$context2 = get_context_instance(50, $COURSE->id);
$select = " contextid in ($context2->id)";
$select2 = '';
@ -178,9 +195,7 @@ function game_showanswers_question( $game, $context)
game_showanswers_question_select( $game, '{question} q', $select, '*', $order, $showcategories, $game->course, $context);
}
function game_showanswers_quiz( $game, $context)
{
function game_showanswers_quiz( $game, $context) {
global $CFG;
$select = "quiz='$game->quizid' ".
@ -192,9 +207,7 @@ function game_showanswers_quiz( $game, $context)
game_showanswers_question_select( $game, $table, $select, 'q.*', 'category,questiontext', false, $game->course, $context);
}
function game_showanswers_question_select( $game, $table, $select, $fields, $order, $showcategoryname, $courseid, $context)
{
function game_showanswers_question_select( $game, $table, $select, $fields, $order, $showcategoryname, $courseid, $context) {
global $CFG, $DB, $OUTPUT;
$sql = "SELECT $fields FROM $table WHERE $select ORDER BY $order";
@ -205,8 +218,9 @@ function game_showanswers_question_select( $game, $table, $select, $fields, $ord
$table .= ",{game_repetitions} gr";
$select .= " AND gr.questionid=q.id AND gr.glossaryentryid=0 AND gr.gameid=".$game->id;
$userid = optional_param('userid', 0, PARAM_INT);
if( $userid)
if ($userid) {
$select .= " AND gr.userid=$userid";
}
$sql = "SELECT q.id as id,SUM(repetitions) as c FROM {$table} WHERE $select GROUP BY q.id";
$reps = $DB->get_records_sql( $sql);
@ -239,8 +253,9 @@ function game_showanswers_question_select( $game, $table, $select, $fields, $ord
echo '<td><b>'.get_string( 'questions', 'quiz').'</b></td>';
echo '<td><b>'.get_string( 'answers', 'quiz').'</b></td>';
echo '<td><b>'.get_string( 'feedbacks', 'game').'</b></td>';
if( $reps)
if ($reps) {
echo '<td><b>'.get_string( 'repetitions', 'game').'</b></td>';
}
echo "</tr>\r\n";
$line = 0;
foreach ($questions as $question) {
@ -259,22 +274,28 @@ function game_showanswers_question_select( $game, $table, $select, $fields, $ord
}
echo '<td>';
echo "<a title=\"Edit\" href=\"{$CFG->wwwroot}/question/question.php?inpopup=1&amp;id=$question->id&courseid=$courseid\" target=\"_blank\"><img src=\"".$OUTPUT->pix_url('t/edit')."\" alt=\"Edit\" /></a> ";
echo "<a title=\"Edit\" ".
"href=\"{$CFG->wwwroot}/question/question.php?inpopup=1&amp;id=$question->id&courseid=$courseid\" target=\"_blank\">";
echo "<img src=\"".$OUTPUT->pix_url('t/edit')."\" alt=\"Edit\" /></a> ";
echo game_filterquestion(str_replace( array( "\'", '\"'), array( "'", '"'), $question->questiontext), $question->id, $context->id, $game->course);
echo game_filterquestion(str_replace( array( "\'", '\"'), array( "'", '"'),
$question->questiontext), $question->id, $context->id, $game->course);
switch ($question->qtype) {
case 'shortanswer':
$recs = $DB->get_records( 'question_answers', array( 'question' => $question->id), 'fraction DESC', 'id,answer,feedback');
$recs = $DB->get_records( 'question_answers',
array( 'question' => $question->id), 'fraction DESC', 'id,answer,feedback');
if ($recs == false) {
$rec = false;
} else {
foreach( $recs as $rec)
foreach ($recs as $rec) {
break;
}
}
echo "<td>$rec->answer</td>";
if( $rec->feedback == '')
if ($rec->feedback == '') {
$rec->feedback = '&nbsp;';
}
echo "<td>$rec->feedback</td>";
break;
case 'multichoice':
@ -284,27 +305,29 @@ function game_showanswers_question_select( $game, $table, $select, $fields, $ord
echo '<td>';
$i = 0;
foreach ($recs as $rec) {
if( $i++ > 0)
if ($i++ > 0) {
echo '<br>';
}
if ($rec->fraction == 1) {
echo " <b>$rec->answer</b>";
if( $rec->feedback == '')
if ($rec->feedback == '') {
$feedback .= '<br>';
else
}
} else {
$feedback .= "<b>$rec->feedback</b><br>";
}else
{
}
} else {
echo " $rec->answer";
if( $rec->feedback == '')
if ($rec->feedback == '') {
$feedback .= '<br>';
else
} else {
$feedback .= "<br>";
}
}
echo '</td>';
if( $feedback == '')
if ($feedback == '') {
$feedback = '&nbsp;';
}
echo "<td>$feedback</td>";
break;
default:
@ -312,22 +335,22 @@ function game_showanswers_question_select( $game, $table, $select, $fields, $ord
break;
}
//Show repetitions
// Show repetitions.
if ($reps) {
if (array_key_exists( $question->id, $reps)) {
$rep = $reps[ $question->id];
echo '<td><center>'.$rep->c.'</td>';
}else
} else {
echo '<td>&nbsp;</td>';
}
}
echo "</tr>\r\n";
}
echo "</table><br>\r\n\r\n";
}
function game_showanswers_glossary( $game)
{
function game_showanswers_glossary( $game) {
global $CFG, $DB;
$table = '{glossary_entries} ge';
@ -342,12 +365,13 @@ function game_showanswers_glossary( $game)
return;
}
//Show repetitions of questions
// Show repetitions of questions.
$table = "{glossary_entries} ge, {game_repetitions} gr";
$select = "glossaryid={$game->glossaryid} AND gr.glossaryentryid=ge.id AND gr.gameid=".$game->id;
$userid = optional_param('userid', 0, PARAM_INT);
if( $userid)
if ($userid) {
$select .= " AND gr.userid=$userid";
}
if ($game->glossarycategoryid) {
$select .= " AND gec.entryid = ge.id ".
" AND gec.categoryid = {$game->glossarycategoryid}";
@ -360,19 +384,22 @@ function game_showanswers_glossary( $game)
echo '<tr><td></td>';
echo '<td><b>'.get_string( 'questions', 'quiz').'</b></td>';
echo '<td><b>'.get_string( 'answers', 'quiz').'</b></td>';
if( $reps != false)
if ($reps != false) {
echo '<td><b>'.get_string( 'repetitions', 'game').'</b></td>';
}
echo "</tr>\r\n";
$line = 0;
foreach ($questions as $question) {
if( $game->param7 == 0){ //Not allowed spaces
if(!( strpos( $question->concept, ' ') === false))
if ($game->param7 == 0) { // Not allowed spaces.
if (!( strpos( $question->concept, ' ') === false)) {
continue;
}
if( $game->param8 == 0){ //Not allowed -
if(!( strpos( $question->concept, '-') === false))
}
if ($game->param8 == 0) { // Not allowed -.
if (!( strpos( $question->concept, '-') === false)) {
continue;
}
}
echo '<tr>';
echo '<td>'.(++$line);
@ -383,23 +410,21 @@ function game_showanswers_glossary( $game)
$query->glossaryentryid = $question->id;
echo '<td>'.game_show_query( $game, $query, $question->definition).'</td>';
echo '<td>'.$question->concept.'</td>';
if ($reps != false) {
if( array_key_exists( $question->id, $reps))
{
if (array_key_exists( $question->id, $reps)) {
$rep = $reps[ $question->id];
echo '<td><center>'.$rep->c.'</td>';
}else
} else {
echo '<td>&nbsp;</td>';
}
}
echo "</tr>\r\n";
}
echo "</table><br>\r\n\r\n";
}
function game_showanswers_bookquiz( $game, $context)
{
function game_showanswers_bookquiz( $game, $context) {
global $CFG;
$select = "gbq.questioncategoryid=q.category ".
@ -408,5 +433,6 @@ function game_showanswers_bookquiz( $game, $context)
$table = "{question} q,{game_bookquiz_questions} gbq,{book_chapters} bc";
$showcategories = ($game->gamekind == 'bookquiz');
game_showanswers_question_select( $game, $table, $select, "DISTINCT q.*", "bc.pagenum,questiontext", $showcategories, $game->course, $context);
game_showanswers_question_select( $game, $table, $select, "DISTINCT q.*",
"bc.pagenum,questiontext", $showcategories, $game->course, $context);
}

78
showattempts.php

@ -1,4 +1,19 @@
<?php // $Id: showattempts.php,v 1.6 2012/07/25 11:16:04 bdaloukas Exp $
<?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 page shows the answers of the current game
*
@ -16,7 +31,7 @@
$PAGE->navbar->add(get_string('showattempts', 'game'));
$action = optional_param('action', "", PARAM_ALPHANUM); // action
$action = optional_param('action', "", PARAM_ALPHANUM); // Action.
if ($action == 'delete') {
game_ondeleteattempt( $game);
}
@ -30,9 +45,7 @@
echo $OUTPUT->footer();
function game_showusers($game)
{
function game_showusers($game) {
global $CFG, $USER, $DB;
$users = array();
@ -42,23 +55,25 @@
$groupid = optional_param('groupid', 0, PARAM_INT);
$sql = "SELECT DISTINCT ra.userid,u.lastname,u.firstname FROM {role_assignments} ra, {user} u ".
" WHERE ra.contextid={$context->id} AND ra.userid=u.id";
if( $groupid != 0)
if ($groupid != 0) {
$sql .= " AND ra.userid IN (SELECT gm.userid FROM {groups_members} gm WHERE gm.groupid=$groupid)";
}
if (($recs = $DB->get_records_sql( $sql))) {
foreach ($recs as $rec) {
$users[ $rec->userid] = $rec->lastname.' '.$rec->firstname;
}
}
if ($guest = guest_user()) {
$users[$guest->id] = fullname($guest);
}
$href = $CFG->wwwroot.'/mod/game/showattempts.php?q='.$game->id.'&userid=';
?>
<script type="text/javascript">
function onselectuser()
{
window.location.href = "<?php echo $CFG->wwwroot.'/mod/game/showattempts.php?q='.$game->id.'&userid=';?>" + document.getElementById('menuuser').value + '&groupid=' + document.getElementById('menugroup').value;
var groupid = document.getElementById('menugroup').value;
window.location.href = "<?php echo href;?>" + document.getElementById('menuuser').value + '&groupid=' + groupid;
}
</script>
<?php
@ -67,7 +82,7 @@
$name = 'user';
$id = 'menu'.$name;
$class = 'menu'.$name;
$class = 'select ' . $class; /// Add 'select' selector always
$class = 'select ' . $class; // Add 'select' selector always.
$nothing = get_string("allparticipants");
$nothingvalue = '0';
$options = $users;
@ -97,8 +112,7 @@
echo $output . '</select>' . "\n";
}
function game_showgroups($game)
{
function game_showgroups($game) {
global $CFG, $USER, $DB;
$groups = array();
@ -107,12 +121,12 @@
$groups[ $rec->id] = $rec->name;
}
}
$href = $CFG->wwwroot.'/mod/game/showattempts.php?q='.$game->id.'&groupid=';
?>
<script type="text/javascript">
function onselectgroup()
{
window.location.href = "<?php echo $CFG->wwwroot.'/mod/game/showattempts.php?q='.$game->id.'&groupid=';?>" + document.getElementById('menugroup').value;
window.location.href = "<?php echo $href;?>" + document.getElementById('menugroup').value;
}
</script>
<?php
@ -121,14 +135,14 @@
$name = 'group';
$id = 'menu'.$name;
$class = 'menu'.$name;
$class = 'select ' . $class; /// Add 'select' selector always
$class = 'select ' . $class; // Add 'select' selector always.
$nothing = get_string("allgroups");
$nothingvalue = '0';
$options = $groups;
$selected = optional_param('groupid', 0, PARAM_INT);
$output = '<select id="'. $id .'" class="'. $class .'" name="'. $name .'" '. $attributes .'>' . "\n";
$output .= ' <option value="'. s($nothingvalue) .'"'. "\n";
$output .= ' <option value="'. $nothingvalue .'"'. "\n";
if ($nothingvalue === $selected) {
$output .= ' selected="selected"';
}
@ -161,13 +175,14 @@
$gamekind = $game->gamekind;
$update = get_coursemodule_from_instance( 'game', $game->id, $game->course)->id;
//Here are user attempts
// Here are user attempts.
$table = "{game_attempts} as ga, {user} u, {game} as g";
$select = "ga.userid=u.id AND ga.gameid={$game->id} AND g.id={$game->id}";
$fields = "ga.id, u.lastname, u.firstname, ga.attempts,".
"timestart, timefinish, timelastattempt, score, ga.lastip, ga.lastremotehost";
if( $userid != 0)
if ($userid != 0) {
$select .= ' AND u.id='.$userid;
}
$sql = "SELECT COUNT(*) AS c FROM $table WHERE $select";
$count = $DB->count_records_sql( $sql);
$maxlines = 20;
@ -179,9 +194,8 @@
for ($i = 0; $i * $maxlines < $count; $i++) {
if ($i == $limitfrom) {
echo ($i + 1).' ';
}else
{
echo "<A HREF=\"{$CFG->wwwroot}/mod/game/showattempts.php?q={$game->id}&amp;limitfrom=$i&\">".($i+1)."</a>";
} else {
echo "<a href=\"{$CFG->wwwroot}/mod/game/showattempts.php?q={$game->id}&amp;limitfrom=$i&\">".($i + 1)."</a>";
echo ' &nbsp;';
}
}
@ -206,9 +220,11 @@
echo '<tr>';
echo '<td><center>';
if (($rec->timefinish == 0) or $allowdelete) {
echo "\r\n<a href=\"{$CFG->wwwroot}/mod/game/showattempts.php?attemptid={$rec->id}&amp;q={$game->id}&amp;action=delete";
if( $allowdelete)
echo "\r\n<a href=\"{$CFG->wwwroot}/mod/game/showattempts.php?attemptid={$rec->id}";
echo "&amp;q={$game->id}&amp;action=delete";
if ($allowdelete) {
echo '&allowdelete=1';
}
echo '">';
echo '<img src="'.$OUTPUT->pix_url('t/delete').'" alt="'.get_string( 'delete').'" /></a>';
}
@ -221,18 +237,22 @@
echo '<td><center>'.round($rec->score * 100).'</center></td>';
echo '<td><center>'.$rec->attempts.'</center></td>';
echo '<td><center>';
//Preview
// Preview.
if (($gamekind == 'cross') or ($gamekind == 'sudoku') or ($gamekind == 'hangman') or ($gamekind == 'cryptex')) {
echo "\r\n<a href=\"{$CFG->wwwroot}/mod/game/preview.php?action=preview&amp;attemptid={$rec->id}&amp;gamekind=$gamekind";
echo "\r\n<a href=\"{$CFG->wwwroot}/mod/game/preview.php?action=preview&amp;";
echo "attemptid={$rec->id}&amp;gamekind=$gamekind";
echo '&amp;update='.$update."&amp;q={$game->id}\">";
echo '<img src="'.$OUTPUT->pix_url('t/preview').'" alt="'.get_string( 'preview', 'game').'" /></a>';
}
echo '</center></td>';
//Show solution
// Show the solution.
echo '<td><center>';
if (($gamekind == 'cross') or ($gamekind == 'sudoku') or ($gamekind == 'hangman') or ($gamekind == 'cryptex') ) {
echo "\r\n<a href=\"{$CFG->wwwroot}/mod/game/preview.php?action=solution&amp;attemptid={$rec->id}&amp;gamekind={$gamekind}&amp;update=$update&amp;&amp;q={$game->id}\">";
echo "\r\n<a href=\"{$CFG->wwwroot}/mod/game/preview.php?action=solution&amp;".
"attemptid={$rec->id}&amp;gamekind={$gamekind}&amp;update=$update&amp;&amp;".
"q={$game->id}\">";
echo '<img src="'.$OUTPUT->pix_url('t/preview').'" alt="'.get_string( 'showsolution', 'game').'" /></a>';
}
echo '</center></td>';
@ -242,16 +262,14 @@
}
}
function game_ondeleteattempt( $game)
{
function game_ondeleteattempt( $game) {
global $CFG, $DB;
$attemptid = required_param('attemptid', PARAM_INT);
$attempt = $DB->get_record( 'game_attempts', array( 'id' => $attemptid));
switch( $game->gamekind)
{
switch( $game->gamekind) {
case 'bookquiz':
$DB->delete_records( 'game_bookquiz_chapters', array( 'attemptid' => $attemptid));
break;

30
tabs.php

@ -1,4 +1,19 @@
<?php // $Id: tabs.php,v 1.7 2012/07/25 11:16:04 bdaloukas Exp $
<?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/>.
/**
* Sets up the tabs used by the game pages based on the users capabilites.
*
@ -29,30 +44,24 @@ $activated = array();
global $USER;
if (has_capability('mod/game:view', $context)) {
$row[] = new tabobject('info', "{$CFG->wwwroot}/mod/game/view.php?q=$game->id", get_string('info', 'game'));
}
if (has_capability('mod/game:viewreports', $context)) {
//if( isteacher( $game->course, $USER->id)){
$row[] = new tabobject('reports', "{$CFG->wwwroot}/mod/game/report.php?q=$game->id", get_string('results', 'game'));
//}
}
if (has_capability('mod/game:preview', $context)) {
$row[] = new tabobject('preview', "{$CFG->wwwroot}/mod/game/attempt.php?a=$game->id", get_string('preview', 'game'));
}
if (has_capability('mod/game:manage', $context)) {
//if( isteacher( $game->course, $USER->id)){
global $USER;
$sesskey = $USER->sesskey;
$url = "{$CFG->wwwroot}/course/mod.php?update=$cm->id&return=true&sesskey=$sesskey";
$row[] = new tabobject('edit', $url, get_string('edit'));
//}
}
if ($currenttab == 'info' && count($row) == 1) {
if ( !($currenttab == 'info' && count($row) == 1)) {
// Don't show only an info tab (e.g. to students).
} else {
$tabs[] = $row;
}
@ -61,7 +70,8 @@ if ($currenttab == 'reports' and isset($mode)) {
$activated[] = 'reports';
$allreports = get_list_of_plugins("mod/game/report");
$reportlist = array ('overview' /*, 'regrade' , 'grading' , 'analysis'*/); // Standard reports we want to show first
// Standard reports we want to show first
$reportlist = array ('overview' /*, 'regrade' , 'grading' , 'analysis'*/);
foreach ($allreports as $report) {
if (!in_array($report, $reportlist)) {
@ -98,5 +108,3 @@ if ($currenttab == 'edit' and isset($mode)) {
}
print_tabs($tabs, $currenttab, $inactive, $activated);
?>

309
translate.php

@ -1,4 +1,19 @@
<?php // $Id: translate.php,v 1.10 2012/07/25 23:07:43 bdaloukas Exp $
<?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/>.
/**
* Check translation of module Game
*
@ -21,8 +36,9 @@ require( 'locallib.php');
$moodle19dir = '/var/www/moodle19';
$context = get_context_instance(CONTEXT_COURSE, $COURSE->id);
if (!has_capability('mod/game:viewreports', $context))
if (!has_capability('mod/game:viewreports', $context)) {
error( get_string( 'only_teachers', 'game'));
}
$langname = array();
$langname['ca'] = 'Català (ca)';
@ -48,12 +64,12 @@ ksort( $langname);
$a = read_dir( $CFG->dirroot.'/mod/game', 'php');
$strings = array();
$files = array();
foreach( $a as $file)
foreach ($a as $file) {
$files[] = $file;
}
sort( $files);
foreach( $files as $file)
{
foreach ($files as $file) {
readsourcecode( $file, $strings);
}
@ -86,43 +102,42 @@ unset( $en[ 'convertto']);
$langs = computelangs();
$sum = array();
$destdir = game_export_createtempdir();
foreach( $langs as $lang)
{
if($lang != 'en' and $lang != 'CVS' and strpos( $lang, '_utf8') == 0 and strpos( $lang, '_uft8') == 0)
{
foreach ($langs as $lang) {
if ($lang != 'en' and $lang != 'CVS' and strpos( $lang, '_utf8') == 0 and strpos( $lang, '_uft8') == 0) {
computediff( $en, $lang, $strings, $langname, $sum, $destdir, $untranslated);
$auntranslated[ $lang] = $untranslated;
}
}
$file_no_translation = 'game_lang_no_translation.zip';
$filezip=game_create_zip( $destdir, $COURSE->id, $file_no_translation);
$filenotranslation = 'game_lang_no_translation.zip';
$filezip = game_create_zip( $destdir, $COURSE->id, $filenotranslation);
remove_dir( $destdir);
$ilang = 0;
echo '<table border=1>';
echo "<tr><td><b>Counter</td><td><b>Language</td><td><b>Missing words</td><td><b>Percent completed</td></tr>";
foreach($sum as $s)
foreach ($sum as $s) {
echo '<tr><td>'.(++$ilang).'</td>'.$s."\r\n";
}
echo "</table>";
echo "<br><a href=\"{$CFG->wwwroot}/file.php/1/export/$file_no_translation\">Words that is not translated yet in each language</a>";
echo "<br><a href=\"{$CFG->wwwroot}/file.php/1/export/$filenotranslation\">Words that is not translated yet in each language</a>";
//Find missing strings on en/game.php
// Find missing strings on en/game.php.
$not = array();
$prevfile = '';
foreach( $strings as $info)
{
foreach ($strings as $info) {
$pos = strpos( $info, '*');
$name = substr( $info, $pos + 2);
$file = substr( $info, 0, $pos - 1);
if( substr( $file, 0, 1) == '/')
if (substr( $file, 0, 1) == '/') {
$file = substr( $file, 1);
if( $file != $prevfile)
{
}
if ($file != $prevfile) {
$prevfile = $file;
}
if( !array_key_exists( $name, $en))
if (!array_key_exists( $name, $en)) {
$not[ $info] = $info;
}
}
$oldfile = '';
unset( $not[ 'tabs.php * $report']);
unset( $not[ 'mod_form.php * game_\'.$gamekin']);
@ -130,106 +145,108 @@ unset( $not[ 'mod.html * game_\'.$form->gamekin']);
unset( $not[ '/report/overview/report.php * fullname\')."\t".get_string(\'startedon']);
unset( $not[ '/hangman/play.php * hangman_correct_\'.$ter']);
if( count( $not))
if (count( $not)) {
echo "<br><br>Missing strings on en/game.php<br>";
foreach( $not as $key => $value)
{
}
foreach ($not as $key => $value) {
$pos = strpos( $value, '*');
$file = trim( substr( $value, 0, $pos));
$key = trim( substr( $value, $pos + 1));
if( $key == 'convertfrom' or $key == 'convertto')
if ($key == 'convertfrom' or $key == 'convertto') {
continue;
}
if( substr( $file, 0, 1) == '/')
if (substr( $file, 0, 1) == '/') {
$file = substr( $file, 1);
if( $file != $oldfile)
{
}
if ($file != $oldfile) {
echo "<br>//$file<br>\r\n";
$fileold = $file;
}
echo '$'."string[ '$key'] = \"\";<br>";
}
//Finds translations to en that are not used now
// Finds translations to en that are not used now.
$ret = '';
foreach( $en as $key => $value)
{
if( !array_key_exists( $key, $strings))
foreach ($en as $key => $value) {
if (!array_key_exists( $key, $strings)) {
$ret .= "$key = $value<br>";
}
if( $ret != '')
}
if ($ret != '') {
echo '<hr><b><center>Translations that are not used</center></b><br>'.$ret;
}
//Creates the zip files of translations
// Creates the zip files of translations.
$destdir = game_export_createtempdir();
sort( $strings);
foreach( $langname as $lang => $name)
{
$strings_lang = readlangfile( $lang, $header);
if (empty($string_lang)) {
foreach ($langname as $lang => $name) {
$stringslang = readlangfile( $lang, $header);
if (empty($stringlang)) {
continue;
}
$ret = '';
foreach( $strings_lang as $key => $value)
{
if( !array_key_exists( $key, $en))
{
if( $key != 'convertfrom' and $key != 'convertto')
foreach ($stringslang as $key => $value) {
if (!array_key_exists( $key, $en)) {
if ($key != 'convertfrom' and $key != 'convertto') {
$ret .= '<br>'.$key."\r\n";
}
}
if( $ret != '')
}
if ($ret != '') {
echo '<hr><b><center>Unused translation for lang '.$lang.'</center></b><br>'.substr( $ret, 4)."\r\n";
}
$ret = $header;
foreach( $strings as $info)
{
foreach ($strings as $info) {
$pos = strpos( $info, '*');
$name = substr( $info, $pos + 2);
$file = substr( $info, 0, $pos - 1);
if( substr( $file, 0, 1) == '/')
if (substr( $file, 0, 1) == '/') {
$file = substr( $file, 1);
if( $file != $prevfile)
{
}
if ($file != $prevfile) {
$prevfile = $file;
$ret .= "\r\n//".$file."\r\n";
}
if( array_key_exists( $name, $strings_lang))
$ret .= '$string'."[ '$name'] = ".$strings_lang[ $name]."\r\n";
if (array_key_exists( $name, $stringslang)) {
$ret .= '$string'."[ '$name'] = ".$stringslang[ $name]."\r\n";
}
}
if( $lang != 'en')
{
if ($lang != 'en') {
$untranslated = $auntranslated[ $lang];
if( $untranslated != '')
if ($untranslated != '') {
$ret .= "\r\n//Untranslated\r\n".$untranslated;
}
}
mkdir( $destdir.'/'.$lang);
$file = $destdir.'/'.$lang.'/game.php';
file_put_contents( $file, $ret);
}
$file_sorted = 'game_lang_sorted.zip';
$filezip=game_create_zip( $destdir, $COURSE->id, $file_sorted);
$filesorted = 'game_lang_sorted.zip';
$filezip = game_create_zip( $destdir, $COURSE->id, $filesorted);
remove_dir( $destdir);
echo "<br><a href=\"{$CFG->wwwroot}/file.php/1/export/$file_sorted\">Sorted translation files</a>";
echo "<br><a href=\"{$CFG->wwwroot}/file.php/1/export/$filesorted\">Sorted translation files</a>";
asort( $en);
$sprev = '';
$keyprev = '';
$ret = '';
foreach( $en as $key => $s)
{
if( $s == $sprev)
foreach ($en as $key => $s) {
if ($s == $sprev) {
$ret .= "<tr><td>$key</td><td>$keyprev</td><td>$s</td></tr>\r\n";
}
$sprev = $s;
$keyprev = $key;
}
if( $ret != '')
echo '<br><center><b>Same translations<center></b><br><table border=1><tr><td><b>Word1</td><td><b>Word2</td><td><b>Translation</td></tr>'.$ret.'</table>';
if ($ret != '') {
echo '<br><center><b>Same translations<center></b><br>';
echo '<table border=1><tr><td><b>Word1</td><td><b>Word2</td><td><b>Translation</td></tr>'.$ret.'</table>';
}
function readlangfile( $lang, &$header)
{
function readlangfile( $lang, &$header) {
global $CFG;
$file = $CFG->dirroot.'/mod/game/lang/'.$lang.'/game.php';
@ -242,44 +259,44 @@ function readlangfile( $lang, &$header)
$lines = file( $file);
$header = '';
$endofheader = false;
foreach( $lines as $line)
{
if( $endofheader == false)
{
if( strpos( $line, '//') === false)
foreach ($lines as $line) {
if ($endofheader == false) {
if (strpos( $line, '//') === false) {
$endofheader = true;
else
} else {
$header .= $line;
}
if( splitlangdefinition($line,$name,$trans))
}
if (splitlangdefinition($line, $name, $trans)) {
$a[ $name] = $trans;
}
}
if( $lang != 'en')
if ($lang != 'en') {
readlangfile_repairmoodle19( $lang, $a);
}
return $a;
}
function splitlangdefinition($line,&$name,&$trans)
{
function splitlangdefinition($line, &$name, &$trans) {
$pos1 = strpos( $line, '=');
if( $pos1 == 0)
if ($pos1 == 0) {
return false;
}
$pos2 = strpos( $line, '//');
if( $pos2 != 0 or substr( $line, 0, 2) == '//')
{
if( $pos2 < $pos1)
return false; //Commented line
if ($pos2 != 0 or substr( $line, 0, 2) == '//') {
if ($pos2 < $pos1) {
return false; // Commented line.
}
}
$name = trim(substr( $line, 0, $pos1 - 1));
$trans = trim(substr( $line, $pos1 + 1));
$pos = strpos( $name, '\'');
if( $pos)
{
if ($pos) {
$name = substr( $name, $pos + 1);
$pos = strrpos( $name, '\'');
$name = substr( $name, 0, $pos);
@ -288,91 +305,93 @@ function splitlangdefinition($line,&$name,&$trans)
return true;
}
function readsourcecode( $file, &$strings)
{
function readsourcecode( $file, &$strings) {
global $CFG;
$lines = file( $file);
foreach( $lines as $line)
{
foreach ($lines as $line) {
parseline( $strings, $line, $file);
}
return $strings;
}
function parseline( &$strings, $line, $filename)
{
function parseline( &$strings, $line, $filename) {
global $CFG;
$filename = substr( $filename, strlen( $CFG->dirroot.'/mod/game/'));
if( strpos($filename, '/'))
if (strpos($filename, '/')) {
$filename = '/'.$filename;
}
$pos0 = 0;
for(;;)
{
for (;;) {
$pos = strpos( $line, 'get_string', $pos0);
if( $pos == false)
if ($pos == false) {
$pos = strpos( $line, 'print_string', $pos0);
if( $pos === false)
}
if ($pos === false) {
break;
}
$pos1 = strpos( $line, '(', $pos);
$pos2 = strpos( $line, ',', $pos);
$pos3 = strpos( $line, ')', $pos);
if( $pos1 == 0 or $pos2 == 0 or $pos3 == 0)
{
if ($pos1 == 0 or $pos2 == 0 or $pos3 == 0) {
$pos0 = $pos + 1;
continue;
}
$name = gets( substr( $line, $pos1 + 1, $pos2 - $pos1 - 1));
$file = gets( substr( $line, $pos2 + 1, $pos3 - $pos2 - 1));
if( $file == 'game')
{
if( !array_key_exists( $name, $strings))
if ($file == 'game') {
if (!array_key_exists( $name, $strings)) {
$strings[ $name] = $filename.' * '.$name;
}else
{
}
} else {
$pos4 = strpos($file, '\'');
if( $pos4)
if ($pos4) {
$file = substr( $file, 0, $pos4);
}
$pos4 = strpos($file, '"');
if($pos4)
if ($pos4) {
$file = substr( $file, 0, $pos4);
}
if( $file == 'game')
{
if( !array_key_exists( $name, $strings))
if ($file == 'game') {
if (!array_key_exists( $name, $strings)) {
$strings[ $name] = $filename.' * '.$name;
}
}
}
$pos0 = $pos + 1;
}
}
function gets( $s)
{
function gets( $s) {
$s = trim( $s);
if( substr( $s, 0, 1) == '"')
if (substr( $s, 0, 1) == '"') {
$s = substr( $s, 1, -1);
if( substr( $s, 0, 1) == '\'')
}
if (substr( $s, 0, 1) == '\'') {
$s = substr( $s, 1, -1);
}
return $s;
}
function read_dir($dir, $ext) {
if( $ext != '')
if ($ext != '') {
$ext = '.' .$ext;
}
$len = strlen( $ext);
$a = array( $dir);
$ret = array();
while (count( $a)) {
$dir = array_pop( $a);
if( strpos( $dir, '/lang/') != 0)
if (strpos( $dir, '/lang/') != 0) {
continue;
}
$d = dir($dir);
while (false !== ($entry = $d->read())) {
@ -381,21 +400,21 @@ function read_dir($dir, $ext) {
if (is_dir($entry)) {
$a[] = $entry;
} else {
if( $len == 0)
if ($len == 0) {
$ret[] = $entry;
else if( substr( $entry, -$len) == $ext)
} else if (substr( $entry, -$len) == $ext) {
$ret[] = $entry;
}
}
}
}
$d->close();
}
return $ret;
}
function computelangs()
{
function computelangs() {
global $CFG;
$dir = $CFG->dirroot.'/mod/game/lang';
@ -412,14 +431,12 @@ function computelangs()
return $ret;
}
function computediff( $en, $lang, $strings, $langname, &$sum, $outdir, &$untranslated)
{
function computediff( $en, $lang, $strings, $langname, &$sum, $outdir, &$untranslated) {
global $CFG;
$untranslated = '';
$counten = count($en);
$trans = readlangfile( $lang, $header);
foreach( $trans as $s => $key)
{
foreach ($trans as $s => $key) {
unset( $en[ $s]);
}
@ -427,69 +444,69 @@ function computediff( $en, $lang, $strings, $langname, &$sum, $outdir, &$untrans
$lines = file( $file);
$count = 0;
$s = '';
foreach( $lines as $line)
{
foreach ($lines as $line) {
$s .= $line;
if( ++$count >= 3)
if (++$count >= 3) {
break;
}
}
$a = array();
foreach( $en as $name => $t)
{
if( array_key_exists( $name, $strings))
foreach ($en as $name => $t) {
if (array_key_exists( $name, $strings)) {
$file = $strings[ $name];
else
} else {
$file = '';
}
$t = strip_tags( $t);
$a[ $file.' * '.$name] = '$'."string[ '$name'] = $t\r\n";
}
ksort( $a);
if( array_key_exists( $lang, $langname))
if (array_key_exists( $lang, $langname)) {
$langprint = $langname[ $lang];
else
} else {
$langprint = $lang;
}
$sum[]="<td>$langprint</td><td><center>".count($a)."</td><td><center>".round(100*($counten-count($a))/$counten,0)." %</td>";
$prev_file = '';
foreach( $a as $key => $line)
{
$sum[] = "<td>$langprint</td><td><center>".count($a)."</td><td><center>".
round(100 * ($counten - count($a)) / $counten, 0)." %</td>";
$prevfile = '';
foreach ($a as $key => $line) {
$pos = strpos( $key, '*');
$file = trim( substr( $key, 0, $pos - 1));
if( substr( $file, 0, 1) == '/')
if (substr( $file, 0, 1) == '/') {
$file = substr( $file, 1);
if( $file != $prev_file)
{
}
if ($file != $prevfile) {
$s .= "\r\n//$file\r\n";
$prev_file = $file;
$prevfile = $file;
}
$s .= $line;
$untranslated .= "//$prev_file ".$line;
$untranslated .= "//$prevfile ".$line;
}
$file = $outdir.'/'.$lang.'.php';
file_put_contents( $file, $s);
}
//Copies the translation from Moodle 19
function readlangfile_repairmoodle19( $lang, &$strings_lang)
{
// Copies the translation from Moodle 19.
function readlangfile_repairmoodle19( $lang, &$stringslang) {
global $moodle19dir;
if( $moodle19dir == '')
if ($moodle19dir == '') {
return;
}
$file = $moodle19dir.'/mod/game/lang/'.$lang.'_utf8/game.php';
$a = array();
$lines = file( $file);
foreach( $lines as $line)
{
if( splitlangdefinition($line,$name,$trans))
{
if( !array_key_exists( $name, $strings_lang))
$strings_lang[ $name] = $trans;
foreach ($lines as $line) {
if (splitlangdefinition($line, $name, $trans)) {
if (!array_key_exists( $name, $stringslang)) {
$stringslang[ $name] = $trans;
}
}
}
}

39
version.php

@ -1,4 +1,19 @@
<?php // $Id: version.php,v 1.49 2012/07/25 22:46:42 bdaloukas Exp $
<?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/>.
/**
* Code fragment to define the version of game
* This fragment is called by moodle_needs_upgrading() and /admin/index.php
@ -10,22 +25,22 @@
defined('MOODLE_INTERNAL') || die();
if( !isset( $plugin))
{
if (!isset( $plugin)) {
$plugin = new stdClass;
$useplugin = 0;
}else if( $plugin == 'mod_game')
{
} else if ($plugin == 'mod_game') {
$plugin = new stdClass;
$useplugin = 1;
}else
} else {
$useplugin = 2;
}
$plugin->component = 'mod_game'; // Full name of the plugin (used for diagnostics)
$plugin->version = 2015122201; // The current module version (Date: YYYYMMDDXX)
$plugin->requires = 2010112400; // Requires Moodle 2.0
$plugin->cron = 0; // Period for cron to check this module (secs)
$plugin->release = '3.36.22.1';
$plugin->component = 'mod_game'; // Full name of the plugin (used for diagnostics).
$plugin->version = 2015122501; // The current module version (Date: YYYYMMDDXX).
$plugin->requires = 2010112400; // Requires Moodle 2.0.
$plugin->cron = 0; // Period for cron to check this module (secs).
$plugin->release = '3.36.25.1';
if( $useplugin != 2)
if ($useplugin != 2) {
$module = $plugin;
}

103
view.php

@ -1,12 +1,26 @@
<?php // $Id: view.php,v 1.14 2012/07/25 11:16:04 bdaloukas Exp $
// This page prints a particular instance of game
<?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 page prints a particular instance of game.
require_once(dirname(__FILE__) . '/../../config.php');
require_once($CFG->libdir.'/gradelib.php');
require_once($CFG->dirroot.'/mod/game/locallib.php');
$id = optional_param('id', 0, PARAM_INT); // Course Module ID, or
$id = optional_param('id', 0, PARAM_INT); // Course Module ID.
if (! $cm = get_coursemodule_from_id('game', $id)) {
print_error('invalidcoursemodule');
@ -18,14 +32,14 @@
print_error('invalidcoursemodule');
}
/// Check login and get context.
// Check login and get context.
require_login($course->id, false, $cm);
$context = game_get_context_module_instance( $cm->id);
require_capability('mod/game:view', $context);
$timenow = time();
/// Cache some other capabilites we use several times.
// Cache some other capabilites we use several times.
$canattempt = true;
$strtimeopenclose = '';
if ($timenow < $game->timeopen) {
@ -46,19 +60,19 @@
$canattempt = true;
}
/// Log this request.
if( game_use_events())
{
// Log this request.
if (game_use_events()) {
require( 'classes/event/course_module_viewed.php');
\mod_game\event\course_module_viewed::viewed($game, $context)->trigger();
}else
} else {
add_to_log($course->id, 'game', 'view', "view.php?id=$cm->id", $game->id, $cm->id);
}
// Mark as viewed
// Mark as viewed.
$completion = new completion_info($course);
$completion->set_module_viewed($cm);
/// Initialize $PAGE, compute blocks
// Initialize $PAGE, compute blocks.
$PAGE->set_url('/mod/game/view.php', array('id' => $cm->id));
$edit = optional_param('edit', -1, PARAM_BOOL);
@ -72,7 +86,9 @@
$buttons = '<table><tr><td><form method="get" action="view.php"><div>'.
'<input type="hidden" name="id" value="'.$cm->id.'" />'.
'<input type="hidden" name="edit" value="'.($PAGE->user_is_editing() ? 'off' : 'on').'" />'.
'<input type="submit" value="'.get_string($PAGE->user_is_editing()?'blockseditoff':'blocksediton').'" /></div></form></td></tr></table>';
'<input type="submit" value="'.
get_string($PAGE->user_is_editing() ? 'blockseditoff' : 'blocksediton').
'" /></div></form></td></tr></table>';
$PAGE->set_button($buttons);
}
@ -81,31 +97,27 @@
echo $OUTPUT->header();
/// Print game name and description
// Print game name and description.
echo $OUTPUT->heading(format_string($game->name));
/// Display information about this game.
// Display information about this game.
echo $OUTPUT->box_start('quizinfo');
if ($game->attempts != 1) {
echo get_string('gradingmethod', 'quiz', game_get_grading_option_name($game->grademethod));
}
echo $OUTPUT->box_end();
/// Show number of attempts summary to those who can view reports.
// Show number of attempts summary to those who can view reports.
if (has_capability('mod/game:viewreports', $context)) {
if ($strattemptnum = game_get_user_attempts($game->id, $USER->id)) {
//echo '<div class="gameattemptcounts"><a href="report.php?mode=overview&amp;id=' .
// $cm->id . '">' . $strattemptnum . "</a></div>\n";
echo get_string( 'attempts', 'game').': '.count( $strattemptnum);
if( $game->maxattempts)
{
if ($game->maxattempts) {
echo ' ('.get_string( 'max', 'quiz').': '.$game->maxattempts.')';
}
}
}
/// Get this user's attempts.
// Get this user's attempts.
$attempts = game_get_user_attempts($game->id, $USER->id);
$lastfinishedattempt = end($attempts);
$unfinished = false;
@ -115,14 +127,14 @@
}
$numattempts = count($attempts);
/// Work out the final grade, checking whether it was overridden in the gradebook.
// Work out the final grade, checking whether it was overridden in the gradebook.
$mygrade = game_get_best_grade($game, $USER->id);
$mygradeoverridden = false;
$gradebookfeedback = '';
$grading_info = grade_get_grades($course->id, 'mod', 'game', $game->id, $USER->id);
if (!empty($grading_info->items)) {
$item = $grading_info->items[0];
$gradinginfo = grade_get_grades($course->id, 'mod', 'game', $game->id, $USER->id);
if (!empty($gradinginfo->items)) {
$item = $gradinginfo->items[0];
if (isset($item->grades[$USER->id])) {
$grade = $item->grades[$USER->id];
@ -136,9 +148,8 @@
}
}
/// Print table with existing attempts
// Print table with existing attempts.
if ($attempts) {
echo $OUTPUT->heading(get_string('summaryofattempts', 'quiz'));
// Work out which columns we need, taking account what data is available in each attempt.
@ -147,10 +158,9 @@
$attemptcolumn = $game->attempts != 1;
$gradecolumn = $someoptions->scores && ($game->grade > 0);
//$markcolumn = $gradecolumn && ($game->grade != $game->sumgrades);
$overallstats = $alloptions->scores;
// Prepare table header
// Prepare table header.
$table = new html_table();
$table->attributes['class'] = 'generaltable gameattemptsummary';
$table->head = array();
@ -175,7 +185,7 @@
$table->align[] = 'left';
$table->size[] = '';
// One row for each attempt
// One row for each attempt.
foreach ($attempts as $attempt) {
$attemptoptions = game_get_reviewoptions($game, $attempt, $context);
$row = array();
@ -189,28 +199,27 @@
}
}
// prepare strings for time taken and date completed
// Prepare strings for time taken and date completed.
$timetaken = '';
$datecompleted = '';
if ($attempt->timefinish > 0) {
// attempt has finished
// Attempt has finished.
$timetaken = format_time($attempt->timefinish - $attempt->timestart);
$datecompleted = userdate($attempt->timefinish);
} else
{
} else {
// The a is still in progress.
$timetaken = format_time($timenow - $attempt->timestart);
$datecompleted = '';
}
$row[] = $datecompleted;
// Ouside the if because we may be showing feedback but not grades. bdaloukas
// Ouside the if because we may be showing feedback but not grades.
$attemptgrade = game_score_to_grade($attempt->score, $game);
if ($gradecolumn) {
if ($attemptoptions->scores) {
$formattedgrade = game_format_grade($game, $attemptgrade);
// highlight the highest grade if appropriate
// Highlight the highest grade if appropriate.
if ($overallstats && !$attempt->preview && $numattempts > 1 && !is_null($mygrade) &&
$attemptgrade == $mygrade && $game->grademethod == QUIZ_GRADEHIGHEST) {
$table->rowclasses[$attempt->attempt] = 'bestrow';
@ -233,9 +242,7 @@
echo html_writer::table($table);
}
/// Print information about the student's best score for this game if possible.
// Print information about the student's best score for this game if possible.
if ($numattempts && $gradecolumn && !is_null($mygrade)) {
$resultinfo = '';
@ -250,6 +257,7 @@
if ($mygradeoverridden) {
$resultinfo .= '<p class="overriddennotice">'.get_string('overriddennotice', 'grades')."</p>\n";
}
if ($gradebookfeedback) {
$resultinfo .= $OUTPUT->heading(get_string('comment', 'game'), 3, 'main');
$resultinfo .= '<p class="gameteacherfeedback">'.$gradebookfeedback."</p>\n";
@ -260,8 +268,7 @@
}
}
/// Determine if we should be showing a start/continue attempt button,
/// or a button to go back to the course page.
// Determine if we should be showing a start/continue attempt button or a button to go back to the course page.
echo $OUTPUT->box_start('gameattempt');
$buttontext = ''; // This will be set something if as start/continue attempt button should appear.
@ -270,12 +277,14 @@
$buttontext = get_string('continueattemptgame', 'game');
}
} else {
//Game is finished. Check if max number of attempts is reached
if( !game_can_start_new_attempt( $game))
// Game is finished. Check if max number of attempts is reached.
if (!game_can_start_new_attempt( $game)) {
$canattempt = false;
}
if ($canattempt) {
echo '<br>';
if ($numattempts == 0) {
$buttontext = get_string('attemptgamenow', 'game');
} else {
@ -284,17 +293,15 @@
}
}
/// Now actually print the appropriate button.
// Now actually print the appropriate button.
echo $strtimeopenclose;
if ($buttontext) {
global $OUTPUT;
$strconfirmstartattempt = '';
/// Show the start button, in a div that is initially hidden.
// Show the start button, in a div that is initially hidden.
echo '<div id="gamestartbuttondiv">';
$url = new moodle_url($CFG->wwwroot.'/mod/game/attempt.php', array('id' => $id));
$button = new single_button($url, $buttontext);

Loading…
Cancel
Save