implement rudimental form for creating Quests and Questgroups
This commit is contained in:
parent
ce44a3c3b8
commit
ed29657115
7 changed files with 271 additions and 7 deletions
|
|
@ -31,7 +31,8 @@
|
|||
* @var array
|
||||
*/
|
||||
public $permissions = array(
|
||||
'questgroup' => array('admin', 'moderator', 'user')
|
||||
'questgroup' => array('admin', 'moderator', 'user'),
|
||||
'create' => array('admin', 'moderator', 'user')
|
||||
);
|
||||
/**
|
||||
* User seminary permissions
|
||||
|
|
@ -39,7 +40,8 @@
|
|||
* @var array
|
||||
*/
|
||||
public $seminaryPermissions = array(
|
||||
'questgroup' => array('admin', 'moderator', 'user')
|
||||
'questgroup' => array('admin', 'moderator', 'user'),
|
||||
'create' => array('admin', 'moderator')
|
||||
);
|
||||
|
||||
|
||||
|
|
@ -174,6 +176,45 @@
|
|||
$this->set('quests', $quests);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Action: create.
|
||||
*
|
||||
* Create a new Questgroup.
|
||||
*
|
||||
* @param string $seminaryUrl URL-Title of a Seminary
|
||||
*/
|
||||
public function create($seminaryUrl)
|
||||
{
|
||||
// Get seminary
|
||||
$seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
|
||||
|
||||
// Create Questgroup
|
||||
$validation = true;
|
||||
if($this->request->getRequestMethod() == 'POST' && !is_null($this->request->getPostParam('create')))
|
||||
{
|
||||
// TODO Validation
|
||||
$title = $this->request->getPostParam('title');
|
||||
|
||||
// Create new Questgroup
|
||||
if($validation === true)
|
||||
{
|
||||
$questgroupId = $this->Questgroups->createQuestgroup(
|
||||
$this->Auth->getUserId(),
|
||||
$seminary['id'],
|
||||
$title
|
||||
);
|
||||
|
||||
// Redirect
|
||||
$this->redirect($this->linker->link(array('seminaries', 'seminary', $seminary['url'])));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Pass data to view
|
||||
$this->set('seminary', $seminary);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -34,7 +34,8 @@
|
|||
'index' => array('admin', 'moderator', 'user'),
|
||||
'quest' => array('admin', 'moderator', 'user'),
|
||||
'submissions' => array('admin', 'moderator', 'user'),
|
||||
'submission' => array('admin', 'moderator', 'user')
|
||||
'submission' => array('admin', 'moderator', 'user'),
|
||||
'create' => array('admin', 'moderator', 'user')
|
||||
);
|
||||
/**
|
||||
* User seminary permissions
|
||||
|
|
@ -42,10 +43,11 @@
|
|||
* @var array
|
||||
*/
|
||||
public $seminaryPermissions = array(
|
||||
'index' => array('admin', 'moderator', 'user'),
|
||||
'quest' => array('admin', 'moderator', 'user'),
|
||||
'submissions' => array('admin', 'moderator'),
|
||||
'submission' => array('admin', 'moderator')
|
||||
'index' => array('admin', 'moderator', 'user'),
|
||||
'quest' => array('admin', 'moderator', 'user'),
|
||||
'submissions' => array('admin', 'moderator'),
|
||||
'submission' => array('admin', 'moderator'),
|
||||
'create' => array('admin', 'moderator')
|
||||
);
|
||||
|
||||
|
||||
|
|
@ -418,6 +420,86 @@
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Action: create.
|
||||
*
|
||||
* Create a new Quest.
|
||||
*
|
||||
* @param string $seminaryUrl URL-Title of a Seminary
|
||||
*/
|
||||
public function create($seminaryUrl)
|
||||
{
|
||||
// Get seminary
|
||||
$seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
|
||||
|
||||
// Quest groups
|
||||
$questgroups = $this->Questgroups->getQuestgroupsForSeminary($seminary['id']);
|
||||
|
||||
// Quest types
|
||||
$questtypes = $this->Questtypes->getQuesttypes();
|
||||
|
||||
// Create Quest
|
||||
$validation = true;
|
||||
if($this->request->getRequestMethod() == 'POST' && !is_null($this->request->getPostParam('create')))
|
||||
{
|
||||
// TODO Validation
|
||||
$name = $this->request->getPostParam('name');
|
||||
$xps = $this->request->getPostParam('xps');
|
||||
$wrongtext = $this->request->getPostParam('wrongtext');
|
||||
$task = $this->request->getPostParam('task');
|
||||
|
||||
// Validate Questgroup
|
||||
$questgroupIndex = null;
|
||||
foreach($questgroups as $index => &$questgroup)
|
||||
{
|
||||
$questgroup['selected'] = ($questgroup['url'] == $this->request->getPostParam('questgroup'));
|
||||
if($questgroup['selected']) {
|
||||
$questgroupIndex = $index;
|
||||
}
|
||||
}
|
||||
if(is_null($questgroupIndex)) {
|
||||
throw new \nre\exceptions\ParamsNotValidException($questgroup);
|
||||
}
|
||||
|
||||
// Validate Questtype
|
||||
$questtypeIndex = null;
|
||||
foreach($questtypes as $index => &$questtype)
|
||||
{
|
||||
$questtype['selected'] = ($questtype['url'] == $this->request->getPostParam('questtype'));
|
||||
if($questtype['selected']) {
|
||||
$questtypeIndex = $index;
|
||||
}
|
||||
}
|
||||
if(is_null($questtypeIndex)) {
|
||||
throw new \nre\exceptions\ParamsNotValidException($questtype);
|
||||
}
|
||||
|
||||
// Create new Quest
|
||||
if($validation === true)
|
||||
{
|
||||
$questId = $this->Quests->createQuest(
|
||||
$this->Auth->getUserId(),
|
||||
$name,
|
||||
$questgroups[$questgroupIndex]['id'],
|
||||
$questtypes[$questtypeIndex]['id'],
|
||||
$xps,
|
||||
$wrongtext,
|
||||
$task
|
||||
);
|
||||
|
||||
// Redirect
|
||||
$this->redirect($this->linker->link(array('quests', 'index', $seminary['url'])));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Pass data to view
|
||||
$this->set('seminary', $seminary);
|
||||
$this->set('questgroups', $questgroups);
|
||||
$this->set('questtypes', $questtypes);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -89,6 +89,25 @@
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get all Questgroups for a Seminary.
|
||||
*
|
||||
* @param int $seminaryId ID of Seminary
|
||||
* @return array List of Questgroups
|
||||
*/
|
||||
public function getQuestgroupsForSeminary($seminaryId)
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT id, title, url '.
|
||||
'FROM questgroups '.
|
||||
'WHERE seminary_id = ? '.
|
||||
'ORDER BY title ASC',
|
||||
'i',
|
||||
$seminaryId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a Questgroup by its ID.
|
||||
*
|
||||
|
|
@ -503,6 +522,33 @@
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a new Questgroup.
|
||||
*
|
||||
* @param int $userId User-ID that creates the new character
|
||||
* @param int $seminaryId ID of Seminary
|
||||
* @param string $title Title for new Questgroup
|
||||
* @return int ID of new Questgroup
|
||||
*/
|
||||
public function createQuestgroup($userId, $seminaryId, $title)
|
||||
{
|
||||
$this->db->query(
|
||||
'INSERT INTO questgroups '.
|
||||
'(created_user_id, seminary_id, title, url) '.
|
||||
'VALUES '.
|
||||
'(?, ?, ?, ?)',
|
||||
'iiss',
|
||||
$userId,
|
||||
$seminaryId,
|
||||
$title,
|
||||
\nre\core\Linker::createLinkParam($title)
|
||||
);
|
||||
|
||||
|
||||
return $this->db->getInsertId();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -405,6 +405,36 @@
|
|||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a new Quest.
|
||||
*
|
||||
* @param int $userId User-ID that creates the new character
|
||||
* @param string $name Name for new Quest
|
||||
* @param int $questgroupId ID of Questgroup
|
||||
* @param int $questtypeId ID of Questtype
|
||||
* @param int $xps XPs for new Quest
|
||||
* @param string $wrongtext Wrongtext for new Quest
|
||||
* @param string $task Task for new Quest
|
||||
* @return int ID of new Quest
|
||||
*/
|
||||
public function createQuest($userId, $name, $questgroupId, $questtypeId, $xps, $wrongtext, $task)
|
||||
{
|
||||
$this->db->query(
|
||||
'INSERT INTO quests '.
|
||||
'(created_user_id, questgroup_id, questtype_id, title, url, xps, wrong_text, task) '.
|
||||
'VALUES '.
|
||||
'(?, ?, ?, ?, ?, ?, ?, ?)',
|
||||
'iiississ',
|
||||
$userId, $questgroupId, $questtypeId,
|
||||
$name, \nre\core\Linker::createLinkParam($name),
|
||||
$xps, $wrongtext, $task
|
||||
);
|
||||
|
||||
|
||||
return $this->db->getInsertId();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -34,6 +34,21 @@
|
|||
|
||||
|
||||
|
||||
/**
|
||||
* Get all registered Questtypes.
|
||||
*
|
||||
* @return array List of registered Questtypes
|
||||
*/
|
||||
public function getQuesttypes()
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT id, title, url, classname '.
|
||||
'FROM questtypes '.
|
||||
'ORDER BY title ASC'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a Questtype by its ID
|
||||
*
|
||||
|
|
|
|||
16
views/html/questgroups/create.tpl
Normal file
16
views/html/questgroups/create.tpl
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
<?php if(!is_null($seminary['seminarymedia_id'])) : ?>
|
||||
<div class="moodpic">
|
||||
<img src="<?=$linker->link(array('media','seminaryheader',$seminary['url']))?>" />
|
||||
</div>
|
||||
<?php endif ?>
|
||||
<h1><a href="<?=$linker->link(array('seminaries',$seminary['url']))?>"><?=$seminary['title']?></a></h1>
|
||||
<h2><?=_('Questgroups')?></h2>
|
||||
<h3><?=_('Create')?></h3>
|
||||
|
||||
<form method="post">
|
||||
<fieldset>
|
||||
<label for="title"><?=_('Title')?>:</label>
|
||||
<input type="text" name="title" value="" placeholder="<?=_('Title')?>" /><br />
|
||||
</fieldset>
|
||||
<input type="submit" name="create" value="<?=_('Create')?>" />
|
||||
</form>
|
||||
34
views/html/quests/create.tpl
Normal file
34
views/html/quests/create.tpl
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
<?php if(!is_null($seminary['seminarymedia_id'])) : ?>
|
||||
<div class="moodpic">
|
||||
<img src="<?=$linker->link(array('media','seminaryheader',$seminary['url']))?>" />
|
||||
</div>
|
||||
<?php endif ?>
|
||||
<h1><a href="<?=$linker->link(array('seminaries',$seminary['url']))?>"><?=$seminary['title']?></a></h1>
|
||||
<h2><a href="<?=$linker->link(array('index',$seminary['url']),1)?>"><?=_('Quests')?></a></h2>
|
||||
<h3><?=_('Create')?></h3>
|
||||
|
||||
<form method="post">
|
||||
<fieldset>
|
||||
<label for="name"><?=_('Name')?>:</label>
|
||||
<input type="text" name="name" value="" placeholder="<?=_('Name')?>" /><br />
|
||||
<label for="questgroup"><?=_('Questgroup')?>:</label>
|
||||
<select name="questgroup">
|
||||
<?php foreach($questgroups as &$questgroup) : ?>
|
||||
<option value="<?=$questgroup['url']?>"><?=$questgroup['title']?></option>
|
||||
<?php endforeach ?>
|
||||
</select><br />
|
||||
<label for="questtype"><?=('Questtype')?>:</label>
|
||||
<select name="questtype">
|
||||
<?php foreach($questtypes as &$questtype) : ?>
|
||||
<option value="<?=$questtype['url']?>"><?=$questtype['title']?></option>
|
||||
<?php endforeach ?>
|
||||
</select><br />
|
||||
<label for="name">XPs:</label>
|
||||
<input type="number" name="xps" value="" placeholder="<?=_('XPs')?>" /><br />
|
||||
<label for="wrongtext"><?=('Wrong text')?>:</label><br />
|
||||
<textarea name="wrongtext" placeholder="<?=_('Wrong text')?>"></textarea><br />
|
||||
<label for="task"><?=_('Task')?>:</label><br />
|
||||
<textarea name="task" placeholder="<?=('Task')?>"></textarea><br />
|
||||
</fieldset>
|
||||
<input type="submit" name="create" value="<?=_('Create')?>" />
|
||||
</form>
|
||||
Loading…
Add table
Add a link
Reference in a new issue