sub menu design update
This commit is contained in:
commit
a557703ce7
207 changed files with 18919 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
|
||||
{
|
||||
}
|
||||
|
||||
?>
|
||||
166
questtypes/submit/SubmitQuesttypeController.inc
Normal file
166
questtypes/submit/SubmitQuesttypeController.inc
Normal file
|
|
@ -0,0 +1,166 @@
|
|||
<?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.
|
||||
*
|
||||
* @throws SubmissionNotValidException
|
||||
* @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 already submitted answer
|
||||
$characterSubmission = $this->Submit->getCharacterSubmission($quest['id'], $character['id']);
|
||||
|
||||
// Save answer
|
||||
if(is_null($characterSubmission) && array_key_exists('answers', $_FILES))
|
||||
{
|
||||
$answer = $_FILES['answers'];
|
||||
|
||||
// Check error
|
||||
if($answer['error'] !== 0) {
|
||||
throw new \hhu\z\exceptions\SubmissionNotValidException(
|
||||
new \hhu\z\exceptions\FileUploadException($answer['error'])
|
||||
);
|
||||
}
|
||||
|
||||
// Check mimetype
|
||||
$mimetypes = $this->Submit->getAllowedMimetypes($seminary['id']);
|
||||
$answerMimetype = null;
|
||||
foreach($mimetypes as &$mimetype) {
|
||||
if($mimetype['mimetype'] == $answer['type']) {
|
||||
$answerMimetype = $mimetype;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(is_null($answerMimetype)) {
|
||||
throw new \hhu\z\exceptions\SubmissionNotValidException(
|
||||
new \hhu\z\exceptions\WrongFiletypeException($answer['type'])
|
||||
);
|
||||
}
|
||||
|
||||
// Check file size
|
||||
if($answer['size'] > $answerMimetype['size']) {
|
||||
throw new \hhu\z\exceptions\SubmissionNotValidException(
|
||||
new \hhu\z\exceptions\MaxFilesizeException()
|
||||
);
|
||||
}
|
||||
|
||||
// Save file
|
||||
if(!$this->Submit->setCharacterSubmission($seminary['id'], $quest['id'], $this->Auth->getUserId(), $character['id'], $answer)) {
|
||||
throw new \hhu\z\exceptions\SubmissionNotValidException(
|
||||
new \hhu\z\exceptions\FileUploadException(error_get_last()['message'])
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
// 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 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)
|
||||
{
|
||||
// Answer (Submission)
|
||||
$characterSubmission = $this->Submit->getCharacterSubmission($quest['id'], $character['id']);
|
||||
|
||||
// Has Character already solved Quest?
|
||||
$solved = $this->Quests->hasCharacterSolvedQuest($quest['id'], $character['id']);
|
||||
|
||||
// Get allowed mimetypes
|
||||
$mimetypes = $this->Submit->getAllowedMimetypes($seminary['id']);
|
||||
|
||||
|
||||
// Pass data to view
|
||||
$this->set('submission', $characterSubmission);
|
||||
$this->set('solved', $solved);
|
||||
$this->set('mimetypes', $mimetypes);
|
||||
$this->set('exception', $exception);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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 Character submission
|
||||
$submission = $this->Submit->getCharacterSubmission($quest['id'], $character['id']);
|
||||
|
||||
// Status
|
||||
$solved = $this->Quests->hasCharacterSolvedQuest($quest['id'], $character['id']);
|
||||
|
||||
|
||||
// Pass data to view
|
||||
$this->set('submission', $submission);
|
||||
$this->set('solved', $solved);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
106
questtypes/submit/SubmitQuesttypeModel.inc
Normal file
106
questtypes/submit/SubmitQuesttypeModel.inc
Normal file
|
|
@ -0,0 +1,106 @@
|
|||
<?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
|
||||
{
|
||||
/**
|
||||
* Required models
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $models = array('uploads');
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Save Character’s submitted upload.
|
||||
*
|
||||
* @param int $questId ID of Quest
|
||||
* @param int $characterId ID of Character
|
||||
* @param array $file Submitted upload
|
||||
*/
|
||||
public function setCharacterSubmission($seminaryId, $questId, $userId, $characterId, $file)
|
||||
{
|
||||
// Save file on harddrive
|
||||
$uploadId = $this->Uploads->uploadFile($userId, $file['name'], $file['tmp_name'], $file['type'], $seminaryId);
|
||||
if($uploadId === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Create database record
|
||||
$this->db->query(
|
||||
'INSERT INTO questtypes_submit_characters '.
|
||||
'(quest_id, character_id, upload_id) '.
|
||||
'VALUES '.
|
||||
'(?, ?, ?) ',
|
||||
'iii',
|
||||
$questId, $characterId, $uploadId
|
||||
);
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get upload 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 upload_id '.
|
||||
'FROM questtypes_submit_characters '.
|
||||
'WHERE quest_id = ? AND character_id = ?',
|
||||
'ii',
|
||||
$questId, $characterId
|
||||
);
|
||||
if(!empty($data)) {
|
||||
return $this->Uploads->getUploadById($data[0]['upload_id']);
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get allowed mimetypes for uploading a file.
|
||||
*
|
||||
* @param int $seminaryId ID of Seminary
|
||||
* @return array Allowed mimetypes
|
||||
*/
|
||||
public function getAllowedMimetypes($seminaryId)
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT id, mimetype, size '.
|
||||
'FROM questtypes_submit_mimetypes '.
|
||||
'WHERE seminary_id = ?',
|
||||
'i',
|
||||
$seminaryId
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
27
questtypes/submit/html/quest.tpl
Normal file
27
questtypes/submit/html/quest.tpl
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
<?php if(!is_null($exception)) : ?>
|
||||
<p class="error">
|
||||
<?php if($exception->getNestedException() instanceof \hhu\z\exceptions\WrongFiletypeException) : ?>
|
||||
<?=sprintf(_('File has wrong type “%s”'), $exception->getNestedException()->getType())?>
|
||||
<?php elseif($exception->getNestedException() instanceof \hhu\z\exceptions\WrongFiletypeException) : ?>
|
||||
<?=_('File exceeds size maximum')?>
|
||||
<?php elseif($exception->getNestedException() instanceof \hhu\z\exceptions\FileUploadException) : ?>
|
||||
<?=sprintf(_('Error during file upload: %s'), $exception->getNestedException()->getNestedMessage())?>
|
||||
<?php else : ?>
|
||||
<?=$exception->getNestedException()->getMessage()?>
|
||||
<?php endif ?>
|
||||
</p>
|
||||
<?php endif ?>
|
||||
<?php if(is_null($submission)) : ?>
|
||||
<form method="post" enctype="multipart/form-data">
|
||||
<input type="file" name="answers" required="required" accept="<?=implode(',', array_map(function($m) { return $m['mimetype']; }, $mimetypes))?>" /><br />
|
||||
<?=_('Allowed file types')?>:
|
||||
<ul>
|
||||
<?php foreach($mimetypes as &$mimetype) : ?>
|
||||
<li><?=$mimetype['mimetype']?> (<?=_('max.')?> <?=$numberFormatter->format(round($mimetype['size']/(1024*1024),2))?> MiB)</li>
|
||||
<?php endforeach ?>
|
||||
</ul>
|
||||
<input type="submit" name="submit" value="<?=_('solve')?>" />
|
||||
</form>
|
||||
<?php else : ?>
|
||||
<a href="<?=$linker->link(array('uploads','index',$submission['url']))?>"><?=$submission['name']?></a> (<?=sprintf(_('submitted at %s on %s h'), $dateFormatter->format(new \DateTime($submission['created'])), $timeFormatter->format(new \DateTime($submission['created'])))?>)
|
||||
<?php endif ?>
|
||||
11
questtypes/submit/html/submission.tpl
Normal file
11
questtypes/submit/html/submission.tpl
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<form method="post">
|
||||
<a href="<?=$linker->link(array('uploads','index',$submission['url']))?>"><?=$submission['name']?></a> (<?=sprintf(_('submitted at %s on %s h'), $dateFormatter->format(new \DateTime($submission['created'])), $timeFormatter->format(new \DateTime($submission['created'])))?>)
|
||||
<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