replace tabs with spaces
This commit is contained in:
parent
0c6100a1ae
commit
45cd7e795d
40 changed files with 27652 additions and 27647 deletions
|
|
@ -1,24 +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 a boss-fight.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class BossfightQuesttypeAgent extends \hhu\z\agents\QuesttypeAgent
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 a boss-fight.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class BossfightQuesttypeAgent extends \hhu\z\agents\QuesttypeAgent
|
||||
{
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -1,292 +1,292 @@
|
|||
<?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 BossfightQuesttypeAgent for a boss-fight.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class BossfightQuesttypeController extends \hhu\z\controllers\QuesttypeController
|
||||
{
|
||||
/**
|
||||
* Required models
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $models = array('media');
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
// Prepare session
|
||||
$this->prepareSession($quest['id']);
|
||||
|
||||
// Remove previous answers
|
||||
$this->Bossfight->clearCharacterSubmissions($quest['id'], $character['id']);
|
||||
|
||||
// Save answers
|
||||
foreach($_SESSION['quests'][$quest['id']]['stages'] as &$stage) {
|
||||
$this->Bossfight->setCharacterSubmission($stage['id'], $character['id']);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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
|
||||
* @param array $answers Character answers for the Quest
|
||||
* @return boolean True/false for a right/wrong answer or null for moderator evaluation
|
||||
*/
|
||||
public function matchAnswersOfCharacter($seminary, $questgroup, $quest, $character, $answers)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Action: quest.
|
||||
*
|
||||
* Display a stage with a text and the answers for the following
|
||||
* stages.
|
||||
*
|
||||
* @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 Boss-Fight
|
||||
$fight = $this->Bossfight->getBossFight($quest['id']);
|
||||
if(!is_null($fight) && !is_null($fight['boss_seminarymedia_id'])) {
|
||||
$fight['bossmedia'] = $this->Media->getSeminaryMediaById($fight['boss_seminarymedia_id']);
|
||||
}
|
||||
|
||||
// Prepare session
|
||||
$this->prepareSession($quest['id']);
|
||||
|
||||
// Get Stage
|
||||
if($this->request->getRequestMethod() == 'POST' && !is_null($this->request->getPostParam('submit_stages')))
|
||||
{
|
||||
$stages = $this->request->getPostParam('submit_stages');
|
||||
$stageId = array_keys($stages)[0];
|
||||
$stage = $this->Bossfight->getStageById($stageId);
|
||||
}
|
||||
else
|
||||
{
|
||||
$_SESSION['quests'][$quest['id']]['stages'] = array();
|
||||
$stage = $this->Bossfight->getFirstStage($quest['id']);
|
||||
}
|
||||
|
||||
// Store Stage in session
|
||||
if(count($_SESSION['quests'][$quest['id']]['stages']) == 0 || $_SESSION['quests'][$quest['id']]['stages'][count($_SESSION['quests'][$quest['id']]['stages'])-1]['id'] != $stage['id']) {
|
||||
$_SESSION['quests'][$quest['id']]['stages'][] = $stage;
|
||||
}
|
||||
|
||||
// Calculate lives
|
||||
$lives = array(
|
||||
'character' => $fight['lives_character'],
|
||||
'boss' => $fight['lives_boss']
|
||||
);
|
||||
foreach($_SESSION['quests'][$quest['id']]['stages'] as &$stage)
|
||||
{
|
||||
$lives['character'] += $stage['livedrain_character'];
|
||||
$lives['boss'] += $stage['livedrain_boss'];
|
||||
}
|
||||
|
||||
// Get Child-Stages
|
||||
$childStages = $this->Bossfight->getChildStages($stage['id']);
|
||||
|
||||
// Get answer of Character
|
||||
if($this->request->getGetParam('show-answer') == 'true') {
|
||||
foreach($childStages as &$childStage) {
|
||||
$childStage['answer'] = $this->Bossfight->getCharacterSubmission($childStage['id'], $character['id']);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Pass data to view
|
||||
$this->set('seminary', $seminary);
|
||||
$this->set('character', $character);
|
||||
$this->set('fight', $fight);
|
||||
$this->set('stage', $stage);
|
||||
$this->set('lives', $lives);
|
||||
$this->set('childStages', $childStages);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Action: submission.
|
||||
*
|
||||
* Display all stages with the answers the character has
|
||||
* choosen.
|
||||
*
|
||||
* @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 Boss-Fight
|
||||
$fight = $this->Bossfight->getBossFight($quest['id']);
|
||||
if(!is_null($fight['boss_seminarymedia_id'])) {
|
||||
$fight['bossmedia'] = $this->Media->getSeminaryMediaById($fight['boss_seminarymedia_id']);
|
||||
}
|
||||
|
||||
// Get stages
|
||||
$stages = array();
|
||||
$stage = $this->Bossfight->getFirstStage($quest['id']);
|
||||
while(!is_null($stage))
|
||||
{
|
||||
$stages[] = $stage;
|
||||
|
||||
$childStages = $this->Bossfight->getChildStages($stage['id']);
|
||||
$stage = null;
|
||||
foreach($childStages as &$childStage)
|
||||
{
|
||||
if($this->Bossfight->getCharacterSubmission($childStage['id'], $character['id']))
|
||||
{
|
||||
$stage = $childStage;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Calculate lives
|
||||
$stages[0]['lives'] = array(
|
||||
'character' => $fight['lives_character'],
|
||||
'boss' => $fight['lives_boss']
|
||||
);
|
||||
for($i=1; $i<count($stages); $i++)
|
||||
{
|
||||
$stages[$i]['lives'] = array(
|
||||
'character' => $stages[$i-1]['lives']['character'] + $stages[$i]['livedrain_character'],
|
||||
'boss' => $stages[$i-1]['lives']['boss'] + $stages[$i]['livedrain_boss'],
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// Pass data to view
|
||||
$this->set('seminary', $seminary);
|
||||
$this->set('character', $character);
|
||||
$this->set('fight', $fight);
|
||||
$this->set('stages', $stages);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
|
||||
/**
|
||||
* TODO Action: edittask.
|
||||
*
|
||||
* Edit the task of a Quest.
|
||||
*
|
||||
* @param array $seminary Current Seminary data
|
||||
* @param array $questgroup Current Questgroup data
|
||||
* @param array $quest Current Quest data
|
||||
*/
|
||||
public function edittask($seminary, $questgroup, $quest)
|
||||
{
|
||||
$fight = $this->Bossfight->getBossFight($quest['id']);
|
||||
/*
|
||||
if(!is_null($fight['boss_seminarymedia_id'])) {
|
||||
$fight['bossmedia'] = $this->Media->getSeminaryMediaById($fight['boss_seminarymedia_id']);
|
||||
}
|
||||
*/
|
||||
|
||||
// Get stages
|
||||
$stage = $this->Bossfight->getFirstStage($quest['id']);
|
||||
$stage['childs'] = $this->getChildStages($stage['id']);
|
||||
/**
|
||||
* Controller of the BossfightQuesttypeAgent for a boss-fight.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class BossfightQuesttypeController extends \hhu\z\controllers\QuesttypeController
|
||||
{
|
||||
/**
|
||||
* Required models
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $models = array('media');
|
||||
|
||||
|
||||
// Pass data to view
|
||||
$this->set('seminary', $seminary);
|
||||
$this->set('fight', $fight);
|
||||
$this->set('stages', $stage);
|
||||
//print_r($stage);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Prepare the session to store stage information in
|
||||
*
|
||||
* @param int $questId ID of Quest
|
||||
*/
|
||||
private function prepareSession($questId)
|
||||
{
|
||||
if(!array_key_exists('quests', $_SESSION)) {
|
||||
$_SESSION['quests'] = array();
|
||||
}
|
||||
if(!array_key_exists($questId, $_SESSION['quests'])) {
|
||||
$_SESSION['quests'][$questId] = array();
|
||||
}
|
||||
if(!array_key_exists('stages', $_SESSION['quests'][$questId])) {
|
||||
$_SESSION['quests'][$questId]['stages'] = array();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get all child-stages of a parent-stage.
|
||||
*
|
||||
* @param int $stageId ID of parent-stage
|
||||
* @return array List of child-stages
|
||||
*/
|
||||
private function getChildStages($stageId)
|
||||
{
|
||||
$childStages = $this->Bossfight->getChildStages($stageId);
|
||||
if(!empty($childStages)) {
|
||||
foreach($childStages as &$stage) {
|
||||
$stage['childs'] = $this->getChildStages($stage['id']);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
// Prepare session
|
||||
$this->prepareSession($quest['id']);
|
||||
|
||||
// Remove previous answers
|
||||
$this->Bossfight->clearCharacterSubmissions($quest['id'], $character['id']);
|
||||
|
||||
// Save answers
|
||||
foreach($_SESSION['quests'][$quest['id']]['stages'] as &$stage) {
|
||||
$this->Bossfight->setCharacterSubmission($stage['id'], $character['id']);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $childStages;
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* 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
|
||||
* @param array $answers Character answers for the Quest
|
||||
* @return boolean True/false for a right/wrong answer or null for moderator evaluation
|
||||
*/
|
||||
public function matchAnswersOfCharacter($seminary, $questgroup, $quest, $character, $answers)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Action: quest.
|
||||
*
|
||||
* Display a stage with a text and the answers for the following
|
||||
* stages.
|
||||
*
|
||||
* @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 Boss-Fight
|
||||
$fight = $this->Bossfight->getBossFight($quest['id']);
|
||||
if(!is_null($fight) && !is_null($fight['boss_seminarymedia_id'])) {
|
||||
$fight['bossmedia'] = $this->Media->getSeminaryMediaById($fight['boss_seminarymedia_id']);
|
||||
}
|
||||
|
||||
// Prepare session
|
||||
$this->prepareSession($quest['id']);
|
||||
|
||||
// Get Stage
|
||||
if($this->request->getRequestMethod() == 'POST' && !is_null($this->request->getPostParam('submit_stages')))
|
||||
{
|
||||
$stages = $this->request->getPostParam('submit_stages');
|
||||
$stageId = array_keys($stages)[0];
|
||||
$stage = $this->Bossfight->getStageById($stageId);
|
||||
}
|
||||
else
|
||||
{
|
||||
$_SESSION['quests'][$quest['id']]['stages'] = array();
|
||||
$stage = $this->Bossfight->getFirstStage($quest['id']);
|
||||
}
|
||||
|
||||
// Store Stage in session
|
||||
if(count($_SESSION['quests'][$quest['id']]['stages']) == 0 || $_SESSION['quests'][$quest['id']]['stages'][count($_SESSION['quests'][$quest['id']]['stages'])-1]['id'] != $stage['id']) {
|
||||
$_SESSION['quests'][$quest['id']]['stages'][] = $stage;
|
||||
}
|
||||
|
||||
// Calculate lives
|
||||
$lives = array(
|
||||
'character' => $fight['lives_character'],
|
||||
'boss' => $fight['lives_boss']
|
||||
);
|
||||
foreach($_SESSION['quests'][$quest['id']]['stages'] as &$stage)
|
||||
{
|
||||
$lives['character'] += $stage['livedrain_character'];
|
||||
$lives['boss'] += $stage['livedrain_boss'];
|
||||
}
|
||||
|
||||
// Get Child-Stages
|
||||
$childStages = $this->Bossfight->getChildStages($stage['id']);
|
||||
|
||||
// Get answer of Character
|
||||
if($this->request->getGetParam('show-answer') == 'true') {
|
||||
foreach($childStages as &$childStage) {
|
||||
$childStage['answer'] = $this->Bossfight->getCharacterSubmission($childStage['id'], $character['id']);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Pass data to view
|
||||
$this->set('seminary', $seminary);
|
||||
$this->set('character', $character);
|
||||
$this->set('fight', $fight);
|
||||
$this->set('stage', $stage);
|
||||
$this->set('lives', $lives);
|
||||
$this->set('childStages', $childStages);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Action: submission.
|
||||
*
|
||||
* Display all stages with the answers the character has
|
||||
* choosen.
|
||||
*
|
||||
* @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 Boss-Fight
|
||||
$fight = $this->Bossfight->getBossFight($quest['id']);
|
||||
if(!is_null($fight['boss_seminarymedia_id'])) {
|
||||
$fight['bossmedia'] = $this->Media->getSeminaryMediaById($fight['boss_seminarymedia_id']);
|
||||
}
|
||||
|
||||
// Get stages
|
||||
$stages = array();
|
||||
$stage = $this->Bossfight->getFirstStage($quest['id']);
|
||||
while(!is_null($stage))
|
||||
{
|
||||
$stages[] = $stage;
|
||||
|
||||
$childStages = $this->Bossfight->getChildStages($stage['id']);
|
||||
$stage = null;
|
||||
foreach($childStages as &$childStage)
|
||||
{
|
||||
if($this->Bossfight->getCharacterSubmission($childStage['id'], $character['id']))
|
||||
{
|
||||
$stage = $childStage;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Calculate lives
|
||||
$stages[0]['lives'] = array(
|
||||
'character' => $fight['lives_character'],
|
||||
'boss' => $fight['lives_boss']
|
||||
);
|
||||
for($i=1; $i<count($stages); $i++)
|
||||
{
|
||||
$stages[$i]['lives'] = array(
|
||||
'character' => $stages[$i-1]['lives']['character'] + $stages[$i]['livedrain_character'],
|
||||
'boss' => $stages[$i-1]['lives']['boss'] + $stages[$i]['livedrain_boss'],
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// Pass data to view
|
||||
$this->set('seminary', $seminary);
|
||||
$this->set('character', $character);
|
||||
$this->set('fight', $fight);
|
||||
$this->set('stages', $stages);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* TODO Action: edittask.
|
||||
*
|
||||
* Edit the task of a Quest.
|
||||
*
|
||||
* @param array $seminary Current Seminary data
|
||||
* @param array $questgroup Current Questgroup data
|
||||
* @param array $quest Current Quest data
|
||||
*/
|
||||
public function edittask($seminary, $questgroup, $quest)
|
||||
{
|
||||
$fight = $this->Bossfight->getBossFight($quest['id']);
|
||||
/*
|
||||
if(!is_null($fight['boss_seminarymedia_id'])) {
|
||||
$fight['bossmedia'] = $this->Media->getSeminaryMediaById($fight['boss_seminarymedia_id']);
|
||||
}
|
||||
*/
|
||||
|
||||
// Get stages
|
||||
$stage = $this->Bossfight->getFirstStage($quest['id']);
|
||||
$stage['childs'] = $this->getChildStages($stage['id']);
|
||||
|
||||
|
||||
// Pass data to view
|
||||
$this->set('seminary', $seminary);
|
||||
$this->set('fight', $fight);
|
||||
$this->set('stages', $stage);
|
||||
//print_r($stage);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Prepare the session to store stage information in
|
||||
*
|
||||
* @param int $questId ID of Quest
|
||||
*/
|
||||
private function prepareSession($questId)
|
||||
{
|
||||
if(!array_key_exists('quests', $_SESSION)) {
|
||||
$_SESSION['quests'] = array();
|
||||
}
|
||||
if(!array_key_exists($questId, $_SESSION['quests'])) {
|
||||
$_SESSION['quests'][$questId] = array();
|
||||
}
|
||||
if(!array_key_exists('stages', $_SESSION['quests'][$questId])) {
|
||||
$_SESSION['quests'][$questId]['stages'] = array();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get all child-stages of a parent-stage.
|
||||
*
|
||||
* @param int $stageId ID of parent-stage
|
||||
* @return array List of child-stages
|
||||
*/
|
||||
private function getChildStages($stageId)
|
||||
{
|
||||
$childStages = $this->Bossfight->getChildStages($stageId);
|
||||
if(!empty($childStages)) {
|
||||
foreach($childStages as &$stage) {
|
||||
$stage['childs'] = $this->getChildStages($stage['id']);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $childStages;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -1,37 +1,37 @@
|
|||
<?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 BossfightQuesttypeAgent for a boss-fight.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class BossfightQuesttypeModel extends \hhu\z\models\QuesttypeModel
|
||||
{
|
||||
/**
|
||||
* Required models
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $models = array('media');
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 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 BossfightQuesttypeAgent for a boss-fight.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class BossfightQuesttypeModel extends \hhu\z\models\QuesttypeModel
|
||||
{
|
||||
/**
|
||||
* Required models
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $models = array('media');
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Copy a Quest
|
||||
*
|
||||
*
|
||||
* @param int $userId ID of creating user
|
||||
* @param int $sourceQuestId ID of Quest to copy from
|
||||
* @param int $targetQuestId ID of Quest to copy to
|
||||
|
|
@ -63,170 +63,170 @@
|
|||
);
|
||||
|
||||
// Copy stages
|
||||
$stage = $this->getFirstStage($sourceQuestId);
|
||||
$stage = $this->getFirstStage($sourceQuestId);
|
||||
$this->copyStage($userId, $targetQuestId, $stage);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a Boss-Fight.
|
||||
*
|
||||
* @param int $questId ID of Quest
|
||||
* @return array Boss-Fight data
|
||||
*/
|
||||
public function getBossFight($questId)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT bossname, boss_seminarymedia_id, lives_character, lives_boss '.
|
||||
'FROM questtypes_bossfight '.
|
||||
'WHERE quest_id = ?',
|
||||
'i',
|
||||
$questId
|
||||
);
|
||||
if(!empty($data)) {
|
||||
/**
|
||||
* Get a Boss-Fight.
|
||||
*
|
||||
* @param int $questId ID of Quest
|
||||
* @return array Boss-Fight data
|
||||
*/
|
||||
public function getBossFight($questId)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT bossname, boss_seminarymedia_id, lives_character, lives_boss '.
|
||||
'FROM questtypes_bossfight '.
|
||||
'WHERE quest_id = ?',
|
||||
'i',
|
||||
$questId
|
||||
);
|
||||
if(!empty($data)) {
|
||||
return $data[0];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the first Stage to begin the Boss-Fight with.
|
||||
*
|
||||
* @param int $questId ID of Quest
|
||||
* @return array Data of first Stage
|
||||
*/
|
||||
public function getFirstStage($questId)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT id, parent_stage_id, text, question, livedrain_character, livedrain_boss '.
|
||||
'FROM questtypes_bossfight_stages '.
|
||||
'WHERE questtypes_bossfight_quest_id = ? AND parent_stage_id IS NULL',
|
||||
'i',
|
||||
$questId
|
||||
);
|
||||
if(!empty($data)) {
|
||||
return $data[0];
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a Stage by its ID.
|
||||
*
|
||||
* @param int $stageId ID of Stage
|
||||
* @return array Stage data or null
|
||||
*/
|
||||
public function getStageById($stageId)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT id, text, question, livedrain_character, livedrain_boss '.
|
||||
'FROM questtypes_bossfight_stages '.
|
||||
'WHERE id = ?',
|
||||
'i',
|
||||
$stageId
|
||||
);
|
||||
if(!empty($data)) {
|
||||
return $data[0];
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the follow-up Stages for a Stage.
|
||||
*
|
||||
* @param int $parentStageId ID of Stage to get follow-up Stages for
|
||||
* @return array List of follow-up Stages
|
||||
*/
|
||||
public function getChildStages($parentStageId)
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT id, parent_stage_id, text, question, livedrain_character, livedrain_boss '.
|
||||
'FROM questtypes_bossfight_stages '.
|
||||
'WHERE parent_stage_id = ?',
|
||||
'i',
|
||||
$parentStageId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Reset all Character submissions of a Boss-Fight.
|
||||
*
|
||||
* @param int $questId ID of Quest
|
||||
* @param int $characterId ID of Character
|
||||
*/
|
||||
public function clearCharacterSubmissions($questId, $characterId)
|
||||
{
|
||||
$this->db->query(
|
||||
'DELETE FROM questtypes_bossfight_stages_characters '.
|
||||
'WHERE questtypes_bossfight_stage_id IN ('.
|
||||
'SELECT id '.
|
||||
'FROM questtypes_bossfight_stages '.
|
||||
'WHERE questtypes_bossfight_quest_id = ?'.
|
||||
') AND character_id = ?',
|
||||
'ii',
|
||||
$questId,
|
||||
$characterId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Save Character’s submitted answer for one Boss-Fight-Stage.
|
||||
*
|
||||
* @param int $regexId ID of list
|
||||
* @param int $characterId ID of Character
|
||||
*/
|
||||
public function setCharacterSubmission($stageId, $characterId)
|
||||
{
|
||||
$this->db->query(
|
||||
'INSERT INTO questtypes_bossfight_stages_characters '.
|
||||
'(questtypes_bossfight_stage_id, character_id) '.
|
||||
'VALUES '.
|
||||
'(?, ?) '.
|
||||
'ON DUPLICATE KEY UPDATE '.
|
||||
'questtypes_bossfight_stage_id = ?',
|
||||
'iii',
|
||||
$stageId, $characterId, $stageId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get answer of one Boss-Fight-Stage submitted by Character.
|
||||
*
|
||||
* @param int $regexId ID of list
|
||||
* @param int $characterId ID of Character
|
||||
* @return boolean Stage taken
|
||||
*/
|
||||
public function getCharacterSubmission($stageId, $characterId)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT questtypes_bossfight_stage_id '.
|
||||
'FROM questtypes_bossfight_stages_characters '.
|
||||
'WHERE questtypes_bossfight_stage_id = ? AND character_id = ? ',
|
||||
'ii',
|
||||
$stageId, $characterId
|
||||
);
|
||||
|
||||
|
||||
return (!empty($data));
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the first Stage to begin the Boss-Fight with.
|
||||
*
|
||||
* @param int $questId ID of Quest
|
||||
* @return array Data of first Stage
|
||||
*/
|
||||
public function getFirstStage($questId)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT id, parent_stage_id, text, question, livedrain_character, livedrain_boss '.
|
||||
'FROM questtypes_bossfight_stages '.
|
||||
'WHERE questtypes_bossfight_quest_id = ? AND parent_stage_id IS NULL',
|
||||
'i',
|
||||
$questId
|
||||
);
|
||||
if(!empty($data)) {
|
||||
return $data[0];
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a Stage by its ID.
|
||||
*
|
||||
* @param int $stageId ID of Stage
|
||||
* @return array Stage data or null
|
||||
*/
|
||||
public function getStageById($stageId)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT id, text, question, livedrain_character, livedrain_boss '.
|
||||
'FROM questtypes_bossfight_stages '.
|
||||
'WHERE id = ?',
|
||||
'i',
|
||||
$stageId
|
||||
);
|
||||
if(!empty($data)) {
|
||||
return $data[0];
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the follow-up Stages for a Stage.
|
||||
*
|
||||
* @param int $parentStageId ID of Stage to get follow-up Stages for
|
||||
* @return array List of follow-up Stages
|
||||
*/
|
||||
public function getChildStages($parentStageId)
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT id, parent_stage_id, text, question, livedrain_character, livedrain_boss '.
|
||||
'FROM questtypes_bossfight_stages '.
|
||||
'WHERE parent_stage_id = ?',
|
||||
'i',
|
||||
$parentStageId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Reset all Character submissions of a Boss-Fight.
|
||||
*
|
||||
* @param int $questId ID of Quest
|
||||
* @param int $characterId ID of Character
|
||||
*/
|
||||
public function clearCharacterSubmissions($questId, $characterId)
|
||||
{
|
||||
$this->db->query(
|
||||
'DELETE FROM questtypes_bossfight_stages_characters '.
|
||||
'WHERE questtypes_bossfight_stage_id IN ('.
|
||||
'SELECT id '.
|
||||
'FROM questtypes_bossfight_stages '.
|
||||
'WHERE questtypes_bossfight_quest_id = ?'.
|
||||
') AND character_id = ?',
|
||||
'ii',
|
||||
$questId,
|
||||
$characterId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Save Character’s submitted answer for one Boss-Fight-Stage.
|
||||
*
|
||||
* @param int $regexId ID of list
|
||||
* @param int $characterId ID of Character
|
||||
*/
|
||||
public function setCharacterSubmission($stageId, $characterId)
|
||||
{
|
||||
$this->db->query(
|
||||
'INSERT INTO questtypes_bossfight_stages_characters '.
|
||||
'(questtypes_bossfight_stage_id, character_id) '.
|
||||
'VALUES '.
|
||||
'(?, ?) '.
|
||||
'ON DUPLICATE KEY UPDATE '.
|
||||
'questtypes_bossfight_stage_id = ?',
|
||||
'iii',
|
||||
$stageId, $characterId, $stageId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get answer of one Boss-Fight-Stage submitted by Character.
|
||||
*
|
||||
* @param int $regexId ID of list
|
||||
* @param int $characterId ID of Character
|
||||
* @return boolean Stage taken
|
||||
*/
|
||||
public function getCharacterSubmission($stageId, $characterId)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT questtypes_bossfight_stage_id '.
|
||||
'FROM questtypes_bossfight_stages_characters '.
|
||||
'WHERE questtypes_bossfight_stage_id = ? AND character_id = ? ',
|
||||
'ii',
|
||||
$stageId, $characterId
|
||||
);
|
||||
|
||||
|
||||
return (!empty($data));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Copy a Bossfight stage and its child-stages.
|
||||
*
|
||||
*
|
||||
* @param int $userId ID of copying user
|
||||
* @param int $targetQuestId ID of Quest to copy to
|
||||
* @param array $stage Data of stage to copy
|
||||
|
|
@ -269,7 +269,7 @@
|
|||
$this->copyStage($userId, $targetQuestId, $childStage, $stageIds);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -1,41 +1,41 @@
|
|||
<form method="post" enctype="multipart/form-data">
|
||||
<fieldset>
|
||||
<legend><?=_('Boss-Fight')?></legend>
|
||||
<label><?=_('Boss name')?></label>
|
||||
<input type="text" name="bossname" value="<?=$fight['bossname']?>" /><br />
|
||||
<label><?=_('Boss image')?></label>
|
||||
<input type="file" name="bossimage" /><br />
|
||||
<label><?=_('Boss lives')?></label>
|
||||
<input type="number" name="lives_boss" value="<?=$fight['lives_boss']?>" /><br />
|
||||
<label><?=_('Character lives')?></label>
|
||||
<input type="number" name="lives_character" value="<?=$fight['lives_character']?>" />
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<legend><?=_('Stages')?></legend>
|
||||
<?php renderStage($stages, $fight['lives_boss'], $fight['lives_character']); ?>
|
||||
</fieldset>
|
||||
<input type="submit" name="save" value="<?=_('save')?>" />
|
||||
<fieldset>
|
||||
<legend><?=_('Boss-Fight')?></legend>
|
||||
<label><?=_('Boss name')?></label>
|
||||
<input type="text" name="bossname" value="<?=$fight['bossname']?>" /><br />
|
||||
<label><?=_('Boss image')?></label>
|
||||
<input type="file" name="bossimage" /><br />
|
||||
<label><?=_('Boss lives')?></label>
|
||||
<input type="number" name="lives_boss" value="<?=$fight['lives_boss']?>" /><br />
|
||||
<label><?=_('Character lives')?></label>
|
||||
<input type="number" name="lives_character" value="<?=$fight['lives_character']?>" />
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<legend><?=_('Stages')?></legend>
|
||||
<?php renderStage($stages, $fight['lives_boss'], $fight['lives_character']); ?>
|
||||
</fieldset>
|
||||
<input type="submit" name="save" value="<?=_('save')?>" />
|
||||
</form>
|
||||
|
||||
<?php function renderStage($stage, $livesBoss, $livesCharacter, $level=0, $indices=array()) { ?>
|
||||
<div style="margin-left:<?=$level?>em">
|
||||
<h2><?=implode('.', $indices)?></h2>
|
||||
<?php if(!empty($stage['question'])) : ?>
|
||||
<p><?=$stage['question']?></p>
|
||||
<?php endif ?>
|
||||
<p><?=_('Character')?> <?=$livesCharacter?> vs. <?=$livesBoss?> <?=_('Boss')?></p>
|
||||
<p><?=$stage['text']?></p>
|
||||
<?php foreach($stage['childs'] as $index => &$childStage) : ?>
|
||||
<?php $childIndices = $indices; ?>
|
||||
<?php $childIndices[] = $index+1; ?>
|
||||
<?php renderStage($childStage, $livesBoss+$childStage['livedrain_boss'], $livesCharacter+$childStage['livedrain_character'], $level+1, $childIndices); ?>
|
||||
<?php endforeach ?>
|
||||
<?php if($livesBoss == 0 && $livesCharacter == 0) : ?>
|
||||
Bedie verloren
|
||||
<?php elseif($livesBoss == 0) : ?>
|
||||
Boss verloren, Character gewonnen
|
||||
<?php elseif($livesCharacter == 0) : ?>
|
||||
Boss gewonnen, Character verloren
|
||||
<?php endif ?>
|
||||
</div>
|
||||
<div style="margin-left:<?=$level?>em">
|
||||
<h2><?=implode('.', $indices)?></h2>
|
||||
<?php if(!empty($stage['question'])) : ?>
|
||||
<p><?=$stage['question']?></p>
|
||||
<?php endif ?>
|
||||
<p><?=_('Character')?> <?=$livesCharacter?> vs. <?=$livesBoss?> <?=_('Boss')?></p>
|
||||
<p><?=$stage['text']?></p>
|
||||
<?php foreach($stage['childs'] as $index => &$childStage) : ?>
|
||||
<?php $childIndices = $indices; ?>
|
||||
<?php $childIndices[] = $index+1; ?>
|
||||
<?php renderStage($childStage, $livesBoss+$childStage['livedrain_boss'], $livesCharacter+$childStage['livedrain_character'], $level+1, $childIndices); ?>
|
||||
<?php endforeach ?>
|
||||
<?php if($livesBoss == 0 && $livesCharacter == 0) : ?>
|
||||
Bedie verloren
|
||||
<?php elseif($livesBoss == 0) : ?>
|
||||
Boss verloren, Character gewonnen
|
||||
<?php elseif($livesCharacter == 0) : ?>
|
||||
Boss gewonnen, Character verloren
|
||||
<?php endif ?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
|
|
|||
|
|
@ -32,23 +32,23 @@
|
|||
<?php if(!is_null($stage)) : ?>
|
||||
<p><?=\hhu\z\Utils::t($stage['text'])?></p>
|
||||
<form method="post" action="<?=$linker->link(null,0,false,null,true,'task')?>">
|
||||
<input type="hidden" name="stage" value="<?=$stage['id']?>" />
|
||||
<ul class="bossfight cf">
|
||||
<?php foreach($childStages as &$childStage) : ?>
|
||||
<li class="option">
|
||||
<p><i>
|
||||
<?php if(array_key_exists('answer', $childStage) && $childStage['answer']) : ?>→<?php endif ?>
|
||||
<?=\hhu\z\Utils::t($childStage['question'])?>
|
||||
</i></p>
|
||||
<p><input type="submit" name="submit_stages[<?=$childStage['id']?>]" value="<?=_('Choose')?>" /></p>
|
||||
</li>
|
||||
<?php endforeach?>
|
||||
<?php if($lives['character'] == 0 || $lives['boss'] == 0) : ?>
|
||||
<li>
|
||||
<input type="hidden" name="answers" value="" />
|
||||
<input type="submit" name="submit" value="<?=_('solve')?>" />
|
||||
</li>
|
||||
<?php endif ?>
|
||||
</ul>
|
||||
<input type="hidden" name="stage" value="<?=$stage['id']?>" />
|
||||
<ul class="bossfight cf">
|
||||
<?php foreach($childStages as &$childStage) : ?>
|
||||
<li class="option">
|
||||
<p><i>
|
||||
<?php if(array_key_exists('answer', $childStage) && $childStage['answer']) : ?>→<?php endif ?>
|
||||
<?=\hhu\z\Utils::t($childStage['question'])?>
|
||||
</i></p>
|
||||
<p><input type="submit" name="submit_stages[<?=$childStage['id']?>]" value="<?=_('Choose')?>" /></p>
|
||||
</li>
|
||||
<?php endforeach?>
|
||||
<?php if($lives['character'] == 0 || $lives['boss'] == 0) : ?>
|
||||
<li>
|
||||
<input type="hidden" name="answers" value="" />
|
||||
<input type="submit" name="submit" value="<?=_('solve')?>" />
|
||||
</li>
|
||||
<?php endif ?>
|
||||
</ul>
|
||||
</form>
|
||||
<?php endif ?>
|
||||
|
|
|
|||
|
|
@ -1,38 +1,38 @@
|
|||
<div class="cf">
|
||||
<section class="opponent">
|
||||
<p class="portrait"><img src="<?=$linker->link(array('media','avatar',$seminary['url'],$character['charactertype_url'],$character['xplevel']))?>" class="hero" /></p>
|
||||
<p class="portrait"><img src="<?=$linker->link(array('media','avatar',$seminary['url'],$character['charactertype_url'],$character['xplevel']))?>" class="hero" /></p>
|
||||
</section>
|
||||
<section class="opponent">
|
||||
<p class="portrait"><img src="<?=$linker->link(array('media','seminary',$seminary['url'],$fight['bossmedia']['url']))?>" class="boss" /></p>
|
||||
<p class="portrait"><img src="<?=$linker->link(array('media','seminary',$seminary['url'],$fight['bossmedia']['url']))?>" class="boss" /></p>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<?php foreach($stages as &$stage) : ?>
|
||||
<p><?=$stage['question']?></p>
|
||||
<div class="cf">
|
||||
<section class="opponent">
|
||||
<p class="fwb"><?=$character['name']?></p>
|
||||
<p>
|
||||
<?php if($stage['lives']['character'] > 0) : ?>
|
||||
<?php foreach(range(1,$stage['lives']['character']) as $i) : ?>
|
||||
<i class="fa fa-heart fa-fw"></i>
|
||||
<?php endforeach ?>
|
||||
<?php else : ?>
|
||||
<?=_('lost')?>
|
||||
<?php endif ?>
|
||||
</p>
|
||||
</section>
|
||||
<section class="opponent">
|
||||
<p class="fwb"><?=$fight['bossname']?></p>
|
||||
<p>
|
||||
<?php if($stage['lives']['boss'] > 0) : ?>
|
||||
<?php foreach(range(1,$stage['lives']['boss']) as $i) : ?>
|
||||
<i class="fa fa-heart fa-fw"></i>
|
||||
<?php endforeach ?>
|
||||
<?php else : ?>
|
||||
<b><?=_('lost')?></b>
|
||||
<?php endif ?>
|
||||
</p>
|
||||
</section>
|
||||
<section class="opponent">
|
||||
<p class="fwb"><?=$character['name']?></p>
|
||||
<p>
|
||||
<?php if($stage['lives']['character'] > 0) : ?>
|
||||
<?php foreach(range(1,$stage['lives']['character']) as $i) : ?>
|
||||
<i class="fa fa-heart fa-fw"></i>
|
||||
<?php endforeach ?>
|
||||
<?php else : ?>
|
||||
<?=_('lost')?>
|
||||
<?php endif ?>
|
||||
</p>
|
||||
</section>
|
||||
<section class="opponent">
|
||||
<p class="fwb"><?=$fight['bossname']?></p>
|
||||
<p>
|
||||
<?php if($stage['lives']['boss'] > 0) : ?>
|
||||
<?php foreach(range(1,$stage['lives']['boss']) as $i) : ?>
|
||||
<i class="fa fa-heart fa-fw"></i>
|
||||
<?php endforeach ?>
|
||||
<?php else : ?>
|
||||
<b><?=_('lost')?></b>
|
||||
<?php endif ?>
|
||||
</p>
|
||||
</section>
|
||||
</div>
|
||||
<?php endforeach ?>
|
||||
|
|
|
|||
|
|
@ -1,24 +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\agents\QuesttypeAgent
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* 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\agents\QuesttypeAgent
|
||||
{
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -1,299 +1,299 @@
|
|||
<?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\controllers\QuesttypeController
|
||||
{
|
||||
/**
|
||||
* Required components
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $components = array('validation');
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 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
|
||||
* @param array $answers Character answers for the Quest
|
||||
* @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 &$list)
|
||||
{
|
||||
$pos = intval($list['number']) - 1;
|
||||
if(!array_key_exists($pos, $answers)) {
|
||||
return false;
|
||||
}
|
||||
if($list['questtypes_choiceinput_choice_id'] != $answers[$pos]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// All answers 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']);
|
||||
|
||||
// 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('task', $task);
|
||||
$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']);
|
||||
|
||||
// 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('task', $task);
|
||||
$this->set('choiceLists', $choiceLists);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
|
||||
/**
|
||||
* Action: edittask.
|
||||
*
|
||||
* Edit the task of a Quest.
|
||||
*
|
||||
* @param array $seminary Current Seminary data
|
||||
* @param array $questgroup Current Questgroup data
|
||||
* @param array $quest Current Quest data
|
||||
*/
|
||||
public function edittask($seminary, $questgroup, $quest)
|
||||
{
|
||||
// Get Task
|
||||
$task = $this->Choiceinput->getChoiceinputQuest($quest['id']);
|
||||
$text = $task['text'];
|
||||
|
||||
// Get lists
|
||||
$choiceLists = $this->Choiceinput->getChoiceinputLists($quest['id']);
|
||||
foreach($choiceLists as &$list)
|
||||
{
|
||||
$list['choices'] = $this->Choiceinput->getChoiceinputChoices($list['id']);
|
||||
foreach($list['choices'] as $index => &$choice) {
|
||||
//$choice['correct'] = ($choice['id'] == $list['questtypes_choiceinput_choice_id']);
|
||||
if($choice['id'] == $list['questtypes_choiceinput_choice_id']) {
|
||||
$list['answer'] = $index;
|
||||
}
|
||||
$choice = $choice['text'];
|
||||
}
|
||||
//$list = $list['choices'];
|
||||
}
|
||||
|
||||
// Values
|
||||
$validations = array();
|
||||
|
||||
// Save data
|
||||
if($this->request->getRequestMethod() == 'POST')
|
||||
{
|
||||
if(!is_null($this->request->getPostParam('preview')) || !is_null($this->request->getPostParam('save')))
|
||||
{
|
||||
// Get params and validate them
|
||||
if(is_null($this->request->getPostParam('text'))) {
|
||||
throw new \nre\exceptions\ParamsNotValidException('text');
|
||||
}
|
||||
$text = $this->request->getPostParam('text');
|
||||
if(is_null($this->request->getPostParam('lists'))) {
|
||||
throw new \nre\exceptions\ParamsNotValidException('lists');
|
||||
}
|
||||
$choiceLists = $this->request->getPostParam('lists');
|
||||
$choiceLists = array_values($choiceLists);
|
||||
foreach($choiceLists as $listIndex => &$list)
|
||||
{
|
||||
// Validate choices
|
||||
if(!array_key_exists('choices', $list)) {
|
||||
throw new \nre\exceptions\ParamsNotValidException('choices');
|
||||
}
|
||||
$choiceIndex = 0;
|
||||
$answer = null;
|
||||
foreach($list['choices'] as $index => &$choice)
|
||||
{
|
||||
// Validate choice
|
||||
$choiceValidation = $this->Validation->validate($choice, \nre\configs\AppConfig::$validation['choice']);
|
||||
if($choiceValidation !== true)
|
||||
{
|
||||
if(!array_key_exists($listIndex, $validations) || !is_array($validations[$listIndex])) {
|
||||
$validations[$listIndex] = array();
|
||||
}
|
||||
if(!array_key_exists('choices', $validations[$listIndex])) {
|
||||
$validations[$listIndex]['choices'] = array();
|
||||
}
|
||||
$validations[$listIndex]['choices'][$choiceIndex] = $choiceValidation;
|
||||
}
|
||||
|
||||
$choiceIndex++;
|
||||
if(array_key_exists('answer', $list) && $list['answer'] == $index) {
|
||||
$answer = $choiceIndex;
|
||||
}
|
||||
}
|
||||
|
||||
// Validate correct answer
|
||||
if(is_null($answer))
|
||||
{
|
||||
if(!array_key_exists($listIndex, $validations) || !is_array($validations[$listIndex])) {
|
||||
$validations[$listIndex] = array();
|
||||
}
|
||||
if(!array_key_exists('answer', $validations[$listIndex])) {
|
||||
$validations[$listIndex]['answer'] = array();
|
||||
}
|
||||
$validations[$listIndex] = $this->Validation->addValidationResult($validations[$listIndex], 'answer', 'exist', true);
|
||||
}
|
||||
}
|
||||
|
||||
// Save and redirect
|
||||
if(!is_null($this->request->getPostParam('save')) && empty($validations))
|
||||
{
|
||||
// Save text
|
||||
$this->Choiceinput->setTextForQuest(
|
||||
$this->Auth->getUserId(),
|
||||
$quest['id'],
|
||||
$text
|
||||
);
|
||||
|
||||
// Save lists and choices
|
||||
foreach($choiceLists as $listIndex => &$list)
|
||||
{
|
||||
// Save list
|
||||
$this->Choiceinput->setListForText(
|
||||
$quest['id'],
|
||||
$listIndex + 1,
|
||||
$list['choices'],
|
||||
$list['answer'] + 1
|
||||
);
|
||||
}
|
||||
|
||||
// Redirect
|
||||
$this->redirect($this->linker->link(array('quest', $seminary['url'], $questgroup['url'], $quest['url']), 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Controller of the ChoiceinputQuesttypeAgent for choosing between
|
||||
* predefined input values.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class ChoiceinputQuesttypeController extends \hhu\z\controllers\QuesttypeController
|
||||
{
|
||||
/**
|
||||
* Required components
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $components = array('validation');
|
||||
|
||||
|
||||
// Pass data to view
|
||||
$this->set('task', $task);
|
||||
$this->set('text', $text);
|
||||
$this->set('choiceLists', $choiceLists);
|
||||
$this->set('validations', $validations);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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
|
||||
* @param array $answers Character answers for the Quest
|
||||
* @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 &$list)
|
||||
{
|
||||
$pos = intval($list['number']) - 1;
|
||||
if(!array_key_exists($pos, $answers)) {
|
||||
return false;
|
||||
}
|
||||
if($list['questtypes_choiceinput_choice_id'] != $answers[$pos]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// All answers 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']);
|
||||
|
||||
// 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('task', $task);
|
||||
$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']);
|
||||
|
||||
// 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('task', $task);
|
||||
$this->set('choiceLists', $choiceLists);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Action: edittask.
|
||||
*
|
||||
* Edit the task of a Quest.
|
||||
*
|
||||
* @param array $seminary Current Seminary data
|
||||
* @param array $questgroup Current Questgroup data
|
||||
* @param array $quest Current Quest data
|
||||
*/
|
||||
public function edittask($seminary, $questgroup, $quest)
|
||||
{
|
||||
// Get Task
|
||||
$task = $this->Choiceinput->getChoiceinputQuest($quest['id']);
|
||||
$text = $task['text'];
|
||||
|
||||
// Get lists
|
||||
$choiceLists = $this->Choiceinput->getChoiceinputLists($quest['id']);
|
||||
foreach($choiceLists as &$list)
|
||||
{
|
||||
$list['choices'] = $this->Choiceinput->getChoiceinputChoices($list['id']);
|
||||
foreach($list['choices'] as $index => &$choice) {
|
||||
//$choice['correct'] = ($choice['id'] == $list['questtypes_choiceinput_choice_id']);
|
||||
if($choice['id'] == $list['questtypes_choiceinput_choice_id']) {
|
||||
$list['answer'] = $index;
|
||||
}
|
||||
$choice = $choice['text'];
|
||||
}
|
||||
//$list = $list['choices'];
|
||||
}
|
||||
|
||||
// Values
|
||||
$validations = array();
|
||||
|
||||
// Save data
|
||||
if($this->request->getRequestMethod() == 'POST')
|
||||
{
|
||||
if(!is_null($this->request->getPostParam('preview')) || !is_null($this->request->getPostParam('save')))
|
||||
{
|
||||
// Get params and validate them
|
||||
if(is_null($this->request->getPostParam('text'))) {
|
||||
throw new \nre\exceptions\ParamsNotValidException('text');
|
||||
}
|
||||
$text = $this->request->getPostParam('text');
|
||||
if(is_null($this->request->getPostParam('lists'))) {
|
||||
throw new \nre\exceptions\ParamsNotValidException('lists');
|
||||
}
|
||||
$choiceLists = $this->request->getPostParam('lists');
|
||||
$choiceLists = array_values($choiceLists);
|
||||
foreach($choiceLists as $listIndex => &$list)
|
||||
{
|
||||
// Validate choices
|
||||
if(!array_key_exists('choices', $list)) {
|
||||
throw new \nre\exceptions\ParamsNotValidException('choices');
|
||||
}
|
||||
$choiceIndex = 0;
|
||||
$answer = null;
|
||||
foreach($list['choices'] as $index => &$choice)
|
||||
{
|
||||
// Validate choice
|
||||
$choiceValidation = $this->Validation->validate($choice, \nre\configs\AppConfig::$validation['choice']);
|
||||
if($choiceValidation !== true)
|
||||
{
|
||||
if(!array_key_exists($listIndex, $validations) || !is_array($validations[$listIndex])) {
|
||||
$validations[$listIndex] = array();
|
||||
}
|
||||
if(!array_key_exists('choices', $validations[$listIndex])) {
|
||||
$validations[$listIndex]['choices'] = array();
|
||||
}
|
||||
$validations[$listIndex]['choices'][$choiceIndex] = $choiceValidation;
|
||||
}
|
||||
|
||||
$choiceIndex++;
|
||||
if(array_key_exists('answer', $list) && $list['answer'] == $index) {
|
||||
$answer = $choiceIndex;
|
||||
}
|
||||
}
|
||||
|
||||
// Validate correct answer
|
||||
if(is_null($answer))
|
||||
{
|
||||
if(!array_key_exists($listIndex, $validations) || !is_array($validations[$listIndex])) {
|
||||
$validations[$listIndex] = array();
|
||||
}
|
||||
if(!array_key_exists('answer', $validations[$listIndex])) {
|
||||
$validations[$listIndex]['answer'] = array();
|
||||
}
|
||||
$validations[$listIndex] = $this->Validation->addValidationResult($validations[$listIndex], 'answer', 'exist', true);
|
||||
}
|
||||
}
|
||||
|
||||
// Save and redirect
|
||||
if(!is_null($this->request->getPostParam('save')) && empty($validations))
|
||||
{
|
||||
// Save text
|
||||
$this->Choiceinput->setTextForQuest(
|
||||
$this->Auth->getUserId(),
|
||||
$quest['id'],
|
||||
$text
|
||||
);
|
||||
|
||||
// Save lists and choices
|
||||
foreach($choiceLists as $listIndex => &$list)
|
||||
{
|
||||
// Save list
|
||||
$this->Choiceinput->setListForText(
|
||||
$quest['id'],
|
||||
$listIndex + 1,
|
||||
$list['choices'],
|
||||
$list['answer'] + 1
|
||||
);
|
||||
}
|
||||
|
||||
// Redirect
|
||||
$this->redirect($this->linker->link(array('quest', $seminary['url'], $questgroup['url'], $quest['url']), 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Pass data to view
|
||||
$this->set('task', $task);
|
||||
$this->set('text', $text);
|
||||
$this->set('choiceLists', $choiceLists);
|
||||
$this->set('validations', $validations);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -1,32 +1,32 @@
|
|||
<?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\models\QuesttypeModel
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 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\models\QuesttypeModel
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Copy a Quest
|
||||
*
|
||||
*
|
||||
* @param int $userId ID of creating user
|
||||
* @param int $sourceQuestId ID of Quest to copy from
|
||||
* @param int $targetQuestId ID of Quest to copy to
|
||||
|
|
@ -97,272 +97,272 @@
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
/**
|
||||
* 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];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the text for a Quest and correct choice input lists count.
|
||||
*
|
||||
* @param int $userId ID of user setting text
|
||||
* @param int $questId ID of Quest to set text for
|
||||
* @param string $text Text for Quest
|
||||
*/
|
||||
public function setTextForQuest($userId, $questId, $text)
|
||||
{
|
||||
$this->db->setAutocommit(false);
|
||||
try {
|
||||
// Set text
|
||||
$this->db->query(
|
||||
'INSERT INTO questtypes_choiceinput '.
|
||||
'(quest_id, created_user_id, text) '.
|
||||
'VALUES '.
|
||||
'(?, ?, ?) '.
|
||||
'ON DUPLICATE KEY UPDATE '.
|
||||
'text = ?',
|
||||
'iiss',
|
||||
$questId,
|
||||
$userId,
|
||||
$text,
|
||||
$text
|
||||
);
|
||||
|
||||
// Count fields
|
||||
$listCount = substr_count($text, '[choiceinput]');
|
||||
|
||||
// Remove fields
|
||||
$this->db->query(
|
||||
'DELETE FROM questtypes_choiceinput_lists '.
|
||||
'WHERE questtypes_choiceinput_quest_id = ? AND number > ?',
|
||||
'ii',
|
||||
$questId,
|
||||
$listCount
|
||||
);
|
||||
|
||||
// Add fields
|
||||
for($i=1; $i<=$listCount; $i++)
|
||||
{
|
||||
$this->db->query(
|
||||
'INSERT IGNORE INTO questtypes_choiceinput_lists '.
|
||||
'(questtypes_choiceinput_quest_id, number, questtypes_choiceinput_choice_id) '.
|
||||
'VALUES '.
|
||||
'(?, ?, NULL) ',
|
||||
'ii',
|
||||
$questId,
|
||||
$i
|
||||
);
|
||||
}
|
||||
|
||||
$this->db->commit();
|
||||
}
|
||||
catch(\Exception $e) {
|
||||
$this->db->rollback();
|
||||
$this->db->setAutocommit(true);
|
||||
throw $e;
|
||||
}
|
||||
|
||||
$this->db->setAutocommit(true);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set list of choices for a text.
|
||||
*
|
||||
* @param int $questId ID of Quest to set choices for
|
||||
* @param int $number List number
|
||||
* @param array $choices List of choices
|
||||
* @param int $correctPos Position of correct answer
|
||||
*/
|
||||
public function setListForText($questId, $number, $choices, $correctPos)
|
||||
{
|
||||
// Get ID of list
|
||||
$listId = $this->db->query(
|
||||
'SELECT id '.
|
||||
'FROM questtypes_choiceinput_lists '.
|
||||
'WHERE questtypes_choiceinput_quest_id = ? AND number = ?',
|
||||
'ii',
|
||||
$questId,
|
||||
$number
|
||||
);
|
||||
$listId = $listId[0]['id'];
|
||||
/**
|
||||
* 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
|
||||
);
|
||||
}
|
||||
|
||||
// Manage choices
|
||||
$this->db->setAutocommit(false);
|
||||
try {
|
||||
// Remove choices
|
||||
$this->db->query(
|
||||
'DELETE FROM questtypes_choiceinput_choices '.
|
||||
'WHERE questtypes_choiceinput_list_id = ? AND pos > ?',
|
||||
'ii',
|
||||
$listId,
|
||||
count($choices)
|
||||
);
|
||||
|
||||
// Add choices
|
||||
foreach($choices as $index => &$choice)
|
||||
{
|
||||
$this->db->query(
|
||||
'INSERT INTO questtypes_choiceinput_choices '.
|
||||
'(questtypes_choiceinput_list_id, pos, text) '.
|
||||
'VALUES '.
|
||||
'(?, ?, ?) '.
|
||||
'ON DUPLICATE KEY UPDATE '.
|
||||
'text = ?',
|
||||
'iiss',
|
||||
$listId,
|
||||
$index + 1,
|
||||
$choice,
|
||||
$choice
|
||||
);
|
||||
}
|
||||
/**
|
||||
* 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
|
||||
);
|
||||
}
|
||||
|
||||
// Set correct choice for list
|
||||
$this->db->query(
|
||||
'UPDATE questtypes_choiceinput_lists '.
|
||||
'SET questtypes_choiceinput_choice_id = ('.
|
||||
'SELECT id '.
|
||||
'FROM questtypes_choiceinput_choices '.
|
||||
'WHERE questtypes_choiceinput_list_id = ? AND pos = ?'.
|
||||
') '.
|
||||
'WHERE id = ?',
|
||||
'iii',
|
||||
$listId,
|
||||
$correctPos,
|
||||
$listId
|
||||
);
|
||||
|
||||
$this->db->commit();
|
||||
}
|
||||
catch(\Exception $e) {
|
||||
$this->db->rollback();
|
||||
$this->db->setAutocommit(true);
|
||||
throw $e;
|
||||
}
|
||||
/**
|
||||
* 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
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$this->db->setAutocommit(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the text for a Quest and correct choice input lists count.
|
||||
*
|
||||
* @param int $userId ID of user setting text
|
||||
* @param int $questId ID of Quest to set text for
|
||||
* @param string $text Text for Quest
|
||||
*/
|
||||
public function setTextForQuest($userId, $questId, $text)
|
||||
{
|
||||
$this->db->setAutocommit(false);
|
||||
try {
|
||||
// Set text
|
||||
$this->db->query(
|
||||
'INSERT INTO questtypes_choiceinput '.
|
||||
'(quest_id, created_user_id, text) '.
|
||||
'VALUES '.
|
||||
'(?, ?, ?) '.
|
||||
'ON DUPLICATE KEY UPDATE '.
|
||||
'text = ?',
|
||||
'iiss',
|
||||
$questId,
|
||||
$userId,
|
||||
$text,
|
||||
$text
|
||||
);
|
||||
|
||||
// Count fields
|
||||
$listCount = substr_count($text, '[choiceinput]');
|
||||
|
||||
// Remove fields
|
||||
$this->db->query(
|
||||
'DELETE FROM questtypes_choiceinput_lists '.
|
||||
'WHERE questtypes_choiceinput_quest_id = ? AND number > ?',
|
||||
'ii',
|
||||
$questId,
|
||||
$listCount
|
||||
);
|
||||
|
||||
// Add fields
|
||||
for($i=1; $i<=$listCount; $i++)
|
||||
{
|
||||
$this->db->query(
|
||||
'INSERT IGNORE INTO questtypes_choiceinput_lists '.
|
||||
'(questtypes_choiceinput_quest_id, number, questtypes_choiceinput_choice_id) '.
|
||||
'VALUES '.
|
||||
'(?, ?, NULL) ',
|
||||
'ii',
|
||||
$questId,
|
||||
$i
|
||||
);
|
||||
}
|
||||
|
||||
$this->db->commit();
|
||||
}
|
||||
catch(\Exception $e) {
|
||||
$this->db->rollback();
|
||||
$this->db->setAutocommit(true);
|
||||
throw $e;
|
||||
}
|
||||
|
||||
$this->db->setAutocommit(true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set list of choices for a text.
|
||||
*
|
||||
* @param int $questId ID of Quest to set choices for
|
||||
* @param int $number List number
|
||||
* @param array $choices List of choices
|
||||
* @param int $correctPos Position of correct answer
|
||||
*/
|
||||
public function setListForText($questId, $number, $choices, $correctPos)
|
||||
{
|
||||
// Get ID of list
|
||||
$listId = $this->db->query(
|
||||
'SELECT id '.
|
||||
'FROM questtypes_choiceinput_lists '.
|
||||
'WHERE questtypes_choiceinput_quest_id = ? AND number = ?',
|
||||
'ii',
|
||||
$questId,
|
||||
$number
|
||||
);
|
||||
$listId = $listId[0]['id'];
|
||||
|
||||
// Manage choices
|
||||
$this->db->setAutocommit(false);
|
||||
try {
|
||||
// Remove choices
|
||||
$this->db->query(
|
||||
'DELETE FROM questtypes_choiceinput_choices '.
|
||||
'WHERE questtypes_choiceinput_list_id = ? AND pos > ?',
|
||||
'ii',
|
||||
$listId,
|
||||
count($choices)
|
||||
);
|
||||
|
||||
// Add choices
|
||||
foreach($choices as $index => &$choice)
|
||||
{
|
||||
$this->db->query(
|
||||
'INSERT INTO questtypes_choiceinput_choices '.
|
||||
'(questtypes_choiceinput_list_id, pos, text) '.
|
||||
'VALUES '.
|
||||
'(?, ?, ?) '.
|
||||
'ON DUPLICATE KEY UPDATE '.
|
||||
'text = ?',
|
||||
'iiss',
|
||||
$listId,
|
||||
$index + 1,
|
||||
$choice,
|
||||
$choice
|
||||
);
|
||||
}
|
||||
|
||||
// Set correct choice for list
|
||||
$this->db->query(
|
||||
'UPDATE questtypes_choiceinput_lists '.
|
||||
'SET questtypes_choiceinput_choice_id = ('.
|
||||
'SELECT id '.
|
||||
'FROM questtypes_choiceinput_choices '.
|
||||
'WHERE questtypes_choiceinput_list_id = ? AND pos = ?'.
|
||||
') '.
|
||||
'WHERE id = ?',
|
||||
'iii',
|
||||
$listId,
|
||||
$correctPos,
|
||||
$listId
|
||||
);
|
||||
|
||||
$this->db->commit();
|
||||
}
|
||||
catch(\Exception $e) {
|
||||
$this->db->rollback();
|
||||
$this->db->setAutocommit(true);
|
||||
throw $e;
|
||||
}
|
||||
|
||||
$this->db->setAutocommit(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -1,179 +1,179 @@
|
|||
<?php if(!empty($validations)) : ?>
|
||||
<ul>
|
||||
<?php foreach($validations as &$list) : ?>
|
||||
<?php foreach($list as $part => &$choices) : ?>
|
||||
<li>
|
||||
<?php if($part == 'choices') : ?>
|
||||
<?php foreach($choices as $field => &$settings) : ?>
|
||||
<ul>
|
||||
<?php foreach($settings as $setting => $value) : ?>
|
||||
<li>
|
||||
<?php
|
||||
switch($setting) {
|
||||
case 'minlength': printf(_('Choice input is too short (min. %d chars)'), $value);
|
||||
break;
|
||||
case 'maxlength': printf(_('Choice input is too long (max. %d chars)'), $value);
|
||||
break;
|
||||
default: echo _('Choice input invalid');
|
||||
}
|
||||
?>
|
||||
</li>
|
||||
<?php endforeach ?>
|
||||
</ul>
|
||||
<?php endforeach ?>
|
||||
<?php elseif($part == 'answer') : ?>
|
||||
<?php foreach($choices as $setting => &$value) : ?>
|
||||
<li>
|
||||
<?php
|
||||
switch($setting) {
|
||||
case 'exist': printf(_('Please select correct choice'));
|
||||
break;
|
||||
}
|
||||
?>
|
||||
</li>
|
||||
<?php endforeach ?>
|
||||
<?php endif ?>
|
||||
</li>
|
||||
<?php endforeach ?>
|
||||
<?php endforeach ?>
|
||||
<?php foreach($validations as &$list) : ?>
|
||||
<?php foreach($list as $part => &$choices) : ?>
|
||||
<li>
|
||||
<?php if($part == 'choices') : ?>
|
||||
<?php foreach($choices as $field => &$settings) : ?>
|
||||
<ul>
|
||||
<?php foreach($settings as $setting => $value) : ?>
|
||||
<li>
|
||||
<?php
|
||||
switch($setting) {
|
||||
case 'minlength': printf(_('Choice input is too short (min. %d chars)'), $value);
|
||||
break;
|
||||
case 'maxlength': printf(_('Choice input is too long (max. %d chars)'), $value);
|
||||
break;
|
||||
default: echo _('Choice input invalid');
|
||||
}
|
||||
?>
|
||||
</li>
|
||||
<?php endforeach ?>
|
||||
</ul>
|
||||
<?php endforeach ?>
|
||||
<?php elseif($part == 'answer') : ?>
|
||||
<?php foreach($choices as $setting => &$value) : ?>
|
||||
<li>
|
||||
<?php
|
||||
switch($setting) {
|
||||
case 'exist': printf(_('Please select correct choice'));
|
||||
break;
|
||||
}
|
||||
?>
|
||||
</li>
|
||||
<?php endforeach ?>
|
||||
<?php endif ?>
|
||||
</li>
|
||||
<?php endforeach ?>
|
||||
<?php endforeach ?>
|
||||
</ul>
|
||||
<?php endif ?>
|
||||
<form method="post">
|
||||
<fieldset>
|
||||
<legend><?=_('Text')?></legend>
|
||||
<button id="add-field" type="button"><?=_('Add field')?></button><br />
|
||||
<textarea id="text" name="text"><?=$text?></textarea>
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<legend><?=_('Choice inputs')?></legend>
|
||||
<ul id="lists">
|
||||
<?php foreach($choiceLists as $listIndex => &$list) : ?>
|
||||
<li id="list-<?=$listIndex?>">
|
||||
<?php if(!empty($validations) && array_key_exists($listIndex, $validations) && !empty($validations[$listIndex]) && array_key_exists('answer', $validations[$listIndex]) && $validations[$listIndex]['answer'] !== true) : ?>
|
||||
<ul>
|
||||
<?php foreach($validations[$listIndex]['answer'] as $setting => $value) : ?>
|
||||
<li>
|
||||
<?php
|
||||
switch($setting) {
|
||||
case 'exist': printf(_('Please select correct choice'));
|
||||
break;
|
||||
}
|
||||
?>
|
||||
</li>
|
||||
<?php endforeach ?>
|
||||
</ul>
|
||||
<?php endif ?>
|
||||
<ul>
|
||||
<?php foreach($list['choices'] as $choiceIndex => &$choice) : ?>
|
||||
<li>
|
||||
<input type="radio" name="lists[<?=$listIndex?>][answer]" value="<?=$choiceIndex?>" <?php if($choiceIndex == $list['answer']) : ?>checked="checked"<?php endif ?> />
|
||||
<input type="text" name="lists[<?=$listIndex?>][choices][<?=$choiceIndex?>]" required="required" value="<?=$choice?>" <?php if(!empty($validations) && array_key_exists($listIndex, $validations) && !empty($validations[$listIndex]) && array_key_exists($choiceIndex, $validations[$listIndex]['choices']) && $validations[$listIndex]['choices'][$choiceInput] !== true) : ?>class="invalid"<?php endif ?> />
|
||||
<button class="remove-choice" type="button">−</button>
|
||||
</li>
|
||||
<?php endforeach ?>
|
||||
<li>
|
||||
<button class="add-choice" type="button">+</button>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
<?php endforeach ?>
|
||||
</ul>
|
||||
</fieldset>
|
||||
<input type="submit" name="preview" value="<?=_('Preview')?>" />
|
||||
<input type="submit" name="save" value="<?=_('save')?>" />
|
||||
<fieldset>
|
||||
<legend><?=_('Text')?></legend>
|
||||
<button id="add-field" type="button"><?=_('Add field')?></button><br />
|
||||
<textarea id="text" name="text"><?=$text?></textarea>
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<legend><?=_('Choice inputs')?></legend>
|
||||
<ul id="lists">
|
||||
<?php foreach($choiceLists as $listIndex => &$list) : ?>
|
||||
<li id="list-<?=$listIndex?>">
|
||||
<?php if(!empty($validations) && array_key_exists($listIndex, $validations) && !empty($validations[$listIndex]) && array_key_exists('answer', $validations[$listIndex]) && $validations[$listIndex]['answer'] !== true) : ?>
|
||||
<ul>
|
||||
<?php foreach($validations[$listIndex]['answer'] as $setting => $value) : ?>
|
||||
<li>
|
||||
<?php
|
||||
switch($setting) {
|
||||
case 'exist': printf(_('Please select correct choice'));
|
||||
break;
|
||||
}
|
||||
?>
|
||||
</li>
|
||||
<?php endforeach ?>
|
||||
</ul>
|
||||
<?php endif ?>
|
||||
<ul>
|
||||
<?php foreach($list['choices'] as $choiceIndex => &$choice) : ?>
|
||||
<li>
|
||||
<input type="radio" name="lists[<?=$listIndex?>][answer]" value="<?=$choiceIndex?>" <?php if($choiceIndex == $list['answer']) : ?>checked="checked"<?php endif ?> />
|
||||
<input type="text" name="lists[<?=$listIndex?>][choices][<?=$choiceIndex?>]" required="required" value="<?=$choice?>" <?php if(!empty($validations) && array_key_exists($listIndex, $validations) && !empty($validations[$listIndex]) && array_key_exists($choiceIndex, $validations[$listIndex]['choices']) && $validations[$listIndex]['choices'][$choiceInput] !== true) : ?>class="invalid"<?php endif ?> />
|
||||
<button class="remove-choice" type="button">−</button>
|
||||
</li>
|
||||
<?php endforeach ?>
|
||||
<li>
|
||||
<button class="add-choice" type="button">+</button>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
<?php endforeach ?>
|
||||
</ul>
|
||||
</fieldset>
|
||||
<input type="submit" name="preview" value="<?=_('Preview')?>" />
|
||||
<input type="submit" name="save" value="<?=_('save')?>" />
|
||||
</form>
|
||||
<h2><?=_('Preview')?></h2>
|
||||
<p>
|
||||
<?php $posStart = 0; ?>
|
||||
<?php foreach($choiceLists as &$list) : ?>
|
||||
<?php $posEnd = mb_strpos($text, '[choiceinput]', $posStart, 'UTF-8'); ?>
|
||||
<?=$t->t(mb_substr($text, $posStart, $posEnd-$posStart, 'UTF-8'))?>
|
||||
<select name="answers[]">
|
||||
<?php foreach($list['choices'] as &$choice) : ?>
|
||||
<option><?=$choice?></option>
|
||||
<?php endforeach ?>
|
||||
</select>
|
||||
<?php $posStart = $posEnd + mb_strlen('[choiceinput]', 'UTF-8'); ?>
|
||||
<?php endforeach ?>
|
||||
<?=$t->t(mb_substr($text, $posStart, mb_strlen($text, 'UTF-8')-$posStart, 'UTF-8'))?>
|
||||
<?php $posStart = 0; ?>
|
||||
<?php foreach($choiceLists as &$list) : ?>
|
||||
<?php $posEnd = mb_strpos($text, '[choiceinput]', $posStart, 'UTF-8'); ?>
|
||||
<?=$t->t(mb_substr($text, $posStart, $posEnd-$posStart, 'UTF-8'))?>
|
||||
<select name="answers[]">
|
||||
<?php foreach($list['choices'] as &$choice) : ?>
|
||||
<option><?=$choice?></option>
|
||||
<?php endforeach ?>
|
||||
</select>
|
||||
<?php $posStart = $posEnd + mb_strlen('[choiceinput]', 'UTF-8'); ?>
|
||||
<?php endforeach ?>
|
||||
<?=$t->t(mb_substr($text, $posStart, mb_strlen($text, 'UTF-8')-$posStart, 'UTF-8'))?>
|
||||
</p>
|
||||
|
||||
<script>
|
||||
var listIndex = <?=count($choiceLists)?>;
|
||||
var choiceIndices = new Array(<?=count($choiceLists)?>);
|
||||
<?php foreach($choiceLists as $index => &$list) : ?>
|
||||
choiceIndices[<?=$index?>] = <?=count($list)?>;
|
||||
<?php endforeach?>
|
||||
var listElement = '<ul><li><button class="add-choice" type="button">+</button></li></ul>';
|
||||
var inputElement = '<input type="radio" name="lists[LISTINDEX][answer]" value="CHOICEINDEX" />' +
|
||||
'<input type="text" name="lists[LISTINDEX][choices][CHOICEINDEX]" required="required" />' +
|
||||
'<button class="remove-choice" type="button">−</button>';
|
||||
$("#add-field").click(function(event) {
|
||||
event.preventDefault();
|
||||
var caret = getCaret("text");
|
||||
insertAtCaret("text", caret, "[choiceinput]");
|
||||
updateFields();
|
||||
});
|
||||
$("#text").on('change keyup paste', function(event) {
|
||||
updateFields();
|
||||
});
|
||||
$(".add-choice").click(addChoice);
|
||||
$(".remove-choice").click(removeChoice);
|
||||
var listIndex = <?=count($choiceLists)?>;
|
||||
var choiceIndices = new Array(<?=count($choiceLists)?>);
|
||||
<?php foreach($choiceLists as $index => &$list) : ?>
|
||||
choiceIndices[<?=$index?>] = <?=count($list)?>;
|
||||
<?php endforeach?>
|
||||
var listElement = '<ul><li><button class="add-choice" type="button">+</button></li></ul>';
|
||||
var inputElement = '<input type="radio" name="lists[LISTINDEX][answer]" value="CHOICEINDEX" />' +
|
||||
'<input type="text" name="lists[LISTINDEX][choices][CHOICEINDEX]" required="required" />' +
|
||||
'<button class="remove-choice" type="button">−</button>';
|
||||
$("#add-field").click(function(event) {
|
||||
event.preventDefault();
|
||||
var caret = getCaret("text");
|
||||
insertAtCaret("text", caret, "[choiceinput]");
|
||||
updateFields();
|
||||
});
|
||||
$("#text").on('change keyup paste', function(event) {
|
||||
updateFields();
|
||||
});
|
||||
$(".add-choice").click(addChoice);
|
||||
$(".remove-choice").click(removeChoice);
|
||||
|
||||
function updateFields()
|
||||
{
|
||||
var newCount = $("#text").val().split("[choiceinput]").length - 1;
|
||||
var oldCount = $("#lists > li").length;
|
||||
var caret = getCaret("text");
|
||||
var pos = $("#text").val().substring(0, caret).split("[choiceinput]").length - 1;
|
||||
if(newCount > oldCount)
|
||||
{
|
||||
// Add lists
|
||||
for(var i=oldCount; i<newCount; i++)
|
||||
{
|
||||
choiceIndices.push(0);
|
||||
var element = '<li id="list-'+listIndex+'">' + listElement + '</li>';
|
||||
if($("#lists > li").length > 0)
|
||||
{
|
||||
if($("#lists > li").length > pos-1) {
|
||||
$($("#lists > li")[pos-1]).before(element);
|
||||
}
|
||||
else {
|
||||
$($("#lists > li")[pos-2]).after(element);
|
||||
}
|
||||
}
|
||||
else {
|
||||
$("#lists").append(element);
|
||||
}
|
||||
$("#list-"+listIndex+" .add-choice").click(addChoice);
|
||||
function updateFields()
|
||||
{
|
||||
var newCount = $("#text").val().split("[choiceinput]").length - 1;
|
||||
var oldCount = $("#lists > li").length;
|
||||
var caret = getCaret("text");
|
||||
var pos = $("#text").val().substring(0, caret).split("[choiceinput]").length - 1;
|
||||
if(newCount > oldCount)
|
||||
{
|
||||
// Add lists
|
||||
for(var i=oldCount; i<newCount; i++)
|
||||
{
|
||||
choiceIndices.push(0);
|
||||
var element = '<li id="list-'+listIndex+'">' + listElement + '</li>';
|
||||
if($("#lists > li").length > 0)
|
||||
{
|
||||
if($("#lists > li").length > pos-1) {
|
||||
$($("#lists > li")[pos-1]).before(element);
|
||||
}
|
||||
else {
|
||||
$($("#lists > li")[pos-2]).after(element);
|
||||
}
|
||||
}
|
||||
else {
|
||||
$("#lists").append(element);
|
||||
}
|
||||
$("#list-"+listIndex+" .add-choice").click(addChoice);
|
||||
|
||||
listIndex++;
|
||||
}
|
||||
}
|
||||
else if(newCount < oldCount)
|
||||
{
|
||||
// Remove lists
|
||||
for(var i=oldCount; i>newCount; i--) {
|
||||
$($("#lists > li")[pos]).remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
listIndex++;
|
||||
}
|
||||
}
|
||||
else if(newCount < oldCount)
|
||||
{
|
||||
// Remove lists
|
||||
for(var i=oldCount; i>newCount; i--) {
|
||||
$($("#lists > li")[pos]).remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function addChoice(event)
|
||||
{
|
||||
event.preventDefault();
|
||||
function addChoice(event)
|
||||
{
|
||||
event.preventDefault();
|
||||
|
||||
var parent = $(event.target).parent();
|
||||
var index = parent.parent().parent().attr('id').substring(5);
|
||||
var element = '<li>' + inputElement.replace(/LISTINDEX/g, index).replace(/CHOICEINDEX/g, choiceIndices[index]) + '</li>';
|
||||
$(event.target).parent().before(element);
|
||||
$(".remove-choice").click(removeChoice);
|
||||
var parent = $(event.target).parent();
|
||||
var index = parent.parent().parent().attr('id').substring(5);
|
||||
var element = '<li>' + inputElement.replace(/LISTINDEX/g, index).replace(/CHOICEINDEX/g, choiceIndices[index]) + '</li>';
|
||||
$(event.target).parent().before(element);
|
||||
$(".remove-choice").click(removeChoice);
|
||||
|
||||
choiceIndices[index]++;
|
||||
}
|
||||
function removeChoice(event)
|
||||
{
|
||||
event.preventDefault();
|
||||
$(event.target).parent().remove();
|
||||
}
|
||||
choiceIndices[index]++;
|
||||
}
|
||||
function removeChoice(event)
|
||||
{
|
||||
event.preventDefault();
|
||||
$(event.target).parent().remove();
|
||||
}
|
||||
</script>
|
||||
|
|
|
|||
|
|
@ -1,17 +1,17 @@
|
|||
<form method="post">
|
||||
<p>
|
||||
<?php $posStart = 0; ?>
|
||||
<?php foreach($choiceLists as &$list) : ?>
|
||||
<?php $posEnd = mb_strpos($task['text'], '[choiceinput]', $posStart, 'UTF-8'); ?>
|
||||
<?=$t->t(mb_substr($task['text'], $posStart, $posEnd-$posStart, 'UTF-8'))?>
|
||||
<select name="answers[]">
|
||||
<?php foreach($list['values'] as &$choice) : ?>
|
||||
<option value="<?=$choice['id']?>" <?php if(array_key_exists('answer', $list) && $list['answer'] == $choice['id']) : ?>selected="selected"<?php endif ?>><?=$choice['text']?></option>
|
||||
<?php endforeach ?>
|
||||
</select>
|
||||
<?php $posStart = $posEnd + mb_strlen('[choiceinput]', 'UTF-8'); ?>
|
||||
<?php endforeach ?>
|
||||
<?=$t->t(mb_substr($task['text'], $posStart, mb_strlen($task['text'], 'UTF-8')-$posStart, 'UTF-8'))?>
|
||||
</p>
|
||||
<input type="submit" name="submit" value="<?=_('solve')?>" />
|
||||
<p>
|
||||
<?php $posStart = 0; ?>
|
||||
<?php foreach($choiceLists as &$list) : ?>
|
||||
<?php $posEnd = mb_strpos($task['text'], '[choiceinput]', $posStart, 'UTF-8'); ?>
|
||||
<?=$t->t(mb_substr($task['text'], $posStart, $posEnd-$posStart, 'UTF-8'))?>
|
||||
<select name="answers[]">
|
||||
<?php foreach($list['values'] as &$choice) : ?>
|
||||
<option value="<?=$choice['id']?>" <?php if(array_key_exists('answer', $list) && $list['answer'] == $choice['id']) : ?>selected="selected"<?php endif ?>><?=$choice['text']?></option>
|
||||
<?php endforeach ?>
|
||||
</select>
|
||||
<?php $posStart = $posEnd + mb_strlen('[choiceinput]', 'UTF-8'); ?>
|
||||
<?php endforeach ?>
|
||||
<?=$t->t(mb_substr($task['text'], $posStart, mb_strlen($task['text'], 'UTF-8')-$posStart, 'UTF-8'))?>
|
||||
</p>
|
||||
<input type="submit" name="submit" value="<?=_('solve')?>" />
|
||||
</form>
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
<p>
|
||||
<?php $posStart = 0; ?>
|
||||
<?php foreach($choiceLists as &$list) : ?>
|
||||
<?php $posEnd = mb_strpos($task['text'], '[choiceinput]', $posStart, 'UTF-8'); ?>
|
||||
<?=$t->t(mb_substr($task['text'], $posStart, $posEnd-$posStart, 'UTF-8'))?>
|
||||
<select name="answers[]" disabled="disabled">
|
||||
<?php foreach($list['values'] as &$choice) : ?>
|
||||
<option value="<?=$choice['id']?>" <?php if(array_key_exists('answer', $list) && $list['answer'] == $choice['id']) : ?>selected="selected"<?php endif ?>><?=$choice['text']?></option>
|
||||
<?php endforeach ?>
|
||||
</select>
|
||||
<?php $posStart = $posEnd + mb_strlen('[choiceinput]', 'UTF-8'); ?>
|
||||
<?php endforeach ?>
|
||||
<?=$t->t(mb_substr($task['text'], $posStart, mb_strlen($task['text'], 'UTF-8')-$posStart, 'UTF-8'))?>
|
||||
<?php $posStart = 0; ?>
|
||||
<?php foreach($choiceLists as &$list) : ?>
|
||||
<?php $posEnd = mb_strpos($task['text'], '[choiceinput]', $posStart, 'UTF-8'); ?>
|
||||
<?=$t->t(mb_substr($task['text'], $posStart, $posEnd-$posStart, 'UTF-8'))?>
|
||||
<select name="answers[]" disabled="disabled">
|
||||
<?php foreach($list['values'] as &$choice) : ?>
|
||||
<option value="<?=$choice['id']?>" <?php if(array_key_exists('answer', $list) && $list['answer'] == $choice['id']) : ?>selected="selected"<?php endif ?>><?=$choice['text']?></option>
|
||||
<?php endforeach ?>
|
||||
</select>
|
||||
<?php $posStart = $posEnd + mb_strlen('[choiceinput]', 'UTF-8'); ?>
|
||||
<?php endforeach ?>
|
||||
<?=$t->t(mb_substr($task['text'], $posStart, mb_strlen($task['text'], 'UTF-8')-$posStart, 'UTF-8'))?>
|
||||
</p>
|
||||
|
|
|
|||
|
|
@ -1,24 +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 solving a crossword.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class CrosswordQuesttypeAgent extends \hhu\z\agents\QuesttypeAgent
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 solving a crossword.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class CrosswordQuesttypeAgent extends \hhu\z\agents\QuesttypeAgent
|
||||
{
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -1,380 +1,380 @@
|
|||
<?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 CrosswordQuesttypeAgent for solving a crossword.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class CrosswordQuesttypeController extends \hhu\z\controllers\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 words
|
||||
$words = $this->Crossword->getWordsForQuest($quest['id']);
|
||||
|
||||
// Iterate words
|
||||
foreach($words as &$word)
|
||||
{
|
||||
// Assemble answer for word
|
||||
$answer = '';
|
||||
if($word['vertical'])
|
||||
{
|
||||
$x = $word['pos_x'];
|
||||
$startY = $word['pos_y'];
|
||||
$endY = $startY + mb_strlen($word['word'], 'UTF-8') - 1;
|
||||
|
||||
foreach(range($startY, $endY) as $y)
|
||||
{
|
||||
if(array_key_exists($x, $answers) && array_key_exists($y, $answers[$x]) && !empty($answers[$x][$y])) {
|
||||
$answer .= $answers[$x][$y];
|
||||
}
|
||||
else {
|
||||
$answer .= ' ';
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$startX = $word['pos_x'];
|
||||
$endX = $startX + mb_strlen($word['word'], 'UTF-8') - 1;
|
||||
$y = $word['pos_y'];
|
||||
|
||||
foreach(range($startX, $endX) as $x)
|
||||
{
|
||||
if(array_key_exists($x, $answers) && array_key_exists($y, $answers[$x]) && !empty($answers[$x][$y])) {
|
||||
$answer .= $answers[$x][$y];
|
||||
}
|
||||
else {
|
||||
$answer .= ' ';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Save answer
|
||||
$this->Crossword->setCharacterSubmission($word['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
|
||||
* @param array $answers Character answers for the Quest
|
||||
* @return boolean True/false for a right/wrong answer or null for moderator evaluation
|
||||
*/
|
||||
public function matchAnswersOfCharacter($seminary, $questgroup, $quest, $character, $answers)
|
||||
{
|
||||
// Get words
|
||||
$words = $this->Crossword->getWordsForQuest($quest['id']);
|
||||
|
||||
// Iterate words
|
||||
foreach($words as &$word)
|
||||
{
|
||||
// Assemble answer for word
|
||||
$answer = '';
|
||||
if($word['vertical'])
|
||||
{
|
||||
$x = $word['pos_x'];
|
||||
$startY = $word['pos_y'];
|
||||
$endY = $startY + mb_strlen($word['word'], 'UTF-8') - 1;
|
||||
|
||||
foreach(range($startY, $endY) as $y)
|
||||
{
|
||||
if(array_key_exists($x, $answers) && array_key_exists($y, $answers[$x]) && !empty($answers[$x][$y])) {
|
||||
$answer .= $answers[$x][$y];
|
||||
}
|
||||
else {
|
||||
$answer .= ' ';
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$startX = $word['pos_x'];
|
||||
$endX = $startX + mb_strlen($word['word'], 'UTF-8') - 1;
|
||||
$y = $word['pos_y'];
|
||||
|
||||
foreach(range($startX, $endX) as $x)
|
||||
{
|
||||
if(array_key_exists($x, $answers) && array_key_exists($y, $answers[$x]) && !empty($answers[$x][$y])) {
|
||||
$answer .= $answers[$x][$y];
|
||||
}
|
||||
else {
|
||||
$answer .= ' ';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check answer
|
||||
if(mb_strtolower($word['word'], 'UTF-8') != mb_strtolower($answer, 'UTF-8')) {
|
||||
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 words
|
||||
$words = $this->Crossword->getWordsForQuest($quest['id']);
|
||||
|
||||
// Create 2D-matrix
|
||||
$matrix = array();
|
||||
$maxX = 0;
|
||||
$maxY = 0;
|
||||
foreach($words as $index => &$word)
|
||||
{
|
||||
if($this->request->getGetParam('show-answer') == 'true' || !$this->Quests->hasCharacterSolvedQuest($quest['id'], $character['id']) || $this->request->getGetParam('status') == 'solved') {
|
||||
$word['answer'] = $this->Crossword->getCharacterSubmission($word['id'], $character['id']);
|
||||
}
|
||||
// Insert word
|
||||
if($word['vertical'])
|
||||
{
|
||||
$x = $word['pos_x'];
|
||||
$startY = $word['pos_y'];
|
||||
$endY = $startY + mb_strlen($word['word'], 'UTF-8') - 1;
|
||||
|
||||
$matrix = array_pad($matrix, $x+1, array());
|
||||
$matrix[$x] = array_pad($matrix[$x], $endY+1, null);
|
||||
$maxX = max($maxX, $x);
|
||||
$maxY = max($maxY, $endY);
|
||||
|
||||
foreach(range($startY, $endY) as $y)
|
||||
{
|
||||
$matrix[$x][$y] = array(
|
||||
'char' => mb_substr($word['word'], $y-$startY, 1, 'UTF-8'),
|
||||
'indices' => (array_key_exists($x, $matrix) && array_key_exists($y, $matrix[$x]) && !is_null($matrix[$x][$y]) && array_key_exists('indices', $matrix[$x][$y])) ? $matrix[$x][$y]['indices'] : array(),
|
||||
'answer' => null
|
||||
);
|
||||
if($y == $startY) {
|
||||
$matrix[$x][$y]['indices'][] = $index;
|
||||
}
|
||||
if(array_key_exists('answer', $word))
|
||||
{
|
||||
$answer = mb_substr($word['answer'], $y-$startY, 1, 'UTF-8');
|
||||
if($answer != ' ') {
|
||||
$matrix[$x][$y]['answer'] = $answer;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$startX = $word['pos_x'];
|
||||
$endX = $startX + mb_strlen($word['word'], 'UTF-8') - 1;
|
||||
$y = $word['pos_y'];
|
||||
|
||||
$matrix = array_pad($matrix, $endX+1, array());
|
||||
$maxX = max($maxX, $endX);
|
||||
$maxY = max($maxY, $y);
|
||||
|
||||
foreach(range($startX, $endX) as $x)
|
||||
{
|
||||
$matrix[$x] = array_pad($matrix[$x], $y+1, null);
|
||||
|
||||
$matrix[$x][$y] = array(
|
||||
'char' => mb_substr($word['word'], $x-$startX, 1, 'UTF-8'),
|
||||
'indices' => (array_key_exists($x, $matrix) && array_key_exists($y, $matrix[$x]) && !is_null($matrix[$x][$y]) && array_key_exists('indices', $matrix[$x][$y])) ? $matrix[$x][$y]['indices'] : array(),
|
||||
'answer' => null
|
||||
);
|
||||
if($x == $startX) {
|
||||
$matrix[$x][$y]['indices'][] = $index;
|
||||
}
|
||||
if(array_key_exists('answer', $word))
|
||||
{
|
||||
$answer = mb_substr($word['answer'], $x-$startX, 1, 'UTF-8');
|
||||
if($answer != ' ') {
|
||||
$matrix[$x][$y]['answer'] = $answer;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Pass data to view
|
||||
$this->set('words', $words);
|
||||
$this->set('maxX', $maxX);
|
||||
$this->set('maxY', $maxY);
|
||||
$this->set('matrix', $matrix);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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 words
|
||||
$words = $this->Crossword->getWordsForQuest($quest['id']);
|
||||
|
||||
// Create 2D-matrix
|
||||
$matrix = array();
|
||||
$maxX = 0;
|
||||
$maxY = 0;
|
||||
foreach($words as $index => &$word)
|
||||
{
|
||||
// Character answer
|
||||
$word['answer'] = $this->Crossword->getCharacterSubmission($word['id'], $character['id']);
|
||||
|
||||
// Insert word
|
||||
if($word['vertical'])
|
||||
{
|
||||
$x = $word['pos_x'];
|
||||
$startY = $word['pos_y'];
|
||||
$endY = $startY + mb_strlen($word['word'], 'UTF-8') - 1;
|
||||
|
||||
$matrix = array_pad($matrix, $x+1, array());
|
||||
$matrix[$x] = array_pad($matrix[$x], $endY+1, null);
|
||||
$maxX = max($maxX, $x);
|
||||
$maxY = max($maxY, $endY);
|
||||
|
||||
foreach(range($startY, $endY) as $y)
|
||||
{
|
||||
$matrix[$x][$y] = array(
|
||||
'char' => mb_substr($word['word'], $y-$startY, 1, 'UTF-8'),
|
||||
'indices' => (array_key_exists($x, $matrix) && array_key_exists($y, $matrix[$x]) && !is_null($matrix[$x][$y]) && array_key_exists('indices', $matrix[$x][$y])) ? $matrix[$x][$y]['indices'] : array(),
|
||||
'answer' => null,
|
||||
'right' => false
|
||||
);
|
||||
if($y == $startY) {
|
||||
$matrix[$x][$y]['indices'][] = $index;
|
||||
}
|
||||
|
||||
if(!is_null($word['answer']))
|
||||
{
|
||||
$answer = mb_substr($word['answer'], $y-$startY, 1, 'UTF-8');
|
||||
if($answer != ' ')
|
||||
{
|
||||
$matrix[$x][$y]['answer'] = $answer;
|
||||
$matrix[$x][$y]['right'] = (mb_strtolower($matrix[$x][$y]['char'], 'UTF-8') == mb_strtolower($answer, 'UTF-8'));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$startX = $word['pos_x'];
|
||||
$endX = $startX + mb_strlen($word['word'], 'UTF-8') - 1;
|
||||
$y = $word['pos_y'];
|
||||
|
||||
$matrix = array_pad($matrix, $endX+1, array());
|
||||
$maxX = max($maxX, $endX);
|
||||
$maxY = max($maxY, $y);
|
||||
|
||||
foreach(range($startX, $endX) as $x)
|
||||
{
|
||||
$matrix[$x] = array_pad($matrix[$x], $y+1, null);
|
||||
|
||||
$matrix[$x][$y] = array(
|
||||
'char' => mb_substr($word['word'], $x-$startX, 1, 'UTF-8'),
|
||||
'indices' => (array_key_exists($x, $matrix) && array_key_exists($y, $matrix[$x]) && !is_null($matrix[$x][$y]) && array_key_exists('indices', $matrix[$x][$y])) ? $matrix[$x][$y]['indices'] : array(),
|
||||
'answer' => null,
|
||||
'right' => false
|
||||
);
|
||||
if($x == $startX) {
|
||||
$matrix[$x][$y]['indices'][] = $index;
|
||||
}
|
||||
if(!is_null($word['answer']))
|
||||
{
|
||||
$answer = mb_substr($word['answer'], $x-$startX, 1, 'UTF-8');
|
||||
if($answer != ' ')
|
||||
{
|
||||
$matrix[$x][$y]['answer'] = $answer;
|
||||
$matrix[$x][$y]['right'] = (mb_strtolower($matrix[$x][$y]['char'], 'UTF-8') == mb_strtolower($answer, 'UTF-8'));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Pass data to view
|
||||
$this->set('words', $words);
|
||||
$this->set('maxX', $maxX);
|
||||
$this->set('maxY', $maxY);
|
||||
$this->set('matrix', $matrix);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
|
||||
/**
|
||||
* TODO Action: edittask.
|
||||
*
|
||||
* Edit the task of a Quest.
|
||||
*
|
||||
* @param array $seminary Current Seminary data
|
||||
* @param array $questgroup Current Questgroup data
|
||||
* @param array $quest Current Quest data
|
||||
*/
|
||||
public function edittask($seminary, $questgroup, $quest)
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* Controller of the CrosswordQuesttypeAgent for solving a crossword.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class CrosswordQuesttypeController extends \hhu\z\controllers\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 words
|
||||
$words = $this->Crossword->getWordsForQuest($quest['id']);
|
||||
|
||||
// Iterate words
|
||||
foreach($words as &$word)
|
||||
{
|
||||
// Assemble answer for word
|
||||
$answer = '';
|
||||
if($word['vertical'])
|
||||
{
|
||||
$x = $word['pos_x'];
|
||||
$startY = $word['pos_y'];
|
||||
$endY = $startY + mb_strlen($word['word'], 'UTF-8') - 1;
|
||||
|
||||
foreach(range($startY, $endY) as $y)
|
||||
{
|
||||
if(array_key_exists($x, $answers) && array_key_exists($y, $answers[$x]) && !empty($answers[$x][$y])) {
|
||||
$answer .= $answers[$x][$y];
|
||||
}
|
||||
else {
|
||||
$answer .= ' ';
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$startX = $word['pos_x'];
|
||||
$endX = $startX + mb_strlen($word['word'], 'UTF-8') - 1;
|
||||
$y = $word['pos_y'];
|
||||
|
||||
foreach(range($startX, $endX) as $x)
|
||||
{
|
||||
if(array_key_exists($x, $answers) && array_key_exists($y, $answers[$x]) && !empty($answers[$x][$y])) {
|
||||
$answer .= $answers[$x][$y];
|
||||
}
|
||||
else {
|
||||
$answer .= ' ';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Save answer
|
||||
$this->Crossword->setCharacterSubmission($word['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
|
||||
* @param array $answers Character answers for the Quest
|
||||
* @return boolean True/false for a right/wrong answer or null for moderator evaluation
|
||||
*/
|
||||
public function matchAnswersOfCharacter($seminary, $questgroup, $quest, $character, $answers)
|
||||
{
|
||||
// Get words
|
||||
$words = $this->Crossword->getWordsForQuest($quest['id']);
|
||||
|
||||
// Iterate words
|
||||
foreach($words as &$word)
|
||||
{
|
||||
// Assemble answer for word
|
||||
$answer = '';
|
||||
if($word['vertical'])
|
||||
{
|
||||
$x = $word['pos_x'];
|
||||
$startY = $word['pos_y'];
|
||||
$endY = $startY + mb_strlen($word['word'], 'UTF-8') - 1;
|
||||
|
||||
foreach(range($startY, $endY) as $y)
|
||||
{
|
||||
if(array_key_exists($x, $answers) && array_key_exists($y, $answers[$x]) && !empty($answers[$x][$y])) {
|
||||
$answer .= $answers[$x][$y];
|
||||
}
|
||||
else {
|
||||
$answer .= ' ';
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$startX = $word['pos_x'];
|
||||
$endX = $startX + mb_strlen($word['word'], 'UTF-8') - 1;
|
||||
$y = $word['pos_y'];
|
||||
|
||||
foreach(range($startX, $endX) as $x)
|
||||
{
|
||||
if(array_key_exists($x, $answers) && array_key_exists($y, $answers[$x]) && !empty($answers[$x][$y])) {
|
||||
$answer .= $answers[$x][$y];
|
||||
}
|
||||
else {
|
||||
$answer .= ' ';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check answer
|
||||
if(mb_strtolower($word['word'], 'UTF-8') != mb_strtolower($answer, 'UTF-8')) {
|
||||
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 words
|
||||
$words = $this->Crossword->getWordsForQuest($quest['id']);
|
||||
|
||||
// Create 2D-matrix
|
||||
$matrix = array();
|
||||
$maxX = 0;
|
||||
$maxY = 0;
|
||||
foreach($words as $index => &$word)
|
||||
{
|
||||
if($this->request->getGetParam('show-answer') == 'true' || !$this->Quests->hasCharacterSolvedQuest($quest['id'], $character['id']) || $this->request->getGetParam('status') == 'solved') {
|
||||
$word['answer'] = $this->Crossword->getCharacterSubmission($word['id'], $character['id']);
|
||||
}
|
||||
// Insert word
|
||||
if($word['vertical'])
|
||||
{
|
||||
$x = $word['pos_x'];
|
||||
$startY = $word['pos_y'];
|
||||
$endY = $startY + mb_strlen($word['word'], 'UTF-8') - 1;
|
||||
|
||||
$matrix = array_pad($matrix, $x+1, array());
|
||||
$matrix[$x] = array_pad($matrix[$x], $endY+1, null);
|
||||
$maxX = max($maxX, $x);
|
||||
$maxY = max($maxY, $endY);
|
||||
|
||||
foreach(range($startY, $endY) as $y)
|
||||
{
|
||||
$matrix[$x][$y] = array(
|
||||
'char' => mb_substr($word['word'], $y-$startY, 1, 'UTF-8'),
|
||||
'indices' => (array_key_exists($x, $matrix) && array_key_exists($y, $matrix[$x]) && !is_null($matrix[$x][$y]) && array_key_exists('indices', $matrix[$x][$y])) ? $matrix[$x][$y]['indices'] : array(),
|
||||
'answer' => null
|
||||
);
|
||||
if($y == $startY) {
|
||||
$matrix[$x][$y]['indices'][] = $index;
|
||||
}
|
||||
if(array_key_exists('answer', $word))
|
||||
{
|
||||
$answer = mb_substr($word['answer'], $y-$startY, 1, 'UTF-8');
|
||||
if($answer != ' ') {
|
||||
$matrix[$x][$y]['answer'] = $answer;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$startX = $word['pos_x'];
|
||||
$endX = $startX + mb_strlen($word['word'], 'UTF-8') - 1;
|
||||
$y = $word['pos_y'];
|
||||
|
||||
$matrix = array_pad($matrix, $endX+1, array());
|
||||
$maxX = max($maxX, $endX);
|
||||
$maxY = max($maxY, $y);
|
||||
|
||||
foreach(range($startX, $endX) as $x)
|
||||
{
|
||||
$matrix[$x] = array_pad($matrix[$x], $y+1, null);
|
||||
|
||||
$matrix[$x][$y] = array(
|
||||
'char' => mb_substr($word['word'], $x-$startX, 1, 'UTF-8'),
|
||||
'indices' => (array_key_exists($x, $matrix) && array_key_exists($y, $matrix[$x]) && !is_null($matrix[$x][$y]) && array_key_exists('indices', $matrix[$x][$y])) ? $matrix[$x][$y]['indices'] : array(),
|
||||
'answer' => null
|
||||
);
|
||||
if($x == $startX) {
|
||||
$matrix[$x][$y]['indices'][] = $index;
|
||||
}
|
||||
if(array_key_exists('answer', $word))
|
||||
{
|
||||
$answer = mb_substr($word['answer'], $x-$startX, 1, 'UTF-8');
|
||||
if($answer != ' ') {
|
||||
$matrix[$x][$y]['answer'] = $answer;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Pass data to view
|
||||
$this->set('words', $words);
|
||||
$this->set('maxX', $maxX);
|
||||
$this->set('maxY', $maxY);
|
||||
$this->set('matrix', $matrix);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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 words
|
||||
$words = $this->Crossword->getWordsForQuest($quest['id']);
|
||||
|
||||
// Create 2D-matrix
|
||||
$matrix = array();
|
||||
$maxX = 0;
|
||||
$maxY = 0;
|
||||
foreach($words as $index => &$word)
|
||||
{
|
||||
// Character answer
|
||||
$word['answer'] = $this->Crossword->getCharacterSubmission($word['id'], $character['id']);
|
||||
|
||||
// Insert word
|
||||
if($word['vertical'])
|
||||
{
|
||||
$x = $word['pos_x'];
|
||||
$startY = $word['pos_y'];
|
||||
$endY = $startY + mb_strlen($word['word'], 'UTF-8') - 1;
|
||||
|
||||
$matrix = array_pad($matrix, $x+1, array());
|
||||
$matrix[$x] = array_pad($matrix[$x], $endY+1, null);
|
||||
$maxX = max($maxX, $x);
|
||||
$maxY = max($maxY, $endY);
|
||||
|
||||
foreach(range($startY, $endY) as $y)
|
||||
{
|
||||
$matrix[$x][$y] = array(
|
||||
'char' => mb_substr($word['word'], $y-$startY, 1, 'UTF-8'),
|
||||
'indices' => (array_key_exists($x, $matrix) && array_key_exists($y, $matrix[$x]) && !is_null($matrix[$x][$y]) && array_key_exists('indices', $matrix[$x][$y])) ? $matrix[$x][$y]['indices'] : array(),
|
||||
'answer' => null,
|
||||
'right' => false
|
||||
);
|
||||
if($y == $startY) {
|
||||
$matrix[$x][$y]['indices'][] = $index;
|
||||
}
|
||||
|
||||
if(!is_null($word['answer']))
|
||||
{
|
||||
$answer = mb_substr($word['answer'], $y-$startY, 1, 'UTF-8');
|
||||
if($answer != ' ')
|
||||
{
|
||||
$matrix[$x][$y]['answer'] = $answer;
|
||||
$matrix[$x][$y]['right'] = (mb_strtolower($matrix[$x][$y]['char'], 'UTF-8') == mb_strtolower($answer, 'UTF-8'));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$startX = $word['pos_x'];
|
||||
$endX = $startX + mb_strlen($word['word'], 'UTF-8') - 1;
|
||||
$y = $word['pos_y'];
|
||||
|
||||
$matrix = array_pad($matrix, $endX+1, array());
|
||||
$maxX = max($maxX, $endX);
|
||||
$maxY = max($maxY, $y);
|
||||
|
||||
foreach(range($startX, $endX) as $x)
|
||||
{
|
||||
$matrix[$x] = array_pad($matrix[$x], $y+1, null);
|
||||
|
||||
$matrix[$x][$y] = array(
|
||||
'char' => mb_substr($word['word'], $x-$startX, 1, 'UTF-8'),
|
||||
'indices' => (array_key_exists($x, $matrix) && array_key_exists($y, $matrix[$x]) && !is_null($matrix[$x][$y]) && array_key_exists('indices', $matrix[$x][$y])) ? $matrix[$x][$y]['indices'] : array(),
|
||||
'answer' => null,
|
||||
'right' => false
|
||||
);
|
||||
if($x == $startX) {
|
||||
$matrix[$x][$y]['indices'][] = $index;
|
||||
}
|
||||
if(!is_null($word['answer']))
|
||||
{
|
||||
$answer = mb_substr($word['answer'], $x-$startX, 1, 'UTF-8');
|
||||
if($answer != ' ')
|
||||
{
|
||||
$matrix[$x][$y]['answer'] = $answer;
|
||||
$matrix[$x][$y]['right'] = (mb_strtolower($matrix[$x][$y]['char'], 'UTF-8') == mb_strtolower($answer, 'UTF-8'));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Pass data to view
|
||||
$this->set('words', $words);
|
||||
$this->set('maxX', $maxX);
|
||||
$this->set('maxY', $maxY);
|
||||
$this->set('matrix', $matrix);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* TODO Action: edittask.
|
||||
*
|
||||
* Edit the task of a Quest.
|
||||
*
|
||||
* @param array $seminary Current Seminary data
|
||||
* @param array $questgroup Current Questgroup data
|
||||
* @param array $quest Current Quest data
|
||||
*/
|
||||
public function edittask($seminary, $questgroup, $quest)
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -1,31 +1,31 @@
|
|||
<?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 CrosswordQuesttypeAgent for solving a crossword.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class CrosswordQuesttypeModel extends \hhu\z\models\QuesttypeModel
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 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 CrosswordQuesttypeAgent for solving a crossword.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class CrosswordQuesttypeModel extends \hhu\z\models\QuesttypeModel
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Copy a Quest
|
||||
*
|
||||
*
|
||||
* @param int $userId ID of creating user
|
||||
* @param int $sourceQuestId ID of Quest to copy from
|
||||
* @param int $targetQuestId ID of Quest to copy to
|
||||
|
|
@ -47,71 +47,71 @@
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get all words for a crossword-Quest.
|
||||
*
|
||||
* @param int $questId ID of Quest
|
||||
* @return array Words
|
||||
*/
|
||||
public function getWordsForQuest($questId)
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT id, question, word, vertical, pos_x, pos_y '.
|
||||
'FROM questtypes_crossword_words '.
|
||||
'WHERE quest_id = ? ',
|
||||
'i',
|
||||
$questId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Save Character’s submitted answer for one crossword-word.
|
||||
*
|
||||
* @param int $regexId ID of word
|
||||
* @param int $characterId ID of Character
|
||||
* @param string $answer Submitted answer for this word
|
||||
*/
|
||||
public function setCharacterSubmission($wordId, $characterId, $answer)
|
||||
{
|
||||
$this->db->query(
|
||||
'INSERT INTO questtypes_crossword_words_characters '.
|
||||
'(questtypes_crossword_word_id, character_id, answer) '.
|
||||
'VALUES '.
|
||||
'(?, ?, ?) '.
|
||||
'ON DUPLICATE KEY UPDATE '.
|
||||
'answer = ?',
|
||||
'iiss',
|
||||
$wordId, $characterId, $answer,
|
||||
$answer
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get answer of one crossword-word submitted by Character.
|
||||
*
|
||||
* @param int $regexId ID of lisword
|
||||
* @param int $characterId ID of Character
|
||||
* @return int Submitted answer for this word or null
|
||||
*/
|
||||
public function getCharacterSubmission($wordId, $characterId)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT answer '.
|
||||
'FROM questtypes_crossword_words_characters '.
|
||||
'WHERE questtypes_crossword_word_id = ? AND character_id = ? ',
|
||||
'ii',
|
||||
$wordId, $characterId
|
||||
);
|
||||
if(!empty($data)) {
|
||||
return $data[0]['answer'];
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* Get all words for a crossword-Quest.
|
||||
*
|
||||
* @param int $questId ID of Quest
|
||||
* @return array Words
|
||||
*/
|
||||
public function getWordsForQuest($questId)
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT id, question, word, vertical, pos_x, pos_y '.
|
||||
'FROM questtypes_crossword_words '.
|
||||
'WHERE quest_id = ? ',
|
||||
'i',
|
||||
$questId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Save Character’s submitted answer for one crossword-word.
|
||||
*
|
||||
* @param int $regexId ID of word
|
||||
* @param int $characterId ID of Character
|
||||
* @param string $answer Submitted answer for this word
|
||||
*/
|
||||
public function setCharacterSubmission($wordId, $characterId, $answer)
|
||||
{
|
||||
$this->db->query(
|
||||
'INSERT INTO questtypes_crossword_words_characters '.
|
||||
'(questtypes_crossword_word_id, character_id, answer) '.
|
||||
'VALUES '.
|
||||
'(?, ?, ?) '.
|
||||
'ON DUPLICATE KEY UPDATE '.
|
||||
'answer = ?',
|
||||
'iiss',
|
||||
$wordId, $characterId, $answer,
|
||||
$answer
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get answer of one crossword-word submitted by Character.
|
||||
*
|
||||
* @param int $regexId ID of lisword
|
||||
* @param int $characterId ID of Character
|
||||
* @return int Submitted answer for this word or null
|
||||
*/
|
||||
public function getCharacterSubmission($wordId, $characterId)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT answer '.
|
||||
'FROM questtypes_crossword_words_characters '.
|
||||
'WHERE questtypes_crossword_word_id = ? AND character_id = ? ',
|
||||
'ii',
|
||||
$wordId, $characterId
|
||||
);
|
||||
if(!empty($data)) {
|
||||
return $data[0]['answer'];
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -1,33 +1,33 @@
|
|||
<form method="post" class="crossword">
|
||||
<table id="matrix">
|
||||
<tbody>
|
||||
<?php foreach(range(0, $maxY) as $y) : ?>
|
||||
<tr>
|
||||
<?php foreach(range(0, $maxX) as $x) : ?>
|
||||
<td>
|
||||
<?php if(array_key_exists($x, $matrix) && array_key_exists($y, $matrix[$x]) && !is_null($matrix[$x][$y])) : ?>
|
||||
<?php if(count($matrix[$x][$y]['indices']) > 0) : ?><span class="index"><?=implode('/',array_map(function($e) { return $e+1; }, $matrix[$x][$y]['indices']))?></span><?php endif ?>
|
||||
<input type="text" name="answers[<?=$x?>][<?=$y?>]" maxlength="1" size="1" value="<?=(!is_null($matrix[$x][$y]['answer'])) ? $matrix[$x][$y]['answer'] : ''?>" />
|
||||
<?php endif ?>
|
||||
</td>
|
||||
<?php endforeach ?>
|
||||
</tr>
|
||||
<?php endforeach ?>
|
||||
</tbody>
|
||||
</table>
|
||||
<ol>
|
||||
<?php foreach($words as &$word) : ?>
|
||||
<li>
|
||||
<?php if($word['vertical']) : ?>
|
||||
<?=_('vertical')?>:
|
||||
<?php else : ?>
|
||||
<?=_('horizontal')?>:
|
||||
<?php endif ?>
|
||||
<?=\hhu\z\Utils::t($word['question'])?>
|
||||
</li>
|
||||
<?php endforeach ?>
|
||||
</ol>
|
||||
<input type="submit" name="submit" value="<?=_('solve')?>" />
|
||||
<table id="matrix">
|
||||
<tbody>
|
||||
<?php foreach(range(0, $maxY) as $y) : ?>
|
||||
<tr>
|
||||
<?php foreach(range(0, $maxX) as $x) : ?>
|
||||
<td>
|
||||
<?php if(array_key_exists($x, $matrix) && array_key_exists($y, $matrix[$x]) && !is_null($matrix[$x][$y])) : ?>
|
||||
<?php if(count($matrix[$x][$y]['indices']) > 0) : ?><span class="index"><?=implode('/',array_map(function($e) { return $e+1; }, $matrix[$x][$y]['indices']))?></span><?php endif ?>
|
||||
<input type="text" name="answers[<?=$x?>][<?=$y?>]" maxlength="1" size="1" value="<?=(!is_null($matrix[$x][$y]['answer'])) ? $matrix[$x][$y]['answer'] : ''?>" />
|
||||
<?php endif ?>
|
||||
</td>
|
||||
<?php endforeach ?>
|
||||
</tr>
|
||||
<?php endforeach ?>
|
||||
</tbody>
|
||||
</table>
|
||||
<ol>
|
||||
<?php foreach($words as &$word) : ?>
|
||||
<li>
|
||||
<?php if($word['vertical']) : ?>
|
||||
<?=_('vertical')?>:
|
||||
<?php else : ?>
|
||||
<?=_('horizontal')?>:
|
||||
<?php endif ?>
|
||||
<?=\hhu\z\Utils::t($word['question'])?>
|
||||
</li>
|
||||
<?php endforeach ?>
|
||||
</ol>
|
||||
<input type="submit" name="submit" value="<?=_('solve')?>" />
|
||||
</form>
|
||||
<script type="text/javascript">
|
||||
// Last position
|
||||
|
|
@ -36,62 +36,62 @@ var posX = 0;
|
|||
|
||||
// Handle key input
|
||||
$('input:text').keyup(function(event) {
|
||||
// Determine current position
|
||||
var row = $(this).closest('tr');
|
||||
var y = $('#matrix tr').index(row);
|
||||
var col = $(this).closest('td');
|
||||
var x = row.children().index(col);
|
||||
|
||||
// Determine current direction
|
||||
var horizontal = (x != posX);
|
||||
|
||||
// Set current position
|
||||
posX = x;
|
||||
posY = y;
|
||||
|
||||
// Next input field
|
||||
var nextInput = null;
|
||||
|
||||
// Hanlde keys
|
||||
switch(event.keyCode)
|
||||
{
|
||||
case 37: // Left
|
||||
nextInput = getColumnInput(row, x-1);
|
||||
break;
|
||||
case 38: // Up
|
||||
nextInput = getRowInput(x, y-1);
|
||||
break;
|
||||
case 39: // Right
|
||||
nextInput = getColumnInput(row, x+1);
|
||||
break;
|
||||
case 40: // Down
|
||||
nextInput = getRowInput(x, y+1);
|
||||
break;
|
||||
default:
|
||||
// Only handy character input
|
||||
if(event.key.length != 1) {
|
||||
break;
|
||||
}
|
||||
|
||||
// Set new character
|
||||
$(this).val(event.key);
|
||||
|
||||
// Go to next input field
|
||||
if(horizontal) {
|
||||
nextInput = getColumnInput(row, x+1);
|
||||
}
|
||||
else {
|
||||
nextInput = getRowInput(x, y+1);
|
||||
}
|
||||
|
||||
event.preventDefault();
|
||||
break;
|
||||
}
|
||||
|
||||
// Select input field
|
||||
if(nextInput != null) {
|
||||
nextInput.focus();
|
||||
}
|
||||
// Determine current position
|
||||
var row = $(this).closest('tr');
|
||||
var y = $('#matrix tr').index(row);
|
||||
var col = $(this).closest('td');
|
||||
var x = row.children().index(col);
|
||||
|
||||
// Determine current direction
|
||||
var horizontal = (x != posX);
|
||||
|
||||
// Set current position
|
||||
posX = x;
|
||||
posY = y;
|
||||
|
||||
// Next input field
|
||||
var nextInput = null;
|
||||
|
||||
// Hanlde keys
|
||||
switch(event.keyCode)
|
||||
{
|
||||
case 37: // Left
|
||||
nextInput = getColumnInput(row, x-1);
|
||||
break;
|
||||
case 38: // Up
|
||||
nextInput = getRowInput(x, y-1);
|
||||
break;
|
||||
case 39: // Right
|
||||
nextInput = getColumnInput(row, x+1);
|
||||
break;
|
||||
case 40: // Down
|
||||
nextInput = getRowInput(x, y+1);
|
||||
break;
|
||||
default:
|
||||
// Only handy character input
|
||||
if(event.key.length != 1) {
|
||||
break;
|
||||
}
|
||||
|
||||
// Set new character
|
||||
$(this).val(event.key);
|
||||
|
||||
// Go to next input field
|
||||
if(horizontal) {
|
||||
nextInput = getColumnInput(row, x+1);
|
||||
}
|
||||
else {
|
||||
nextInput = getRowInput(x, y+1);
|
||||
}
|
||||
|
||||
event.preventDefault();
|
||||
break;
|
||||
}
|
||||
|
||||
// Select input field
|
||||
if(nextInput != null) {
|
||||
nextInput.focus();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
|
@ -100,16 +100,16 @@ $('input:text').keyup(function(event) {
|
|||
*/
|
||||
function getColumnInput(row, x)
|
||||
{
|
||||
nextCol = $('td', row)[x];
|
||||
if(nextCol != null) {
|
||||
return $('input:text', nextCol)[0];
|
||||
}
|
||||
else {
|
||||
// TODO get next number
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
nextCol = $('td', row)[x];
|
||||
if(nextCol != null) {
|
||||
return $('input:text', nextCol)[0];
|
||||
}
|
||||
else {
|
||||
// TODO get next number
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -118,19 +118,19 @@ function getColumnInput(row, x)
|
|||
*/
|
||||
function getRowInput(x, y)
|
||||
{
|
||||
nextRow = $('#matrix tr')[y];
|
||||
if(nextRow != null)
|
||||
{
|
||||
nextCol = $('td', nextRow)[x];
|
||||
if(nextCol != null) {
|
||||
return $('input:text', nextCol)[0];
|
||||
}
|
||||
}
|
||||
else {
|
||||
// TODO get nextnumber
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
nextRow = $('#matrix tr')[y];
|
||||
if(nextRow != null)
|
||||
{
|
||||
nextCol = $('td', nextRow)[x];
|
||||
if(nextCol != null) {
|
||||
return $('input:text', nextCol)[0];
|
||||
}
|
||||
}
|
||||
else {
|
||||
// TODO get nextnumber
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
</script>
|
||||
|
|
|
|||
|
|
@ -1,48 +1,48 @@
|
|||
<form method="post" class="crossword">
|
||||
<table>
|
||||
<tbody>
|
||||
<?php foreach(range(0, $maxY) as $y) : ?>
|
||||
<tr>
|
||||
<?php foreach(range(0, $maxX) as $x) : ?>
|
||||
<td>
|
||||
<?php if(array_key_exists($x, $matrix) && array_key_exists($y, $matrix[$x]) && !is_null($matrix[$x][$y])) : ?>
|
||||
<?php if(count($matrix[$x][$y]['indices']) > 0) : ?><span class="index"><?=implode('/',array_map(function($e) { return $e+1; }, $matrix[$x][$y]['indices']))?></span><?php endif ?>
|
||||
<input type="text" name="answers[<?=$x?>][<?=$y?>]" maxlength="1" size="1" disabled="disabled" style="background-color:<?=($matrix[$x][$y]['right']) ? 'green' : 'red'?>" value="<?=(!is_null($matrix[$x][$y]['answer'])) ? $matrix[$x][$y]['answer'] : ''?>" />
|
||||
<?php endif ?>
|
||||
</td>
|
||||
<?php endforeach ?>
|
||||
</tr>
|
||||
<?php endforeach ?>
|
||||
</tbody>
|
||||
</table>
|
||||
<ol>
|
||||
<?php foreach($words as &$word) : ?>
|
||||
<li>
|
||||
<?php if($word['vertical']) : ?>
|
||||
<?=_('vertical')?>:
|
||||
<?php else : ?>
|
||||
<?=_('horizontal')?>:
|
||||
<?php endif ?>
|
||||
<?=$word['question']?>
|
||||
</li>
|
||||
<?php endforeach ?>
|
||||
</ol>
|
||||
<table>
|
||||
<tbody>
|
||||
<?php foreach(range(0, $maxY) as $y) : ?>
|
||||
<tr>
|
||||
<?php foreach(range(0, $maxX) as $x) : ?>
|
||||
<td>
|
||||
<?php if(array_key_exists($x, $matrix) && array_key_exists($y, $matrix[$x]) && !is_null($matrix[$x][$y])) : ?>
|
||||
<?php if(count($matrix[$x][$y]['indices']) > 0) : ?><span class="index"><?=implode('/',array_map(function($e) { return $e+1; }, $matrix[$x][$y]['indices']))?></span><?php endif ?>
|
||||
<input type="text" name="answers[<?=$x?>][<?=$y?>]" maxlength="1" size="1" disabled="disabled" style="background-color:<?=($matrix[$x][$y]['right']) ? 'green' : 'red'?>" value="<?=(!is_null($matrix[$x][$y]['answer'])) ? $matrix[$x][$y]['answer'] : ''?>" />
|
||||
<?php endif ?>
|
||||
</td>
|
||||
<?php endforeach ?>
|
||||
</tr>
|
||||
<?php endforeach ?>
|
||||
</tbody>
|
||||
</table>
|
||||
<ol>
|
||||
<?php foreach($words as &$word) : ?>
|
||||
<li>
|
||||
<?php if($word['vertical']) : ?>
|
||||
<?=_('vertical')?>:
|
||||
<?php else : ?>
|
||||
<?=_('horizontal')?>:
|
||||
<?php endif ?>
|
||||
<?=$word['question']?>
|
||||
</li>
|
||||
<?php endforeach ?>
|
||||
</ol>
|
||||
</form>
|
||||
<script type="text/javascript">
|
||||
$('input:text').bind("keyup", function(e) {
|
||||
var n = $("input:text").length;
|
||||
if(e.which == 8 || e.which == 46) {
|
||||
var nextIndex = $('input:text').index(this) - 1;
|
||||
var del = 1;
|
||||
}
|
||||
else {
|
||||
var nextIndex = $('input:text').index(this) + 1;
|
||||
}
|
||||
if(nextIndex < n) {
|
||||
$('input:text')[nextIndex].focus();
|
||||
if(del == 1) {
|
||||
$('input:text')[nextIndex].value = '';
|
||||
}
|
||||
}
|
||||
var n = $("input:text").length;
|
||||
if(e.which == 8 || e.which == 46) {
|
||||
var nextIndex = $('input:text').index(this) - 1;
|
||||
var del = 1;
|
||||
}
|
||||
else {
|
||||
var nextIndex = $('input:text').index(this) + 1;
|
||||
}
|
||||
if(nextIndex < n) {
|
||||
$('input:text')[nextIndex].focus();
|
||||
if(del == 1) {
|
||||
$('input:text')[nextIndex].value = '';
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
|
|
|||
|
|
@ -1,24 +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 Drag&Drop.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class DragndropQuesttypeAgent extends \hhu\z\agents\QuesttypeAgent
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 Drag&Drop.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class DragndropQuesttypeAgent extends \hhu\z\agents\QuesttypeAgent
|
||||
{
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -1,148 +1,148 @@
|
|||
<?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 DragndropQuesttypeAgent for Drag&Drop.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class DragndropQuesttypeController extends \hhu\z\controllers\QuesttypeController
|
||||
{
|
||||
/**
|
||||
* Required models
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $models = array('media');
|
||||
/**
|
||||
* Required components
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $components = array('validation');
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 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 Drag&Drop field
|
||||
$dndField = $this->Dragndrop->getDragndrop($quest['id']);
|
||||
|
||||
// Get Drops
|
||||
$drops = $this->Dragndrop->getDrops($dndField['quest_id']);
|
||||
|
||||
// Save user answers
|
||||
foreach($drops as &$drop)
|
||||
{
|
||||
// Determine user answer
|
||||
$answer = null;
|
||||
if(array_key_exists($drop['id'], $answers) && !empty($answers[$drop['id']]))
|
||||
{
|
||||
$a = intval(substr($answers[$drop['id']], 4));
|
||||
if($a !== false && $a > 0) {
|
||||
$answer = $a;
|
||||
}
|
||||
}
|
||||
|
||||
// Update database record
|
||||
$this->Dragndrop->setCharacterSubmission($drop['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
|
||||
* @param array $answers Character answers for the Quest
|
||||
* @return boolean True/false for a right/wrong answer or null for moderator evaluation
|
||||
*/
|
||||
public function matchAnswersOfCharacter($seminary, $questgroup, $quest, $character, $answers)
|
||||
{
|
||||
// Get Drag&Drop field
|
||||
$dndField = $this->Dragndrop->getDragndrop($quest['id']);
|
||||
|
||||
// Get Drags
|
||||
$drags = $this->Dragndrop->getDrags($dndField['quest_id'], true);
|
||||
|
||||
// Match drags with user answers
|
||||
foreach($drags as &$drag)
|
||||
{
|
||||
$founds = array_keys($answers, 'drag'.$drag['id']);
|
||||
if(count($founds) != 1) {
|
||||
return false;
|
||||
}
|
||||
if(!$this->Dragndrop->dragMatchesDrop($drag['id'], $founds[0])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Set status
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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 Drag&Drop field
|
||||
$dndField = $this->Dragndrop->getDragndrop($quest['id']);
|
||||
|
||||
/**
|
||||
* 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 DragndropQuesttypeAgent for Drag&Drop.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class DragndropQuesttypeController extends \hhu\z\controllers\QuesttypeController
|
||||
{
|
||||
/**
|
||||
* Required models
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $models = array('media');
|
||||
/**
|
||||
* Required components
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $components = array('validation');
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 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 Drag&Drop field
|
||||
$dndField = $this->Dragndrop->getDragndrop($quest['id']);
|
||||
|
||||
// Get Drops
|
||||
$drops = $this->Dragndrop->getDrops($dndField['quest_id']);
|
||||
|
||||
// Save user answers
|
||||
foreach($drops as &$drop)
|
||||
{
|
||||
// Determine user answer
|
||||
$answer = null;
|
||||
if(array_key_exists($drop['id'], $answers) && !empty($answers[$drop['id']]))
|
||||
{
|
||||
$a = intval(substr($answers[$drop['id']], 4));
|
||||
if($a !== false && $a > 0) {
|
||||
$answer = $a;
|
||||
}
|
||||
}
|
||||
|
||||
// Update database record
|
||||
$this->Dragndrop->setCharacterSubmission($drop['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
|
||||
* @param array $answers Character answers for the Quest
|
||||
* @return boolean True/false for a right/wrong answer or null for moderator evaluation
|
||||
*/
|
||||
public function matchAnswersOfCharacter($seminary, $questgroup, $quest, $character, $answers)
|
||||
{
|
||||
// Get Drag&Drop field
|
||||
$dndField = $this->Dragndrop->getDragndrop($quest['id']);
|
||||
|
||||
// Get Drags
|
||||
$drags = $this->Dragndrop->getDrags($dndField['quest_id'], true);
|
||||
|
||||
// Match drags with user answers
|
||||
foreach($drags as &$drag)
|
||||
{
|
||||
$founds = array_keys($answers, 'drag'.$drag['id']);
|
||||
if(count($founds) != 1) {
|
||||
return false;
|
||||
}
|
||||
if(!$this->Dragndrop->dragMatchesDrop($drag['id'], $founds[0])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Set status
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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 Drag&Drop field
|
||||
$dndField = $this->Dragndrop->getDragndrop($quest['id']);
|
||||
if(!is_null($dndField) && !is_null($dndField['questmedia_id'])) {
|
||||
$dndField['media'] = $this->Media->getSeminaryMediaById($dndField['questmedia_id']);
|
||||
}
|
||||
|
||||
// Get Drags
|
||||
$drags = array();
|
||||
|
||||
// Get Drags
|
||||
$drags = array();
|
||||
if(!is_null($dndField))
|
||||
{
|
||||
$dragsByIndex = $this->Dragndrop->getDrags($dndField['quest_id']);
|
||||
|
|
@ -151,91 +151,91 @@
|
|||
$drags[$drag['id']] = $drag;
|
||||
}
|
||||
}
|
||||
|
||||
// Get Drops
|
||||
$drops = array();
|
||||
|
||||
// Get Drops
|
||||
$drops = array();
|
||||
if(!is_null($dndField)) {
|
||||
$drops = $this->Dragndrop->getDrops($dndField['quest_id']);
|
||||
}
|
||||
|
||||
// Get Character answers
|
||||
if($this->request->getGetParam('show-answer') == 'true' || !$this->Quests->hasCharacterSolvedQuest($quest['id'], $character['id']) || $this->request->getGetParam('status') == 'solved')
|
||||
{
|
||||
foreach($drops as &$drop)
|
||||
{
|
||||
$drop['answer'] = $this->Dragndrop->getCharacterSubmission($drop['id'], $character['id']);
|
||||
if(!is_null($drop['answer']))
|
||||
{
|
||||
$drop['answer'] = $drags[$drop['answer']];
|
||||
unset($drags[$drop['answer']['id']]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Pass data to view
|
||||
$this->set('seminary', $seminary);
|
||||
$this->set('field', $dndField);
|
||||
$this->set('drops', $drops);
|
||||
$this->set('drags', $drags);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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 Drag&Drop field
|
||||
$dndField = $this->Dragndrop->getDragndrop($quest['id']);
|
||||
$dndField['media'] = $this->Media->getSeminaryMediaById($dndField['questmedia_id']);
|
||||
|
||||
// Get Drags
|
||||
$drags = array();
|
||||
$dragsByIndex = $this->Dragndrop->getDrags($dndField['quest_id']);
|
||||
foreach($dragsByIndex as &$drag) {
|
||||
$drag['media'] = $this->Media->getSeminaryMediaById($drag['questmedia_id']);
|
||||
$drags[$drag['id']] = $drag;
|
||||
}
|
||||
|
||||
// Get Drops
|
||||
$drops = $this->Dragndrop->getDrops($dndField['quest_id']);
|
||||
|
||||
// Get Character answers
|
||||
foreach($drops as &$drop)
|
||||
{
|
||||
$drop['answer'] = $this->Dragndrop->getCharacterSubmission($drop['id'], $character['id']);
|
||||
if(!is_null($drop['answer']))
|
||||
{
|
||||
$drop['answer'] = $drags[$drop['answer']];
|
||||
unset($drags[$drop['answer']['id']]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Pass data to view
|
||||
$this->set('seminary', $seminary);
|
||||
$this->set('field', $dndField);
|
||||
$this->set('drops', $drops);
|
||||
$this->set('drags', $drags);
|
||||
}
|
||||
|
||||
// Get Character answers
|
||||
if($this->request->getGetParam('show-answer') == 'true' || !$this->Quests->hasCharacterSolvedQuest($quest['id'], $character['id']) || $this->request->getGetParam('status') == 'solved')
|
||||
{
|
||||
foreach($drops as &$drop)
|
||||
{
|
||||
$drop['answer'] = $this->Dragndrop->getCharacterSubmission($drop['id'], $character['id']);
|
||||
if(!is_null($drop['answer']))
|
||||
{
|
||||
$drop['answer'] = $drags[$drop['answer']];
|
||||
unset($drags[$drop['answer']['id']]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Pass data to view
|
||||
$this->set('seminary', $seminary);
|
||||
$this->set('field', $dndField);
|
||||
$this->set('drops', $drops);
|
||||
$this->set('drags', $drags);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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 Drag&Drop field
|
||||
$dndField = $this->Dragndrop->getDragndrop($quest['id']);
|
||||
$dndField['media'] = $this->Media->getSeminaryMediaById($dndField['questmedia_id']);
|
||||
|
||||
// Get Drags
|
||||
$drags = array();
|
||||
$dragsByIndex = $this->Dragndrop->getDrags($dndField['quest_id']);
|
||||
foreach($dragsByIndex as &$drag) {
|
||||
$drag['media'] = $this->Media->getSeminaryMediaById($drag['questmedia_id']);
|
||||
$drags[$drag['id']] = $drag;
|
||||
}
|
||||
|
||||
// Get Drops
|
||||
$drops = $this->Dragndrop->getDrops($dndField['quest_id']);
|
||||
|
||||
// Get Character answers
|
||||
foreach($drops as &$drop)
|
||||
{
|
||||
$drop['answer'] = $this->Dragndrop->getCharacterSubmission($drop['id'], $character['id']);
|
||||
if(!is_null($drop['answer']))
|
||||
{
|
||||
$drop['answer'] = $drags[$drop['answer']];
|
||||
unset($drags[$drop['answer']['id']]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Pass data to view
|
||||
$this->set('seminary', $seminary);
|
||||
$this->set('field', $dndField);
|
||||
$this->set('drops', $drops);
|
||||
$this->set('drags', $drags);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Action: edittask.
|
||||
*
|
||||
*
|
||||
* Edit the task of a Quest.
|
||||
*
|
||||
* @param array $seminary Current Seminary data
|
||||
* @param array $questgroup Current Questgroup data
|
||||
* @param array $quest Current Quest data
|
||||
*
|
||||
* @param array $seminary Current Seminary data
|
||||
* @param array $questgroup Current Questgroup data
|
||||
* @param array $quest Current Quest data
|
||||
*/
|
||||
public function edittask($seminary, $questgroup, $quest)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,37 +1,37 @@
|
|||
<?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 DragndropQuesttypeAgent for Drag&Drop.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class DragndropQuesttypeModel extends \hhu\z\models\QuesttypeModel
|
||||
{
|
||||
/**
|
||||
* Required models
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $models = array('media');
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 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 DragndropQuesttypeAgent for Drag&Drop.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class DragndropQuesttypeModel extends \hhu\z\models\QuesttypeModel
|
||||
{
|
||||
/**
|
||||
* Required models
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $models = array('media');
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Copy a Quest
|
||||
*
|
||||
*
|
||||
* @param int $userId ID of creating user
|
||||
* @param int $sourceQuestId ID of Quest to copy from
|
||||
* @param int $targetQuestId ID of Quest to copy to
|
||||
|
|
@ -130,7 +130,7 @@
|
|||
|
||||
/**
|
||||
* Create a new Drag&Drop field for a Quest.
|
||||
*
|
||||
*
|
||||
* @param int $userId ID of creating user
|
||||
* @param int $questId ID of Quest to create Drag&Drop field for
|
||||
* @param int $questmediaId ID of Questmedia to use for the field
|
||||
|
|
@ -155,51 +155,51 @@
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Drag&Drop-field.
|
||||
*
|
||||
* @param int $questId ID of Quest
|
||||
* @return array Drag&Drop-field
|
||||
*/
|
||||
public function getDragndrop($questId)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT quest_id, questmedia_id, width, height '.
|
||||
'FROM questtypes_dragndrop '.
|
||||
'WHERE quest_id = ?',
|
||||
'i',
|
||||
$questId
|
||||
);
|
||||
if(!empty($data)) {
|
||||
return $data[0];
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Drop-items.
|
||||
*
|
||||
* @param int $dragndropId ID of Drag&Drop-field
|
||||
* @return array Drop-items
|
||||
*/
|
||||
public function getDrops($dragndropId)
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT id, top, `left`, width, height '.
|
||||
'FROM questtypes_dragndrop_drops '.
|
||||
'WHERE questtypes_dragndrop_id = ?',
|
||||
'i',
|
||||
$dragndropId
|
||||
);
|
||||
}
|
||||
/**
|
||||
* Get Drag&Drop-field.
|
||||
*
|
||||
* @param int $questId ID of Quest
|
||||
* @return array Drag&Drop-field
|
||||
*/
|
||||
public function getDragndrop($questId)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT quest_id, questmedia_id, width, height '.
|
||||
'FROM questtypes_dragndrop '.
|
||||
'WHERE quest_id = ?',
|
||||
'i',
|
||||
$questId
|
||||
);
|
||||
if(!empty($data)) {
|
||||
return $data[0];
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Drop-items.
|
||||
*
|
||||
* @param int $dragndropId ID of Drag&Drop-field
|
||||
* @return array Drop-items
|
||||
*/
|
||||
public function getDrops($dragndropId)
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT id, top, `left`, width, height '.
|
||||
'FROM questtypes_dragndrop_drops '.
|
||||
'WHERE questtypes_dragndrop_id = ?',
|
||||
'i',
|
||||
$dragndropId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Drop-items for a Drag-item
|
||||
*
|
||||
*
|
||||
* @param int $dragId ID of Drag-item to get Drop-items for
|
||||
* @return array List of Drop-items
|
||||
*/
|
||||
|
|
@ -218,7 +218,7 @@
|
|||
|
||||
/**
|
||||
* Set correct Drop-items for a Drag-item.
|
||||
*
|
||||
*
|
||||
* @param int $userId ID of creating user
|
||||
* @param int $dragId ID of Drag-item to set Drop-items for
|
||||
* @param array $dropIds List of Drop-items to set for Drag-item
|
||||
|
|
@ -274,7 +274,7 @@
|
|||
|
||||
/**
|
||||
* Create a new Drop-item for a Drag&Drop-field.
|
||||
*
|
||||
*
|
||||
* @param int $dragndropId ID of Drag&Drop-field to create Drop-item for
|
||||
* @param int $width Width of Drop-item
|
||||
* @param int $height Height of Drop-item
|
||||
|
|
@ -299,7 +299,7 @@
|
|||
|
||||
/**
|
||||
* Edit Drop-item.
|
||||
*
|
||||
*
|
||||
* @param int $dropId ID of Drop-item to edit
|
||||
* @param int $width New width of Drop-item
|
||||
* @param int $height New height of Drop-item
|
||||
|
|
@ -321,7 +321,7 @@
|
|||
|
||||
/**
|
||||
* Delete a Drop-item.
|
||||
*
|
||||
*
|
||||
* @param int $dropId ID of Drop-item to delete
|
||||
*/
|
||||
public function deleteDrop($dropId)
|
||||
|
|
@ -333,38 +333,38 @@
|
|||
$dropId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Drag-items.
|
||||
*
|
||||
* @param int $dragndropId ID of Drag&Drop-field
|
||||
* @param boolean $onlyUsed Only Drag-items that are used for a Drop-item
|
||||
* @return array Drag-items
|
||||
*/
|
||||
public function getDrags($dragndropId, $onlyUsed=false)
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT id, questmedia_id '.
|
||||
'FROM questtypes_dragndrop_drags '.
|
||||
'WHERE questtypes_dragndrop_id = ?'.
|
||||
($onlyUsed
|
||||
? ' AND EXISTS ('.
|
||||
'SELECT questtypes_dragndrop_drag_id '.
|
||||
'FROM questtypes_dragndrop_drops_drags '.
|
||||
'WHERE questtypes_dragndrop_drag_id = questtypes_dragndrop_drags.id'.
|
||||
')'
|
||||
: null
|
||||
),
|
||||
'i',
|
||||
$dragndropId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Drag-items.
|
||||
*
|
||||
* @param int $dragndropId ID of Drag&Drop-field
|
||||
* @param boolean $onlyUsed Only Drag-items that are used for a Drop-item
|
||||
* @return array Drag-items
|
||||
*/
|
||||
public function getDrags($dragndropId, $onlyUsed=false)
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT id, questmedia_id '.
|
||||
'FROM questtypes_dragndrop_drags '.
|
||||
'WHERE questtypes_dragndrop_id = ?'.
|
||||
($onlyUsed
|
||||
? ' AND EXISTS ('.
|
||||
'SELECT questtypes_dragndrop_drag_id '.
|
||||
'FROM questtypes_dragndrop_drops_drags '.
|
||||
'WHERE questtypes_dragndrop_drag_id = questtypes_dragndrop_drags.id'.
|
||||
')'
|
||||
: null
|
||||
),
|
||||
'i',
|
||||
$dragndropId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a new Drag-item.
|
||||
*
|
||||
*
|
||||
* @param int $dragndropId ID of Drag&Drop-field to add Drag-item for
|
||||
* @param int $questmediaId ID of Questmedia to use for this Drag-item
|
||||
* @return int ID of newly created Drag-item
|
||||
|
|
@ -386,7 +386,7 @@
|
|||
|
||||
/**
|
||||
* Edit Drag-item.
|
||||
*
|
||||
*
|
||||
* @param int $dragId ID of Drag-item to edit
|
||||
* @param int $questmediaId ID of new Questmedia to use for this Drag-item
|
||||
*/
|
||||
|
|
@ -405,7 +405,7 @@
|
|||
|
||||
/**
|
||||
* Delete a Drag-item.
|
||||
*
|
||||
*
|
||||
* @param int $dragId ID of Drag-item to delete
|
||||
*/
|
||||
public function deleteDrag($dragId)
|
||||
|
|
@ -417,91 +417,91 @@
|
|||
$dragId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if a Drag-item mathes a Drop-item.
|
||||
*
|
||||
* @param int $dragId ID of Drag-field
|
||||
* @param int $dropId ID of Drop-field
|
||||
* @return boolean Drag-item is valid for Drop-item
|
||||
*/
|
||||
public function dragMatchesDrop($dragId, $dropId)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT count(*) AS c '.
|
||||
'FROM questtypes_dragndrop_drops_drags '.
|
||||
'WHERE questtypes_dragndrop_drop_id = ? AND questtypes_dragndrop_drag_id = ?',
|
||||
'ii',
|
||||
$dropId, $dragId
|
||||
);
|
||||
if(!empty($data)) {
|
||||
return ($data[0]['c'] > 0);
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Save Character’s submitted answer for one Drop-field.
|
||||
*
|
||||
* @param int $dropId ID of Drop-field
|
||||
* @param int $characterId ID of Character
|
||||
* @param string $answer Submitted Drag-field-ID for this field
|
||||
*/
|
||||
public function setCharacterSubmission($dropId, $characterId, $answer)
|
||||
{
|
||||
if(is_null($answer))
|
||||
{
|
||||
$this->db->query(
|
||||
'DELETE FROM questtypes_dragndrop_drops_characters '.
|
||||
'WHERE questtypes_dragndrop_drop_id = ? AND character_id = ?',
|
||||
'ii',
|
||||
$dropId, $characterId
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->db->query(
|
||||
'INSERT INTO questtypes_dragndrop_drops_characters '.
|
||||
'(questtypes_dragndrop_drop_id, character_id, questtypes_dragndrop_drag_id) '.
|
||||
'VALUES '.
|
||||
'(?, ?, ?) '.
|
||||
'ON DUPLICATE KEY UPDATE '.
|
||||
'questtypes_dragndrop_drag_id = ?',
|
||||
'iiii',
|
||||
$dropId, $characterId, $answer, $answer
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Character’s saved answer for one Drop-field.
|
||||
*
|
||||
* @param int $dropId ID of Drop-field
|
||||
* @param int $characterId ID of Character
|
||||
* @return int ID of Drag-field or null
|
||||
*/
|
||||
public function getCharacterSubmission($dropId, $characterId)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT questtypes_dragndrop_drag_id '.
|
||||
'FROM questtypes_dragndrop_drops_characters '.
|
||||
'WHERE questtypes_dragndrop_drop_id = ? AND character_id = ?',
|
||||
'ii',
|
||||
$dropId, $characterId
|
||||
);
|
||||
if(!empty($data)) {
|
||||
return $data[0]['questtypes_dragndrop_drag_id'];
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if a Drag-item mathes a Drop-item.
|
||||
*
|
||||
* @param int $dragId ID of Drag-field
|
||||
* @param int $dropId ID of Drop-field
|
||||
* @return boolean Drag-item is valid for Drop-item
|
||||
*/
|
||||
public function dragMatchesDrop($dragId, $dropId)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT count(*) AS c '.
|
||||
'FROM questtypes_dragndrop_drops_drags '.
|
||||
'WHERE questtypes_dragndrop_drop_id = ? AND questtypes_dragndrop_drag_id = ?',
|
||||
'ii',
|
||||
$dropId, $dragId
|
||||
);
|
||||
if(!empty($data)) {
|
||||
return ($data[0]['c'] > 0);
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Save Character’s submitted answer for one Drop-field.
|
||||
*
|
||||
* @param int $dropId ID of Drop-field
|
||||
* @param int $characterId ID of Character
|
||||
* @param string $answer Submitted Drag-field-ID for this field
|
||||
*/
|
||||
public function setCharacterSubmission($dropId, $characterId, $answer)
|
||||
{
|
||||
if(is_null($answer))
|
||||
{
|
||||
$this->db->query(
|
||||
'DELETE FROM questtypes_dragndrop_drops_characters '.
|
||||
'WHERE questtypes_dragndrop_drop_id = ? AND character_id = ?',
|
||||
'ii',
|
||||
$dropId, $characterId
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->db->query(
|
||||
'INSERT INTO questtypes_dragndrop_drops_characters '.
|
||||
'(questtypes_dragndrop_drop_id, character_id, questtypes_dragndrop_drag_id) '.
|
||||
'VALUES '.
|
||||
'(?, ?, ?) '.
|
||||
'ON DUPLICATE KEY UPDATE '.
|
||||
'questtypes_dragndrop_drag_id = ?',
|
||||
'iiii',
|
||||
$dropId, $characterId, $answer, $answer
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Character’s saved answer for one Drop-field.
|
||||
*
|
||||
* @param int $dropId ID of Drop-field
|
||||
* @param int $characterId ID of Character
|
||||
* @return int ID of Drag-field or null
|
||||
*/
|
||||
public function getCharacterSubmission($dropId, $characterId)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT questtypes_dragndrop_drag_id '.
|
||||
'FROM questtypes_dragndrop_drops_characters '.
|
||||
'WHERE questtypes_dragndrop_drop_id = ? AND character_id = ?',
|
||||
'ii',
|
||||
$dropId, $characterId
|
||||
);
|
||||
if(!empty($data)) {
|
||||
return $data[0]['questtypes_dragndrop_drag_id'];
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue