improved readability for crossword input field numbers
This commit is contained in:
commit
b9bca6e2c5
35 changed files with 21548 additions and 0 deletions
24
questtypes/choiceinput/ChoiceinputQuesttypeAgent.inc
Normal file
24
questtypes/choiceinput/ChoiceinputQuesttypeAgent.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 choosing between predefined input values.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class ChoiceinputQuesttypeAgent extends \hhu\z\QuesttypeAgent
|
||||
{
|
||||
}
|
||||
|
||||
?>
|
||||
157
questtypes/choiceinput/ChoiceinputQuesttypeController.inc
Normal file
157
questtypes/choiceinput/ChoiceinputQuesttypeController.inc
Normal file
|
|
@ -0,0 +1,157 @@
|
|||
<?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 ChoiceinputQuesttypeAgent for choosing between
|
||||
* predefined input values.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class ChoiceinputQuesttypeController extends \hhu\z\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 lists
|
||||
$choiceLists = $this->Choiceinput->getChoiceinputLists($quest['id']);
|
||||
|
||||
// Save answers
|
||||
foreach($choiceLists as &$list)
|
||||
{
|
||||
$pos = intval($list['number']) - 1;
|
||||
$answer = (array_key_exists($pos, $answers)) ? $answers[$pos] : null;
|
||||
$this->Choiceinput->setCharacterSubmission($list['id'], $character['id'], $answer);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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
|
||||
* @return boolean True/false for a right/wrong answer or null for moderator evaluation
|
||||
*/
|
||||
public function matchAnswersOfCharacter($seminary, $questgroup, $quest, $character, $answers)
|
||||
{
|
||||
// Get lists
|
||||
$choiceLists = $this->Choiceinput->getChoiceinputLists($quest['id']);
|
||||
|
||||
// Match lists with user answers
|
||||
foreach($choiceLists as $i => &$list)
|
||||
{
|
||||
if(!array_key_exists($i, $answers)) {
|
||||
return false;
|
||||
}
|
||||
if($list['questtypes_choiceinput_choice_id'] != $answers[$i]) {
|
||||
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 Task
|
||||
$task = $this->Choiceinput->getChoiceinputQuest($quest['id']);
|
||||
|
||||
// Process text
|
||||
$textParts = preg_split('/(\$\$)/', ' '.$task['text'].' ');
|
||||
|
||||
// Get lists
|
||||
$choiceLists = $this->Choiceinput->getChoiceinputLists($quest['id']);
|
||||
foreach($choiceLists as &$list) {
|
||||
$list['values'] = $this->Choiceinput->getChoiceinputChoices($list['id']);
|
||||
}
|
||||
|
||||
// Get Character answers
|
||||
if($this->request->getGetParam('show-answer') == 'true')
|
||||
{
|
||||
foreach($choiceLists as &$list) {
|
||||
$list['answer'] = $this->Choiceinput->getCharacterSubmission($list['id'], $character['id']);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Pass data to view
|
||||
$this->set('texts', $textParts);
|
||||
$this->set('choiceLists', $choiceLists);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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 Task
|
||||
$task = $this->Choiceinput->getChoiceinputQuest($quest['id']);
|
||||
|
||||
// Process text
|
||||
$textParts = preg_split('/(\$\$)/', ' '.$task['text'].' ');
|
||||
|
||||
// Get lists
|
||||
$choiceLists = $this->Choiceinput->getChoiceinputLists($quest['id']);
|
||||
foreach($choiceLists as &$list)
|
||||
{
|
||||
$list['values'] = $this->Choiceinput->getChoiceinputChoices($list['id']);
|
||||
$list['answer'] = $this->Choiceinput->getCharacterSubmission($list['id'], $character['id']);
|
||||
$list['right'] = ($list['questtypes_choiceinput_choice_id'] == $list['answer']);
|
||||
}
|
||||
|
||||
|
||||
// Pass data to view
|
||||
$this->set('texts', $textParts);
|
||||
$this->set('choiceLists', $choiceLists);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
153
questtypes/choiceinput/ChoiceinputQuesttypeModel.inc
Normal file
153
questtypes/choiceinput/ChoiceinputQuesttypeModel.inc
Normal file
|
|
@ -0,0 +1,153 @@
|
|||
<?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 ChoiceinputQuesttypeAgent for choosing between
|
||||
* predefined input values.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class ChoiceinputQuesttypeModel extends \hhu\z\QuesttypeModel
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get choiceinput-text for a Quest.
|
||||
*
|
||||
* @param int $questId ID of Quest
|
||||
* @return array Choiceinput-text
|
||||
*/
|
||||
public function getChoiceinputQuest($questId)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT text '.
|
||||
'FROM questtypes_choiceinput '.
|
||||
'WHERE quest_id = ?',
|
||||
'i',
|
||||
$questId
|
||||
);
|
||||
if(!empty($data)) {
|
||||
return $data[0];
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get all lists of input values for a choiceinput-text.
|
||||
*
|
||||
* @param int $questId ID of Quest
|
||||
* @return array List
|
||||
*/
|
||||
public function getChoiceinputLists($questId)
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT id, number, questtypes_choiceinput_choice_id '.
|
||||
'FROM questtypes_choiceinput_lists '.
|
||||
'WHERE questtypes_choiceinput_quest_id = ? '.
|
||||
'ORDER BY number ASC',
|
||||
'i',
|
||||
$questId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the list of values for a choiceinput-list.
|
||||
*
|
||||
* @param int $listId ID of list
|
||||
* @return array Input values
|
||||
*/
|
||||
public function getChoiceinputChoices($listId)
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT id, pos, text '.
|
||||
'FROM questtypes_choiceinput_choices '.
|
||||
'WHERE questtypes_choiceinput_list_id = ? '.
|
||||
'ORDER BY pos ASC',
|
||||
'i',
|
||||
$listId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Save Character’s submitted answer for one choiceinput-list.
|
||||
*
|
||||
* @param int $regexId ID of list
|
||||
* @param int $characterId ID of Character
|
||||
* @param string $answer Submitted answer for this list
|
||||
*/
|
||||
public function setCharacterSubmission($listId, $characterId, $answer)
|
||||
{
|
||||
if(is_null($answer))
|
||||
{
|
||||
$this->db->query(
|
||||
'INSERT INTO questtypes_choiceinput_lists_characters '.
|
||||
'(questtypes_choiceinput_list_id, character_id, questtypes_choiceinput_choice_id) '.
|
||||
'VALUES '.
|
||||
'(?, ?, NULL) '.
|
||||
'ON DUPLICATE KEY UPDATE '.
|
||||
'questtypes_choiceinput_choice_id = NULL',
|
||||
'ii',
|
||||
$listId, $characterId
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->db->query(
|
||||
'INSERT INTO questtypes_choiceinput_lists_characters '.
|
||||
'(questtypes_choiceinput_list_id, character_id, questtypes_choiceinput_choice_id) '.
|
||||
'VALUES '.
|
||||
'(?, ?, ?) '.
|
||||
'ON DUPLICATE KEY UPDATE '.
|
||||
'questtypes_choiceinput_choice_id = ?',
|
||||
'iiii',
|
||||
$listId, $characterId, $answer, $answer
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get answer of one choiceinput-list submitted by Character.
|
||||
*
|
||||
* @param int $regexId ID of list
|
||||
* @param int $characterId ID of Character
|
||||
* @return int Submitted answer for this list or null
|
||||
*/
|
||||
public function getCharacterSubmission($listId, $characterId)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT questtypes_choiceinput_choice_id '.
|
||||
'FROM questtypes_choiceinput_lists_characters '.
|
||||
'WHERE questtypes_choiceinput_list_id = ? AND character_id = ? ',
|
||||
'ii',
|
||||
$listId, $characterId
|
||||
);
|
||||
if(!empty($data)) {
|
||||
return $data[0]['questtypes_choiceinput_choice_id'];
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
15
questtypes/choiceinput/html/quest.tpl
Normal file
15
questtypes/choiceinput/html/quest.tpl
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
<form method="post">
|
||||
<?php foreach($texts as $i => &$text) : ?>
|
||||
<?php if($i > 0) : ?>
|
||||
<select name="answers[<?=$i-1?>]">
|
||||
<?php foreach($choiceLists[$i-1]['values'] as &$choice) : ?>
|
||||
<option value="<?=$choice['id']?>" <?php if(array_key_exists('answer', $choiceLists[$i-1]) && $choiceLists[$i-1] == $choice['id']) : ?>selected="selected"<?php endif ?>><?=$choice['text']?></option>
|
||||
<?php endforeach ?>
|
||||
</select>
|
||||
<?php endif ?>
|
||||
<?=\hhu\z\Utils::t($text)?>
|
||||
<?php endforeach ?>
|
||||
|
||||
<br /><br />
|
||||
<input type="submit" name="submit" value="<?=_('solve')?>" />
|
||||
</form>
|
||||
12
questtypes/choiceinput/html/submission.tpl
Normal file
12
questtypes/choiceinput/html/submission.tpl
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
<form method="post">
|
||||
<?php foreach($texts as $i => &$text) : ?>
|
||||
<?php if($i > 0) : ?>
|
||||
<select name="answers[<?=$i-1?>]" disabled="disabled">
|
||||
<?php foreach($choiceLists[$i-1]['values'] as &$choice) : ?>
|
||||
<option value="<?=$choice['id']?>" <?php if(array_key_exists('answer', $choiceLists[$i-1]) && $choiceLists[$i-1]['answer'] == $choice['id']) : ?>selected="selected"<?php endif ?>><?=$choice['text']?></option>
|
||||
<?php endforeach ?>
|
||||
</select>
|
||||
<?php endif ?>
|
||||
<?=\hhu\z\Utils::t($text)?>
|
||||
<?php endforeach ?>
|
||||
</form>
|
||||
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\QuesttypeAgent
|
||||
{
|
||||
}
|
||||
|
||||
?>
|
||||
352
questtypes/crossword/CrosswordQuesttypeController.inc
Normal file
352
questtypes/crossword/CrosswordQuesttypeController.inc
Normal file
|
|
@ -0,0 +1,352 @@
|
|||
<?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\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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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
|
||||
* @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') {
|
||||
$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;
|
||||
var_dump($matrix[$x][$y]['indices']);
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
93
questtypes/crossword/CrosswordQuesttypeModel.inc
Normal file
93
questtypes/crossword/CrosswordQuesttypeModel.inc
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
<?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\QuesttypeModel
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
49
questtypes/crossword/html/quest.tpl
Normal file
49
questtypes/crossword/html/quest.tpl
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
<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" 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">
|
||||
$('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>
|
||||
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>
|
||||
24
questtypes/dragndrop/DragndropQuesttypeAgent.inc
Normal file
24
questtypes/dragndrop/DragndropQuesttypeAgent.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 Drag&Drop.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class DragndropQuesttypeAgent extends \hhu\z\QuesttypeAgent
|
||||
{
|
||||
}
|
||||
|
||||
?>
|
||||
199
questtypes/dragndrop/DragndropQuesttypeController.inc
Normal file
199
questtypes/dragndrop/DragndropQuesttypeController.inc
Normal file
|
|
@ -0,0 +1,199 @@
|
|||
<?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 DragndropQuesttypeAgent for Drag&Drop.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class DragndropQuesttypeController extends \hhu\z\QuesttypeController
|
||||
{
|
||||
/**
|
||||
* Required models
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $models = array('media');
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 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 Drag&Drop field
|
||||
$dndField = $this->Dragndrop->getDragndrop($quest['id']);
|
||||
|
||||
// Get Drops
|
||||
$drops = $this->Dragndrop->getDrops($dndField['quest_id']);
|
||||
|
||||
// Save user answers
|
||||
foreach($drops as &$drop)
|
||||
{
|
||||
// Determine user answer
|
||||
$answer = null;
|
||||
if(array_key_exists($drop['id'], $answers) && !empty($answers[$drop['id']]))
|
||||
{
|
||||
$a = intval(substr($answers[$drop['id']], 4));
|
||||
if($a !== false && $a > 0) {
|
||||
$answer = $a;
|
||||
}
|
||||
}
|
||||
|
||||
// Update database record
|
||||
$this->Dragndrop->setCharacterSubmission($drop['id'], $character['id'], $answer);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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
|
||||
* @return boolean True/false for a right/wrong answer or null for moderator evaluation
|
||||
*/
|
||||
public function matchAnswersOfCharacter($seminary, $questgroup, $quest, $character, $answers)
|
||||
{
|
||||
// Get Drag&Drop field
|
||||
$dndField = $this->Dragndrop->getDragndrop($quest['id']);
|
||||
|
||||
// Get Drops
|
||||
$drops = $this->Dragndrop->getDrops($dndField['quest_id']);
|
||||
|
||||
// Match drops with user answers
|
||||
foreach($drops as &$drop)
|
||||
{
|
||||
if(!array_key_exists($drop['id'], $answers) || intval(substr($answers[$drop['id']], 4)) !== $drop['questtypes_dragndrop_drag_id']) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Set status
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Action: quest.
|
||||
*
|
||||
* Display a text with input fields and evaluate if user input
|
||||
* matches with stored regular expressions.
|
||||
*
|
||||
* @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 Drag&Drop field
|
||||
$dndField = $this->Dragndrop->getDragndrop($quest['id']);
|
||||
$dndField['media'] = $this->Media->getSeminaryMediaById($dndField['questmedia_id']);
|
||||
|
||||
// Get Drags
|
||||
$drags = array();
|
||||
$dragsByIndex = $this->Dragndrop->getDrags($dndField['quest_id']);
|
||||
foreach($dragsByIndex as &$drag) {
|
||||
$drag['media'] = $this->Media->getSeminaryMediaById($drag['questmedia_id']);
|
||||
$drags[$drag['id']] = $drag;
|
||||
}
|
||||
|
||||
// Get Drops
|
||||
$drops = $this->Dragndrop->getDrops($dndField['quest_id']);
|
||||
|
||||
// Get Character answers
|
||||
if($this->request->getGetParam('show-answer') == 'true')
|
||||
{
|
||||
foreach($drops as &$drop)
|
||||
{
|
||||
$drop['answer'] = $this->Dragndrop->getCharacterSubmission($drop['id'], $character['id']);
|
||||
if(!is_null($drop['answer']))
|
||||
{
|
||||
$drop['answer'] = $drags[$drop['answer']];
|
||||
unset($drags[$drop['answer']['id']]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Pass data to view
|
||||
$this->set('seminary', $seminary);
|
||||
$this->set('field', $dndField);
|
||||
$this->set('drops', $drops);
|
||||
$this->set('drags', $drags);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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 Drag&Drop field
|
||||
$dndField = $this->Dragndrop->getDragndrop($quest['id']);
|
||||
$dndField['media'] = $this->Media->getSeminaryMediaById($dndField['questmedia_id']);
|
||||
|
||||
// Get Drags
|
||||
$drags = array();
|
||||
$dragsByIndex = $this->Dragndrop->getDrags($dndField['quest_id']);
|
||||
foreach($dragsByIndex as &$drag) {
|
||||
$drag['media'] = $this->Media->getSeminaryMediaById($drag['questmedia_id']);
|
||||
$drags[$drag['id']] = $drag;
|
||||
}
|
||||
|
||||
// Get Drops
|
||||
$drops = $this->Dragndrop->getDrops($dndField['quest_id']);
|
||||
|
||||
// Get Character answers
|
||||
foreach($drops as &$drop)
|
||||
{
|
||||
$drop['answer'] = $this->Dragndrop->getCharacterSubmission($drop['id'], $character['id']);
|
||||
if(!is_null($drop['answer']))
|
||||
{
|
||||
$drop['answer'] = $drags[$drop['answer']];
|
||||
unset($drags[$drop['answer']['id']]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Pass data to view
|
||||
$this->set('seminary', $seminary);
|
||||
$this->set('field', $dndField);
|
||||
$this->set('drops', $drops);
|
||||
$this->set('drags', $drags);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
146
questtypes/dragndrop/DragndropQuesttypeModel.inc
Normal file
146
questtypes/dragndrop/DragndropQuesttypeModel.inc
Normal file
|
|
@ -0,0 +1,146 @@
|
|||
<?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 DragndropQuesttypeAgent for Drag&Drop.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class DragndropQuesttypeModel extends \hhu\z\QuesttypeModel
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get Drag&Drop-field.
|
||||
*
|
||||
* @param int $questId ID of Quest
|
||||
* @return array Drag&Drop-field
|
||||
*/
|
||||
public function getDragndrop($questId)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT quest_id, questmedia_id, width, height '.
|
||||
'FROM questtypes_dragndrop '.
|
||||
'WHERE quest_id = ?',
|
||||
'i',
|
||||
$questId
|
||||
);
|
||||
if(!empty($data)) {
|
||||
return $data[0];
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Drop-items.
|
||||
*
|
||||
* @param int $dragndropId ID of Drag&Drop-field
|
||||
* @return array Drop-items
|
||||
*/
|
||||
public function getDrops($dragndropId)
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT id, top, `left`, width, height, questtypes_dragndrop_drag_id '.
|
||||
'FROM questtypes_dragndrop_drops '.
|
||||
'WHERE questtypes_dragndrop_id = ?',
|
||||
'i',
|
||||
$dragndropId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Drag-items.
|
||||
*
|
||||
* @param int $dragndropId ID of Drag&Drop-field
|
||||
* @return array Drag-items
|
||||
*/
|
||||
public function getDrags($dragndropId)
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT id, questmedia_id '.
|
||||
'FROM questtypes_dragndrop_drags '.
|
||||
'WHERE questtypes_dragndrop_id = ?',
|
||||
'i',
|
||||
$dragndropId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Save Character’s submitted answer for one Drop-field.
|
||||
*
|
||||
* @param int $dropId ID of Drop-field
|
||||
* @param int $characterId ID of Character
|
||||
* @param string $answer Submitted Drag-field-ID for this field
|
||||
*/
|
||||
public function setCharacterSubmission($dropId, $characterId, $answer)
|
||||
{
|
||||
if(is_null($answer))
|
||||
{
|
||||
$this->db->query(
|
||||
'DELETE FROM questtypes_dragndrop_drops_characters '.
|
||||
'WHERE questtypes_dragndrop_drop_id = ? AND character_id = ?',
|
||||
'ii',
|
||||
$dropId, $characterId
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->db->query(
|
||||
'INSERT INTO questtypes_dragndrop_drops_characters '.
|
||||
'(questtypes_dragndrop_drop_id, character_id, questtypes_dragndrop_drag_id) '.
|
||||
'VALUES '.
|
||||
'(?, ?, ?) '.
|
||||
'ON DUPLICATE KEY UPDATE '.
|
||||
'questtypes_dragndrop_drag_id = ?',
|
||||
'iiii',
|
||||
$dropId, $characterId, $answer, $answer
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Character’s saved answer for one Drop-field.
|
||||
*
|
||||
* @param int $dropId ID of Drop-field
|
||||
* @param int $characterId ID of Character
|
||||
* @return int ID of Drag-field or null
|
||||
*/
|
||||
public function getCharacterSubmission($dropId, $characterId)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT questtypes_dragndrop_drag_id '.
|
||||
'FROM questtypes_dragndrop_drops_characters '.
|
||||
'WHERE questtypes_dragndrop_drop_id = ? AND character_id = ?',
|
||||
'ii',
|
||||
$dropId, $characterId
|
||||
);
|
||||
if(!empty($data)) {
|
||||
return $data[0]['questtypes_dragndrop_drag_id'];
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
17
questtypes/dragndrop/html/quest.tpl
Normal file
17
questtypes/dragndrop/html/quest.tpl
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
<form method="post">
|
||||
<div id="dropZone" style="width:<?=$field['width']?>px; height:<?=$field['height']?>px; background-image:url('<?=$linker->link(array('media','seminary',$seminary['url'],$field['media']['url']))?>')">
|
||||
<?php foreach($drops as &$drop) : ?>
|
||||
<div id="drop<?=$drop['id']?>" ondragenter="onDragEnter(event)" ondragover="onDragOver(event)" ondragleave="onDragLeave(event)" ondrop="onDrop(event)" style="position:absolute; width:<?=$drop['width']?>px; height:<?=$drop['height']?>px; margin:<?=$drop['top']?>px 0 0 <?=$drop['left']?>px;"><?php if(array_key_exists('answer', $drop) && !is_null($drop['answer'])) : ?><img id="drag<?=$drop['answer']['id']?>" draggable="true" ondragstart="onDragStart(event)" ondragend="onDragEnd(event)" src="<?=$linker->link(array('media','index',$seminary['url'],$drop['answer']['media']['url']))?>" /><?php endif ?></div>
|
||||
<input type="hidden" id="dnd_drop<?=$drop['id']?>" name="answers[<?=$drop['id']?>]" value="<?=(!is_null($drop['answer'])) ? 'drag'.$drop['answer']['id'] : null ?>" />
|
||||
<?php endforeach ?>
|
||||
</div>
|
||||
|
||||
<div id="dragZone" ondragenter="onDragEnter(event)" ondragover="onDragOver(event)" ondragleave="onDragLeave(event)" ondrop="onDrop(event, false)" style="width:100%; min-height:5em;">
|
||||
<?php foreach($drags as &$drag) : ?>
|
||||
<img id="drag<?=$drag['id']?>" draggable="true" ondragstart="onDragStart(event)" ondragend="onDragEnd(event)" src="<?=$linker->link(array('media','seminary',$seminary['url'],$drag['media']['url']))?>" />
|
||||
<?php endforeach ?>
|
||||
</div>
|
||||
|
||||
<br />
|
||||
<input type="submit" name="submit" value="<?=_('solve')?>" />
|
||||
</form>
|
||||
15
questtypes/dragndrop/html/submission.tpl
Normal file
15
questtypes/dragndrop/html/submission.tpl
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
<div style="width:<?=$field['width']?>px; height:<?=$field['height']?>px; background-image:url('<?=$linker->link(array('media','seminary',$seminary['url'],$field['media']['url']))?>')">
|
||||
<?php foreach($drops as &$drop) : ?>
|
||||
<div id="drop<?=$drop['id']?>" style="position:absolute; width:<?=$drop['width']?>px; height:<?=$drop['height']?>px; margin:<?=$drop['top']?>px 0 0 <?=$drop['left']?>px;">
|
||||
<?php if(!is_null($drop['answer'])) : ?>
|
||||
<img id="drag<?=$drop['answer']['id']?>" src="<?=$linker->link(array('media','seminary',$seminary['url'],$drop['answer']['media']['url']))?>" />
|
||||
<?php endif ?>
|
||||
</div>
|
||||
<?php endforeach ?>
|
||||
</div>
|
||||
|
||||
<div style="width:100%; min-height:5em;">
|
||||
<?php foreach($drags as &$drag) : ?>
|
||||
<img id="drag<?=$drag['id']?>" src="<?=$linker->link(array('media','seminary',$seminary['url'],$drag['media']['url']))?>" />
|
||||
<?php endforeach ?>
|
||||
</div>
|
||||
24
questtypes/dummy/DummyQuesttypeAgent.inc
Normal file
24
questtypes/dummy/DummyQuesttypeAgent.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;
|
||||
|
||||
|
||||
/**
|
||||
* Dummy-QuesttypeAgent for testing basic QuesttypeAgent-functionality.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class DummyQuesttypeAgent extends \hhu\z\QuesttypeAgent
|
||||
{
|
||||
}
|
||||
|
||||
?>
|
||||
93
questtypes/dummy/DummyQuesttypeController.inc
Normal file
93
questtypes/dummy/DummyQuesttypeController.inc
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
<?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 Dummy-QuesttypeAgent for testing basic
|
||||
* QuesttypeAgent-functionality.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class DummyQuesttypeController extends \hhu\z\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)
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
// Set status
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Action: quest.
|
||||
*
|
||||
* Show the task of 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 Exception $exception Character submission exception
|
||||
*/
|
||||
public function quest($seminary, $questgroup, $quest, $character, $exception)
|
||||
{
|
||||
// Nothing to do
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
// Nothing to do
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
25
questtypes/dummy/DummyQuesttypeModel.inc
Normal file
25
questtypes/dummy/DummyQuesttypeModel.inc
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
<?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 Dummy-QuesttypeAgent for testing basic
|
||||
* QuesttypeAgent-functionality.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class DummyQuesttypeModel extends \hhu\z\QuesttypeModel
|
||||
{
|
||||
}
|
||||
|
||||
?>
|
||||
4
questtypes/dummy/html/quest.tpl
Normal file
4
questtypes/dummy/html/quest.tpl
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
<form method="post">
|
||||
<input type="submit" name="submit" value="richtige Antwort" />
|
||||
<input type="submit" name="wrong" value="falsche Antwort" />
|
||||
</form>
|
||||
0
questtypes/dummy/html/submission.tpl
Normal file
0
questtypes/dummy/html/submission.tpl
Normal file
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue