implement basic QuesttypeAgent ?Drag&Drop?
This commit is contained in:
parent
4f1ec44c77
commit
1c8756d48e
5 changed files with 306 additions and 0 deletions
24
questtypes/dragndrop/DragndropQuesttypeAgent.inc
Normal file
24
questtypes/dragndrop/DragndropQuesttypeAgent.inc
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* The Legend of Z
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
* @copyright 2014 Heinrich-Heine-Universität Düsseldorf
|
||||
* @license http://www.gnu.org/licenses/gpl.html
|
||||
* @link https://bitbucket.org/coderkun/the-legend-of-z
|
||||
*/
|
||||
|
||||
namespace hhu\z\questtypes;
|
||||
|
||||
|
||||
/**
|
||||
* QuesttypeAgent for Drag&Drop.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class DragndropQuesttypeAgent extends \hhu\z\QuesttypeAgent
|
||||
{
|
||||
}
|
||||
|
||||
?>
|
||||
149
questtypes/dragndrop/DragndropQuesttypeController.inc
Normal file
149
questtypes/dragndrop/DragndropQuesttypeController.inc
Normal file
|
|
@ -0,0 +1,149 @@
|
|||
<?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\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)
|
||||
{
|
||||
// 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)
|
||||
{
|
||||
if(!array_key_exists($drop['id'], $answers)) {
|
||||
$this->Dragndrop->setCharacterSubmission($drop['id'], $character['id'], $answers[$drop['id']]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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
|
||||
* @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 Drops
|
||||
$drops = $this->Dragndrop->getDrops($dndField['quest_id']);
|
||||
|
||||
// Match drops with user answers
|
||||
$allSolved = true;
|
||||
foreach($drops as &$drop)
|
||||
{
|
||||
if(!array_key_exists($drop['id'], $answers) || $answer[$drop['id']] != $drop['questtypes_dragndrop_drag_id'])
|
||||
{
|
||||
$allSolved = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Set status
|
||||
return $allSolved;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
public function quest($seminary, $questgroup, $quest, $character)
|
||||
{
|
||||
// Get Drag&Drop field
|
||||
$dndField = $this->Dragndrop->getDragndrop($quest['id']);
|
||||
$dndField['media'] = $this->Media->getMediaById($dndField['questmedia_id']);
|
||||
|
||||
// Get Drops
|
||||
$drops = $this->Dragndrop->getDrops($dndField['quest_id']);
|
||||
|
||||
// Get Drags
|
||||
$drags = $this->Dragndrop->getDrags($dndField['quest_id']);
|
||||
foreach($drags as &$drag) {
|
||||
$drag['media'] = $this->Media->getMediaById($drag['questmedia_id']);
|
||||
}
|
||||
|
||||
// Has Character already solved Quest?
|
||||
$solved = $this->Quests->hasCharacterSolvedQuest($quest['id'], $character['id']);
|
||||
|
||||
|
||||
// Pass data to view
|
||||
$this->set('seminary', $seminary);
|
||||
$this->set('field', $dndField);
|
||||
$this->set('drops', $drops);
|
||||
$this->set('drags', $drags);
|
||||
$this->set('solved', $solved);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Action: submission.
|
||||
* TODO 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)
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
109
questtypes/dragndrop/DragndropQuesttypeModel.inc
Normal file
109
questtypes/dragndrop/DragndropQuesttypeModel.inc
Normal file
|
|
@ -0,0 +1,109 @@
|
|||
<?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\QuesttypeModel
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 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, questtypes_dragndrop_drag_id '.
|
||||
'FROM questtypes_dragndrop_drops '.
|
||||
'WHERE questtypes_dragndrop_id = ?',
|
||||
'i',
|
||||
$dragndropId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Drag-items.
|
||||
*
|
||||
* @param int $dragndropId ID of Drag&Drop-field
|
||||
* @return array Drag-items
|
||||
*/
|
||||
public function getDrags($dragndropId)
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT id, questmedia_id '.
|
||||
'FROM questtypes_dragndrop_drags '.
|
||||
'WHERE questtypes_dragndrop_id = ?',
|
||||
'i',
|
||||
$dragndropId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Save Character’s submitted answer for one Drag&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)
|
||||
{
|
||||
$this->db->query(
|
||||
'INSERT INTO questtypes_dragndrop_drops_characters '.
|
||||
'(questtypes_dragndrop_drops_id, character_id, questtypes_dragndrop_drag_id) '.
|
||||
'VALUES '.
|
||||
'(?, ?, ?) '.
|
||||
'ON DUPLICATE KEY UPDATE '.
|
||||
'questtypes_dragndrop_drag_id = ?',
|
||||
'iiii',
|
||||
$dropId, $characterId, $answer, $answer
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
17
questtypes/dragndrop/html/quest.tpl
Normal file
17
questtypes/dragndrop/html/quest.tpl
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
<form method="post">
|
||||
<div id="dnd" 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) : ?>
|
||||
<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>
|
||||
<input type="hidden" id="dnd_drop<?=$drop['id']?>" name="dnd[<?=$drop['id']?>]" value="" />
|
||||
<?php endforeach ?>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<?php foreach($drags as &$drag) : ?>
|
||||
<img id="drag<?=$drag['id']?>" src="<?=$linker->link(array('media','index',$seminary['url'],$drag['media']['url']))?>" />
|
||||
<?php endforeach ?>
|
||||
</div>
|
||||
|
||||
<br />
|
||||
<input type="submit" name="submit" value="<?=_('solve')?>" <?=($solved) ? 'disabled="disabled"' : '' ?> />
|
||||
</form>
|
||||
7
questtypes/dragndrop/html/submission.tpl
Normal file
7
questtypes/dragndrop/html/submission.tpl
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
<?php foreach($texts as $i => &$text) : ?>
|
||||
<?php if($i > 0) : ?>
|
||||
<span style="background-color:grey"><?=$regexs[$i-1]['answer']?></span>
|
||||
<?php if($regexs[$i-1]['right']) : ?>✓<?php else: ?>✕<?php endif ?>
|
||||
<?php endif ?>
|
||||
<?=\hhu\z\Utils::t($text)?>
|
||||
<?php endforeach ?>
|
||||
Loading…
Add table
Add a link
Reference in a new issue