Browse Source

Fix:Coding style

MOODLE_20_STABLE
Vasilis Daloukas 9 years ago
parent
commit
acbd0158ff
  1. 22
      classes/event/course_module_instance_list_viewed.php
  2. 16
      classes/event/course_module_viewed.php
  3. 18
      classes/event/game_played.php
  4. 17
      classes/plugininfo/booktool.php
  5. 17
      classes/plugininfo/gametool.php
  6. 1370
      cross/cross_class.php
  7. 447
      cross/crossdb_class.php
  8. 443
      cross/play.php

22
classes/event/course_module_instance_list_viewed.php

@ -1,4 +1,18 @@
<?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/>.
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
@ -13,7 +27,7 @@
namespace mod_game\event;
defined('MOODLE_INTERNAL') || die();
/**
/*
* The mod_game instance list viewed event class.
*
* @package mod_game
@ -32,8 +46,8 @@ class course_module_instance_list_viewed extends \core\event\course_module_insta
$params = array(
'context' => \context_course::instance($course->id)
);
$event = \mod_game\event\course_module_instance_list_viewed::create($params);
$event = \mod_game\event\course_module_instance_list_viewed::create( $params);
$event->add_record_snapshot('course', $course);
return $event;
}}
}
}

16
classes/event/course_module_viewed.php

@ -1,4 +1,18 @@
<?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/>.
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
@ -36,7 +50,6 @@ class course_module_viewed extends \core\event\course_module_viewed {
'context' => $context,
'objectid' => $game->id
);
/** @var course_module_viewed $event */
$event = self::create($data);
$event->add_record_snapshot('game', $game);
return $event;
@ -47,7 +60,6 @@ class course_module_viewed extends \core\event\course_module_viewed {
'context' => $context,
'objectid' => $game->id
);
/** @var course_module_viewed $event */
$event = self::create($data);
$event->add_record_snapshot('game', $game);
return $event;

18
classes/event/game_played.php

