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/keyword/KeywordStationtypeAgent.inc
Normal file
24
stationtypes/keyword/KeywordStationtypeAgent.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 keyword access.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class KeywordStationtypeAgent extends \hhu\z\agents\StationtypeAgent
|
||||
{
|
||||
}
|
||||
|
||||
?>
|
||||
201
stationtypes/keyword/KeywordStationtypeController.inc
Normal file
201
stationtypes/keyword/KeywordStationtypeController.inc
Normal file
|
|
@ -0,0 +1,201 @@
|
|||
<?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 keyword access.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class KeywordStationtypeController extends \hhu\z\controllers\StationtypeController
|
||||
{
|
||||
/**
|
||||
* Required models
|
||||
*/
|
||||
public $models = array('charactergroupsqueststations');
|
||||
/**
|
||||
* Required components
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $components = array('validation', 'questtypedata');
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Save the answer of a Character group for 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
|
||||
* @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->Keyword->setCharactergroupSubmission($station['id'], $charactergroup['id'], $answer);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if answer of a Character group for a Station matches the correct one.
|
||||
*
|
||||
* @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
|
||||
* @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 right answers
|
||||
$task = $this->Keyword->getKeywordTask($station['id']);
|
||||
|
||||
// Match regex with user answers
|
||||
return $this->isMatching($task['keyword_regex'], $answer);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Action: quest.
|
||||
*
|
||||
* Show 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
|
||||
* @param array $charactergroup Current Character group data
|
||||
*/
|
||||
public function quest($seminary, $groupsgroup, $quest, $station, $charactergroup)
|
||||
{
|
||||
// Get submission
|
||||
$submission = null;
|
||||
if(!is_null($charactergroup)) {
|
||||
$submission = $this->Keyword->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('submission', $submission);
|
||||
$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 right answers
|
||||
$task = $this->Keyword->getKeywordTask($station['id']);
|
||||
|
||||
// Values
|
||||
$keyword = $task['keyword_regex'];
|
||||
$validations = array();
|
||||
|
||||
// Save data
|
||||
if($this->request->getRequestMethod() == 'POST' && !is_null($this->request->getPostParam('save')))
|
||||
{
|
||||
// Get params and validate them
|
||||
$keyword = $this->request->getPostParam('keyword');
|
||||
|
||||
// Validate regex
|
||||
$keywordValidation = @preg_match($keyword, '') !== false;
|
||||
if($keywordValidation !== true) {
|
||||
$validations = $this->Validation->addValidationResult($validations, 'keyword', 'regex', $keywordValidation);
|
||||
}
|
||||
|
||||
// Save and redirect
|
||||
if(empty($validations))
|
||||
{
|
||||
// Save keyword
|
||||
$this->Keyword->setKeywordForStation(
|
||||
$this->Auth->getUserId(),
|
||||
$station['id'],
|
||||
$keyword
|
||||
);
|
||||
|
||||
// Redirect
|
||||
$this->redirect(
|
||||
$this->linker->link(
|
||||
array(
|
||||
'station',
|
||||
$seminary['url'],
|
||||
$groupsgroup['url'],
|
||||
$quest['url'],
|
||||
$station['url']
|
||||
),
|
||||
1
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Pass data to view
|
||||
$this->set('keyword', $keyword);
|
||||
$this->set('validations', $validations);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Check if an Character answer matches a Regex.
|
||||
*
|
||||
* @param string $regex Regex to match against
|
||||
* @param string $answer Character answer to match
|
||||
* @return boolean Whether answer matches Regex or not
|
||||
*/
|
||||
private function isMatching($regex, $answer)
|
||||
{
|
||||
// Check regex
|
||||
if(empty($regex)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Execute regex
|
||||
$score = preg_match($regex, trim($answer));
|
||||
|
||||
|
||||
// Return result
|
||||
return ($score !== false && $score > 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
145
stationtypes/keyword/KeywordStationtypeModel.inc
Normal file
145
stationtypes/keyword/KeywordStationtypeModel.inc
Normal file
|
|
@ -0,0 +1,145 @@
|
|||
<?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 keyword access.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class KeywordStationtypeModel 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 keyword
|
||||
$this->db->query(
|
||||
'INSERT INTO stationtypes_keyword '.
|
||||
'(station_id, created_user_id, keyword_regex) '.
|
||||
'SELECT ?, ?, keyword_regex '.
|
||||
'FROM stationtypes_keyword '.
|
||||
'WHERE station_id = ?',
|
||||
'iii',
|
||||
$targetStationId, $userId,
|
||||
$sourceStationId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the task of a keyword Station
|
||||
*
|
||||
* @param int $stationId ID of Station
|
||||
* @return array Task data
|
||||
*/
|
||||
public function getKeywordTask($stationId)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT keyword_regex '.
|
||||
'FROM stationtypes_keyword '.
|
||||
'WHERE station_id = ?',
|
||||
'i',
|
||||
$stationId
|
||||
);
|
||||
if(!empty($data)) {
|
||||
return $data[0];
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the keyword (regex) for a Station.
|
||||
*
|
||||
* @param int $userId ID of creating user
|
||||
* @param int $stationId ID ot Station to set keyword for
|
||||
* @param string $keyword Keyword (regex)
|
||||
*/
|
||||
public function setKeywordForStation($userId, $stationId, $keyword)
|
||||
{
|
||||
$this->db->query(
|
||||
'INSERT INTO stationtypes_keyword '.
|
||||
'(station_id, created_user_id, keyword_regex) '.
|
||||
'VALUES '.
|
||||
'(?, ?, ?) '.
|
||||
'ON DUPLICATE KEY UPDATE '.
|
||||
'created_user_id = ?, keyword_regex = ?',
|
||||
'iisis',
|
||||
$stationId, $userId, $keyword,
|
||||
$userId, $keyword
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Save Character group’s submitted answer for a station.
|
||||
*
|
||||
* @param int $stationId ID of Station
|
||||
* @param int $charactergroupId ID of Character group
|
||||
* @param string $answer Submitted answer
|
||||
*/
|
||||
public function setCharactergroupSubmission($stationId, $charactergroupId, $answer)
|
||||
{
|
||||
$this->db->query(
|
||||
'INSERT INTO stationtypes_keyword_charactergroups '.
|
||||
'(station_id, charactergroup_id, keyword) '.
|
||||
'VALUES '.
|
||||
'(?, ?, ?) '.
|
||||
'ON DUPLICATE KEY UPDATE '.
|
||||
'keyword = ?',
|
||||
'iiss',
|
||||
$stationId, $charactergroupId, $answer, $answer
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Character group’s submitted answer for a station.
|
||||
*
|
||||
* @param int $stationId ID of Station
|
||||
* @param int $charactergroupId ID of Character group
|
||||
* @return string Submitted answer
|
||||
*/
|
||||
public function getCharactergroupSubmission($stationId, $charactergroupId)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT keyword '.
|
||||
'FROM stationtypes_keyword_charactergroups '.
|
||||
'WHERE station_id = ? AND charactergroup_id = ?',
|
||||
'ii',
|
||||
$stationId, $charactergroupId
|
||||
);
|
||||
if(!empty($data)) {
|
||||
return $data[0]['keyword'];
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
29
stationtypes/keyword/html/edittask.tpl
Normal file
29
stationtypes/keyword/html/edittask.tpl
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
<?php if(!empty($validations)) : ?>
|
||||
<ul>
|
||||
<?php foreach($validations as $field => &$settings) : ?>
|
||||
<li>
|
||||
<ul>
|
||||
<?php foreach($settings as $setting => $value) : ?>
|
||||
<li>
|
||||
<?php
|
||||
switch($setting) {
|
||||
case 'regex': echo _('Regex invalid');
|
||||
break;
|
||||
default: echo _('Regex invalid');
|
||||
}
|
||||
?>
|
||||
</li>
|
||||
<?php endforeach ?>
|
||||
</ul>
|
||||
</li>
|
||||
<?php endforeach ?>
|
||||
</ul>
|
||||
<?php endif ?>
|
||||
|
||||
<form method="post">
|
||||
<fieldset>
|
||||
<label for="keyword"><?=_('Keyword')?>:</label>
|
||||
<input type="text" name="keyword" value="<?=$keyword?>" placeholder="/regex/i" />
|
||||
</fieldset>
|
||||
<input type="submit" name="save" value="<?=_('save')?>" />
|
||||
</form>
|
||||
6
stationtypes/keyword/html/quest.tpl
Normal file
6
stationtypes/keyword/html/quest.tpl
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
<form method="post" class="keyword">
|
||||
<input type="text" id="keyword" name="answer" <?php if(!is_null($submission)) : ?>value="<?=$submission?>"<?php endif ?> <?php if($tried) : ?>disabled="disabled"<?php endif ?>/>
|
||||
<?php if(!$tried) : ?>
|
||||
<input type="submit" name="submit" value="<?=_('solve')?>" />
|
||||
<?php endif ?>
|
||||
</form>
|
||||
|
|
@ -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 multiple choice task.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class MultiplechoiceStationtypeAgent extends \hhu\z\agents\StationtypeAgent
|
||||
{
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
@ -0,0 +1,196 @@
|
|||
<?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 multiple choice task.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class MultiplechoiceStationtypeController 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)
|
||||
{
|
||||
$answers = (!is_array($answer)) ? array() : $answer;
|
||||
$solutions = $this->Multiplechoice->getAnswers($station['id']);
|
||||
foreach($solutions as &$solution)
|
||||
{
|
||||
$answer = (array_key_exists($solution['pos']-1, $answers)) ? true : false;
|
||||
$this->Multiplechoice->setCharactergroupSubmission($solution['id'], $charactergroup['id'], $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)
|
||||
{
|
||||
$answers = (!is_array($answer)) ? array() : $answer;
|
||||
$solutions = $this->Multiplechoice->getAnswers($station['id']);
|
||||
foreach($solutions as &$solution)
|
||||
{
|
||||
if(is_null($solution['tick'])) {
|
||||
continue;
|
||||
}
|
||||
if($solution['tick']) {
|
||||
if(!array_key_exists($solution['pos']-1, $answers)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(array_key_exists($solution['pos']-1, $answers)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// All questions correct answerd
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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 answers
|
||||
$answers = $this->Multiplechoice->getAnswers($station['id']);
|
||||
if(!is_null($charactergroup)) {
|
||||
foreach($answers as &$answer) {
|
||||
$answer['submission'] = $this->Multiplechoice->getCharactergroupSubmission(
|
||||
$answer['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('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 questions
|
||||
$answers = $this->Multiplechoice->getAnswers($station['id']);
|
||||
|
||||
// Save data
|
||||
if($this->request->getRequestMethod() == 'POST' && !is_null($this->request->getPostParam('save')))
|
||||
{
|
||||
// Get params
|
||||
$answers = $this->request->getPostParam('answers');
|
||||
if(is_null($answers)) {
|
||||
$answers = array();
|
||||
}
|
||||
$answers = array_values($answers);
|
||||
|
||||
// Save answers
|
||||
foreach($answers as $answerIndex => &$answer)
|
||||
{
|
||||
$this->Multiplechoice->setAnswer(
|
||||
$this->Auth->getUserId(),
|
||||
$station['id'],
|
||||
$answerIndex + 1,
|
||||
$answer['answer'],
|
||||
array_key_exists('tick', $answer)
|
||||
);
|
||||
}
|
||||
|
||||
// Delete deleted answers
|
||||
$this->Multiplechoice->deleteAnswers(
|
||||
$station['id'],
|
||||
count($answers)
|
||||
);
|
||||
|
||||
// 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('answers', $answers);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
166
stationtypes/multiplechoice/MultiplechoiceStationtypeModel.inc
Normal file
166
stationtypes/multiplechoice/MultiplechoiceStationtypeModel.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\stationtypes;
|
||||
|
||||
|
||||
/**
|
||||
* Model of the StationtypeAgent for a multiple choice task.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class MultiplechoiceStationtypeModel 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 answers
|
||||
$this->db->query(
|
||||
'INSERT INTO stationtypes_multiplechoice '.
|
||||
'(created_user_id, station_id, pos, answer, tick) '.
|
||||
'SELECT ?, ?, pos, answer, tick '.
|
||||
'FROM stationtypes_multiplechoice '.
|
||||
'WHERE station_id = ?',
|
||||
'iii',
|
||||
$userId, $targetStationId,
|
||||
$sourceStationId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get all answers for a Station
|
||||
*
|
||||
* @param int $stationId ID of Station
|
||||
* @return array List of answers
|
||||
*/
|
||||
public function getAnswers($stationId)
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT id, pos, answer, tick '.
|
||||
'FROM stationtypes_multiplechoice '.
|
||||
'WHERE 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
|
||||
* @param int $tick Whether the answer is correct or not
|
||||
*/
|
||||
public function setAnswer($userId, $stationId, $pos, $answer, $tick)
|
||||
{
|
||||
$this->db->query(
|
||||
'INSERT INTO stationtypes_multiplechoice '.
|
||||
'(created_user_id, station_id, pos, answer, tick) '.
|
||||
'VALUES '.
|
||||
'(?, ?, ?, ?, ?) '.
|
||||
'ON DUPLICATE KEY UPDATE '.
|
||||
'answer = ?, tick = ?',
|
||||
'iiisisi',
|
||||
$userId,
|
||||
$stationId,
|
||||
$pos,
|
||||
$answer,
|
||||
$tick,
|
||||
$answer,
|
||||
$tick
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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_multiplechoice '.
|
||||
'WHERE station_id = ? AND pos > ?',
|
||||
'ii',
|
||||
$stationId,
|
||||
$offset
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Save Character group’s submission for an answer
|
||||
*
|
||||
* @param int $answerId ID of answer
|
||||
* @param int $charactergroupId ID of Character group
|
||||
* @param string $answer Submitted answer
|
||||
*/
|
||||
public function setCharactergroupSubmission($answerId, $charactergroupId, $answer)
|
||||
{
|
||||
$this->db->query(
|
||||
'INSERT INTO stationtypes_multiplechoice_charactergroups '.
|
||||
'(stationtypes_multiplechoice_id, charactergroup_id, ticked) '.
|
||||
'VALUES '.
|
||||
'(?, ?, ?) '.
|
||||
'ON DUPLICATE KEY UPDATE '.
|
||||
'ticked = ?',
|
||||
'iiii',
|
||||
$answerId, $charactergroupId, $answer, $answer
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Character group’s submission for an answer.
|
||||
*
|
||||
* @param int $answerId ID of answer
|
||||
* @param int $charactergroupId ID of Character group
|
||||
* @return boolean Submission
|
||||
*/
|
||||
public function getCharactergroupSubmission($answerId, $charactergroupId)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT ticked '.
|
||||
'FROM stationtypes_multiplechoice_charactergroups '.
|
||||
'WHERE stationtypes_multiplechoice_id = ? AND charactergroup_id = ?',
|
||||
'ii',
|
||||
$answerId, $charactergroupId
|
||||
);
|
||||
if(!empty($data)) {
|
||||
return boolval($data[0]['ticked']);
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
60
stationtypes/multiplechoice/html/edittask.tpl
Normal file
60
stationtypes/multiplechoice/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="checkbox" name="answers[<?=$answerIndex?>][tick]" <?php if(array_key_exists('tick', $answer) && $answer['tick']) : ?>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="checkbox" name="answers[ANSWERINDEX][tick]" /> <?=_('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/multiplechoice/html/quest.tpl
Normal file
13
stationtypes/multiplechoice/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="checkbox" id="answer[<?=$i?>]" name="answer[<?=$i?>]" value="true" <?php if(array_key_exists('submission', $answer) && $answer['submission'] === true) : ?>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>
|
||||
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