hide map for Character groups Quest Stations when there are no stations
This commit is contained in:
commit
df14dfafc3
4371 changed files with 1220224 additions and 0 deletions
24
questtypes/crossword/CrosswordQuesttypeAgent.inc
Normal file
24
questtypes/crossword/CrosswordQuesttypeAgent.inc
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* The Legend of Z
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
* @copyright 2014 Heinrich-Heine-Universität Düsseldorf
|
||||
* @license http://www.gnu.org/licenses/gpl.html
|
||||
* @link https://bitbucket.org/coderkun/the-legend-of-z
|
||||
*/
|
||||
|
||||
namespace hhu\z\questtypes;
|
||||
|
||||
|
||||
/**
|
||||
* QuesttypeAgent for solving a crossword.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class CrosswordQuesttypeAgent extends \hhu\z\agents\QuesttypeAgent
|
||||
{
|
||||
}
|
||||
|
||||
?>
|
||||
380
questtypes/crossword/CrosswordQuesttypeController.inc
Normal file
380
questtypes/crossword/CrosswordQuesttypeController.inc
Normal file
|
|
@ -0,0 +1,380 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* The Legend of Z
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
* @copyright 2014 Heinrich-Heine-Universität Düsseldorf
|
||||
* @license http://www.gnu.org/licenses/gpl.html
|
||||
* @link https://bitbucket.org/coderkun/the-legend-of-z
|
||||
*/
|
||||
|
||||
namespace hhu\z\questtypes;
|
||||
|
||||
|
||||
/**
|
||||
* Controller of the CrosswordQuesttypeAgent for solving a crossword.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class CrosswordQuesttypeController extends \hhu\z\controllers\QuesttypeController
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Save the answers of a Character for a Quest.
|
||||
*
|
||||
* @param array $seminary Current Seminary data
|
||||
* @param array $questgroup Current Questgroup data
|
||||
* @param array $quest Current Quest data
|
||||
* @param array $character Current Character data
|
||||
* @param array $answers Character answers for the Quest
|
||||
*/
|
||||
public function saveAnswersOfCharacter($seminary, $questgroup, $quest, $character, $answers)
|
||||
{
|
||||
// Get words
|
||||
$words = $this->Crossword->getWordsForQuest($quest['id']);
|
||||
|
||||
// Iterate words
|
||||
foreach($words as &$word)
|
||||
{
|
||||
// Assemble answer for word
|
||||
$answer = '';
|
||||
if($word['vertical'])
|
||||
{
|
||||
$x = $word['pos_x'];
|
||||
$startY = $word['pos_y'];
|
||||
$endY = $startY + mb_strlen($word['word'], 'UTF-8') - 1;
|
||||
|
||||
foreach(range($startY, $endY) as $y)
|
||||
{
|
||||
if(array_key_exists($x, $answers) && array_key_exists($y, $answers[$x]) && !empty($answers[$x][$y])) {
|
||||
$answer .= $answers[$x][$y];
|
||||
}
|
||||
else {
|
||||
$answer .= ' ';
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$startX = $word['pos_x'];
|
||||
$endX = $startX + mb_strlen($word['word'], 'UTF-8') - 1;
|
||||
$y = $word['pos_y'];
|
||||
|
||||
foreach(range($startX, $endX) as $x)
|
||||
{
|
||||
if(array_key_exists($x, $answers) && array_key_exists($y, $answers[$x]) && !empty($answers[$x][$y])) {
|
||||
$answer .= $answers[$x][$y];
|
||||
}
|
||||
else {
|
||||
$answer .= ' ';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Save answer
|
||||
$this->Crossword->setCharacterSubmission($word['id'], $character['id'], $answer);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Save additional data for the answers of a Character for a Quest.
|
||||
*
|
||||
* @param array $seminary Current Seminary data
|
||||
* @param array $questgroup Current Questgroup data
|
||||
* @param array $quest Current Quest data
|
||||
* @param array $character Current Character data
|
||||
* @param array $data Additional (POST-) data
|
||||
*/
|
||||
public function saveDataForCharacterAnswers($seminary, $questgroup, $quest, $character, $data)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if answers of a Character for a Quest match the correct ones.
|
||||
*
|
||||
* @param array $seminary Current Seminary data
|
||||
* @param array $questgroup Current Questgroup data
|
||||
* @param array $quest Current Quest data
|
||||
* @param array $character Current Character data
|
||||
* @param array $answers Character answers for the Quest
|
||||
* @return boolean True/false for a right/wrong answer or null for moderator evaluation
|
||||
*/
|
||||
public function matchAnswersOfCharacter($seminary, $questgroup, $quest, $character, $answers)
|
||||
{
|
||||
// Get words
|
||||
$words = $this->Crossword->getWordsForQuest($quest['id']);
|
||||
|
||||
// Iterate words
|
||||
foreach($words as &$word)
|
||||
{
|
||||
// Assemble answer for word
|
||||
$answer = '';
|
||||
if($word['vertical'])
|
||||
{
|
||||
$x = $word['pos_x'];
|
||||
$startY = $word['pos_y'];
|
||||
$endY = $startY + mb_strlen($word['word'], 'UTF-8') - 1;
|
||||
|
||||
foreach(range($startY, $endY) as $y)
|
||||
{
|
||||
if(array_key_exists($x, $answers) && array_key_exists($y, $answers[$x]) && !empty($answers[$x][$y])) {
|
||||
$answer .= $answers[$x][$y];
|
||||
}
|
||||
else {
|
||||
$answer .= ' ';
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$startX = $word['pos_x'];
|
||||
$endX = $startX + mb_strlen($word['word'], 'UTF-8') - 1;
|
||||
$y = $word['pos_y'];
|
||||
|
||||
foreach(range($startX, $endX) as $x)
|
||||
{
|
||||
if(array_key_exists($x, $answers) && array_key_exists($y, $answers[$x]) && !empty($answers[$x][$y])) {
|
||||
$answer .= $answers[$x][$y];
|
||||
}
|
||||
else {
|
||||
$answer .= ' ';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check answer
|
||||
if(mb_strtolower($word['word'], 'UTF-8') != mb_strtolower($answer, 'UTF-8')) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// All answer right
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Action: quest.
|
||||
*
|
||||
* Display a text with lists with predefined values.
|
||||
*
|
||||
* @param array $seminary Current Seminary data
|
||||
* @param array $questgroup Current Questgroup data
|
||||
* @param array $quest Current Quest data
|
||||
* @param array $character Current Character data
|
||||
* @param \Exception $exception Character submission exception
|
||||
*/
|
||||
public function quest($seminary, $questgroup, $quest, $character, $exception)
|
||||
{
|
||||
// Get words
|
||||
$words = $this->Crossword->getWordsForQuest($quest['id']);
|
||||
|
||||
// Create 2D-matrix
|
||||
$matrix = array();
|
||||
$maxX = 0;
|
||||
$maxY = 0;
|
||||
foreach($words as $index => &$word)
|
||||
{
|
||||
if($this->request->getGetParam('show-answer') == 'true' || !$this->Quests->hasCharacterSolvedQuest($quest['id'], $character['id']) || $this->request->getGetParam('status') == 'solved') {
|
||||
$word['answer'] = $this->Crossword->getCharacterSubmission($word['id'], $character['id']);
|
||||
}
|
||||
// Insert word
|
||||
if($word['vertical'])
|
||||
{
|
||||
$x = $word['pos_x'];
|
||||
$startY = $word['pos_y'];
|
||||
$endY = $startY + mb_strlen($word['word'], 'UTF-8') - 1;
|
||||
|
||||
$matrix = array_pad($matrix, $x+1, array());
|
||||
$matrix[$x] = array_pad($matrix[$x], $endY+1, null);
|
||||
$maxX = max($maxX, $x);
|
||||
$maxY = max($maxY, $endY);
|
||||
|
||||
foreach(range($startY, $endY) as $y)
|
||||
{
|
||||
$matrix[$x][$y] = array(
|
||||
'char' => mb_substr($word['word'], $y-$startY, 1, 'UTF-8'),
|
||||
'indices' => (array_key_exists($x, $matrix) && array_key_exists($y, $matrix[$x]) && !is_null($matrix[$x][$y]) && array_key_exists('indices', $matrix[$x][$y])) ? $matrix[$x][$y]['indices'] : array(),
|
||||
'answer' => null
|
||||
);
|
||||
if($y == $startY) {
|
||||
$matrix[$x][$y]['indices'][] = $index;
|
||||
}
|
||||
if(array_key_exists('answer', $word))
|
||||
{
|
||||
$answer = mb_substr($word['answer'], $y-$startY, 1, 'UTF-8');
|
||||
if($answer != ' ') {
|
||||
$matrix[$x][$y]['answer'] = $answer;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$startX = $word['pos_x'];
|
||||
$endX = $startX + mb_strlen($word['word'], 'UTF-8') - 1;
|
||||
$y = $word['pos_y'];
|
||||
|
||||
$matrix = array_pad($matrix, $endX+1, array());
|
||||
$maxX = max($maxX, $endX);
|
||||
$maxY = max($maxY, $y);
|
||||
|
||||
foreach(range($startX, $endX) as $x)
|
||||
{
|
||||
$matrix[$x] = array_pad($matrix[$x], $y+1, null);
|
||||
|
||||
$matrix[$x][$y] = array(
|
||||
'char' => mb_substr($word['word'], $x-$startX, 1, 'UTF-8'),
|
||||
'indices' => (array_key_exists($x, $matrix) && array_key_exists($y, $matrix[$x]) && !is_null($matrix[$x][$y]) && array_key_exists('indices', $matrix[$x][$y])) ? $matrix[$x][$y]['indices'] : array(),
|
||||
'answer' => null
|
||||
);
|
||||
if($x == $startX) {
|
||||
$matrix[$x][$y]['indices'][] = $index;
|
||||
}
|
||||
if(array_key_exists('answer', $word))
|
||||
{
|
||||
$answer = mb_substr($word['answer'], $x-$startX, 1, 'UTF-8');
|
||||
if($answer != ' ') {
|
||||
$matrix[$x][$y]['answer'] = $answer;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Pass data to view
|
||||
$this->set('words', $words);
|
||||
$this->set('maxX', $maxX);
|
||||
$this->set('maxY', $maxY);
|
||||
$this->set('matrix', $matrix);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Action: submission.
|
||||
*
|
||||
* Show the submission of a Character for a Quest.
|
||||
*
|
||||
* @param array $seminary Current Seminary data
|
||||
* @param array $questgroup Current Questgroup data
|
||||
* @param array $quest Current Quest data
|
||||
* @param array $character Current Character data
|
||||
*/
|
||||
public function submission($seminary, $questgroup, $quest, $character)
|
||||
{
|
||||
// Get words
|
||||
$words = $this->Crossword->getWordsForQuest($quest['id']);
|
||||
|
||||
// Create 2D-matrix
|
||||
$matrix = array();
|
||||
$maxX = 0;
|
||||
$maxY = 0;
|
||||
foreach($words as $index => &$word)
|
||||
{
|
||||
// Character answer
|
||||
$word['answer'] = $this->Crossword->getCharacterSubmission($word['id'], $character['id']);
|
||||
|
||||
// Insert word
|
||||
if($word['vertical'])
|
||||
{
|
||||
$x = $word['pos_x'];
|
||||
$startY = $word['pos_y'];
|
||||
$endY = $startY + mb_strlen($word['word'], 'UTF-8') - 1;
|
||||
|
||||
$matrix = array_pad($matrix, $x+1, array());
|
||||
$matrix[$x] = array_pad($matrix[$x], $endY+1, null);
|
||||
$maxX = max($maxX, $x);
|
||||
$maxY = max($maxY, $endY);
|
||||
|
||||
foreach(range($startY, $endY) as $y)
|
||||
{
|
||||
$matrix[$x][$y] = array(
|
||||
'char' => mb_substr($word['word'], $y-$startY, 1, 'UTF-8'),
|
||||
'indices' => (array_key_exists($x, $matrix) && array_key_exists($y, $matrix[$x]) && !is_null($matrix[$x][$y]) && array_key_exists('indices', $matrix[$x][$y])) ? $matrix[$x][$y]['indices'] : array(),
|
||||
'answer' => null,
|
||||
'right' => false
|
||||
);
|
||||
if($y == $startY) {
|
||||
$matrix[$x][$y]['indices'][] = $index;
|
||||
}
|
||||
|
||||
if(!is_null($word['answer']))
|
||||
{
|
||||
$answer = mb_substr($word['answer'], $y-$startY, 1, 'UTF-8');
|
||||
if($answer != ' ')
|
||||
{
|
||||
$matrix[$x][$y]['answer'] = $answer;
|
||||
$matrix[$x][$y]['right'] = (mb_strtolower($matrix[$x][$y]['char'], 'UTF-8') == mb_strtolower($answer, 'UTF-8'));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$startX = $word['pos_x'];
|
||||
$endX = $startX + mb_strlen($word['word'], 'UTF-8') - 1;
|
||||
$y = $word['pos_y'];
|
||||
|
||||
$matrix = array_pad($matrix, $endX+1, array());
|
||||
$maxX = max($maxX, $endX);
|
||||
$maxY = max($maxY, $y);
|
||||
|
||||
foreach(range($startX, $endX) as $x)
|
||||
{
|
||||
$matrix[$x] = array_pad($matrix[$x], $y+1, null);
|
||||
|
||||
$matrix[$x][$y] = array(
|
||||
'char' => mb_substr($word['word'], $x-$startX, 1, 'UTF-8'),
|
||||
'indices' => (array_key_exists($x, $matrix) && array_key_exists($y, $matrix[$x]) && !is_null($matrix[$x][$y]) && array_key_exists('indices', $matrix[$x][$y])) ? $matrix[$x][$y]['indices'] : array(),
|
||||
'answer' => null,
|
||||
'right' => false
|
||||
);
|
||||
if($x == $startX) {
|
||||
$matrix[$x][$y]['indices'][] = $index;
|
||||
}
|
||||
if(!is_null($word['answer']))
|
||||
{
|
||||
$answer = mb_substr($word['answer'], $x-$startX, 1, 'UTF-8');
|
||||
if($answer != ' ')
|
||||
{
|
||||
$matrix[$x][$y]['answer'] = $answer;
|
||||
$matrix[$x][$y]['right'] = (mb_strtolower($matrix[$x][$y]['char'], 'UTF-8') == mb_strtolower($answer, 'UTF-8'));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Pass data to view
|
||||
$this->set('words', $words);
|
||||
$this->set('maxX', $maxX);
|
||||
$this->set('maxY', $maxY);
|
||||
$this->set('matrix', $matrix);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* TODO Action: edittask.
|
||||
*
|
||||
* Edit the task of a Quest.
|
||||
*
|
||||
* @param array $seminary Current Seminary data
|
||||
* @param array $questgroup Current Questgroup data
|
||||
* @param array $quest Current Quest data
|
||||
*/
|
||||
public function edittask($seminary, $questgroup, $quest)
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
128
questtypes/crossword/CrosswordQuesttypeModel.inc
Normal file
128
questtypes/crossword/CrosswordQuesttypeModel.inc
Normal file
|
|
@ -0,0 +1,128 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* The Legend of Z
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
* @copyright 2014 Heinrich-Heine-Universität Düsseldorf
|
||||
* @license http://www.gnu.org/licenses/gpl.html
|
||||
* @link https://bitbucket.org/coderkun/the-legend-of-z
|
||||
*/
|
||||
|
||||
namespace hhu\z\questtypes;
|
||||
|
||||
|
||||
/**
|
||||
* Model of the CrosswordQuesttypeAgent for solving a crossword.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class CrosswordQuesttypeModel extends \hhu\z\models\QuesttypeModel
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Copy a Quest
|
||||
*
|
||||
* @param int $userId ID of creating user
|
||||
* @param int $sourceQuestId ID of Quest to copy from
|
||||
* @param int $targetQuestId ID of Quest to copy to
|
||||
* @param int $seminaryMediaIds Mapping of SeminaryMedia-IDs from source Seminary to targetSeminary
|
||||
*/
|
||||
public function copyQuest($userId, $sourceQuestId, $targetQuestId, $seminaryMediaIds)
|
||||
{
|
||||
// Copy words
|
||||
$this->db->query(
|
||||
'INSERT INTO questtypes_crossword_words '.
|
||||
'(quest_id, question, word, vertical, pos_x, pos_y) '.
|
||||
'SELECT ?, question, word, vertical, pos_x, pos_y '.
|
||||
'FROM questtypes_crossword_words '.
|
||||
'WHERE quest_id = ?',
|
||||
'ii',
|
||||
$targetQuestId,
|
||||
$sourceQuestId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delete a Quest.
|
||||
*
|
||||
* @param int $questId ID of Quest to delete
|
||||
*/
|
||||
public function deleteQuest($questId)
|
||||
{
|
||||
$this->db->query('DELETE FROM questtypes_crossword_words WHERE quest_id = ?', 'i', $questId);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get all words for a crossword-Quest.
|
||||
*
|
||||
* @param int $questId ID of Quest
|
||||
* @return array Words
|
||||
*/
|
||||
public function getWordsForQuest($questId)
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT id, question, word, vertical, pos_x, pos_y '.
|
||||
'FROM questtypes_crossword_words '.
|
||||
'WHERE quest_id = ? ',
|
||||
'i',
|
||||
$questId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Save Character’s submitted answer for one crossword-word.
|
||||
*
|
||||
* @param int $regexId ID of word
|
||||
* @param int $characterId ID of Character
|
||||
* @param string $answer Submitted answer for this word
|
||||
*/
|
||||
public function setCharacterSubmission($wordId, $characterId, $answer)
|
||||
{
|
||||
$this->db->query(
|
||||
'INSERT INTO questtypes_crossword_words_characters '.
|
||||
'(questtypes_crossword_word_id, character_id, answer) '.
|
||||
'VALUES '.
|
||||
'(?, ?, ?) '.
|
||||
'ON DUPLICATE KEY UPDATE '.
|
||||
'answer = ?',
|
||||
'iiss',
|
||||
$wordId, $characterId, $answer,
|
||||
$answer
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get answer of one crossword-word submitted by Character.
|
||||
*
|
||||
* @param int $regexId ID of lisword
|
||||
* @param int $characterId ID of Character
|
||||
* @return int Submitted answer for this word or null
|
||||
*/
|
||||
public function getCharacterSubmission($wordId, $characterId)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT answer '.
|
||||
'FROM questtypes_crossword_words_characters '.
|
||||
'WHERE questtypes_crossword_word_id = ? AND character_id = ? ',
|
||||
'ii',
|
||||
$wordId, $characterId
|
||||
);
|
||||
if(!empty($data)) {
|
||||
return $data[0]['answer'];
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
1
questtypes/crossword/html/edittask.tpl
Normal file
1
questtypes/crossword/html/edittask.tpl
Normal file
|
|
@ -0,0 +1 @@
|
|||
<p>TODO</p>
|
||||
136
questtypes/crossword/html/quest.tpl
Normal file
136
questtypes/crossword/html/quest.tpl
Normal file
|
|
@ -0,0 +1,136 @@
|
|||
<form method="post" class="crossword">
|
||||
<table id="matrix">
|
||||
<tbody>
|
||||
<?php foreach(range(0, $maxY) as $y) : ?>
|
||||
<tr>
|
||||
<?php foreach(range(0, $maxX) as $x) : ?>
|
||||
<td>
|
||||
<?php if(array_key_exists($x, $matrix) && array_key_exists($y, $matrix[$x]) && !is_null($matrix[$x][$y])) : ?>
|
||||
<?php if(count($matrix[$x][$y]['indices']) > 0) : ?><span class="index"><?=implode('/',array_map(function($e) { return $e+1; }, $matrix[$x][$y]['indices']))?></span><?php endif ?>
|
||||
<input type="text" name="answers[<?=$x?>][<?=$y?>]" maxlength="1" size="1" value="<?=(!is_null($matrix[$x][$y]['answer'])) ? $matrix[$x][$y]['answer'] : ''?>" />
|
||||
<?php endif ?>
|
||||
</td>
|
||||
<?php endforeach ?>
|
||||
</tr>
|
||||
<?php endforeach ?>
|
||||
</tbody>
|
||||
</table>
|
||||
<ol>
|
||||
<?php foreach($words as &$word) : ?>
|
||||
<li>
|
||||
<?php if($word['vertical']) : ?>
|
||||
<?=_('vertical')?>:
|
||||
<?php else : ?>
|
||||
<?=_('horizontal')?>:
|
||||
<?php endif ?>
|
||||
<?=\hhu\z\Utils::t($word['question'])?>
|
||||
</li>
|
||||
<?php endforeach ?>
|
||||
</ol>
|
||||
<input type="submit" name="submit" value="<?=_('solve')?>" />
|
||||
</form>
|
||||
<script type="text/javascript">
|
||||
// Last position
|
||||
var posX = 0;
|
||||
var posX = 0;
|
||||
|
||||
// Handle key input
|
||||
$('input:text').keyup(function(event) {
|
||||
// Determine current position
|
||||
var row = $(this).closest('tr');
|
||||
var y = $('#matrix tr').index(row);
|
||||
var col = $(this).closest('td');
|
||||
var x = row.children().index(col);
|
||||
|
||||
// Determine current direction
|
||||
var horizontal = (x != posX);
|
||||
|
||||
// Set current position
|
||||
posX = x;
|
||||
posY = y;
|
||||
|
||||
// Next input field
|
||||
var nextInput = null;
|
||||
|
||||
// Hanlde keys
|
||||
switch(event.keyCode)
|
||||
{
|
||||
case 37: // Left
|
||||
nextInput = getColumnInput(row, x-1);
|
||||
break;
|
||||
case 38: // Up
|
||||
nextInput = getRowInput(x, y-1);
|
||||
break;
|
||||
case 39: // Right
|
||||
nextInput = getColumnInput(row, x+1);
|
||||
break;
|
||||
case 40: // Down
|
||||
nextInput = getRowInput(x, y+1);
|
||||
break;
|
||||
default:
|
||||
// Only handy character input
|
||||
if(event.key.length != 1) {
|
||||
break;
|
||||
}
|
||||
|
||||
// Set new character
|
||||
$(this).val(event.key);
|
||||
|
||||
// Go to next input field
|
||||
if(horizontal) {
|
||||
nextInput = getColumnInput(row, x+1);
|
||||
}
|
||||
else {
|
||||
nextInput = getRowInput(x, y+1);
|
||||
}
|
||||
|
||||
event.preventDefault();
|
||||
break;
|
||||
}
|
||||
|
||||
// Select input field
|
||||
if(nextInput != null) {
|
||||
nextInput.focus();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* Get the input field of the column x of the given row.
|
||||
*/
|
||||
function getColumnInput(row, x)
|
||||
{
|
||||
nextCol = $('td', row)[x];
|
||||
if(nextCol != null) {
|
||||
return $('input:text', nextCol)[0];
|
||||
}
|
||||
else {
|
||||
// TODO get next number
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the input field of the column y of row x.
|
||||
*/
|
||||
function getRowInput(x, y)
|
||||
{
|
||||
nextRow = $('#matrix tr')[y];
|
||||
if(nextRow != null)
|
||||
{
|
||||
nextCol = $('td', nextRow)[x];
|
||||
if(nextCol != null) {
|
||||
return $('input:text', nextCol)[0];
|
||||
}
|
||||
}
|
||||
else {
|
||||
// TODO get nextnumber
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
</script>
|
||||
48
questtypes/crossword/html/submission.tpl
Normal file
48
questtypes/crossword/html/submission.tpl
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
<form method="post" class="crossword">
|
||||
<table>
|
||||
<tbody>
|
||||
<?php foreach(range(0, $maxY) as $y) : ?>
|
||||
<tr>
|
||||
<?php foreach(range(0, $maxX) as $x) : ?>
|
||||
<td>
|
||||
<?php if(array_key_exists($x, $matrix) && array_key_exists($y, $matrix[$x]) && !is_null($matrix[$x][$y])) : ?>
|
||||
<?php if(count($matrix[$x][$y]['indices']) > 0) : ?><span class="index"><?=implode('/',array_map(function($e) { return $e+1; }, $matrix[$x][$y]['indices']))?></span><?php endif ?>
|
||||
<input type="text" name="answers[<?=$x?>][<?=$y?>]" maxlength="1" size="1" disabled="disabled" style="background-color:<?=($matrix[$x][$y]['right']) ? 'green' : 'red'?>" value="<?=(!is_null($matrix[$x][$y]['answer'])) ? $matrix[$x][$y]['answer'] : ''?>" />
|
||||
<?php endif ?>
|
||||
</td>
|
||||
<?php endforeach ?>
|
||||
</tr>
|
||||
<?php endforeach ?>
|
||||
</tbody>
|
||||
</table>
|
||||
<ol>
|
||||
<?php foreach($words as &$word) : ?>
|
||||
<li>
|
||||
<?php if($word['vertical']) : ?>
|
||||
<?=_('vertical')?>:
|
||||
<?php else : ?>
|
||||
<?=_('horizontal')?>:
|
||||
<?php endif ?>
|
||||
<?=$word['question']?>
|
||||
</li>
|
||||
<?php endforeach ?>
|
||||
</ol>
|
||||
</form>
|
||||
<script type="text/javascript">
|
||||
$('input:text').bind("keyup", function(e) {
|
||||
var n = $("input:text").length;
|
||||
if(e.which == 8 || e.which == 46) {
|
||||
var nextIndex = $('input:text').index(this) - 1;
|
||||
var del = 1;
|
||||
}
|
||||
else {
|
||||
var nextIndex = $('input:text').index(this) + 1;
|
||||
}
|
||||
if(nextIndex < n) {
|
||||
$('input:text')[nextIndex].focus();
|
||||
if(del == 1) {
|
||||
$('input:text')[nextIndex].value = '';
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
Loading…
Add table
Add a link
Reference in a new issue