add Stationtype ?keyword?
This commit is contained in:
parent
08f83280f7
commit
cb2865c1d5
5 changed files with 238 additions and 0 deletions
|
@ -1933,6 +1933,44 @@ CREATE TABLE `stationtypes` (
|
|||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
--
|
||||
-- Table structure for table `stationtypes_keyword`
|
||||
--
|
||||
|
||||
DROP TABLE IF EXISTS `stationtypes_keyword`;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!40101 SET character_set_client = utf8 */;
|
||||
CREATE TABLE `stationtypes_keyword` (
|
||||
`station_id` int(11) NOT NULL,
|
||||
`created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
`created_user_id` int(11) NOT NULL,
|
||||
`keyword_regex` varchar(256) COLLATE utf8mb4_unicode_ci NOT NULL,
|
||||
PRIMARY KEY (`station_id`),
|
||||
KEY `created_user_id` (`created_user_id`),
|
||||
CONSTRAINT `stationtypes_keyword_ibfk_1` FOREIGN KEY (`station_id`) REFERENCES `charactergroupsqueststations` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `stationtypes_keyword_ibfk_2` FOREIGN KEY (`created_user_id`) REFERENCES `users` (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
--
|
||||
-- Table structure for table `stationtypes_keyword_charactergroups`
|
||||
--
|
||||
|
||||
DROP TABLE IF EXISTS `stationtypes_keyword_charactergroups`;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!40101 SET character_set_client = utf8 */;
|
||||
CREATE TABLE `stationtypes_keyword_charactergroups` (
|
||||
`station_id` int(11) NOT NULL,
|
||||
`charactergroup_id` int(11) NOT NULL,
|
||||
`created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
`keyword` varchar(32) COLLATE utf8mb4_unicode_ci NOT NULL,
|
||||
PRIMARY KEY (`station_id`,`charactergroup_id`),
|
||||
KEY `charactergroup_id` (`charactergroup_id`),
|
||||
CONSTRAINT `stationtypes_keyword_charactergroups_ibfk_1` FOREIGN KEY (`station_id`) REFERENCES `charactergroupsqueststations` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `stationtypes_keyword_charactergroups_ibfk_2` FOREIGN KEY (`charactergroup_id`) REFERENCES `charactergroups` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
--
|
||||
-- Table structure for table `userroles`
|
||||
--
|
||||
|
|
24
stationtypes/keyword/KeywordStationtypeAgent.inc
Normal file
24
stationtypes/keyword/KeywordStationtypeAgent.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\stationtypes;
|
||||
|
||||
|
||||
/**
|
||||
* StationtypeAgent for keyword access.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class KeywordStationtypeAgent extends \hhu\z\agents\StationtypeAgent
|
||||
{
|
||||
}
|
||||
|
||||
?>
|
98
stationtypes/keyword/KeywordStationtypeController.inc
Normal file
98
stationtypes/keyword/KeywordStationtypeController.inc
Normal file
|
@ -0,0 +1,98 @@
|
|||
<?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\stationtypes;
|
||||
|
||||
|
||||
/**
|
||||
* Controller of the StationtypeAgent for keyword access.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class KeywordStationtypeController extends \hhu\z\controllers\StationtypeController
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Save the answer of a Character group for a Station.
|
||||
*
|
||||
* @param array $seminary Current Seminary data
|
||||
* @param array $questgroup Current Questgroup data
|
||||
* @param array $quest Current Quest data
|
||||
* @param array $station Current Station data
|
||||
* @param array $charactergroup Current Character group data
|
||||
* @param array $answer Character group answer for the Station
|
||||
*/
|
||||
public function saveAnswer($seminary, $groupsgroup, $quest, $station, $charactergroup, $answer)
|
||||
{
|
||||
$this->Keyword->setCharactergroupSubmission($station['id'], $charactergroup['id'], $answer);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if answer of a Character group for a Station matches the correct one.
|
||||
*
|
||||
* @param array $seminary Current Seminary data
|
||||
* @param array $questgroup Current Questgroup data
|
||||
* @param array $quest Current Quest data
|
||||
* @param array $station Current Station data
|
||||
* @param array $charactergroup Current Character group data
|
||||
* @param array $answer Character group answer for the Station
|
||||
* @return boolean True/false for a right/wrong answer
|
||||
*/
|
||||
public function matchAnswer($seminary, $groupsgroup, $quest, $station, $charactergroup, $answer)
|
||||
{
|
||||
// Get right answers
|
||||
$task = $this->Keyword->getKeywordTask($station['id']);
|
||||
|
||||
// Match regex with user answers
|
||||
return $this->isMatching($task['keyword_regex'], $answer);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Action: quest.
|
||||
*
|
||||
* Show the task of a Station.
|
||||
*
|
||||
* @param array $seminary Current Seminary data
|
||||
* @param array $questgroup Current Questgroup data
|
||||
* @param array $quest Current Quest data
|
||||
* @param array $station Current Station data
|
||||
* @param array $charactergroup Current Character group data
|
||||
*/
|
||||
public function quest($seminary, $groupsgroup, $quest, $station, $charactergroup)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Check if an Character answer matches a Regex.
|
||||
*
|
||||
* @param string $regex Regex to match against
|
||||
* @param string $answer Character answer to match
|
||||
* @return boolean Whether answer matches Regex or not
|
||||
*/
|
||||
private function isMatching($regex, $answer)
|
||||
{
|
||||
$score = preg_match($regex, trim($answer));
|
||||
|
||||
|
||||
return ($score !== false && $score > 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
74
stationtypes/keyword/KeywordStationtypeModel.inc
Normal file
74
stationtypes/keyword/KeywordStationtypeModel.inc
Normal file
|
@ -0,0 +1,74 @@
|
|||
<?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\stationtypes;
|
||||
|
||||
|
||||
/**
|
||||
* Model of the StationtypeAgent for keyword access.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class KeywordStationtypeModel extends \hhu\z\models\StationtypeModel
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get the task of a keyword Station
|
||||
*
|
||||
* @param int $stationId ID of Station
|
||||
* @return array Task data
|
||||
*/
|
||||
public function getKeywordTask($stationId)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT keyword_regex '.
|
||||
'FROM stationtypes_keyword '.
|
||||
'WHERE station_id = ?',
|
||||
'i',
|
||||
$stationId
|
||||
);
|
||||
if(!empty($data)) {
|
||||
return $data[0];
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Save Character group’s submitted answer for a station.
|
||||
*
|
||||
* @param int $stationId ID of Station
|
||||
* @param int $charactergroupId ID of Character group
|
||||
* @param string $answer Submitted answer
|
||||
*/
|
||||
public function setCharactergroupSubmission($stationId, $charactergroupId, $answer)
|
||||
{
|
||||
$this->db->query(
|
||||
'INSERT INTO stationtypes_keyword_charactergroups '.
|
||||
'(station_id, charactergroup_id, keyword) '.
|
||||
'VALUES '.
|
||||
'(?, ?, ?) '.
|
||||
'ON DUPLICATE KEY UPDATE '.
|
||||
'keyword = ?',
|
||||
'iiss',
|
||||
$stationId, $charactergroupId, $answer, $answer
|
||||
);
|
||||
var_dump("saved");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
4
stationtypes/keyword/html/quest.tpl
Normal file
4
stationtypes/keyword/html/quest.tpl
Normal file
|
@ -0,0 +1,4 @@
|
|||
<form method="post" class="keyword">
|
||||
<input type="text" id="keyword" name="answer" />
|
||||
<input type="submit" name="submit" value="<?=_('solve')?>" />
|
||||
</form>
|
Loading…
Add table
Reference in a new issue