/** Load a crossword. * @param $crossword_id int Id of crossword. * @param $puzzle CrosswordPuzzle Puzzle to load into. * @return bool true if successful. */ function LoadCrossword($crossword_id, &$puzzle) { // First get dimentions $sql = 'SELECT `crossword_width` AS width, ' . ' `crossword_height` AS height ' . 'FROM `crosswords` ' . 'WHERE `crossword_id` = ?'; $bind = array($crossword_id); $results = $this->db->query($sql, $bind)->result_array(); if (count($results) === 0) { return false; } // Set up the result $width = (int) $results[0]['width']; $height = (int) $results[0]['height']; $puzzle = new CrosswordPuzzle($width, $height); // Get the lights $sql = 'SELECT `crossword_light_posx` AS posx, ' . ' `crossword_light_posy` AS posy, ' . ' `crossword_light_orientation` AS orientation, ' . ' `crossword_light_solution` AS solution, ' . ' `crossword_light_normal_clue` AS quickClue, ' . ' `crossword_light_cryptic_clue` AS crypticClue ' . 'FROM `crossword_lights` ' . 'WHERE `crossword_light_crossword_id` = ?'; // Use bind from above $results = $this->db->query($sql, $bind)->result_array(); foreach ($results as &$result) { $puzzle->addLight((int) $result['posx'], (int) $result['posy'], $result['orientation'] == 'horizontal' ? CrosswordGrid::$HORIZONTAL : CrosswordGrid::$VERTICAL, new CrosswordClue($result['solution'], $result['quickClue'], $result['crypticClue'])); } return true; }