Browse Source

Change name of game_snakes_databases.cols to usedcols

MOODLE_20_STABLE
bdaloukas 8 years ago
parent
commit
503b2a51cd
  1. 8
      CHANGES.md
  2. 4
      db/install.xml
  3. 40
      db/upgrade.php
  4. 4
      mod_form.php
  5. 16
      snakes/play.php
  6. 2
      version.php

8
CHANGES.md

@ -1,7 +1,9 @@
Changes in version 2017-06-19 (20170619)
- Fix Moodle 3.4 compatibility problems
- Fix codeprechecks problems
- Stable version
- Change field name game_snakes_database.cols => usedcols
- Change field name game_snakes_database.rows => usedrows
Changes in version 2017-06-10 (20170610)
- Fix phpdocs problems
Changes in version 2017-06-09 (20170609)
- Fix Moodle 3.4 compatibility problems

4
db/install.xml

@ -287,8 +287,8 @@
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
<FIELD NAME="name" TYPE="char" LENGTH="100" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="cols" TYPE="int" LENGTH="3" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="rows" TYPE="int" LENGTH="3" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="usedcols" TYPE="int" LENGTH="3" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="usedrows" TYPE="int" LENGTH="3" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="data" TYPE="text" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="fileboard" TYPE="char" LENGTH="100" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="direction" TYPE="int" LENGTH="2" NOTNULL="false" SEQUENCE="false"/>

40
db/upgrade.php

