hide map for Character groups Quest Stations when there are no stations
This commit is contained in:
commit
df14dfafc3
4371 changed files with 1220224 additions and 0 deletions
24
stationtypes/singlechoice/SinglechoiceStationtypeAgent.inc
Normal file
24
stationtypes/singlechoice/SinglechoiceStationtypeAgent.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\stationtypes;
|
||||
|
||||
|
||||
/**
|
||||
* StationtypeAgent for a single choice task.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class SinglechoiceStationtypeAgent extends \hhu\z\agents\StationtypeAgent
|
||||
{
|
||||
}
|
||||
|
||||
?>
|
203
stationtypes/singlechoice/SinglechoiceStationtypeController.inc
Normal file
203
stationtypes/singlechoice/SinglechoiceStationtypeController.inc
Normal file
|
@ -0,0 +1,203 @@
|
|||
<?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\stationtypes;
|
||||
|
||||
|
||||
/**
|
||||
* Controller of the StationtypeAgent for a single choice task.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class SinglechoiceStationtypeController extends \hhu\z\controllers\StationtypeController
|
||||
{
|
||||
/**
|
||||
* Required models
|
||||
*/
|
||||
public $models = array('charactergroupsqueststations');
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Save the answer of a Character group for a Station.
|
||||
*
|
||||
* @param array $seminary Current Seminary data
|
||||
* @param array $questgroup Current Questgroup data
|
||||
* @param array $quest Current Quest data
|
||||
* @param array $station Current Station data
|
||||
* @param array $charactergroup Current Character group data
|
||||
* @param array $answer Character group answer for the Station
|
||||
*/
|
||||
public function saveAnswer($seminary, $groupsgroup, $quest, $station, $charactergroup, $answer)
|
||||
{
|
||||
$this->Singlechoice->setCharactergroupSubmission(
|
||||
$station['id'],
|
||||
$charactergroup['id'],
|
||||
intval($answer)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if answer of a Character group for a Station matches the correct one.
|
||||
*
|
||||
* @param array $seminary Current Seminary data
|
||||
* @param array $questgroup Current Questgroup data
|
||||
* @param array $quest Current Quest data
|
||||
* @param array $station Current Station data
|
||||
* @param array $charactergroup Current Character group data
|
||||
* @param array $answer Character group answer for the Station
|
||||
* @return boolean True/false for a right/wrong answer
|
||||
*/
|
||||
public function matchAnswer($seminary, $groupsgroup, $quest, $station, $charactergroup, $answer)
|
||||
{
|
||||
// Get question
|
||||
$question = $this->Singlechoice->getQuestion($station['id']);
|
||||
|
||||
|
||||
// ID of answer maches correct one’s
|
||||
return $question['answer_id'] == intval($answer);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Action: quest.
|
||||
*
|
||||
* Show the task of a Station.
|
||||
*
|
||||
* @param array $seminary Current Seminary data
|
||||
* @param array $questgroup Current Questgroup data
|
||||
* @param array $quest Current Quest data
|
||||
* @param array $station Current Station data
|
||||
* @param array $charactergroup Current Character group data
|
||||
*/
|
||||
public function quest($seminary, $groupsgroup, $quest, $station, $charactergroup)
|
||||
{
|
||||
// Get question
|
||||
$question = $this->Singlechoice->getQuestion($station['id']);
|
||||
|
||||
// Get answers
|
||||
$answers = $this->Singlechoice->getAnswers($station['id']);
|
||||
|
||||
// Get submission
|
||||
if(!is_null($charactergroup)) {
|
||||
$question['submission'] = $this->Singlechoice->getCharactergroupSubmission(
|
||||
$station['id'],
|
||||
$charactergroup['id']
|
||||
);
|
||||
}
|
||||
|
||||
// Get status
|
||||
$tried = false;
|
||||
if(!is_null($charactergroup)) {
|
||||
$tried = $this->Charactergroupsqueststations->hasCharactergroupTriedStation(
|
||||
$station['id'],
|
||||
$charactergroup['id']
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// Pass data to view
|
||||
$this->set('question', $question);
|
||||
$this->set('answers', $answers);
|
||||
$this->set('tried', $tried);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Action: edittask.
|
||||
*
|
||||
* Edit the task of a Station.
|
||||
*
|
||||
* @param array $seminary Current Seminary data
|
||||
* @param array $groupsgroup Current Groups group data
|
||||
* @param array $quest Current Quest data
|
||||
* @param array $station Current Station data
|
||||
*/
|
||||
public function edittask($seminary, $groupsgroup, $quest, $station)
|
||||
{
|
||||
// Get question
|
||||
$question = $this->Singlechoice->getQuestion($station['id']);
|
||||
|
||||
// Get answers
|
||||
$answers = $this->Singlechoice->getAnswers($station['id']);
|
||||
|
||||
// Save data
|
||||
if($this->request->getRequestMethod() == 'POST' && !is_null($this->request->getPostParam('save')))
|
||||
{
|
||||
// Get params
|
||||
$corectAnswerIndex = $this->request->getPostParam('answer');
|
||||
$corectAnswerIndex = intval($corectAnswerIndex);
|
||||
$answers = $this->request->getPostParam('answers');
|
||||
if(is_null($answers)) {
|
||||
$answers = array();
|
||||
}
|
||||
|
||||
// Save question
|
||||
$this->Singlechoice->setQuestion(
|
||||
$this->Auth->getUserId(),
|
||||
$station['id']
|
||||
);
|
||||
|
||||
// Save answers
|
||||
$correctAnswerId = null;
|
||||
$index = 0;
|
||||
foreach($answers as $answerIndex => &$answer)
|
||||
{
|
||||
$answerId = $this->Singlechoice->setAnswer(
|
||||
$this->Auth->getUserId(),
|
||||
$station['id'],
|
||||
++$index,
|
||||
$answer['answer']
|
||||
);
|
||||
if($answerIndex == $corectAnswerIndex || is_null($correctAnswerId)) {
|
||||
$correctAnswerId = $answerId;
|
||||
}
|
||||
}
|
||||
|
||||
// Delete deleted answers
|
||||
$this->Singlechoice->deleteAnswers(
|
||||
$station['id'],
|
||||
count($answers)
|
||||
);
|
||||
|
||||
// Set correct answer
|
||||
$this->Singlechoice->setCorrectAnswer(
|
||||
$station['id'],
|
||||
$correctAnswerId
|
||||
);
|
||||
|
||||
// Redirect
|
||||
$this->redirect(
|
||||
$this->linker->link(
|
||||
array(
|
||||
'station',
|
||||
$seminary['url'],
|
||||
$groupsgroup['url'],
|
||||
$quest['url'],
|
||||
$station['url']
|
||||
),
|
||||
1
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// Pass data to view
|
||||
$this->set('task', $station['task']);
|
||||
$this->set('question', $question);
|
||||
$this->set('answers', $answers);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
282
stationtypes/singlechoice/SinglechoiceStationtypeModel.inc
Normal file
282
stationtypes/singlechoice/SinglechoiceStationtypeModel.inc
Normal file
|
@ -0,0 +1,282 @@
|
|||
<?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\stationtypes;
|
||||
|
||||
|
||||
/**
|
||||
* Model of the StationtypeAgent for a single choice task.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class SinglechoiceStationtypeModel extends \hhu\z\models\StationtypeModel
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Copy a Station.
|
||||
*
|
||||
* @param int $userId ID of creating user
|
||||
* @param int $sourceStationId ID of Station to copy from
|
||||
* @param int $targetStationId ID of Station to copy to
|
||||
* @param int $seminaryMediaIds Mapping of SeminaryMedia-IDs from source Seminary to targetSeminary
|
||||
*/
|
||||
public function copyStation($userId, $sourceStationId, $targetStationId, $seminaryMediaIds)
|
||||
{
|
||||
// Copy question
|
||||
$question = $this->getQuestion($sourceStationId);
|
||||
$this->db->query(
|
||||
'INSERT INTO stationtypes_singlechoice '.
|
||||
'(station_id, created_user_id) '.
|
||||
'VALUES '.
|
||||
'(?, ?)',
|
||||
'ii',
|
||||
$targetStationId, $userId
|
||||
);
|
||||
|
||||
// Copy answers
|
||||
$answerIds = array();
|
||||
$answers = $this->getAnswers($sourceStationId);
|
||||
foreach($answers as &$answer) {
|
||||
$this->db->query(
|
||||
'INSERT INTO stationtypes_singlechoice_answers '.
|
||||
'(stationtypes_singlechoice_station_id, pos, answer) '.
|
||||
'SELECT ?, pos, answer '.
|
||||
'FROM stationtypes_singlechoice_answers '.
|
||||
'WHERE id = ?',
|
||||
'ii',
|
||||
$targetStationId,
|
||||
$answer['id']
|
||||
);
|
||||
$answerIds[$answer['id']] = $this->db->getInsertId();
|
||||
}
|
||||
|
||||
// Set correct answer
|
||||
if(!is_null($question['answer_id'])) {
|
||||
$this->setCorrectAnswer(
|
||||
$targetStationId,
|
||||
$answerIds[$question['answer_id']]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the question for a Station.
|
||||
*
|
||||
* @param int $userId ID of creating user
|
||||
* @param int $stationId ID of Station to set
|
||||
*/
|
||||
public function setQuestion($userId, $stationId)
|
||||
{
|
||||
$this->db->query(
|
||||
'INSERT INTO stationtypes_singlechoice '.
|
||||
'(station_id, created_user_id) '.
|
||||
'VALUES '.
|
||||
'(?, ?) '.
|
||||
'ON DUPLICATE KEY UPDATE '.
|
||||
'created_user_id = ?',
|
||||
'iii',
|
||||
$stationId,
|
||||
$userId,
|
||||
$userId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the question for a Station.
|
||||
*
|
||||
* @param int $stationId ID of Station to get question for
|
||||
* @return array Question data
|
||||
*/
|
||||
public function getQuestion($stationId)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT station_id, created, answer_id '.
|
||||
'FROM stationtypes_singlechoice '.
|
||||
'WHERE station_id = ?',
|
||||
'i',
|
||||
$stationId
|
||||
);
|
||||
if(!empty($data)) {
|
||||
return $data[0];
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get all answers for a question.
|
||||
*
|
||||
* @param int $stationId ID of Station
|
||||
* @return array List of answers
|
||||
*/
|
||||
public function getAnswers($stationId)
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT id, pos, answer '.
|
||||
'FROM stationtypes_singlechoice_answers '.
|
||||
'WHERE stationtypes_singlechoice_station_id = ? '.
|
||||
'ORDER BY pos',
|
||||
'i',
|
||||
$stationId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set an answer for a Station.
|
||||
*
|
||||
* @param int $userId ID of creating user
|
||||
* @param int $stationId ID of Station to set answer for
|
||||
* @param int $pos Position of answer
|
||||
* @param string $answer Answer text
|
||||
*/
|
||||
public function setAnswer($userId, $stationId, $pos, $answer)
|
||||
{
|
||||
// Check if answer already exists
|
||||
$data = $this->db->query(
|
||||
'SELECT id '.
|
||||
'FROM stationtypes_singlechoice_answers '.
|
||||
'WHERE stationtypes_singlechoice_station_id = ? AND pos = ?',
|
||||
'ii',
|
||||
$stationId,
|
||||
$pos
|
||||
);
|
||||
|
||||
// Set new answer
|
||||
if(!empty($data))
|
||||
{
|
||||
// Update answer
|
||||
$answerId = $data[0]['id'];
|
||||
$this->db->query(
|
||||
'UPDATE stationtypes_singlechoice_answers '.
|
||||
'SET answer = ? '.
|
||||
'WHERE id = ?',
|
||||
'si',
|
||||
$answer,
|
||||
$answerId
|
||||
);
|
||||
|
||||
return $answerId;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Insert new answer
|
||||
$this->db->query(
|
||||
'INSERT INTO stationtypes_singlechoice_answers '.
|
||||
'(stationtypes_singlechoice_station_id, pos, answer) '.
|
||||
'VALUES '.
|
||||
'(?, ?, ?)',
|
||||
'iis',
|
||||
$stationId,
|
||||
$pos,
|
||||
$answer
|
||||
);
|
||||
|
||||
// Get ID of inserted anser
|
||||
return $this->db->getInsertId();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the correct answer for a Station/question.
|
||||
*
|
||||
* @param int $stationId ID of Station to set
|
||||
* @param int $answerId ID of correct answer
|
||||
*/
|
||||
public function setCorrectAnswer($stationId, $answerId)
|
||||
{
|
||||
$this->db->query(
|
||||
'UPDATE stationtypes_singlechoice '.
|
||||
'SET answer_id = ? '.
|
||||
'WHERE station_id = ?',
|
||||
'ii',
|
||||
$answerId,
|
||||
$stationId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delete all answers of a Station above a given index.
|
||||
*
|
||||
* @param int $stationId ID of Station to delete answers for
|
||||
* @param int $offset Offset to delete answers above
|
||||
*/
|
||||
public function deleteAnswers($stationId, $offset)
|
||||
{
|
||||
// Delete answers
|
||||
$this->db->query(
|
||||
'DELETE FROM stationtypes_singlechoice_answers '.
|
||||
'WHERE stationtypes_singlechoice_station_id = ? AND pos > ?',
|
||||
'ii',
|
||||
$stationId,
|
||||
$offset
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Save Character group’s submitted answer for a station/question.
|
||||
*
|
||||
* @param int $stationId ID of Station/question
|
||||
* @param int $charactergroupId ID of Character group
|
||||
* @param int $answerId ID of submitted answer
|
||||
*/
|
||||
public function setCharactergroupSubmission($stationId, $charactergroupId, $answerId)
|
||||
{
|
||||
$this->db->query(
|
||||
'INSERT INTO stationtypes_singlechoice_charactergroups '.
|
||||
'(stationtypes_singlechoice_station_id, charactergroup_id, answer_id) '.
|
||||
'VALUES '.
|
||||
'(?, ?, ?) '.
|
||||
'ON DUPLICATE KEY UPDATE '.
|
||||
'answer_id = ?',
|
||||
'iiii',
|
||||
$stationId, $charactergroupId, $answerId, $answerId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Character group’s submission for a Station/question.
|
||||
*
|
||||
* @param int $stationId ID of Station/question
|
||||
* @param int $charactergroupId ID of Character group
|
||||
* @return int ID of submitted answer
|
||||
*/
|
||||
public function getCharactergroupSubmission($stationId, $charactergroupId)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT answer_id '.
|
||||
'FROM stationtypes_singlechoice_charactergroups '.
|
||||
'WHERE stationtypes_singlechoice_station_id = ? AND charactergroup_id = ?',
|
||||
'ii',
|
||||
$stationId, $charactergroupId
|
||||
);
|
||||
if(!empty($data)) {
|
||||
return intval($data[0]['answer_id']);
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
60
stationtypes/singlechoice/html/edittask.tpl
Normal file
60
stationtypes/singlechoice/html/edittask.tpl
Normal file
|
@ -0,0 +1,60 @@
|
|||
<form method="post">
|
||||
<fieldset>
|
||||
<legend><?=_('Question')?></legend>
|
||||
<?=$t->t($task)?>
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<legend><?=_('Answers')?></legend>
|
||||
<ol id="answers">
|
||||
<?php foreach($answers as $answerIndex => &$answer) : ?>
|
||||
<li>
|
||||
<?=_('Answer')?>:<br />
|
||||
<label>
|
||||
<input id="answer-<?=$answerIndex?>-tick" type="radio" name="answer" value="<?=$answerIndex?>" <?php if($answer['id'] == $question['answer_id']) : ?>checked="checked"<?php endif ?> />
|
||||
<?=_('correct')?>
|
||||
</label>
|
||||
<textarea id="answer-<?=$answerIndex?>" name="answers[<?=$answerIndex?>][answer]" class="answer">
|
||||
<?=$answer['answer']?>
|
||||
</textarea>
|
||||
<button class="remove-answer" type="button">−</button>
|
||||
<hr />
|
||||
</li>
|
||||
<?php endforeach ?>
|
||||
<li>
|
||||
<button class="add-answer" type="button">+</button>
|
||||
</li>
|
||||
</ol>
|
||||
</fieldset>
|
||||
<input type="submit" name="save" value="<?=_('save')?>" />
|
||||
</form>
|
||||
|
||||
<script>
|
||||
// Text editors
|
||||
$('textarea.answer').markItUp(mySettings);
|
||||
|
||||
// Answers
|
||||
var answerIndex = <?=count($answers)?>;
|
||||
var answerElement = '<label><input id="answer-ANSWERINDEX-tick" type="radio" name="answer" value="ANSWERINDEX" /> <?=_('correct answer')?></label>' +
|
||||
'<textarea id="answer-ANSWERINDEX" name="answers[ANSWERINDEX][answer]" class="answer"></textarea>' +
|
||||
'<button class="remove-answer" type="button">−</button>' +
|
||||
'<hr />';
|
||||
$(".add-answer").click(addAnswer);
|
||||
$(".remove-answer").click(removeAnswer);
|
||||
function addAnswer(event)
|
||||
{
|
||||
event.preventDefault();
|
||||
|
||||
var parent = $(event.target).parent();
|
||||
var element = '<li>' + answerElement.replace(/ANSWERINDEX/g, answerIndex) + '</li>';
|
||||
parent.before(element);
|
||||
$("#answers li:nth-last-child(2) .remove-answer").click(removeAnswer);
|
||||
$('#answers li:nth-last-child(2) textarea.answer').markItUp(mySettings);
|
||||
|
||||
answerIndex++;
|
||||
}
|
||||
function removeAnswer(event)
|
||||
{
|
||||
event.preventDefault();
|
||||
$(event.target).parent().remove();
|
||||
}
|
||||
</script>
|
13
stationtypes/singlechoice/html/quest.tpl
Normal file
13
stationtypes/singlechoice/html/quest.tpl
Normal file
|
@ -0,0 +1,13 @@
|
|||
<form method="post" class="multiplechoice">
|
||||
<ol class="mchoice">
|
||||
<?php foreach($answers as $i => &$answer) : ?>
|
||||
<li class="cf">
|
||||
<input type="radio" id="answer[<?=$i?>]" name="answer" value="<?=$answer['id']?>" <?php if(array_key_exists('submission', $question) && $question['submission'] === $answer['id']) : ?>checked="checked"<?php endif ?> <?php if($tried) : ?>disabled="disabled"<?php endif ?>/>
|
||||
<label for="answer[<?=$i?>]"><?=$t->t($answer['answer'])?></label>
|
||||
</li>
|
||||
<?php endforeach ?>
|
||||
</ol>
|
||||
<?php if(!$tried) : ?>
|
||||
<input type="submit" name="submit" value="<?=_('solve')?>" />
|
||||
<?php endif ?>
|
||||
</form>
|
Loading…
Add table
Add a link
Reference in a new issue