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/choiceinput/ChoiceinputQuesttypeAgent.inc
Normal file
24
questtypes/choiceinput/ChoiceinputQuesttypeAgent.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 choosing between predefined input values.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class ChoiceinputQuesttypeAgent extends \hhu\z\QuesttypeAgent
|
||||
{
|
||||
}
|
||||
|
||||
?>
|
||||
171
questtypes/choiceinput/ChoiceinputQuesttypeController.inc
Normal file
171
questtypes/choiceinput/ChoiceinputQuesttypeController.inc
Normal file
|
|
@ -0,0 +1,171 @@
|
|||
<?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 ChoiceinputQuesttypeAgent for choosing between
|
||||
* predefined input values.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class ChoiceinputQuesttypeController 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 lists
|
||||
$choiceLists = $this->Choiceinput->getChoiceinputLists($quest['id']);
|
||||
|
||||
// Save answers
|
||||
foreach($choiceLists as &$list)
|
||||
{
|
||||
$pos = intval($list['number']) - 1;
|
||||
$answer = (array_key_exists($pos, $answers)) ? $answers[$pos] : null;
|
||||
$this->Choiceinput->setCharacterSubmission($list['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 lists
|
||||
$choiceLists = $this->Choiceinput->getChoiceinputLists($quest['id']);
|
||||
|
||||
// Match lists with user answers
|
||||
foreach($choiceLists as $i => &$list)
|
||||
{
|
||||
if(!array_key_exists($i, $answers)) {
|
||||
return false;
|
||||
}
|
||||
if($list['questtypes_choiceinput_choice_id'] != $answers[$i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// All answer right
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Action: quest.
|
||||
*
|
||||
* Display a text with lists with predefined values.
|
||||
*
|
||||
* @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->Choiceinput->getChoiceinputQuest($quest['id']);
|
||||
|
||||
// Process text
|
||||
$textParts = preg_split('/(\$\$)/', ' '.$task['text'].' ');
|
||||
|
||||
// Get lists
|
||||
$choiceLists = $this->Choiceinput->getChoiceinputLists($quest['id']);
|
||||
foreach($choiceLists as &$list) {
|
||||
$list['values'] = $this->Choiceinput->getChoiceinputChoices($list['id']);
|
||||
}
|
||||
|
||||
// Get Character answers
|
||||
if($this->request->getGetParam('show-answer') == 'true' || !$this->Quests->hasCharacterSolvedQuest($quest['id'], $character['id']) || $this->request->getGetParam('status') == 'solved')
|
||||
{
|
||||
foreach($choiceLists as &$list) {
|
||||
$list['answer'] = $this->Choiceinput->getCharacterSubmission($list['id'], $character['id']);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Pass data to view
|
||||
$this->set('texts', $textParts);
|
||||
$this->set('choiceLists', $choiceLists);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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->Choiceinput->getChoiceinputQuest($quest['id']);
|
||||
|
||||
// Process text
|
||||
$textParts = preg_split('/(\$\$)/', ' '.$task['text'].' ');
|
||||
|
||||
// Get lists
|
||||
$choiceLists = $this->Choiceinput->getChoiceinputLists($quest['id']);
|
||||
foreach($choiceLists as &$list)
|
||||
{
|
||||
$list['values'] = $this->Choiceinput->getChoiceinputChoices($list['id']);
|
||||
$list['answer'] = $this->Choiceinput->getCharacterSubmission($list['id'], $character['id']);
|
||||
$list['right'] = ($list['questtypes_choiceinput_choice_id'] == $list['answer']);
|
||||
}
|
||||
|
||||
|
||||
// Pass data to view
|
||||
$this->set('texts', $textParts);
|
||||
$this->set('choiceLists', $choiceLists);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
153
questtypes/choiceinput/ChoiceinputQuesttypeModel.inc
Normal file
153
questtypes/choiceinput/ChoiceinputQuesttypeModel.inc
Normal file
|
|
@ -0,0 +1,153 @@
|
|||
<?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 ChoiceinputQuesttypeAgent for choosing between
|
||||
* predefined input values.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class ChoiceinputQuesttypeModel extends \hhu\z\QuesttypeModel
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get choiceinput-text for a Quest.
|
||||
*
|
||||
* @param int $questId ID of Quest
|
||||
* @return array Choiceinput-text
|
||||
*/
|
||||
public function getChoiceinputQuest($questId)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT text '.
|
||||
'FROM questtypes_choiceinput '.
|
||||
'WHERE quest_id = ?',
|
||||
'i',
|
||||
$questId
|
||||
);
|
||||
if(!empty($data)) {
|
||||
return $data[0];
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get all lists of input values for a choiceinput-text.
|
||||
*
|
||||
* @param int $questId ID of Quest
|
||||
* @return array List
|
||||
*/
|
||||
public function getChoiceinputLists($questId)
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT id, number, questtypes_choiceinput_choice_id '.
|
||||
'FROM questtypes_choiceinput_lists '.
|
||||
'WHERE questtypes_choiceinput_quest_id = ? '.
|
||||
'ORDER BY number ASC',
|
||||
'i',
|
||||
$questId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the list of values for a choiceinput-list.
|
||||
*
|
||||
* @param int $listId ID of list
|
||||
* @return array Input values
|
||||
*/
|
||||
public function getChoiceinputChoices($listId)
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT id, pos, text '.
|
||||
'FROM questtypes_choiceinput_choices '.
|
||||
'WHERE questtypes_choiceinput_list_id = ? '.
|
||||
'ORDER BY pos ASC',
|
||||
'i',
|
||||
$listId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Save Character’s submitted answer for one choiceinput-list.
|
||||
*
|
||||
* @param int $regexId ID of list
|
||||
* @param int $characterId ID of Character
|
||||
* @param string $answer Submitted answer for this list
|
||||
*/
|
||||
public function setCharacterSubmission($listId, $characterId, $answer)
|
||||
{
|
||||
if(is_null($answer))
|
||||
{
|
||||
$this->db->query(
|
||||
'INSERT INTO questtypes_choiceinput_lists_characters '.
|
||||
'(questtypes_choiceinput_list_id, character_id, questtypes_choiceinput_choice_id) '.
|
||||
'VALUES '.
|
||||
'(?, ?, NULL) '.
|
||||
'ON DUPLICATE KEY UPDATE '.
|
||||
'questtypes_choiceinput_choice_id = NULL',
|
||||
'ii',
|
||||
$listId, $characterId
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->db->query(
|
||||
'INSERT INTO questtypes_choiceinput_lists_characters '.
|
||||
'(questtypes_choiceinput_list_id, character_id, questtypes_choiceinput_choice_id) '.
|
||||
'VALUES '.
|
||||
'(?, ?, ?) '.
|
||||
'ON DUPLICATE KEY UPDATE '.
|
||||
'questtypes_choiceinput_choice_id = ?',
|
||||
'iiii',
|
||||
$listId, $characterId, $answer, $answer
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get answer of one choiceinput-list submitted by Character.
|
||||
*
|
||||
* @param int $regexId ID of list
|
||||
* @param int $characterId ID of Character
|
||||
* @return int Submitted answer for this list or null
|
||||
*/
|
||||
public function getCharacterSubmission($listId, $characterId)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT questtypes_choiceinput_choice_id '.
|
||||
'FROM questtypes_choiceinput_lists_characters '.
|
||||
'WHERE questtypes_choiceinput_list_id = ? AND character_id = ? ',
|
||||
'ii',
|
||||
$listId, $characterId
|
||||
);
|
||||
if(!empty($data)) {
|
||||
return $data[0]['questtypes_choiceinput_choice_id'];
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
15
questtypes/choiceinput/html/quest.tpl
Normal file
15
questtypes/choiceinput/html/quest.tpl
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
<form method="post">
|
||||
<?php foreach($texts as $i => &$text) : ?>
|
||||
<?php if($i > 0) : ?>
|
||||
<select name="answers[<?=$i-1?>]">
|
||||
<?php foreach($choiceLists[$i-1]['values'] as &$choice) : ?>
|
||||
<option value="<?=$choice['id']?>" <?php if(array_key_exists('answer', $choiceLists[$i-1]) && $choiceLists[$i-1]['answer'] == $choice['id']) : ?>selected="selected"<?php endif ?>><?=$choice['text']?></option>
|
||||
<?php endforeach ?>
|
||||
</select>
|
||||
<?php endif ?>
|
||||
<?=$t->t($text)?>
|
||||
<?php endforeach ?>
|
||||
|
||||
<br /><br />
|
||||
<input type="submit" name="submit" value="<?=_('solve')?>" />
|
||||
</form>
|
||||
12
questtypes/choiceinput/html/submission.tpl
Normal file
12
questtypes/choiceinput/html/submission.tpl
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
<form method="post">
|
||||
<?php foreach($texts as $i => &$text) : ?>
|
||||
<?php if($i > 0) : ?>
|
||||
<select name="answers[<?=$i-1?>]" disabled="disabled">
|
||||
<?php foreach($choiceLists[$i-1]['values'] as &$choice) : ?>
|
||||
<option value="<?=$choice['id']?>" <?php if(array_key_exists('answer', $choiceLists[$i-1]) && $choiceLists[$i-1]['answer'] == $choice['id']) : ?>selected="selected"<?php endif ?>><?=$choice['text']?></option>
|
||||
<?php endforeach ?>
|
||||
</select>
|
||||
<?php endif ?>
|
||||
<?=$t->t($text)?>
|
||||
<?php endforeach ?>
|
||||
</form>
|
||||
Loading…
Add table
Add a link
Reference in a new issue