only shows Character answer on request for Questtype ?Drag&Drop?

This commit is contained in:
coderkun 2014-04-04 01:09:38 +02:00
commit 8c6a68509f
3 changed files with 20 additions and 15 deletions

View file

@ -123,14 +123,18 @@
// Get Drops // Get Drops
$drops = $this->Dragndrop->getDrops($dndField['quest_id']); $drops = $this->Dragndrop->getDrops($dndField['quest_id']);
// Get Character answers
if($this->request->getGetParam('show-answer') == 'true')
{
foreach($drops as &$drop) foreach($drops as &$drop)
{ {
// Get saved user answer $drop['answer'] = $this->Dragndrop->getCharacterSubmission($drop['id'], $character['id']);
$drop['useranswer'] = $this->Dragndrop->getCharacterSubmission($drop['id'], $character['id']); if(!is_null($drop['answer']))
if(!is_null($drop['useranswer']))
{ {
$drop['useranswer'] = $drags[$drop['useranswer']]; $drop['answer'] = $drags[$drop['answer']];
unset($drags[$drop['useranswer']['id']]); unset($drags[$drop['answer']['id']]);
}
} }
} }
@ -169,14 +173,15 @@
// Get Drops // Get Drops
$drops = $this->Dragndrop->getDrops($dndField['quest_id']); $drops = $this->Dragndrop->getDrops($dndField['quest_id']);
// Get Character answers
foreach($drops as &$drop) foreach($drops as &$drop)
{ {
// Get saved user answer $drop['answer'] = $this->Dragndrop->getCharacterSubmission($drop['id'], $character['id']);
$drop['useranswer'] = $this->Dragndrop->getCharacterSubmission($drop['id'], $character['id']); if(!is_null($drop['answer']))
if(!is_null($drop['useranswer']))
{ {
$drop['useranswer'] = $drags[$drop['useranswer']]; $drop['answer'] = $drags[$drop['answer']];
unset($drags[$drop['useranswer']['id']]); unset($drags[$drop['answer']['id']]);
} }
} }

View file

@ -1,8 +1,8 @@
<form method="post"> <form method="post">
<div id="dropZone" style="width:<?=$field['width']?>px; height:<?=$field['height']?>px; background-image:url('<?=$linker->link(array('media','index',$seminary['url'],$field['media']['url']))?>')"> <div id="dropZone" style="width:<?=$field['width']?>px; height:<?=$field['height']?>px; background-image:url('<?=$linker->link(array('media','index',$seminary['url'],$field['media']['url']))?>')">
<?php foreach($drops as &$drop) : ?> <?php foreach($drops as &$drop) : ?>
<div id="drop<?=$drop['id']?>" ondragenter="onDragEnter(event)" ondragover="onDragOver(event)" ondragleave="onDragLeave(event)" ondrop="onDrop(event)" style="position:absolute; width:<?=$drop['width']?>px; height:<?=$drop['height']?>px; margin:<?=$drop['top']?>px 0 0 <?=$drop['left']?>px;"><?php if(!is_null($drop['useranswer'])) : ?><img id="drag<?=$drop['useranswer']['id']?>" draggable="true" ondragstart="onDragStart(event)" ondragend="onDragEnd(event)" src="<?=$linker->link(array('media','index',$seminary['url'],$drop['useranswer']['media']['url']))?>" /><?php endif ?></div> <div id="drop<?=$drop['id']?>" ondragenter="onDragEnter(event)" ondragover="onDragOver(event)" ondragleave="onDragLeave(event)" ondrop="onDrop(event)" style="position:absolute; width:<?=$drop['width']?>px; height:<?=$drop['height']?>px; margin:<?=$drop['top']?>px 0 0 <?=$drop['left']?>px;"><?php if(array_key_exists('answer', $drop) && !is_null($drop['answer'])) : ?><img id="drag<?=$drop['answer']['id']?>" draggable="true" ondragstart="onDragStart(event)" ondragend="onDragEnd(event)" src="<?=$linker->link(array('media','index',$seminary['url'],$drop['answer']['media']['url']))?>" /><?php endif ?></div>
<input type="hidden" id="dnd_drop<?=$drop['id']?>" name="answers[<?=$drop['id']?>]" value="<?=(!is_null($drop['useranswer'])) ? 'drag'.$drop['useranswer']['id'] : null ?>" /> <input type="hidden" id="dnd_drop<?=$drop['id']?>" name="answers[<?=$drop['id']?>]" value="<?=(!is_null($drop['answer'])) ? 'drag'.$drop['answer']['id'] : null ?>" />
<?php endforeach ?> <?php endforeach ?>
</div> </div>

View file

@ -1,8 +1,8 @@
<div style="width:<?=$field['width']?>px; height:<?=$field['height']?>px; background-image:url('<?=$linker->link(array('media','index',$seminary['url'],$field['media']['url']))?>')"> <div style="width:<?=$field['width']?>px; height:<?=$field['height']?>px; background-image:url('<?=$linker->link(array('media','index',$seminary['url'],$field['media']['url']))?>')">
<?php foreach($drops as &$drop) : ?> <?php foreach($drops as &$drop) : ?>
<div id="drop<?=$drop['id']?>" style="position:absolute; width:<?=$drop['width']?>px; height:<?=$drop['height']?>px; margin:<?=$drop['top']?>px 0 0 <?=$drop['left']?>px;"> <div id="drop<?=$drop['id']?>" style="position:absolute; width:<?=$drop['width']?>px; height:<?=$drop['height']?>px; margin:<?=$drop['top']?>px 0 0 <?=$drop['left']?>px;">
<?php if(!is_null($drop['useranswer'])) : ?> <?php if(!is_null($drop['answer'])) : ?>
<img id="drag<?=$drop['useranswer']['id']?>" src="<?=$linker->link(array('media','index',$seminary['url'],$drop['useranswer']['media']['url']))?>" /> <img id="drag<?=$drop['answer']['id']?>" src="<?=$linker->link(array('media','index',$seminary['url'],$drop['answer']['media']['url']))?>" />
<?php endif ?> <?php endif ?>
</div> </div>
<?php endforeach ?> <?php endforeach ?>