@ -1,4 +1,18 @@
<?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/>.
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
@ -38,7 +52,6 @@ class game_played extends \core\event\base {
'context' => $context,
'objectid' => $game->id
);
/** @var chapter_viewed $event */
$event = self::create($data);
$event->add_record_snapshot('game', $game);
return $event;
@ -50,7 +63,8 @@ class game_played extends \core\event\base {
* @return array|null
*/
protected function get_legacy_logdata() {
return array($this->courseid, 'game', 'view', 'view.php?id=' . $this->contextinstanceid, $this->objectid, $this->contextinstanceid);
return array($this->courseid, 'game', 'view', 'view.php?id=' . $this->contextinstanceid,
$this->objectid, $this->contextinstanceid);
}
/**

17
classes/plugininfo/booktool.php

@ -1,4 +1,21 @@
<?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/>.
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Subplugin info class.
*

17
classes/plugininfo/gametool.php

@ -1,4 +1,21 @@
<?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/>.
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Subplugin info class.
*

1370
cross/cross_class.php

File diff suppressed because it is too large

447
cross/crossdb_class.php

@ -1,4 +1,21 @@
<?php // $Id: crossdb_class.php,v 1.17 2012/07/25 11:16:05 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/>.
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* This class is a cross that can load and save to a table
*
@ -7,242 +24,230 @@
* @package game
**/
class CrossDB extends Cross
{
function savecross( $game, &$crossm, $crossd, $id)
{
global $DB, $USER;
$crossm->id = $id;
$crossm->sourcemodule = $game->sourcemodule;
$this->delete_records( $id);
if (!(game_insert_record( "game_cross", $crossm))){
print_error( 'Insert page: new page game_cross not inserted');
}
foreach( $crossd as $rec)
{
$rec->attemptid = $id;
$rec->questiontext = addslashes( $rec->questiontext);
$rec->gamekind = $game->gamekind;
$rec->gameid = $game->id;
$rec->userid = $USER->id;
$rec->sourcemodule = $game->sourcemodule;
if (!$DB->insert_record( 'game_queries', $rec)){
print_error( 'Insert page: new page game_queries not inserted');
}
class CrossDB extends Cross {
public function savecross( $game, &$crossm, $crossd, $id) {
global $DB, $USER;
$crossm->id = $id;
$crossm->sourcemodule = $game->sourcemodule;
$this->delete_records( $id);
if (!(game_insert_record( "game_cross", $crossm))) {
print_error( 'Insert page: new page game_cross not inserted');
}
foreach ($crossd as $rec) {
$rec->attemptid = $id;
$rec->questiontext = addslashes( $rec->questiontext);
$rec->gamekind = $game->gamekind;
$rec->gameid = $game->id;
$rec->userid = $USER->id;
$rec->sourcemodule = $game->sourcemodule;
if (!$DB->insert_record( 'game_queries', $rec)) {
print_error( 'Insert page: new page game_queries not inserted');
}
game_update_repetitions($game->id, $USER->id, $rec->questionid, $rec->glossaryentryid);
}
}
return true;
}
}
function delete_records( $id)
{
public function delete_records( $id) {
global $DB;
if( !$DB->delete_records( 'game_queries', array( 'attemptid' => $id))){
print_error( "Can't delete from game_queries attemptid=$id");
if (!$DB->delete_records( 'game_queries', array( 'attemptid' => $id))) {
print_error( "Can't delete from game_queries attemptid=$id");
}
if( !$DB->delete_records( 'game_cross', array( 'id' => $id))){
print_error( "Can't delete from game_cross id=$id");
if (!$DB->delete_records( 'game_cross', array( 'id' => $id))) {
print_error( "Can't delete from game_cross id=$id");
}
}
function loadcross( $g, &$done, &$html, $game, $attempt, $crossrec, $onlyshow, $showsolution, &$finishattempt, $showhtmlsolutions, &$language, $showstudentguess, $context)
{
global $DB;
$info = '';
$correctLetters = 0;
$allLetters = 0;
$wrongLetters = 0;
$html = '';
$done = false;
$loadfromdb = ( $g == "");
$this->m_mincol = $this->m_minrow = 0;
$this->m_maxcol = $crossrec->cols;
$this->m_maxrow = $crossrec->rows;
if( $g == ""){
$g = str_repeat( ' ', $this->m_maxcol * $this->m_maxrow);
}
$load = false;
$puzzle = str_repeat('.', $this->m_maxrow * $this->m_maxcol);
if ($recs = $DB->get_records( 'game_queries', array( 'attemptid' => $crossrec->id)))
{
$a = array();
foreach ($recs as $rec)
{
if( $rec->horizontal)
$key = sprintf( 'h%10d %10d', $rec->row, $rec->col);
else
$key = sprintf( 'v%10d %10d', $rec->col, $rec->row);
$a[ $key] = $rec;
}
ksort( $a);
$b = array();
$correctletters = $wrongletters = $restletters = 0;
foreach( $a as $rec){
$this->updatecrossquestions( $rec, $g, $pos, $correctletters, $wrongletters, $restletters, $game, $attempt, $crossrec, $loadfromdb);
$b[] = $rec;
if( ($rec->col != 0) and ($rec->row != 0)){
$load = true;
}
if( $language == ''){
$language = game_detectlanguage( $rec->answertext);
public function loadcross( $g, &$done, &$html, $game, $attempt, $crossrec, $onlyshow, $showsolution,
&$finishattempt, $showhtmlsolutions, &$language, $showstudentguess, $context) {
global $DB;
$info = '';
$correctletters = 0;
$allletters = 0;
$wrongletters = 0;
$html = '';
$done = false;
$loadfromdb = ( $g == "");
$this->mmincol = $this->mminrow = 0;
$this->mmaxcol = $crossrec->cols;
$this->mmaxrow = $crossrec->rows;
if ($g == "") {
$g = str_repeat( ' ', $this->m_maxcol * $this->m_maxrow);
}
$load = false;
$puzzle = str_repeat('.', $this->m_maxrow * $this->m_maxcol);
if ($recs = $DB->get_records( 'game_queries', array( 'attemptid' => $crossrec->id))) {
$a = array();
foreach ($recs as $rec) {
if ($rec->horizontal) {
$key = sprintf( 'h%10d %10d', $rec->row, $rec->col);
} else {
$key = sprintf( 'v%10d %10d', $rec->col, $rec->row);
}
$a[ $key] = $rec;
}
}
$info = $this->game_cross_computecheck( $correctletters, $wrongletters, $restletters, $game, $attempt, $done, $onlyshow, $showsolution, $finishattempt);
$html = $this->showhtml_base( $crossrec, $b, $showsolution, $showhtmlsolutions, $showstudentguess, $context, $game);
ksort( $a);
$b = array();
$correctletters = $wrongletters = $restletters = 0;
foreach ($a as $rec) {
$this->updatecrossquestions( $rec, $g, $pos, $correctletters,
$wrongletters, $restletters, $game, $attempt, $crossrec, $loadfromdb);
$b[] = $rec;
if (($rec->col != 0) and ($rec->row != 0)) {
$load = true;
}
if ($language == '') {
$language = game_detectlanguage( $rec->answertext);
}
}
$info = $this->game_cross_computecheck( $correctletters, $wrongletters,
$restletters, $game, $attempt, $done, $onlyshow, $showsolution, $finishattempt);
$html = $this->showhtml_base( $crossrec, $b, $showsolution, $showhtmlsolutions, $showstudentguess, $context, $game);
}
if ($load == false) {
$finishattempt = true;
}
return $info;
}
if( $load == false)
{
$finishattempt = true;
}
return $info;
}
function game_cross_computecheck( $correctletters, $wrongletters, $restletters, $game, $attempt, &$done, $onlyshow, $showsolution, $finishattempt)
{
$ret = '';
//if( $correctletters == 0 and $wrongletters == 0){
// return $ret;
//}
$and = get_string( 'and', 'game');
$a = array();
if( $correctletters)
$a[] = $correctletters.' '.( $correctletters > 1 ? get_string( 'cross_corrects', 'game') :get_string( 'cross_correct', 'game'));
if( $wrongletters)
$a[] = '<b>'.$wrongletters.' '.( $wrongletters > 1 ? get_string( 'cross_errors', 'game') : get_string( 'cross_error', 'game')).'</b>';
if( $correctletters > 1 or $wrongletters > 1) {
$ret = get_string( 'cross_found_many', 'game');
}else if( count( $a))
{
$ret = get_string( 'cross_found_one', 'game');
}else
$ret = '';
$i = 0;
foreach( $a as $msg)
{
$i++;
if( $i == 1){
$ret .= ' '.$msg;
}else if( $i == count($a))
{
$ret .= ' '.get_string( 'and', 'game').' '.$msg;
}else
{
$ret .= ', '.$msg;
}
}
$done = ( $restletters == 0 ? true : false);
if( $finishattempt == false){
if( $onlyshow or $showsolution){
return $ret;
}
}else{
$done = 1;
}
$grade = $correctletters / ($correctletters + $restletters);
$ret .= '<br>'.get_string( 'grade', 'game').' '.round( $grade * 100).' %';
game_updateattempts( $game, $attempt, $grade, $done);
return $ret;
}
//rec is a record of cross_questions
function updatecrossquestions( &$rec, &$g, &$pos, &$correctletters, &$wrongletters, &$restletters, $game, $attempt, $crossrec, $loadfromdb)
{
global $DB, $USER;
$word = $rec->answertext;
$len = game_strlen( $word);
if( $loadfromdb)
$guess = $rec->studentanswer;
else
$guess = game_substr( $g, $pos, $len);
$len_guess = game_strlen( $guess);;
$pos += $len;
$is_empty = true;
for($i = 0; $i < $len; $i++)
{
if( $i < $len_guess)
$letterguess = game_substr( $guess, $i, 1);
else
$letterguess = " ";
if( $letterguess != ' ')
$is_empty = false;
$letterword= game_substr( $word, $i, 1);
if( $letterword != $letterguess)
{
if( ($letterguess != ' ' and $letterguess != '_')){
public function game_cross_computecheck( $correctletters, $wrongletters, $restletters, $game,
$attempt, &$done, $onlyshow, $showsolution, $finishattempt) {
$ret = '';
$and = get_string( 'and', 'game');
$a = array();
if ($correctletters) {
$a[] = $correctletters.' '.
( $correctletters > 1 ? get_string( 'cross_corrects', 'game') : get_string( 'cross_correct', 'game'));
}
if ($wrongletters) {
$a[] = '<b>'.$wrongletters.' '.
( $wrongletters > 1 ? get_string( 'cross_errors', 'game') : get_string( 'cross_error', 'game')).'</b>';
}
if ($correctletters > 1 or $wrongletters > 1) {
$ret = get_string( 'cross_found_many', 'game');
} else if ( count( $a)) {
$ret = get_string( 'cross_found_one', 'game');
} else {
$ret = '';
}
$i = 0;
foreach ($a as $msg) {
$i++;
if ($i == 1) {
$ret .= ' '.$msg;
} else if ( $i == count($a)) {
$ret .= ' '.get_string( 'and', 'game').' '.$msg;
} else {
$ret .= ', '.$msg;
}
}
$done = ( $restletters == 0 ? true : false);
if ($finishattempt == false) {
if ($onlyshow or $showsolution) {
return $ret;
}
} else {
$done = 1;
}
$grade = $correctletters / ($correctletters + $restletters);
$ret .= '<br>'.get_string( 'grade', 'game').' '.round( $grade * 100).' %';
game_updateattempts( $game, $attempt, $grade, $done);
return $ret;
}
// Rec is a record of cross_questions.
public function updatecrossquestions( &$rec, &$g, &$pos, &$correctletters, &$wrongletters,
&$restletters, $game, $attempt, $crossrec, $loadfromdb) {
global $DB, $USER;
$word = $rec->answertext;
$len = game_strlen( $word);
if ($loadfromdb) {
$guess = $rec->studentanswer;
} else {
$guess = game_substr( $g, $pos, $len);
}
$lenguess = game_strlen( $guess);;
$pos += $len;
$isempty = true;
for ($i = 0; $i < $len; $i++) {
if ($i < $lenguess) {
$letterguess = game_substr( $guess, $i, 1);
} else {
$letterguess = " ";
}
if ($letterguess != ' ') {
$isempty = false;
}
$letterword = game_substr( $word, $i, 1);
if ($letterword != $letterguess) {
if (($letterguess != ' ' and $letterguess != '_')) {
$wrongletters++;
}
game_setchar( $guess, $i, '_');
$restletters++;
}else if( $letterguess == ' '){
if( $guess == $word){
$correctletters++;
}else
{
//$wrongletters++;
//game_setchar( $guess, $i, '_');
}
}else
{
$correctletters++;
}
}
if( $is_empty){
return;
}
if( ($rec->studentanswer == $guess )){
return;
}
$rec->studentanswer = $guess;
$updrec = new stdClass();
$updrec->studentanswer = $guess;
$updrec->id = $rec->id;
if (!$DB->update_record( 'game_queries', $updrec, $rec->id)){
print_error( 'Update game_queries: not updated');
}
$score = $correctletters / $len;
game_update_queries( $game, $attempt, $rec, $score, $guess);
}
}
} else if ($letterguess == ' ') {
if ($guess == $word) {
$correctletters++;
}
} else {
$correctletters++;
}
}
if ($isempty) {
return;
}
if (($rec->studentanswer == $guess )) {
return;
}
$rec->studentanswer = $guess;
$updrec = new stdClass();
$updrec->studentanswer = $guess;
$updrec->id = $rec->id;
if (!$DB->update_record( 'game_queries', $updrec, $rec->id)) {
print_error( 'Update game_queries: not updated');
}
$score = $correctletters / $len;
game_update_queries( $game, $attempt, $rec, $score, $guess);
}
}

443
cross/play.php

@ -1,144 +1,163 @@
<?php // $Id: play.php,v 1.23 2012/08/15 14:38:06 bdaloukas Exp $
// This files plays the game "Crossword"
<?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/>.
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
// This files plays the game "Crossword".
require( "cross_class.php");
require( "crossdb_class.php");
function game_cross_continue( $id, $game, $attempt, $cross, $g, $endofgame, $context)
{
if( $endofgame){
if( $g == ''){
game_updateattempts( $game, $attempt, -1, true);
$endofgame = false;
}
}
function game_cross_continue( $id, $game, $attempt, $cross, $g, $endofgame, $context) {
if ($endofgame) {
if ($g == '') {
game_updateattempts( $game, $attempt, -1, true);
$endofgame = false;
}
}
if( $attempt != false and $cross != false){
return game_cross_play( $id, $game, $attempt, $cross, $g, false, false, $endofgame, false, false, false, false, true, $context);
}
if( $attempt == false){
$attempt = game_addattempt( $game);
}
game_cross_new( $game, $attempt->id, $crossm);
game_updateattempts( $game, $attempt, 0, 0);
if ($attempt != false and $cross != false) {
return game_cross_play( $id, $game, $attempt, $cross, $g, false, false, $endofgame,
false, false, false, false, true, $context);
}
if ($attempt == false) {
$attempt = game_addattempt( $game);
}
game_cross_new( $game, $attempt->id, $crossm);
game_updateattempts( $game, $attempt, 0, 0);
return game_cross_play( $id, $game, $attempt, $crossm, '', false, false, false, false, false, false, false, true, $context);
}
function game_cross_new( $game, $attemptid, &$crossm)
{
function game_cross_new( $game, $attemptid, &$crossm) {
global $DB, $USER;
$cross = new CrossDB();
$questions = array();
$infos = array();
$cross = new CrossDB();
$answers = array();
$recs = game_questions_shortanswer( $game);
if( $recs == false){
print_error( 'game_cross_continue: '.get_string( 'no_words', 'game'));
}
$infos = array();
$questions = array();
$infos = array();
$answers = array();
$recs = game_questions_shortanswer( $game);
if ($recs == false) {
print_error( 'game_cross_continue: '.get_string( 'no_words', 'game'));
}
$infos = array();
$reps = array();
foreach( $recs as $rec){
if( $game->param7 == false){
if( game_strpos( $rec->answertext, ' ')){
continue; //spaces not allowed
}
}
$rec->answertext = game_upper( $rec->answertext);
$answers[ $rec->answertext] = game_repairquestion( $rec->questiontext);
$infos[ $rec->answertext] = array( $game->sourcemodule, $rec->questionid, $rec->glossaryentryid, $rec->attachment);
foreach ($recs as $rec) {
if ($game->param7 == false) {
if (game_strpos( $rec->answertext, ' ')) {
continue; // Spaces not allowed.
}
}
$rec->answertext = game_upper( $rec->answertext);
$answers[ $rec->answertext] = game_repairquestion( $rec->questiontext);
$infos[ $rec->answertext] = array( $game->sourcemodule, $rec->questionid, $rec->glossaryentryid, $rec->attachment);
$a = array( 'gameid' => $game->id, 'userid' => $USER->id, 'questionid' => $rec->questionid, 'glossaryentryid' => $rec->glossaryentryid);
if(($rec2 = $DB->get_record('game_repetitions', $a, 'id,repetitions AS r')) != false){
$a = array( 'gameid' => $game->id, 'userid' => $USER->id,
'questionid' => $rec->questionid, 'glossaryentryid' => $rec->glossaryentryid);
if (($rec2 = $DB->get_record('game_repetitions', $a, 'id,repetitions AS r')) != false) {
$reps[ $rec->answertext] = $rec2->r;
}
}
$cross->setwords( $answers, $game->param1, $reps);
//game->param4 is minimum words in crossword
//game->param2 is maximum words in crossword
if( $cross->computedata( $crossm, $crossd, $lettets, $game->param4, $game->param2)){
$new_crossd = array();
foreach( $crossd as $rec)
{
$info = $infos[ $rec->answertext];
if( $info != false){
$rec->sourcemodule = $info[ 0];
$rec->questionid = $info[ 1];
$rec->glossaryentryid = $info[ 2];
$rec->attachment = $info[ 3];
}
$new_crossd[] = $rec;
}
$cross->savecross( $game, $crossm, $new_crossd, $attemptid);
}
if( count( $crossd) == 0){
print_error( 'game_cross_continue: '.get_string( 'no_words', 'game'));
}
}
$cross->setwords( $answers, $game->param1, $reps);
// The game->param4 is minimum words in crossword.
// The game->param2 is maximum words in crossword.
if ($cross->computedata( $crossm, $crossd, $lettets, $game->param4, $game->param2)) {
$newcrossd = array();
foreach ($crossd as $rec) {
$info = $infos[ $rec->answertext];
if ($info != false) {
$rec->sourcemodule = $info[ 0];
$rec->questionid = $info[ 1];
$rec->glossaryentryid = $info[ 2];
$rec->attachment = $info[ 3];
}
$newcrossd[] = $rec;
}
$cross->savecross( $game, $crossm, $newcrossd, $attemptid);
}
if (count( $crossd) == 0) {
print_error( 'game_cross_continue: '.get_string( 'no_words', 'game'));
}
}
function showlegend( $legend, $title)
{
if( count( $legend) == 0)
function showlegend( $legend, $title) {
if (count( $legend) == 0) {
return;
}
echo "<br><b>$title</b><br>";
foreach( $legend as $key => $line)
{
foreach ($legend as $key => $line) {
$line = game_repairquestion( $line);
echo game_filtertext( "$key: $line<br>", 0);
}
}
function game_cross_play( $id, $game, $attempt, $crossrec, $g, $onlyshow, $showsolution, $endofgame, $print, $checkbutton, $showhtmlsolutions, $showhtmlprintbutton,$showstudentguess, $context)
{
global $CFG, $DB;
function game_cross_play( $id, $game, $attempt, $crossrec, $g, $onlyshow, $showsolution,
$endofgame, $print, $checkbutton, $showhtmlsolutions, $showhtmlprintbutton, $showstudentguess, $context) {
global $CFG, $DB;
$cross = new CrossDB();
$cross = new CrossDB();
$language = $attempt->language;
$info = $cross->loadcross( $g, $done, $html, $game, $attempt, $crossrec, $onlyshow, $showsolution, $endofgame, $showhtmlsolutions, $attempt->language,$showstudentguess, $context);
$info = $cross->loadcross( $g, $done, $html, $game, $attempt, $crossrec, $onlyshow,
$showsolution, $endofgame, $showhtmlsolutions, $attempt->language,
$showstudentguess, $context);
if( $language != $attempt->language){
if( !$DB->set_field( 'game_attempts', 'language', $attempt->language, array( 'id' => $attempt->id))){
print_error( "game_cross_play: Can't set language");
if ($language != $attempt->language) {
if (!$DB->set_field( 'game_attempts', 'language', $attempt->language, array( 'id' => $attempt->id))) {
print_error( "game_cross_play: Can't set language");
}
}
if( $done or $endofgame){
if (! $cm = $DB->get_record( 'course_modules', array( 'id' => $id))) {
print_error("Course Module ID was incorrect id=$id");
}
if( $endofgame == false){
echo '<B>'.get_string( 'win', 'game').'</B><BR>';
}
if( game_can_start_new_attempt( $game))
{
echo '<br>';
echo "<a href=\"{$CFG->wwwroot}/mod/game/attempt.php?id=$id&forcenew=1\">".get_string( 'nextgame', 'game').'</a> &nbsp; &nbsp; &nbsp; &nbsp; ';
}
}else if( $info != ''){
echo "<br>$info<br>";
}
if ($done or $endofgame) {
if (! $cm = $DB->get_record( 'course_modules', array( 'id' => $id))) {
print_error("Course Module ID was incorrect id=$id");
}
if( $attempt->language != '')
if ($endofgame == false) {
echo '<B>'.get_string( 'win', 'game').'</B><BR>';
}
if (game_can_start_new_attempt( $game)) {
echo '<br>';
echo "<a href=\"{$CFG->wwwroot}/mod/game/attempt.php?id=$id&forcenew=1\">".
get_string( 'nextgame', 'game').'</a> &nbsp; &nbsp; &nbsp; &nbsp; ';
}
} else if ($info != '') {
echo "<br>$info<br>";
}
if ($attempt->language != '') {
$wordrtl = game_right_to_left( $attempt->language);
else
} else {
$wordrtl = right_to_left();
}
$reverseprint = ($wordrtl != right_to_left());
if( $reverseprint)
if ($reverseprint) {
$textdir = 'dir="'.($wordrtl ? 'rtl' : 'ltr').'"';
else
} else {
$textdir = '';
}
?>
<style type="text/css"><!--
@ -257,17 +276,16 @@ margin-top: 1em;
</head>
<?php
if( $print){
echo '<body onload="window.print()">';
}else{
echo '<body>';
}
if ($print) {
echo '<body onload="window.print()">';
} else {
echo '<body>';
}
if( $game->toptext != ''){
echo $game->toptext.'<br>';
}
if ($game->toptext != '') {
echo $game->toptext.'<br>';
}
?>
<h1></h1>
<div id="waitmessage" class="answerboxstyle">
@ -280,7 +298,7 @@ if( $print){
<p><table cellpadding="0" cellspacing="0" border="0">
<?php
if( $game->param3 == 2){
if ($game->param3 == 2) {
echo "<tr>\r\n";
game_cross_show_welcome( $game);
echo "</tr>\r\n";
@ -289,7 +307,8 @@ if( $print){
?>
<tr>
<td class="crosswordarea"><table id="crossword" cellpadding="3" cellspacing="0" style="display: none; border-collapse: collapse;" <?php echo $textdir;?>>
<td class="crosswordarea">
<table id="crossword" cellpadding="3" cellspacing="0" style="display: none; border-collapse: collapse;" <?php echo $textdir;?>>
<script language="JavaScript" type="text/javascript"><!--
@ -316,8 +335,8 @@ if (document.getElementById("waitmessage") != null)
CurrentWord = -1;
PrevWordHorizontal = false;
<?PHP
echo $html;
<?php
echo $html;
?>
OnlyCheckOnce = false;
@ -419,7 +438,10 @@ if (document.getElementById("waitmessage") != null)
{
if (TableAcrossWord[x][y] >= 0 || TableDownWord[x][y] >= 0)
{
document.write("<td id=\"c" + PadNumber(x) + PadNumber(y) + "\" class=\"gamebox boxnormal_unsel\" onclick=\"SelectThisWord(event);\">");
var s;
s = "<td id=\"c" + PadNumber(x) + PadNumber(y);
s += "\" class=\"gamebox boxnormal_unsel\" onclick=\"SelectThisWord(event);\">";
document.write( s);
if( solu[x][y] != '')
document.write( solu[x][y]);
@ -567,7 +589,7 @@ function SelectThisWord(event)
else
TableCell = CellAt(x, y + i);
// Add its contents to the word we're building.
if (TableCell.innerHTML != null && TableCell.innerHTML.length > 0 && TableCell.innerHTML != " " && TableCell.innerHTML.toLowerCase() != "&nbsp;")
if (TableCell.innerHTML != null && TableCell.innerHTML.length > 0 && TableCell.innerHTML != " " && TableCell.innerHTML.toLowerCase() != "&nbsp;")
{
TheirWord += TableCell.innerHTML.toUpperCase();
TheirWordLength++;
@ -579,13 +601,13 @@ function SelectThisWord(event)
}
document.getElementById("wordlabel").innerHTML = TheirWord;
<?php
$msg = "\"".get_string( 'cross_across', 'game').", \" : \"".
get_string( 'cross_down', 'game').", \"";
$letters = "\" ".get_string( 'letter', 'game').".\" : \" ".
get_string( 'letters', 'game').".\"";
?>
document.getElementById("wordinfo").innerHTML = ((CurrentWord <= LastHorizontalWord) ? <?php echo $msg ?>) + WordLength[CurrentWord] + (WordLength[CurrentWord] == 1 ? <?php echo $letters;?>);
<?php
$msg = "\"".get_string( 'cross_across', 'game').", \" : \"".
get_string( 'cross_down', 'game').", \"";
$letters = "\" ".get_string( 'letter', 'game').".\" : \" ".
get_string( 'letters', 'game').".\"";
?>
document.getElementById("wordinfo").innerHTML = ((CurrentWord <= LastHorizontalWord) ? <?php echo $msg ?>) + WordLength[CurrentWord] + (WordLength[CurrentWord] == 1 ? <?php echo $letters;?>);
document.getElementById("wordclue").innerHTML = Clue[CurrentWord];
document.getElementById("worderror").style.display = "none";
//document.getElementById("cheatbutton").style.display = (Word.length == 0) ? "none" : "";
@ -630,13 +652,13 @@ function OKClick()
}
if (TheirWord.length < WordLength[CurrentWord])
{
document.getElementById("worderror").innerHTML = "<?php echo get_string( 'cross_error_wordlength1', 'game');?>" + WordLength[CurrentWord] + " <?php echo get_string( 'cross_error_wordlength2', 'game');?>";
document.getElementById("worderror").innerHTML = "<?php echo get_string( 'cross_error_wordlength1', 'game');?>" + WordLength[CurrentWord] + " <?php echo get_string( 'cross_error_wordlength2', 'game');?>";
document.getElementById("worderror").style.display = "block";
return;
}
if (TheirWord.length > WordLength[CurrentWord])
{
document.getElementById("worderror").innerHTML = "<?php echo get_string( 'cross_error_wordlength1', 'game');?>" + WordLength[CurrentWord] + " <?php echo get_string( 'cross_error_wordlength2', 'game');?>";;
document.getElementById("worderror").innerHTML = "<?php echo get_string( 'cross_error_wordlength1', 'game');?>" + WordLength[CurrentWord] + " <?php echo get_string( 'cross_error_wordlength2', 'game');?>";;
document.getElementById("worderror").style.display = "block";
return;
}
@ -653,7 +675,7 @@ function OKClick()
}
<?php
if( $showhtmlsolutions == false){
if ($showhtmlsolutions == false) {
?>
function PackPuzzle( sData)
{
@ -742,55 +764,54 @@ function CheckServerClick( endofgame)
sData += "&finishattempt=1";
<?php
if( $onlyshow == false){
global $CFG;
$params = 'id='.$id.'&action=crosscheck&g=';
echo "window.location = \"{$CFG->wwwroot}/mod/game/attempt.php?$params\"+ sData;\r\n";
}
if ($onlyshow == false) {
global $CFG;
$params = 'id='.$id.'&action=crosscheck&g=';
echo "window.location = \"{$CFG->wwwroot}/mod/game/attempt.php?$params\"+ sData;\r\n";
}
?>
}
<?php
}
}
?>
function OnPrint()
{
<?php
global $CFG;
global $CFG;
$params = "id=$id&gameid=$game->id";
echo "window.open( \"{$CFG->wwwroot}/mod/game/print.php?$params\")";
?>
}
<?php
if( $showhtmlprintbutton){
if ($showhtmlprintbutton) {
?>
function PrintHtmlClick()
{
document.getElementById("printhtmlbutton").style.display = "none";
<?php
if( $showhtmlsolutions){
?> document.getElementById("checkhtmlbutton").style.display = "none"; <?php
}
if ($showhtmlsolutions) {
?> document.getElementById("checkhtmlbutton").style.display = "none"; <?php
}
?>
window.print();
<?php
if( $showhtmlsolutions){
?> document.getElementById("checkhtmlbutton").style.display = "block"; <?php
}
if ($showhtmlsolutions) {
?> document.getElementById("checkhtmlbutton").style.display = "block"; <?php
}
?>
document.getElementById("printhtmlbutton").style.display = "block";
}
<?php
}
}
?>
<?php
if( $showhtmlprintbutton){
if ($showhtmlprintbutton) {
?>
/**
@ -905,11 +926,9 @@ function CheckHtmlClick()
}
}
<?php
}
}
if( $showhtmlsolutions)
{
if ($showhtmlsolutions) {
?>
function decodeutf8(utftext) {
var string = "";
@ -941,7 +960,7 @@ if( $showhtmlsolutions)
return string;
}
<?php
}
}
?>
//-->
@ -950,10 +969,10 @@ if( $showhtmlsolutions)
</table></td>
<?php
if( $game->param3 == 2){
if ($game->param3 == 2) {
echo '<td>&nbsp &nbsp &nbsp</td>';
game_cross_show_legends( $cross);
}else{
} else {
game_cross_show_welcome( $game);
}
?>
@ -962,80 +981,77 @@ if( $showhtmlsolutions)
<?php
if( $onlyshow == false){
echo '<div style="margin-top: 1em;">';
echo '<button id="checkbutton" type="button" onclick="CheckServerClick( 0);" style="display: none;">'.get_string( 'cross_checkbutton', 'game');
echo '</button>';
echo ' &nbsp;&nbsp;&nbsp;&nbsp;<button id="finishattemptbutton" type="button" onclick="CheckServerClick( 1);" style="display: none;">'.get_string( 'cross_endofgamebutton', 'game');
echo '</button>';
if( $game->param5 == 1 or $game->param5 == NULL)
{
echo ' &nbsp;&nbsp;&nbsp;&nbsp;<button id="printbutton" type="button" onclick="OnPrint( 0);" style="display: none;">'.get_string( 'print', 'game');
echo '</button>';
if ($onlyshow == false) {
echo '<div style="margin-top: 1em;">';
echo '<button id="checkbutton" type="button" onclick="CheckServerClick( 0);" style="display: none;">'.
get_string( 'cross_checkbutton', 'game');
echo '</button>';
echo ' &nbsp;&nbsp;&nbsp;&nbsp;<button id="finishattemptbutton" type="button" onclick="CheckServerClick( 1);" style="display: none;">'.
get_string( 'cross_endofgamebutton', 'game');
echo '</button>';
if ($game->param5 == 1 or $game->param5 == NULL) {
echo ' &nbsp;&nbsp;&nbsp;&nbsp;<button id="printbutton" type="button" onclick="OnPrint( 0);" style="display: none;">'.get_string( 'print', 'game');
echo '</button>';
}
echo "</div>\r\n";
}
if( $showhtmlsolutions or $showhtmlprintbutton){
echo '<br>';
}
if( $showhtmlsolutions){
echo '<button id="checkhtmlbutton" type="button" onclick="CheckHtmlClick();" visible=true>'.get_string( 'cross_checkbutton', 'game');
echo '</button>';
}
if( $showhtmlprintbutton){
if( $showhtmlsolutions){
echo "&nbsp;&nbsp;&nbsp;&nbsp;";
}
echo '<button id="printhtmlbutton" type="button" onclick="PrintHtmlClick( 0);" visible=true>'.get_string( 'print', 'game');
echo '</button>';
}
echo "</div>\r\n";
}
if ($showhtmlsolutions or $showhtmlprintbutton) {
echo '<br>';
}
if ($showhtmlsolutions) {
echo '<button id="checkhtmlbutton" type="button" onclick="CheckHtmlClick();" visible=true>'.get_string( 'cross_checkbutton', 'game');
echo '</button>';
}
if( $game->param3 == 2){
if ($showhtmlprintbutton) {
if ($showhtmlsolutions) {
echo "&nbsp;&nbsp;&nbsp;&nbsp;";
}
echo '<button id="printhtmlbutton" type="button" onclick="PrintHtmlClick( 0);" visible=true>'.get_string( 'print', 'game');
echo '</button>';
}
if ($game->param3 == 2) {
echo '<td>&nbsp &nbsp &nbsp</td>';
game_cross_show_welcome( $game);
}else{
} else {
game_cross_show_legends( $cross);
}
if( $game->bottomtext != ''){
echo '<br><br>'.$game->bottomtext;
}
if( $attempt != false){
if( $attempt->timefinish == 0 and $endofgame == 0)
{
?>
if ($game->bottomtext != '') {
echo '<br><br>'.$game->bottomtext;
}
if ($attempt != false) {
if ($attempt->timefinish == 0 and $endofgame == 0) {
?>
<script language="JavaScript" type="text/javascript"><!--
if (Initialized)
{
<?php
if( $print == false){
echo "document.getElementById(\"welcomemessage\").style.display = \"\";";
}
if( $showsolution == false)
{
<?php
if ($print == false) {
echo "document.getElementById(\"welcomemessage\").style.display = \"\";";
}
if ($showsolution == false) {
?>
document.getElementById("checkbutton").style.display = "";
document.getElementById("finishattemptbutton").style.display = "";
document.getElementById("printbutton").style.display = "";
<?php
}
?>
}
?>
}
//-->
</script>
<?php
<?php
}
}
}
?>
@ -1045,16 +1061,15 @@ if( $attempt != false){
<?php
}
function game_cross_show_welcome( $game){
if( $game->param3 <> 2){
function game_cross_show_welcome( $game) {
if ($game->param3 <> 2) {
game_cross_show_welcome0( $game);
}else{
} else {
game_cross_show_welcome1();
}
}
function game_cross_show_welcome0( $game){
function game_cross_show_welcome0( $game) {
?>
<td valign="top" style="padding-left: 1em;">
@ -1071,7 +1086,7 @@ function game_cross_show_welcome0( $game){
style="font-weight: bold; <? if( $game->param6 == 0) echo 'text-transform:uppercase;'; ?>"
onkeypress="WordEntryKeyPress(event)" onchange="WordEntryKeyPress(event)" autocomplete="off"></div>
<?php
if( $game->param3 == 2){
if ($game->param3 == 2) {
game_cross_show_welcome( $game);
}
?>
@ -1090,7 +1105,7 @@ function game_cross_show_welcome0( $game){
<?php
}
function game_cross_show_welcome1(){
function game_cross_show_welcome1() {
?>
<td valign="top" style="padding-left: 1em;">
@ -1129,7 +1144,7 @@ function game_cross_show_welcome1(){
<?php
}
function game_cross_show_legends( $cross){
function game_cross_show_legends( $cross) {
echo '<td>';
ShowLegend( $cross->m_LegendH, get_string( 'cross_across', 'game'));
ShowLegend( $cross->m_LegendV, get_string( 'cross_down', 'game'));

Loading…
Cancel
Save