function game_cross_continue($id, $game, $attempt, $cross, $g = '', $endofgame = '') { 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); } if ($attempt == false) { $attempt = game_addattempt($game); } $textlib = textlib_get_instance(); $cross = new CrossDB(); $questions = array(); $infos = array(); $answers = array(); $recs = game_questions_shortanswer($game); if ($recs == false) { error('game_cross_continue: ' . get_string('cross_nowords', 'game')); } $infos = array(); foreach ($recs as $rec) { if ($game->param7 == false) { if ($textlib->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); } $cross->setwords($answers, $game->param1); if ($cross->computedata($crossm, $crossd, $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->save($game, $crossm, $new_crossd, $attempt->id); game_updateattempts($game, $attempt, 0, 0); return game_cross_play($id, $game, $attempt, $crossm, '', false, false, false, false, false, false, false); } if (count($crossd) == 0) { error('game_cross_continue: ' . get_string('cross_nowords', 'game')); } }
function save($game, &$crossm, $crossd, $id, $letters) { global $USER; CrossDB::delete_cross($id); if (CrossDB::save($game, $crossm, $crossd, $id) == false) { return false; } $crossm->id = $id; $newrec->id = $id; $newrec->letters = $letters; if (!($cryptexid = game_insert_record("game_cryptex", $newrec))) { print_error('Insert page: new page game_cryptex not inserted'); } return $newrec; }
function game_cross_new($game, $attemptid, &$crossm) { global $DB, $USER; $textlib = textlib_get_instance(); $cross = new CrossDB(); $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 ($textlib->strpos($rec->answertext, ' ')) { continue; //spaces not allowed } } $rec->answertext = game_upper($rec->answertext); $answers[$rec->answertext] = $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 r')) != false) { $reps[$rec->answertext] = $rec2->r; } } $cross->setwords($answers, $game->param1, $reps); if ($cross->computedata($crossm, $crossd, $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->save($game, $crossm, $new_crossd, $attemptid); } if (count($crossd) == 0) { print_error('game_cross_continue: ' . get_string('no_words', 'game')); } }