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