implement QuesttypeAgent ?Submit?
This commit is contained in:
parent
a4aefd55c9
commit
df2b0780f4
5 changed files with 238 additions and 0 deletions
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
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
117
questtypes/submit/SubmitQuesttypeController.inc
Normal file
117
questtypes/submit/SubmitQuesttypeController.inc
Normal file
|
|
@ -0,0 +1,117 @@
|
||||||
|
<?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']));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Pass data to view
|
||||||
|
$this->set('submission', $characterSubmission);
|
||||||
|
$this->set('wordcount', $wordcount);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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>
|
||||||
Loading…
Add table
Add a link
Reference in a new issue