issue fix: dynamic images for quest groups
This commit is contained in:
commit
207b735df5
187 changed files with 15803 additions and 0 deletions
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
|
||||
{
|
||||
}
|
||||
|
||||
?>
|
||||
84
questtypes/dummy/DummyQuesttypeController.inc
Normal file
84
questtypes/dummy/DummyQuesttypeController.inc
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
<?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 int $questId ID of Quest to save answers for
|
||||
* @param int $characterId ID of Character to save answers of
|
||||
* @param array $answers Character answers for the Quest
|
||||
*/
|
||||
public function saveAnswersOfCharacter($questId, $characterId, $answers)
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if answers of a Character for a Quest match the correct ones.
|
||||
*
|
||||
* @param int $questId ID of Quest to match answers for
|
||||
* @param int $characterId ID of Character to match answers of
|
||||
* @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($questId, $characterId, $answers)
|
||||
{
|
||||
// Set status
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Action: quest.
|
||||
*
|
||||
* Show the task of a Quest.
|
||||
*
|
||||
* @param int $questId ID of Quest to show
|
||||
* @param int $characterId ID of Character
|
||||
*/
|
||||
public function quest($questId, $characterId)
|
||||
{
|
||||
// Nothing to do
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Action: submission.
|
||||
*
|
||||
* Show the submission of a Character for a Quest.
|
||||
*
|
||||
* @param int $questId ID of Quest to show submission for
|
||||
* @param int $characterId ID of Character to show submission of
|
||||
*/
|
||||
public function submission($questId, $characterId)
|
||||
{
|
||||
// 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
24
questtypes/multiplechoice/MultiplechoiceQuesttypeAgent.inc
Normal file
24
questtypes/multiplechoice/MultiplechoiceQuesttypeAgent.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 multiple choice.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class MultiplechoiceQuesttypeAgent extends \hhu\z\QuesttypeAgent
|
||||
{
|
||||
}
|
||||
|
||||
?>
|
||||
130
questtypes/multiplechoice/MultiplechoiceQuesttypeController.inc
Normal file
130
questtypes/multiplechoice/MultiplechoiceQuesttypeController.inc
Normal file
|
|
@ -0,0 +1,130 @@
|
|||
<?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 MultiplechoiceQuesttypeAgent multiple choice.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class MultiplechoiceQuesttypeController extends \hhu\z\QuesttypeController
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Save the answers of a Character for a Quest.
|
||||
*
|
||||
* @param int $questId ID of Quest to save answers for
|
||||
* @param int $characterId ID of Character to save answers of
|
||||
* @param array $answers Character answers for the Quest
|
||||
*/
|
||||
public function saveAnswersOfCharacter($questId, $characterId, $answers)
|
||||
{
|
||||
// Get questions
|
||||
$questions = $this->Multiplechoice->getQuestionsOfQuest($questId);
|
||||
|
||||
// Save answers
|
||||
foreach($questions as &$question)
|
||||
{
|
||||
$answer = (array_key_exists(intval($question['pos'])-1, $answers)) ? true : false;
|
||||
$this->Multiplechoice->setCharacterSubmission($question['id'], $characterId, $answer);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if answers of a Character for a Quest match the correct ones.
|
||||
*
|
||||
* @param int $questId ID of Quest to match answers for
|
||||
* @param int $characterId ID of Character to match answers of
|
||||
* @return boolean True/false for a right/wrong answer or null for moderator evaluation
|
||||
*/
|
||||
public function matchAnswersOfCharacter($questId, $characterId, $answers)
|
||||
{
|
||||
// Get right answers
|
||||
$tickQuestions = $this->Multiplechoice->getTickQuestionsOfQuest($questId);
|
||||
|
||||
// Match tick questions with user answers
|
||||
$allSolved = true;
|
||||
foreach($tickQuestions as &$tickQuestion)
|
||||
{
|
||||
$pos = intval($tickQuestion['pos'])-1;
|
||||
if(!array_key_exists($pos, $answers) || $answers[$pos] != 'true')
|
||||
{
|
||||
$allSolved = false;
|
||||
break;
|
||||
}
|
||||
else {
|
||||
unset($answers[$pos]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Return status
|
||||
return ($allSolved && count($answers) == 0);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Action: quest.
|
||||
*
|
||||
* Display questions with a checkbox to let the user choose the
|
||||
* right ones.
|
||||
*
|
||||
* @param int $questId ID of Quest to show
|
||||
* @param int $characterId ID of Character
|
||||
*/
|
||||
public function quest($questId, $characterId)
|
||||
{
|
||||
// Get questions
|
||||
$questions = $this->Multiplechoice->getQuestionsOfQuest($questId);
|
||||
foreach($questions as &$question) {
|
||||
$question['answer'] = $this->Multiplechoice->getCharacterSubmission($question['id'], $characterId);
|
||||
}
|
||||
|
||||
// Has Character already solved Quest?
|
||||
$solved = $this->Quests->hasCharacterSolvedQuest($questId, $characterId);
|
||||
|
||||
|
||||
// Pass data to view
|
||||
$this->set('questions', $questions);
|
||||
$this->set('solved', $solved);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Action: submission.
|
||||
*
|
||||
* Show the submission of a Character for a Quest.
|
||||
*
|
||||
* @param int $questId ID of Quest to show submission for
|
||||
* @param int $characterId ID of Character to show submission of
|
||||
*/
|
||||
public function submission($questId, $characterId)
|
||||
{
|
||||
// Get questions
|
||||
$questions = $this->Multiplechoice->getQuestionsOfQuest($questId);
|
||||
foreach($questions as &$question) {
|
||||
$question['answer'] = $this->Multiplechoice->getCharacterSubmission($question['id'], $characterId);
|
||||
}
|
||||
|
||||
|
||||
// Pass data to view
|
||||
$this->set('questions', $questions);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
111
questtypes/multiplechoice/MultiplechoiceQuesttypeModel.inc
Normal file
111
questtypes/multiplechoice/MultiplechoiceQuesttypeModel.inc
Normal file
|
|
@ -0,0 +1,111 @@
|
|||
<?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 MultiplechoiceQuesttypeAgent for multiple choice.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class MultiplechoiceQuesttypeModel extends \hhu\z\QuesttypeModel
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get all multiple choice questions of a Quest.
|
||||
*
|
||||
* @param int $questId ID of Quest
|
||||
* @return array Multiple choice questions
|
||||
*/
|
||||
public function getQuestionsOfQuest($questId)
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT id, pos, question, tick '.
|
||||
'FROM questtypes_multiplechoice '.
|
||||
'WHERE quest_id = ?',
|
||||
'i',
|
||||
$questId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get all multiple choice questions of a Quest that should be
|
||||
* ticked.
|
||||
*
|
||||
* @param int $questId ID of Quest
|
||||
* @return array Multiple choice questions that should be ticked
|
||||
*/
|
||||
public function getTickQuestionsOfQuest($questId)
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT id, question, tick, pos '.
|
||||
'FROM questtypes_multiplechoice '.
|
||||
'WHERE quest_id = ? AND tick = True',
|
||||
'i',
|
||||
$questId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Save Character’s submitted answer for one option.
|
||||
*
|
||||
* @param int $multipleChoiceId ID of multiple choice option
|
||||
* @param int $characterId ID of Character
|
||||
* @param boolean $answer Submitted answer for this option
|
||||
*/
|
||||
public function setCharacterSubmission($multipleChoiceId, $characterId, $answer)
|
||||
{
|
||||
$this->db->query(
|
||||
'INSERT INTO questtypes_multiplechoice_characters '.
|
||||
'(questtypes_multiplechoice_id, character_id, ticked) '.
|
||||
'VALUES '.
|
||||
'(?, ?, ?) '.
|
||||
'ON DUPLICATE KEY UPDATE '.
|
||||
'ticked = ?',
|
||||
'iiii',
|
||||
$multipleChoiceId, $characterId, $answer, $answer
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get answer of one option submitted by Character.
|
||||
*
|
||||
* @param int $multipleChoiceId ID of multiple choice option
|
||||
* @param int $characterId ID of Character
|
||||
* @return boolean Submitted answer of Character or false
|
||||
*/
|
||||
public function getCharacterSubmission($multipleChoiscId, $characterId)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT ticked '.
|
||||
'FROM questtypes_multiplechoice_characters '.
|
||||
'WHERE questtypes_multiplechoice_id = ? AND character_id = ? ',
|
||||
'ii',
|
||||
$multipleChoiscId, $characterId
|
||||
);
|
||||
if(!empty($data)) {
|
||||
return $data[0]['ticked'];
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
11
questtypes/multiplechoice/html/quest.tpl
Normal file
11
questtypes/multiplechoice/html/quest.tpl
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<form method="post">
|
||||
<ol>
|
||||
<?php foreach($questions as $i => &$question) : ?>
|
||||
<li>
|
||||
<input type="checkbox" id="answers[<?=$i?>]" name="answers[<?=$i?>]" value="true" <?=($question['answer']) ? 'checked="checked"' : '' ?> <?=($solved) ? 'disabled="disabled"' : '' ?>/>
|
||||
<label for="answers[<?=$i?>]"><?=\hhu\z\Utils::t($question['question'])?></label>
|
||||
</li>
|
||||
<?php endforeach ?>
|
||||
</ol>
|
||||
<input type="submit" name="submit" value="<?=_('solve')?>" <?=($solved) ? 'disabled="disabled"' : '' ?> />
|
||||
</form>
|
||||
9
questtypes/multiplechoice/html/submission.tpl
Normal file
9
questtypes/multiplechoice/html/submission.tpl
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
<ul>
|
||||
<?php foreach($questions as &$question) : ?>
|
||||
<li>
|
||||
<?php if($question['answer']) : ?>☑<?php else : ?>☐<?php endif ?>
|
||||
<?php if($question['answer'] == $question['tick']) : ?>✓<?php else : ?>×<?php endif ?>
|
||||
<?=$question['question']?>
|
||||
</li>
|
||||
<?php endforeach ?>
|
||||
</ul>
|
||||
24
questtypes/submit/SubmitQuesttypeAgent.inc
Normal file
24
questtypes/submit/SubmitQuesttypeAgent.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 submitting.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class SubmitQuesttypeAgent extends \hhu\z\QuesttypeAgent
|
||||
{
|
||||
}
|
||||
|
||||
?>
|
||||
121
questtypes/submit/SubmitQuesttypeController.inc
Normal file
121
questtypes/submit/SubmitQuesttypeController.inc
Normal file
|
|
@ -0,0 +1,121 @@
|
|||
<?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 SubmitQuesttypeAgent for a submit task.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class SubmitQuesttypeController extends \hhu\z\QuesttypeController
|
||||
{
|
||||
/**
|
||||
* Required models
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $models = array('quests');
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Save the answers of a Character for a Quest.
|
||||
*
|
||||
* @param int $questId ID of Quest to save answers for
|
||||
* @param int $characterId ID of Character to save answers of
|
||||
* @param array $answers Character answers for the Quest
|
||||
*/
|
||||
public function saveAnswersOfCharacter($questId, $characterId, $answers)
|
||||
{
|
||||
// Get already submitted answer
|
||||
$characterSubmission = $this->Submit->getCharacterSubmission($questId, $characterId);
|
||||
|
||||
// Save answer
|
||||
if(is_null($characterSubmission) && array_key_exists(0, $answers)) {
|
||||
$this->Submit->setCharacterSubmission($questId, $characterId, $answers[0]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if answers of a Character for a Quest match the correct ones.
|
||||
*
|
||||
* @param int $questId ID of Quest to match answers for
|
||||
* @param int $characterId ID of Character to match answers of
|
||||
* @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($questId, $characterId, $answers)
|
||||
{
|
||||
// A moderator has to evaluate the answer
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Action: quest.
|
||||
*
|
||||
* Display a big textbox to let the user enter a text that has
|
||||
* to be evaluated by a moderator.
|
||||
*
|
||||
* @param int $questId ID of Quest to show
|
||||
* @param int $characterId ID of Character
|
||||
*/
|
||||
public function quest($questId, $characterId)
|
||||
{
|
||||
// Answer (Submission)
|
||||
$characterSubmission = $this->Submit->getCharacterSubmission($questId, $characterId);
|
||||
|
||||
// Wordcount
|
||||
$wordcount = 0;
|
||||
if(!is_null($characterSubmission)) {
|
||||
$wordcount = count(preg_split('/\s+/', $characterSubmission['text']));
|
||||
}
|
||||
|
||||
// Has Character already solved Quest?
|
||||
$solved = $this->Quests->hasCharacterSolvedQuest($questId, $characterId);
|
||||
|
||||
|
||||
// Pass data to view
|
||||
$this->set('submission', $characterSubmission);
|
||||
$this->set('wordcount', $wordcount);
|
||||
$this->set('solved', $solved);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Action: submission.
|
||||
*
|
||||
* Show the submission of a Character for a Quest.
|
||||
*
|
||||
* @param int $questId ID of Quest to show submission for
|
||||
* @param int $characterId ID of Character to show submission of
|
||||
*/
|
||||
public function submission($questId, $characterId)
|
||||
{
|
||||
// Get Character submission
|
||||
$submission = $this->Submit->getCharacterSubmission($questId, $characterId);
|
||||
|
||||
// Status
|
||||
$solved = $this->Quests->hasCharacterSolvedQuest($questId, $characterId);
|
||||
|
||||
|
||||
// Pass data to view
|
||||
$this->set('submission', $submission);
|
||||
$this->set('solved', $solved);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
72
questtypes/submit/SubmitQuesttypeModel.inc
Normal file
72
questtypes/submit/SubmitQuesttypeModel.inc
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
<?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 SubmitQuesttypeAgent for a submit task.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class SubmitQuesttypeModel extends \hhu\z\QuesttypeModel
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Save Character’s submitted text.
|
||||
*
|
||||
* @param int $questId ID of Quest
|
||||
* @param int $characterId ID of Character
|
||||
* @param string $text Submitted text
|
||||
*/
|
||||
public function setCharacterSubmission($questId, $characterId, $text)
|
||||
{
|
||||
$this->db->query(
|
||||
'INSERT INTO questtypes_submit_characters '.
|
||||
'(quest_id, character_id, text) '.
|
||||
'VALUES '.
|
||||
'(?, ?, ?) ',
|
||||
'iis',
|
||||
$questId, $characterId, $text
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get text submitted by Character.
|
||||
*
|
||||
* @param int $questId ID of Quest
|
||||
* @param int $characterId ID of Character
|
||||
* @return array Text submitted by Character or NULL
|
||||
*/
|
||||
public function getCharacterSubmission($questId, $characterId)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT created, text '.
|
||||
'FROM questtypes_submit_characters '.
|
||||
'WHERE quest_id = ? AND character_id = ?',
|
||||
'ii',
|
||||
$questId, $characterId
|
||||
);
|
||||
if(!empty($data)) {
|
||||
return $data[0];
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
14
questtypes/submit/html/quest.tpl
Normal file
14
questtypes/submit/html/quest.tpl
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
<form method="post">
|
||||
<textarea name="answers[]" <?=(!is_null($submission)) ? 'disabled="disabled"' : ''?>><?=!is_null($submission) ? $submission['text'] : ''?></textarea><br />
|
||||
|
||||
<?php if(!is_null($submission)) : ?>
|
||||
<?php if($wordcount > 1) : ?>
|
||||
<?=$wordcount?> <?=_('Words')?><br />
|
||||
<?php else : ?>
|
||||
<?=$wordcount?> <?=_('Word')?><br />
|
||||
<?php endif ?>
|
||||
(<?=sprintf(_('submitted at %s on %s h'), $dateFormatter->format(new \DateTime($submission['created'])), $timeFormatter->format(new \DateTime($submission['created'])))?>)
|
||||
<?php else : ?>
|
||||
<input type="submit" name="submit" value="<?=_('solve')?>" />
|
||||
<?php endif ?>
|
||||
</form>
|
||||
11
questtypes/submit/html/submission.tpl
Normal file
11
questtypes/submit/html/submission.tpl
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<form method="post">
|
||||
<?=\hhu\z\Utils::t($submission['text'])?>
|
||||
<br /><br />
|
||||
|
||||
<?php if($solved) : ?>
|
||||
<?=_('solved')?>
|
||||
<?php else : ?>
|
||||
<input type="submit" name="submit" value="<?=_('solved')?>" />
|
||||
<input type="submit" name="submit" value="<?=_('unsolved')?>" />
|
||||
<?php endif ?>
|
||||
</form>
|
||||
24
questtypes/textinput/TextinputQuesttypeAgent.inc
Normal file
24
questtypes/textinput/TextinputQuesttypeAgent.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 inserting text.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class TextinputQuesttypeAgent extends \hhu\z\QuesttypeAgent
|
||||
{
|
||||
}
|
||||
|
||||
?>
|
||||
159
questtypes/textinput/TextinputQuesttypeController.inc
Normal file
159
questtypes/textinput/TextinputQuesttypeController.inc
Normal file
|
|
@ -0,0 +1,159 @@
|
|||
<?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 TextinputQuesttypeAgent for for inserting text.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class TextinputQuesttypeController extends \hhu\z\QuesttypeController
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Save the answers of a Character for a Quest.
|
||||
*
|
||||
* @param int $questId ID of Quest to save answers for
|
||||
* @param int $characterId ID of Character to save answers of
|
||||
* @param array $answers Character answers for the Quest
|
||||
*/
|
||||
public function saveAnswersOfCharacter($questId, $characterId, $answers)
|
||||
{
|
||||
// Get regexs
|
||||
$regexs = $this->Textinput->getTextinputRegexs($questId);
|
||||
|
||||
// Save answers
|
||||
foreach($regexs as &$regex)
|
||||
{
|
||||
$pos = intval($regex['number']) - 1;
|
||||
$answer = (array_key_exists($pos, $answers)) ? $answers[$pos] : '';
|
||||
$this->Textinput->setCharacterSubmission($regex['id'], $characterId, $answer);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if answers of a Character for a Quest match the correct ones.
|
||||
*
|
||||
* @param int $questId ID of Quest to match answers for
|
||||
* @param int $characterId ID of Character to match answers of
|
||||
* @return boolean True/false for a right/wrong answer or null for moderator evaluation
|
||||
*/
|
||||
public function matchAnswersOfCharacter($questId, $characterId, $answers)
|
||||
{
|
||||
// Get right answers
|
||||
$regexs = $this->Textinput->getTextinputRegexs($questId);
|
||||
|
||||
// Match regexs with user answers
|
||||
$allSolved = true;
|
||||
foreach($regexs as $i => &$regex)
|
||||
{
|
||||
if(!array_key_exists($i, $answers))
|
||||
{
|
||||
$allSolved = false;
|
||||
break;
|
||||
}
|
||||
|
||||
if(!$this->isMatching($regex['regex'], $answers[$i]))
|
||||
{
|
||||
$allSolved = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Set status
|
||||
return $allSolved;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Action: quest.
|
||||
*
|
||||
* Display a text with input fields and evaluate if user input
|
||||
* matches with stored regular expressions.
|
||||
*
|
||||
* @param int $questId ID of Quest to show
|
||||
* @param int $characterId ID of Character
|
||||
*/
|
||||
public function quest($questId, $characterId)
|
||||
{
|
||||
// Get Task
|
||||
$task = $this->Textinput->getTextinputQuest($questId);
|
||||
|
||||
// Process text
|
||||
$textParts = preg_split('/(\$\$)/', $task['text'], -1, PREG_SPLIT_NO_EMPTY);
|
||||
|
||||
// Get Character answers
|
||||
$regexs = $this->Textinput->getTextinputRegexs($questId);
|
||||
foreach($regexs as &$regex) {
|
||||
$regex['answer'] = $this->Textinput->getCharacterSubmission($regex['id'], $characterId);
|
||||
}
|
||||
|
||||
// Has Character already solved Quest?
|
||||
$solved = $this->Quests->hasCharacterSolvedQuest($questId, $characterId);
|
||||
|
||||
|
||||
// Pass data to view
|
||||
$this->set('texts', $textParts);
|
||||
$this->set('regexs', $regexs);
|
||||
$this->set('solved', $solved);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Action: submission.
|
||||
*
|
||||
* Show the submission of a Character for a Quest.
|
||||
*
|
||||
* @param int $questId ID of Quest to show submission for
|
||||
* @param int $characterId ID of Character to show submission of
|
||||
*/
|
||||
public function submission($questId, $characterId)
|
||||
{
|
||||
// Get Task
|
||||
$task = $this->Textinput->getTextinputQuest($questId);
|
||||
|
||||
// Process text
|
||||
$textParts = preg_split('/(\$\$)/', $task['text'], -1, PREG_SPLIT_NO_EMPTY);
|
||||
|
||||
// Get Character answers
|
||||
$regexs = $this->Textinput->getTextinputRegexs($questId);
|
||||
foreach($regexs as &$regex) {
|
||||
$regex['answer'] = $this->Textinput->getCharacterSubmission($regex['id'], $characterId);
|
||||
$regex['right'] = $this->isMatching($regex['regex'], $regex['answer']);
|
||||
}
|
||||
|
||||
|
||||
// Pass data to view
|
||||
$this->set('texts', $textParts);
|
||||
$this->set('regexs', $regexs);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private function isMatching($regex, $answer)
|
||||
{
|
||||
$score = preg_match($regex, $answer);
|
||||
|
||||
|
||||
return ($score !== false && $score > 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
114
questtypes/textinput/TextinputQuesttypeModel.inc
Normal file
114
questtypes/textinput/TextinputQuesttypeModel.inc
Normal file
|
|
@ -0,0 +1,114 @@
|
|||
<?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 TextinputQuesttypeAgent for inserting text.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class TextinputQuesttypeModel extends \hhu\z\QuesttypeModel
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get textinput-text for a Quest.
|
||||
*
|
||||
* @param int $questId ID of Quest
|
||||
* @return array Textinput-text
|
||||
*/
|
||||
public function getTextinputQuest($questId)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT text '.
|
||||
'FROM questtypes_textinput '.
|
||||
'WHERE quest_id = ?',
|
||||
'i',
|
||||
$questId
|
||||
);
|
||||
|
||||
|
||||
return $data[0];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get regular expressions for a textinput-text.
|
||||
*
|
||||
* @param int $questId ID of Quest
|
||||
* @return array Regexs
|
||||
*/
|
||||
public function getTextinputRegexs($questId)
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT id, number, regex '.
|
||||
'FROM questtypes_textinput_regexs '.
|
||||
'WHERE questtypes_textinput_quest_id = ? '.
|
||||
'ORDER BY number ASC',
|
||||
'i',
|
||||
$questId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Save Character’s submitted answer for one textinput field.
|
||||
*
|
||||
* @param int $regexId ID of regex
|
||||
* @param int $characterId ID of Character
|
||||
* @param string $answer Submitted answer for this field
|
||||
*/
|
||||
public function setCharacterSubmission($regexId, $characterId, $answer)
|
||||
{
|
||||
$this->db->query(
|
||||
'INSERT INTO questtypes_textinput_regexs_characters '.
|
||||
'(questtypes_textinput_regex_id, character_id, value) '.
|
||||
'VALUES '.
|
||||
'(?, ?, ?) '.
|
||||
'ON DUPLICATE KEY UPDATE '.
|
||||
'value = ?',
|
||||
'iiss',
|
||||
$regexId, $characterId, $answer, $answer
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get answer of one regex input field submitted by Character.
|
||||
*
|
||||
* @param int $regexId ID of regex
|
||||
* @param int $characterId ID of Character
|
||||
* @return string Submitted answer for this field or empty string
|
||||
*/
|
||||
public function getCharacterSubmission($regexId, $characterId)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT value '.
|
||||
'FROM questtypes_textinput_regexs_characters '.
|
||||
'WHERE questtypes_textinput_regex_id = ? AND character_id = ? ',
|
||||
'ii',
|
||||
$regexId, $characterId
|
||||
);
|
||||
if(!empty($data)) {
|
||||
return $data[0]['value'];
|
||||
}
|
||||
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
11
questtypes/textinput/html/quest.tpl
Normal file
11
questtypes/textinput/html/quest.tpl
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<form method="post">
|
||||
<?php foreach($texts as $i => &$text) : ?>
|
||||
<?php if($i > 0) : ?>
|
||||
<input type="text" name="answers[<?=$i-1?>]" value="<?=$regexs[$i-1]['answer']?>" <?=($solved) ? 'disabled="disabled"' : '' ?>/>
|
||||
<?php endif ?>
|
||||
<?=\hhu\z\Utils::t($text)?>
|
||||
<?php endforeach ?>
|
||||
|
||||
<br /><br />
|
||||
<input type="submit" name="submit" value="<?=_('solve')?>" <?=($solved) ? 'disabled="disabled"' : '' ?> />
|
||||
</form>
|
||||
7
questtypes/textinput/html/submission.tpl
Normal file
7
questtypes/textinput/html/submission.tpl
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
<?php foreach($texts as $i => &$text) : ?>
|
||||
<?php if($i > 0) : ?>
|
||||
<span style="background-color:grey"><?=$regexs[$i-1]['answer']?></span>
|
||||
<?php if($regexs[$i-1]['right']) : ?>✓<?php else: ?>✕<?php endif ?>
|
||||
<?php endif ?>
|
||||
<?=\hhu\z\Utils::t($text)?>
|
||||
<?php endforeach ?>
|
||||
Loading…
Add table
Add a link
Reference in a new issue