implement uploading a file as answer for Questtype ?Submit?
This commit is contained in:
parent
ef09434005
commit
dff8345797
6 changed files with 207 additions and 34 deletions
|
|
@ -32,6 +32,7 @@
|
|||
/**
|
||||
* 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
|
||||
|
|
@ -44,8 +45,34 @@
|
|||
$characterSubmission = $this->Submit->getCharacterSubmission($quest['id'], $character['id']);
|
||||
|
||||
// Save answer
|
||||
if(is_null($characterSubmission) && array_key_exists(0, $answers)) {
|
||||
$this->Submit->setCharacterSubmission($quest['id'], $character['id'], $answers[0]);
|
||||
if(is_null($characterSubmission) && array_key_exists('answers', $_FILES))
|
||||
{
|
||||
$answer = $_FILES['answers'];
|
||||
|
||||
// Check mimetype
|
||||
$mimetypes = $this->Submit->getAllowedMimetypes($seminary['id']);
|
||||
$answerMimetype = null;
|
||||
foreach($mimetypes as &$mimetype) {
|
||||
if($mimetype['mimetype'] == $answer['type']) {
|
||||
$answerMimetype = $mimetype;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Check file
|
||||
if(is_null($answerMimetype)) {
|
||||
throw new \hhu\z\exceptions\SubmissionNotValidException(
|
||||
new \hhu\z\exceptions\WrongFiletypeException()
|
||||
);
|
||||
}
|
||||
if($answer['size'] > $answerMimetype['size']) {
|
||||
throw new \hhu\z\exceptions\SubmissionNotValidException(
|
||||
new \hhu\z\exceptions\MaxFilesizeException()
|
||||
);
|
||||
}
|
||||
|
||||
// Save file
|
||||
$this->Submit->setCharacterSubmission($seminary['id'], $quest['id'], $this->Auth->getUserId(), $character['id'], $answer);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -73,30 +100,29 @@
|
|||
* 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 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)
|
||||
public function quest($seminary, $questgroup, $quest, $character, $exception)
|
||||
{
|
||||
// Answer (Submission)
|
||||
$characterSubmission = $this->Submit->getCharacterSubmission($quest['id'], $character['id']);
|
||||
|
||||
// Wordcount
|
||||
$wordcount = 0;
|
||||
if(!is_null($characterSubmission)) {
|
||||
$wordcount = count(preg_split('/\s+/', $characterSubmission['text']));
|
||||
}
|
||||
|
||||
// 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('wordcount', $wordcount);
|
||||
$this->set('solved', $solved);
|
||||
$this->set('mimetypes', $mimetypes);
|
||||
$this->set('exception', $exception);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue