questlab/questtypes/textinput/TextinputQuesttypeModel.inc
2014-03-21 14:10:55 +01:00

114 lines
2.4 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?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 TextinputQuesttypeAgent for inserting text.
*
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
*/
class TextinputQuesttypeModel extends \hhu\z\QuesttypeModel
{
/**
* Get textinput-text for a Quest.
*
* @param int $questId ID of Quest
* @return array Textinput-text
*/
public function getTextinputQuest($questId)
{
$data = $this->db->query(
'SELECT text '.
'FROM questtypes_textinput '.
'WHERE quest_id = ?',
'i',
$questId
);
return $data[0];
}
/**
* Get regular expressions for a textinput-text.
*
* @param int $questId ID of Quest
* @return array Regexs
*/
public function getTextinputRegexs($questId)
{
return $this->db->query(
'SELECT id, number, regex '.
'FROM questtypes_textinput_regexs '.
'WHERE questtypes_textinput_quest_id = ? '.
'ORDER BY number ASC',
'i',
$questId
);
}
/**
* Save Characters submitted answer for one textinput field.
*
* @param int $regexId ID of regex
* @param int $characterId ID of Character
* @param string $answer Submitted answer for this field
*/
public function setCharacterSubmission($regexId, $characterId, $answer)
{
$this->db->query(
'INSERT INTO questtypes_textinput_regexs_characters '.
'(questtypes_textinput_regex_id, character_id, value) '.
'VALUES '.
'(?, ?, ?) '.
'ON DUPLICATE KEY UPDATE '.
'value = ?',
'iiss',
$regexId, $characterId, $answer, $answer
);
}
/**
* Get answer of one regex input field submitted by Character.
*
* @param int $regexId ID of regex
* @param int $characterId ID of Character
* @return string Submitted answer for this field or empty string
*/
public function getCharacterSubmission($regexId, $characterId)
{
$data = $this->db->query(
'SELECT value '.
'FROM questtypes_textinput_regexs_characters '.
'WHERE questtypes_textinput_regex_id = ? AND character_id = ? ',
'ii',
$regexId, $characterId
);
if(!empty($data)) {
return $data[0]['value'];
}
return '';
}
}
?>