function game_cross_new($game, $attemptid, &$crossm) { global $DB, $USER; $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 (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) { $reps[$rec->answertext] = $rec2->r; } } $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, $game->param8)) { $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') . $game->id); } }
public function savecryptex($game, &$crossm, $crossd, $id, $letters) { global $USER; CrossDB::delete_records($id); if (CrossDB::savecross($game, $crossm, $crossd, $id) == false) { return false; } $crossm->id = $id; $newrec = new stdClass(); $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; }