@ -1556,6 +1556,23 @@ function xmldb_game_upgrade($oldversion) {
$dbman->change_field_type($table, $field);
}
if ($oldversion < ($ver = 2017061604)) {
$table = new xmldb_table('game_cross');
$field = new xmldb_field('usedrows', XMLDB_TYPE_INTEGER, '3', XMLDB_UNSIGNED, null, null, '0', 'id');
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
$field = new xmldb_field('rows', XMLDB_TYPE_INTEGER, '3', XMLDB_UNSIGNED, null, null, '0', 'id');
if ($dbman->field_exists($table, $field)) {
$sql = "UPDATE {$CFG->prefix}game_cross SET usedrows=rows";
$DB->execute( $sql);
$dbman->drop_field($table, $field);
} else {
$dbman->add_field($table, $field);
}
}
if ($oldversion < ($ver = 2017061604)) {
$table = new xmldb_table('game_cross');
$field = new xmldb_field('usedcols', XMLDB_TYPE_INTEGER, '3', XMLDB_UNSIGNED, null, null, '0', 'id');
@ -1573,8 +1590,8 @@ function xmldb_game_upgrade($oldversion) {
}
}
if ($oldversion < ($ver = 2017061604)) {
$table = new xmldb_table('game_cross');
if ($oldversion < ($ver = 2017061901)) {
$table = new xmldb_table('game_snakes_database');
$field = new xmldb_field('usedrows', XMLDB_TYPE_INTEGER, '3', XMLDB_UNSIGNED, null, null, '0', 'id');
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
@ -1582,7 +1599,7 @@ function xmldb_game_upgrade($oldversion) {
$field = new xmldb_field('rows', XMLDB_TYPE_INTEGER, '3', XMLDB_UNSIGNED, null, null, '0', 'id');
if ($dbman->field_exists($table, $field)) {
$sql = "UPDATE {$CFG->prefix}game_cross SET usedrows=rows";
$sql = "UPDATE {$CFG->prefix}game_snakes_database SET usedrows=rows";
$DB->execute( $sql);
$dbman->drop_field($table, $field);
} else {
@ -1590,5 +1607,22 @@ function xmldb_game_upgrade($oldversion) {
}
}
if ($oldversion < ($ver = 2017061901)) {
$table = new xmldb_table('game_snakes_database');
$field = new xmldb_field('usedcols', XMLDB_TYPE_INTEGER, '3', XMLDB_UNSIGNED, null, null, '0', 'id');
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
$field = new xmldb_field('cols', XMLDB_TYPE_INTEGER, '3', XMLDB_UNSIGNED, null, null, '0', 'id');
if ($dbman->field_exists($table, $field)) {
$sql = "UPDATE {$CFG->prefix}game_snakes_database SET usedcols=cols";
$DB->execute( $sql);
$dbman->drop_field($table, $field);
} else {
$dbman->add_field($table, $field);
}
}
return true;
}

4
mod_form.php

@ -508,8 +508,8 @@ class mod_game_mod_form extends moodleform_mod {
if ($board != 0) {
$rec = $DB->get_record( 'game_snakes_database', array( 'id' => $board));
$defaultvalues->snakes_data = $rec->data;
$defaultvalues->snakes_cols = $rec->cols;
$defaultvalues->snakes_rows = $rec->rows;
$defaultvalues->snakes_cols = $rec->usedcols;
$defaultvalues->snakes_rows = $rec->usedrows;
$defaultvalues->snakes_headerx = $rec->headerx;
$defaultvalues->snakes_headery = $rec->headery;
$defaultvalues->snakes_footerx = $rec->footerx;

16
snakes/play.php

@ -74,7 +74,7 @@ function game_snakes_play( $id, $game, $attempt, $snakes, $context) {
$board = game_snakes_get_board( $game);
$showboard = false;
if ($snakes->position > $board->cols * $board->rows && $snakes->queryid <> 0) {
if ($snakes->position > $board->usedcols * $board->usedrows && $snakes->queryid <> 0) {
$finish = true;
if (! $cm = $DB->get_record('course_modules', array( 'id' => $id))) {
@ -180,11 +180,11 @@ top:<?php p( -2 * round($board->height / 3));?>px; ">
* @param stdClass $board
*/
function game_snakes_computeplayerposition( $snakes, $board) {
$x = ($snakes->position - 1) % $board->cols;
$y = floor( ($snakes->position - 1) / $board->cols);
$x = ($snakes->position - 1) % $board->usedcols;
$y = floor( ($snakes->position - 1) / $board->usedcols);
$cellwidth = ($board->width - $board->headerx - $board->footerx) / $board->cols;
$cellheight = ($board->height - $board->headery - $board->footery) / $board->rows;
$cellwidth = ($board->width - $board->headerx - $board->footerx) / $board->usedcols;
$cellheight = ($board->height - $board->headery - $board->footery) / $board->usedrows;
$pos = new stdClass();
$pos->width = 22;
@ -196,7 +196,7 @@ function game_snakes_computeplayerposition( $snakes, $board) {
switch( $board->direction) {
case 1:
if (($y % 2) == 1) {
$x = $board->cols - $x - 1;
$x = $board->usedcols - $x - 1;
}
$pos->x = $board->headerx + $x * $cellwidth + ($cellwidth - $pos->width) / 2 + $pos->ofsx;
$pos->y = $board->footery + $y * $cellheight + ($cellheight - $pos->height) / 2 + $pos->ofsy;
@ -488,8 +488,8 @@ function game_snakes_position( $id, $game, $attempt, $snakes, $correct, $query,
}
$board = $DB->get_record_select( 'game_snakes_database', "id=$snakes->snakesdatabaseid");
$gradeattempt = $snakes->position / ($board->cols * $board->rows);
$finished = ( $snakes->position > $board->cols * $board->rows ? 1 : 0);
$gradeattempt = $snakes->position / ($board->usedcols * $board->usedrows);
$finished = ( $snakes->position > $board->usedcols * $board->usedrows ? 1 : 0);
game_updateattempts( $game, $attempt, $gradeattempt, $finished);

2
version.php

@ -39,7 +39,7 @@ $plugin->version = 2017061901; // The current module version (Date: YYYYMMDDX
$plugin->requires = 2010112400; // Requires Moodle 2.0.
$plugin->cron = 0; // Period for cron to check this module (secs).
$plugin->release = '2017-06-19';
$plugin->maturity = MATURITY_STABLE;
$plugin->maturity = MATURITY_BETA;
if ($useplugin != 2) {
$module = $plugin;

Loading…
Cancel
Save