add some checks to not throw IdNotFound exception for empty Quests (fixes #9)
This commit is contained in:
parent
fed6d4a80c
commit
df7c22c8fc
7 changed files with 68 additions and 52 deletions
|
|
@ -99,7 +99,7 @@
|
||||||
{
|
{
|
||||||
// Get Boss-Fight
|
// Get Boss-Fight
|
||||||
$fight = $this->Bossfight->getBossFight($quest['id']);
|
$fight = $this->Bossfight->getBossFight($quest['id']);
|
||||||
if(!is_null($fight['boss_seminarymedia_id'])) {
|
if(!is_null($fight) && !is_null($fight['boss_seminarymedia_id'])) {
|
||||||
$fight['bossmedia'] = $this->Media->getSeminaryMediaById($fight['boss_seminarymedia_id']);
|
$fight['bossmedia'] = $this->Media->getSeminaryMediaById($fight['boss_seminarymedia_id']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -71,7 +71,6 @@
|
||||||
/**
|
/**
|
||||||
* Get a Boss-Fight.
|
* Get a Boss-Fight.
|
||||||
*
|
*
|
||||||
* @throws \nre\exceptions\IdNotFoundException
|
|
||||||
* @param int $questId ID of Quest
|
* @param int $questId ID of Quest
|
||||||
* @return array Boss-Fight data
|
* @return array Boss-Fight data
|
||||||
*/
|
*/
|
||||||
|
|
@ -84,12 +83,11 @@
|
||||||
'i',
|
'i',
|
||||||
$questId
|
$questId
|
||||||
);
|
);
|
||||||
if(empty($data)) {
|
if(!empty($data)) {
|
||||||
throw new \nre\exceptions\IdNotFoundException($questId);
|
return $data[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
return $data[0];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,34 +1,36 @@
|
||||||
|
<?php if(!is_null($fight)) : ?>
|
||||||
<div class="cf">
|
<div class="cf">
|
||||||
<section class="opponent">
|
<section class="opponent">
|
||||||
<p class="fwb"><?=$character['name']?></p>
|
<p class="fwb"><?=$character['name']?></p>
|
||||||
<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>
|
||||||
<p>
|
<p>
|
||||||
<?php if($lives['character'] > 0) : ?>
|
<?php if($lives['character'] > 0) : ?>
|
||||||
<?php foreach(range(1,$lives['character']) as $i) : ?>
|
<?php foreach(range(1,$lives['character']) as $i) : ?>
|
||||||
<i class="fa fa-heart fa-fw"></i>
|
<i class="fa fa-heart fa-fw"></i>
|
||||||
<?php endforeach ?>
|
<?php endforeach ?>
|
||||||
<?php else : ?>
|
<?php else : ?>
|
||||||
<?=_('lost')?>
|
<?=_('lost')?>
|
||||||
<?php endif ?>
|
<?php endif ?>
|
||||||
</p>
|
</p>
|
||||||
</section>
|
</section>
|
||||||
<section class="opponent">
|
<section class="opponent">
|
||||||
<p class="fwb"><?=$fight['bossname']?></p>
|
<p class="fwb"><?=$fight['bossname']?></p>
|
||||||
<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>
|
||||||
<p>
|
<p>
|
||||||
<?php if($lives['boss'] > 0) : ?>
|
<?php if($lives['boss'] > 0) : ?>
|
||||||
<?php foreach(range(1,$lives['boss']) as $i) : ?>
|
<?php foreach(range(1,$lives['boss']) as $i) : ?>
|
||||||
<i class="fa fa-heart fa-fw"></i>
|
<i class="fa fa-heart fa-fw"></i>
|
||||||
<?php endforeach ?>
|
<?php endforeach ?>
|
||||||
<?php else : ?>
|
<?php else : ?>
|
||||||
<b><?=_('lost')?></b>
|
<b><?=_('lost')?></b>
|
||||||
<?php endif ?>
|
<?php endif ?>
|
||||||
</p>
|
</p>
|
||||||
</section>
|
</section>
|
||||||
</div>
|
</div>
|
||||||
|
<?php endif ?>
|
||||||
|
|
||||||
|
<?php if(!is_null($stage)) : ?>
|
||||||
<p><?=\hhu\z\Utils::t($stage['text'])?></p>
|
<p><?=\hhu\z\Utils::t($stage['text'])?></p>
|
||||||
|
|
||||||
<form method="post" action="<?=$linker->link(null,0,false,null,true,'task')?>">
|
<form method="post" action="<?=$linker->link(null,0,false,null,true,'task')?>">
|
||||||
<input type="hidden" name="stage" value="<?=$stage['id']?>" />
|
<input type="hidden" name="stage" value="<?=$stage['id']?>" />
|
||||||
<ul class="bossfight cf">
|
<ul class="bossfight cf">
|
||||||
|
|
@ -49,3 +51,4 @@
|
||||||
<?php endif ?>
|
<?php endif ?>
|
||||||
</ul>
|
</ul>
|
||||||
</form>
|
</form>
|
||||||
|
<?php endif ?>
|
||||||
|
|
|
||||||
|
|
@ -131,18 +131,26 @@
|
||||||
{
|
{
|
||||||
// Get Drag&Drop field
|
// Get Drag&Drop field
|
||||||
$dndField = $this->Dragndrop->getDragndrop($quest['id']);
|
$dndField = $this->Dragndrop->getDragndrop($quest['id']);
|
||||||
$dndField['media'] = $this->Media->getSeminaryMediaById($dndField['questmedia_id']);
|
if(!is_null($dndField) && !is_null($dndField['questmedia_id'])) {
|
||||||
|
$dndField['media'] = $this->Media->getSeminaryMediaById($dndField['questmedia_id']);
|
||||||
|
}
|
||||||
|
|
||||||
// Get Drags
|
// Get Drags
|
||||||
$drags = array();
|
$drags = array();
|
||||||
$dragsByIndex = $this->Dragndrop->getDrags($dndField['quest_id']);
|
if(!is_null($dndField))
|
||||||
foreach($dragsByIndex as &$drag) {
|
{
|
||||||
$drag['media'] = $this->Media->getSeminaryMediaById($drag['questmedia_id']);
|
$dragsByIndex = $this->Dragndrop->getDrags($dndField['quest_id']);
|
||||||
$drags[$drag['id']] = $drag;
|
foreach($dragsByIndex as &$drag) {
|
||||||
}
|
$drag['media'] = $this->Media->getSeminaryMediaById($drag['questmedia_id']);
|
||||||
|
$drags[$drag['id']] = $drag;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Get Drops
|
// Get Drops
|
||||||
$drops = $this->Dragndrop->getDrops($dndField['quest_id']);
|
$drops = array();
|
||||||
|
if(!is_null($dndField)) {
|
||||||
|
$this->Dragndrop->getDrops($dndField['quest_id']);
|
||||||
|
}
|
||||||
|
|
||||||
// Get Character answers
|
// Get Character answers
|
||||||
if($this->request->getGetParam('show-answer') == 'true' || !$this->Quests->hasCharacterSolvedQuest($quest['id'], $character['id']) || $this->request->getGetParam('status') == 'solved')
|
if($this->request->getGetParam('show-answer') == 'true' || !$this->Quests->hasCharacterSolvedQuest($quest['id'], $character['id']) || $this->request->getGetParam('status') == 'solved')
|
||||||
|
|
|
||||||
|
|
@ -172,18 +172,19 @@
|
||||||
|
|
||||||
// Get current question
|
// Get current question
|
||||||
$question = $this->Multiplechoice->getQuestionOfQuest($quest['id'], $pos);
|
$question = $this->Multiplechoice->getQuestionOfQuest($quest['id'], $pos);
|
||||||
|
if(!is_null($question))
|
||||||
|
{
|
||||||
|
// Get answers
|
||||||
|
$question['answers'] = $this->Multiplechoice->getAnswersOfQuestion($question['id']);
|
||||||
|
|
||||||
// Get answers
|
// Get previous user answers
|
||||||
$question['answers'] = $this->Multiplechoice->getAnswersOfQuestion($question['id']);
|
if($this->request->getGetParam('show-answer') == 'true' || !$this->Quests->hasCharacterSolvedQuest($quest['id'], $character['id']) || $this->request->getGetParam('status') == 'solved')
|
||||||
|
{
|
||||||
|
foreach($question['answers'] as &$answer) {
|
||||||
// Get previous user answers
|
$answer['useranswer'] = $this->Multiplechoice->getCharacterSubmission($answer['id'], $character['id']);
|
||||||
if($this->request->getGetParam('show-answer') == 'true' || !$this->Quests->hasCharacterSolvedQuest($quest['id'], $character['id']) || $this->request->getGetParam('status') == 'solved')
|
}
|
||||||
{
|
}
|
||||||
foreach($question['answers'] as &$answer) {
|
}
|
||||||
$answer['useranswer'] = $this->Multiplechoice->getCharacterSubmission($answer['id'], $character['id']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Pass data to view
|
// Pass data to view
|
||||||
|
|
|
||||||
|
|
@ -135,11 +135,15 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Show count
|
||||||
|
$showcount = (count($this->request->getGetParams()) > 1);
|
||||||
|
|
||||||
|
|
||||||
// Pass data to view
|
// Pass data to view
|
||||||
$this->set('task', $task);
|
$this->set('task', $task);
|
||||||
$this->set('fields', $fields);
|
$this->set('fields', $fields);
|
||||||
$this->set('count', $correctAnswersCount);
|
$this->set('count', $correctAnswersCount);
|
||||||
|
$this->set('showcount', $showcount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,8 @@
|
||||||
<?php endforeach ?>
|
<?php endforeach ?>
|
||||||
<?=$t->t(mb_substr($task['text'], $posStart, mb_strlen($task['text'], 'UTF-8')-$posStart, 'UTF-8'))?>
|
<?=$t->t(mb_substr($task['text'], $posStart, mb_strlen($task['text'], 'UTF-8')-$posStart, 'UTF-8'))?>
|
||||||
</p>
|
</p>
|
||||||
|
<?php if($showcount) : ?>
|
||||||
<p><?=sprintf(_('You filled %d of %d fields correctly'), $count, count($fields))?>.</p>
|
<p><?=sprintf(_('You filled %d of %d fields correctly'), $count, count($fields))?>.</p>
|
||||||
|
<?php endif ?>
|
||||||
<input type="submit" name="submit" value="<?=_('solve')?>" />
|
<input type="submit" name="submit" value="<?=_('solve')?>" />
|
||||||
</form>
|
</form>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue