implement copying of Stations for Seminary copy feature
This commit is contained in:
commit
40a233fa7d
4342 changed files with 1215466 additions and 0 deletions
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
|
||||
{
|
||||
}
|
||||
|
||||
?>
|
||||
168
stationtypes/keyword/KeywordStationtypeController.inc
Normal file
168
stationtypes/keyword/KeywordStationtypeController.inc
Normal file
|
|
@ -0,0 +1,168 @@
|
|||
<?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
|
||||
{
|
||||
/**
|
||||
* Required components
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $components = array('validation', 'questtypedata');
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Save the answer of a Character group for a Station.
|
||||
*
|
||||
* @param array $seminary Current Seminary data
|
||||
* @param array $groupsgroup Current Groups group 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 $groupsgroup Current Groups group 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 $groupsgroup Current Groups group 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)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Action: edittask.
|
||||
*
|
||||
* Edit the task of a Station.
|
||||
*
|
||||
* @param array $seminary Current Seminary data
|
||||
* @param array $groupsgroup Current Groups group data
|
||||
* @param array $quest Current Quest data
|
||||
* @param array $station Current Station data
|
||||
*/
|
||||
public function edittask($seminary, $groupsgroup, $quest, $station)
|
||||
{
|
||||
// Get right answers
|
||||
$task = $this->Keyword->getKeywordTask($station['id']);
|
||||
|
||||
// Values
|
||||
$keyword = $task['keyword_regex'];
|
||||
$validations = array();
|
||||
|
||||
// Save data
|
||||
if($this->request->getRequestMethod() == 'POST' && !is_null($this->request->getPostParam('save')))
|
||||
{
|
||||
// Get params and validate them
|
||||
$keyword = $this->request->getPostParam('keyword');
|
||||
|
||||
// Validate regex
|
||||
$keywordValidation = @preg_match($keyword, '') !== false;
|
||||
if($keywordValidation !== true) {
|
||||
$validations = $this->Validation->addValidationResult($validations, 'keyword', 'regex', $keywordValidation);
|
||||
}
|
||||
|
||||
// Save and redirect
|
||||
if(empty($validations))
|
||||
{
|
||||
// Save keyword
|
||||
$this->Keyword->setKeywordForStation(
|
||||
$this->Auth->getUserId(),
|
||||
$station['id'],
|
||||
$keyword
|
||||
);
|
||||
|
||||
// Redirect
|
||||
$this->redirect(
|
||||
$this->linker->link(
|
||||
array(
|
||||
'station',
|
||||
$seminary['url'],
|
||||
$groupsgroup['url'],
|
||||
$quest['url'],
|
||||
$station['url']
|
||||
),
|
||||
1
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Pass data to view
|
||||
$this->set('keyword', $keyword);
|
||||
$this->set('validations', $validations);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
121
stationtypes/keyword/KeywordStationtypeModel.inc
Normal file
121
stationtypes/keyword/KeywordStationtypeModel.inc
Normal file
|
|
@ -0,0 +1,121 @@
|
|||
<?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
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Copy a Station.
|
||||
*
|
||||
* @param int $userId ID of creating user
|
||||
* @param int $sourceStationId ID of Station to copy from
|
||||
* @param int $targetStationId ID of Station to copy to
|
||||
* @param int $seminaryMediaIds Mapping of SeminaryMedia-IDs from source Seminary to targetSeminary
|
||||
*/
|
||||
public function copyStation($userId, $sourceStationId, $targetStationId, $seminaryMediaIds)
|
||||
{
|
||||
// Copy keyword
|
||||
$this->db->query(
|
||||
'INSERT INTO stationtypes_keyword '.
|
||||
'(station_id, created_user_id, keyword_regex) '.
|
||||
'SELECT ?, ?, keyword_regex '.
|
||||
'FROM stationtypes_keyword '.
|
||||
'WHERE station_id = ?',
|
||||
'iii',
|
||||
$targetStationId, $userId,
|
||||
$sourceStationId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the keyword (regex) for a Station.
|
||||
*
|
||||
* @param int $userId ID of creating user
|
||||
* @param int $stationId ID ot Station to set keyword for
|
||||
* @param string $keyword Keyword (regex)
|
||||
*/
|
||||
public function setKeywordForStation($userId, $stationId, $keyword)
|
||||
{
|
||||
$this->db->query(
|
||||
'INSERT INTO stationtypes_keyword '.
|
||||
'(station_id, created_user_id, keyword_regex) '.
|
||||
'VALUES '.
|
||||
'(?, ?, ?) '.
|
||||
'ON DUPLICATE KEY UPDATE '.
|
||||
'created_user_id = ?, keyword_regex = ?',
|
||||
'iisis',
|
||||
$stationId, $userId, $keyword,
|
||||
$userId, $keyword
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
29
stationtypes/keyword/html/edittask.tpl
Normal file
29
stationtypes/keyword/html/edittask.tpl
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
<?php if(!empty($validations)) : ?>
|
||||
<ul>
|
||||
<?php foreach($validations as $field => &$settings) : ?>
|
||||
<li>
|
||||
<ul>
|
||||
<?php foreach($settings as $setting => $value) : ?>
|
||||
<li>
|
||||
<?php
|
||||
switch($setting) {
|
||||
case 'regex': echo _('Regex invalid');
|
||||
break;
|
||||
default: echo _('Regex invalid');
|
||||
}
|
||||
?>
|
||||
</li>
|
||||
<?php endforeach ?>
|
||||
</ul>
|
||||
</li>
|
||||
<?php endforeach ?>
|
||||
</ul>
|
||||
<?php endif ?>
|
||||
|
||||
<form method="post">
|
||||
<fieldset>
|
||||
<label for="keyword"><?=_('Keyword')?>:</label>
|
||||
<input type="text" name="keyword" value="<?=$keyword?>" placeholder="/regex/i" />
|
||||
</fieldset>
|
||||
<input type="submit" name="save" value="<?=_('save')?>" />
|
||||
</form>
|
||||
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
Add a link
Reference in a new issue