implement task editing for Stationtype ?keyword?
This commit is contained in:
parent
112c7d0b4f
commit
a1e46ff2aa
|
@ -19,6 +19,12 @@
|
|||
*/
|
||||
class KeywordStationtypeController extends \hhu\z\controllers\StationtypeController
|
||||
{
|
||||
/**
|
||||
* Required components
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $components = array('validation', 'questtypedata');
|
||||
|
||||
|
||||
|
||||
|
@ -27,7 +33,7 @@
|
|||
* Save the answer of a Character group for a Station.
|
||||
*
|
||||
* @param array $seminary Current Seminary data
|
||||
* @param array $questgroup Current Questgroup 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
|
||||
|
@ -43,7 +49,7 @@
|
|||
* 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 $groupsgroup Current Groups group data
|
||||
* @param array $quest Current Quest data
|
||||
* @param array $station Current Station data
|
||||
* @param array $charactergroup Current Character group data
|
||||
|
@ -65,17 +71,81 @@
|
|||
*
|
||||
* 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
|
||||
* @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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
@ -47,6 +47,29 @@
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
|
|
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>
|
Loading…
Reference in a new issue