use client?s mimetype as fallback for uploads
This commit is contained in:
commit
a75696e4e7
3468 changed files with 596986 additions and 0 deletions
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
|
||||
{
|
||||
}
|
||||
|
||||
?>
|
||||
185
questtypes/textinput/TextinputQuesttypeController.inc
Normal file
185
questtypes/textinput/TextinputQuesttypeController.inc
Normal file
|
|
@ -0,0 +1,185 @@
|
|||
<?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 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 regexs
|
||||
$regexs = $this->Textinput->getTextinputRegexs($quest['id']);
|
||||
|
||||
// Save answers
|
||||
foreach($regexs as &$regex)
|
||||
{
|
||||
$pos = intval($regex['number']) - 1;
|
||||
$answer = (array_key_exists($pos, $answers)) ? $answers[$pos] : '';
|
||||
$this->Textinput->setCharacterSubmission($regex['id'], $character['id'], $answer);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Save additional data for the answers 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
|
||||
* @param array $data Additional (POST-) data
|
||||
*/
|
||||
public function saveDataForCharacterAnswers($seminary, $questgroup, $quest, $character, $data)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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
|
||||
* @return boolean True/false for a right/wrong answer or null for moderator evaluation
|
||||
*/
|
||||
public function matchAnswersOfCharacter($seminary, $questgroup, $quest, $character, $answers)
|
||||
{
|
||||
// Get right answers
|
||||
$regexs = $this->Textinput->getTextinputRegexs($quest['id']);
|
||||
|
||||
// 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 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)
|
||||
{
|
||||
// Get Task
|
||||
$task = $this->Textinput->getTextinputQuest($quest['id']);
|
||||
|
||||
// Process text
|
||||
$textParts = preg_split('/(\$\$)/', ' '.$task['text'].' ', -1, PREG_SPLIT_NO_EMPTY);
|
||||
|
||||
// Has Character already solved Quest?
|
||||
$solved = $this->Quests->hasCharacterSolvedQuest($quest['id'], $character['id']);
|
||||
|
||||
// Get Character answers
|
||||
$regexs = null;
|
||||
if(!$solved || $this->request->getGetParam('show-answer') == 'true' || $this->request->getGetParam('status') == 'solved')
|
||||
{
|
||||
$regexs = $this->Textinput->getTextinputRegexs($quest['id']);
|
||||
foreach($regexs as &$regex) {
|
||||
$regex['answer'] = $this->Textinput->getCharacterSubmission($regex['id'], $character['id']);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Pass data to view
|
||||
$this->set('texts', $textParts);
|
||||
$this->set('regexs', $regexs);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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 Task
|
||||
$task = $this->Textinput->getTextinputQuest($quest['id']);
|
||||
|
||||
// Process text
|
||||
$textParts = preg_split('/(\$\$)/', $task['text'], -1, PREG_SPLIT_NO_EMPTY);
|
||||
|
||||
// Get Character answers
|
||||
$regexs = $this->Textinput->getTextinputRegexs($quest['id']);
|
||||
foreach($regexs as &$regex) {
|
||||
$regex['answer'] = $this->Textinput->getCharacterSubmission($regex['id'], $character['id']);
|
||||
$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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
117
questtypes/textinput/TextinputQuesttypeModel.inc
Normal file
117
questtypes/textinput/TextinputQuesttypeModel.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;
|
||||
|
||||
|
||||
/**
|
||||
* 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
|
||||
);
|
||||
if(!empty($data)) {
|
||||
return $data[0];
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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" class="textinput">
|
||||
<p>
|
||||
<?php foreach($texts as $i => &$text) : ?>
|
||||
<?php if($i > 0) : ?>
|
||||
<input type="text" name="answers[<?=$i-1?>]" value="<?=$regexs[$i-1]['answer']?>" />
|
||||
<?php endif ?>
|
||||
<?=$t->t($text)?>
|
||||
<?php endforeach ?>
|
||||
</p>
|
||||
<input type="submit" name="submit" value="<?=_('solve')?>" />
|
||||
</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 ?>
|
||||
<?=$t->t($text)?>
|
||||
<?php endforeach ?>
|
||||
Loading…
Add table
Add a link
Reference in a new issue