belanglose vervollst?ndigung / test

This commit is contained in:
Daniel 2014-03-17 16:00:48 +01:00
commit a017c7a79d
177 changed files with 14495 additions and 0 deletions

View 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
{
}
?>

View file

@ -0,0 +1,48 @@
<?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
{
/**
* Action: index.
*/
public function index()
{
// Check for submission
if($this->request->getRequestMethod() == 'POST')
{
// Right answer (dummy)
if(!is_null($this->request->getPostParam('submit'))) {
$this->setQuestSolved();
}
// Wrong answer (dummy)
else {
$this->setQuestUnsolved();
}
}
}
}
?>

View 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
{
}
?>

View 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>

View 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
{
}
?>

View file

@ -0,0 +1,88 @@
<?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
{
/**
* Action: index.
*
* Display a text with input fields and evaluate if user input
* matches with stored regular expressions.
*/
public function index($questId)
{
// Answers
if(!array_key_exists('answers', $_SESSION)) {
$_SESSION['answers'] = array();
}
$answers = array_key_exists($questId, $_SESSION['answers']) ? $_SESSION['answers'][$questId] : array();
// Check for submission
if($this->request->getRequestMethod() == 'POST' && !is_null($this->request->getPostParam('submit')))
{
// Get answers
$answers = $this->request->getPostParam('answers');
// Store answers in session
$_SESSION['answers'][$questId] = $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]);
}
}
// Set status
if($allSolved && count($answers) == 0) {
$this->setQuestSolved();
}
else {
$this->setQuestUnsolved();
}
}
// Get questions
$questions = $this->Multiplechoice->getQuestionsOfQuest($questId);
// Pass data to view
$this->set('questions', $questions);
$this->set('answers', $answers);
}
}
?>

View file

@ -0,0 +1,64 @@
<?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 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 question, tick, pos '.
'FROM questtypes_multiplechoice '.
'WHERE quest_id = ? AND tick = True',
'i',
$questId
);
}
}
?>

View 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" <?=(array_key_exists($i, $answers)) ? 'checked="checked' : '' ?> />
<label for="answers[<?=$i?>]"><?=\hhu\z\Utils::t($question['question'])?></label>
</li>
<?php endforeach ?>
</ol>
<input type="submit" name="submit" value="<?=_('solve')?>" />
</form>

View 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
{
}
?>

View file

@ -0,0 +1,94 @@
<?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
{
/**
* Action: index.
*
* Display a text with input fields and evaluate if user input
* matches with stored regular expressions.
*/
public function index($questId)
{
// Answers
if(!array_key_exists('answers', $_SESSION)) {
$_SESSION['answers'] = array();
}
$answers = array_key_exists($questId, $_SESSION['answers']) ? $_SESSION['answers'][$questId] : array();
// Check for submission
if($this->request->getRequestMethod() == 'POST' && !is_null($this->request->getPostParam('submit')))
{
// Get answers
$answers = $this->request->getPostParam('answers');
// Store answers in session
$_SESSION['answers'][$questId] = $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;
}
$score = preg_match($regex['regex'], $answers[$i]);
if($score === 0 || $score === false)
{
$allSolved = false;
break;
}
}
// Set status
if($allSolved) {
$this->setQuestSolved();
}
else {
$this->setQuestUnsolved();
}
}
// Get Task
$task = $this->Textinput->getTextinputQuest($questId);
// Process text
$textParts = preg_split('/(\$\$)/', $task['text'], -1, PREG_SPLIT_NO_EMPTY);
// Pass data to view
$this->set('texts', $textParts);
$this->set('answers', $answers);
}
}
?>

View file

@ -0,0 +1,67 @@
<?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 number, regex '.
'FROM questtypes_textinput_regexs '.
'WHERE questtypes_textinput_quest_id = ? '.
'ORDER BY number ASC',
'i',
$questId
);
}
}
?>

View 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="<?=(array_key_exists($i-1, $answers)) ? $answers[$i-1] : '' ?>" />
<?php endif ?>
<?=\hhu\z\Utils::t($text)?>
<?php endforeach ?>
<br /><br />
<input type="submit" name="submit" value="<?=_('solve')?>" />
</form>