implement CRUD for Character groups Quests (Issue #30)
This commit is contained in:
parent
c4449c1835
commit
53c1002ab2
10 changed files with 754 additions and 41 deletions
|
|
@ -25,7 +25,13 @@
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public $models = array('seminaries', 'charactergroups', 'charactergroupsquests', 'media');
|
||||
public $models = array('seminaries', 'charactergroups', 'charactergroupsquests', 'media', 'questgroups');
|
||||
/**
|
||||
* Required components
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $components = array('validation');
|
||||
/**
|
||||
* User permissions
|
||||
*
|
||||
|
|
@ -68,6 +74,10 @@
|
|||
// Get Character groups-group Quests
|
||||
$quest = $this->Charactergroupsquests->getQuestByUrl($groupsgroup['id'], $questUrl);
|
||||
|
||||
// Get Questgroup
|
||||
$questgroup = $this->Questgroups->getQuestgroupById($quest['questgroups_id']);
|
||||
$questgroup['entered'] = $this->Questgroups->hasCharacterEnteredQuestgroup($questgroup['id'], self::$character['id']);
|
||||
|
||||
// Get Character groups-groups
|
||||
$groups = $this->Charactergroupsquests->getGroupsForQuest($quest['id']);
|
||||
|
||||
|
|
@ -82,10 +92,269 @@
|
|||
$this->set('seminary', $seminary);
|
||||
$this->set('groupsgroup', $groupsgroup);
|
||||
$this->set('quest', $quest);
|
||||
$this->set('questgroup', $questgroup);
|
||||
$this->set('groups', $groups);
|
||||
$this->set('media', $questmedia);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Action: create.
|
||||
*
|
||||
* Create a new Character groups Quest for a Character
|
||||
* groups-group of a Seminary.
|
||||
*
|
||||
* @param string $seminaryUrl URL-Title of a Seminary
|
||||
* @param string $groupsgroupUrl URL-Title of a Character groups-group
|
||||
*/
|
||||
public function create($seminaryUrl, $groupsgroupUrl)
|
||||
{
|
||||
// Get seminary
|
||||
$seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
|
||||
|
||||
// Get Character groups-group
|
||||
$groupsgroup = $this->Charactergroups->getGroupsgroupByUrl($seminary['id'], $groupsgroupUrl);
|
||||
|
||||
// Get Questgroups
|
||||
$questgroups = $this->Questgroups->getQuestgroupsForSeminary($seminary['id']);
|
||||
|
||||
// Values
|
||||
$title = '';
|
||||
$xps = 0;
|
||||
$description = '';
|
||||
$rules = '';
|
||||
$wonText = '';
|
||||
$lostText = '';
|
||||
$fields = array('title', 'xps');
|
||||
$validation = array();
|
||||
|
||||
// Create a new Character groups Quest
|
||||
if($this->request->getRequestMethod() == 'POST' && !is_null($this->request->getPostParam('create')))
|
||||
{
|
||||
// Get params and validate them
|
||||
$validation = $this->Validation->validateParams($this->request->getPostParams(), $fields);
|
||||
$title = $this->request->getPostParam('title');
|
||||
if($this->Charactergroupsquests->characterGroupsQuestTitleExists($title)) {
|
||||
$validation = $this->Validation->addValidationResult($validation, 'title', 'exist', true);
|
||||
}
|
||||
$xps = $this->request->getPostParam('xps');
|
||||
$description = $this->request->getPostParam('description');
|
||||
$rules = $this->request->getPostParam('rules');
|
||||
$wonText = $this->request->getPostParam('wonText');
|
||||
$lostText = $this->request->getPostParam('lostText');
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
// Create groups Quest
|
||||
if($validation === true)
|
||||
{
|
||||
$questId = $this->Charactergroupsquests->createQuest(
|
||||
$this->Auth->getUserId(),
|
||||
$groupsgroup['id'],
|
||||
$questgroups[$questgroupIndex]['id'],
|
||||
$title,
|
||||
$description,
|
||||
$xps,
|
||||
$rules,
|
||||
$wonText,
|
||||
$lostText
|
||||
);
|
||||
|
||||
// Redirect to Quest page
|
||||
$quest = $this->Charactergroupsquests->getQuestById($questId);
|
||||
$this->redirect($this->linker->link(array('quest', $seminary['url'], $groupsgroup['url'], $quest['url']), 1));
|
||||
}
|
||||
}
|
||||
|
||||
// Get validation settings
|
||||
$validationSettings = array();
|
||||
foreach($fields as &$field) {
|
||||
$validationSettings[$field] = \nre\configs\AppConfig::$validation[$field];
|
||||
}
|
||||
|
||||
|
||||
// Pass data to view
|
||||
$this->set('seminary', $seminary);
|
||||
$this->set('groupsgroup', $groupsgroup);
|
||||
$this->set('questgroups', $questgroups);
|
||||
$this->set('title', $title);
|
||||
$this->set('xps', $xps);
|
||||
$this->set('description', $description);
|
||||
$this->set('rules', $rules);
|
||||
$this->set('wonText', $wonText);
|
||||
$this->set('lostText', $lostText);
|
||||
$this->set('validation', $validation);
|
||||
$this->set('validationSettings', $validationSettings);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Action: edit.
|
||||
*
|
||||
* Edit a Character groups Quest of a Character groups-group
|
||||
* of a Seminary.
|
||||
*
|
||||
* @throws IdNotFoundException
|
||||
* @param string $seminaryUrl URL-Title of a Seminary
|
||||
* @param string $groupsgroupUrl URL-Title of a Character groups-group
|
||||
* @param string $questUrl URL-Title of a Character groups Quest
|
||||
*/
|
||||
public function edit($seminaryUrl, $groupsgroupUrl, $questUrl)
|
||||
{
|
||||
// Get seminary
|
||||
$seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
|
||||
|
||||
// Get Character groups-group
|
||||
$groupsgroup = $this->Charactergroups->getGroupsgroupByUrl($seminary['id'], $groupsgroupUrl);
|
||||
|
||||
// Get Character groups-group Quests
|
||||
$quest = $this->Charactergroupsquests->getQuestByUrl($groupsgroup['id'], $questUrl);
|
||||
|
||||
// Get Questgroups
|
||||
$questgroups = $this->Questgroups->getQuestgroupsForSeminary($seminary['id']);
|
||||
foreach($questgroups as $index => &$questgroup) {
|
||||
$questgroup['selected'] = ($questgroup['id'] == $quest['questgroups_id']);
|
||||
}
|
||||
|
||||
// Values
|
||||
$title = $quest['title'];
|
||||
$xps = $quest['xps'];
|
||||
$description = $quest['description'];
|
||||
$rules = $quest['rules'];
|
||||
$wonText = $quest['won_text'];
|
||||
$lostText = $quest['lost_text'];
|
||||
$fields = array('title', 'xps');
|
||||
$validation = array();
|
||||
|
||||
// Edit Character group
|
||||
if($this->request->getRequestMethod() == 'POST' && !is_null($this->request->getPostParam('edit')))
|
||||
{
|
||||
// Get params and validate them
|
||||
$validation = $this->Validation->validateParams($this->request->getPostParams(), $fields);
|
||||
$title = $this->request->getPostParam('title');
|
||||
if($this->Charactergroupsquests->characterGroupsQuestTitleExists($title, $quest['id'])) {
|
||||
$validation = $this->Validation->addValidationResult($validation, 'title', 'exist', true);
|
||||
}
|
||||
$xps = $this->request->getPostParam('xps');
|
||||
$description = $this->request->getPostParam('description');
|
||||
$rules = $this->request->getPostParam('rules');
|
||||
$wonText = $this->request->getPostParam('wonText');
|
||||
$lostText = $this->request->getPostParam('lostText');
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
// Edit groups Quest
|
||||
if($validation === true)
|
||||
{
|
||||
$this->Charactergroupsquests->editQuest(
|
||||
$quest['id'],
|
||||
$groupsgroup['id'],
|
||||
$questgroups[$questgroupIndex]['id'],
|
||||
$title,
|
||||
$description,
|
||||
$xps,
|
||||
$rules,
|
||||
$wonText,
|
||||
$lostText
|
||||
);
|
||||
|
||||
// Redirect to Quest page
|
||||
$quest = $this->Charactergroupsquests->getQuestById($quest['id']);
|
||||
$this->redirect($this->linker->link(array('quest', $seminary['url'], $groupsgroup['url'], $quest['url']), 1));
|
||||
}
|
||||
}
|
||||
|
||||
// Get validation settings
|
||||
$validationSettings = array();
|
||||
foreach($fields as &$field) {
|
||||
$validationSettings[$field] = \nre\configs\AppConfig::$validation[$field];
|
||||
}
|
||||
|
||||
|
||||
// Pass data to view
|
||||
$this->set('seminary', $seminary);
|
||||
$this->set('groupsgroup', $groupsgroup);
|
||||
$this->set('quest', $quest);
|
||||
$this->set('questgroups', $questgroups);
|
||||
$this->set('title', $title);
|
||||
$this->set('xps', $xps);
|
||||
$this->set('description', $description);
|
||||
$this->set('rules', $rules);
|
||||
$this->set('wonText', $wonText);
|
||||
$this->set('lostText', $lostText);
|
||||
$this->set('validation', $validation);
|
||||
$this->set('validationSettings', $validationSettings);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Action: delete.
|
||||
*
|
||||
* Delete a Character groups Quest of a Character groups-group
|
||||
* of a Seminary.
|
||||
*
|
||||
* @throws IdNotFoundException
|
||||
* @param string $seminaryUrl URL-Title of a Seminary
|
||||
* @param string $groupsgroupUrl URL-Title of a Character groups-group
|
||||
* @param string $questUrl URL-Title of a Character groups Quest
|
||||
*/
|
||||
public function delete($seminaryUrl, $groupsgroupUrl, $questUrl)
|
||||
{
|
||||
// Get seminary
|
||||
$seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
|
||||
|
||||
// Get Character groups-group
|
||||
$groupsgroup = $this->Charactergroups->getGroupsgroupByUrl($seminary['id'], $groupsgroupUrl);
|
||||
|
||||
// Get Character groups-group Quests
|
||||
$quest = $this->Charactergroupsquests->getQuestByUrl($groupsgroup['id'], $questUrl);
|
||||
|
||||
// Check request method
|
||||
if($this->request->getRequestMethod() == 'POST')
|
||||
{
|
||||
// Check confirmation
|
||||
if(!is_null($this->request->getPostParam('delete')))
|
||||
{
|
||||
// Delete seminary
|
||||
$this->Charactergroupsquests->deleteQuest($quest['id']);
|
||||
|
||||
// Redirect to overview
|
||||
$this->redirect($this->linker->link(array('charactergroups', 'groupsgroup', $seminary['url'], $groupsgroup['url'])));
|
||||
}
|
||||
|
||||
// Redirect to entry
|
||||
$this->redirect($this->linker->link(array('quest', $seminary['url'], $groupsgroup['url'], $quest['url']), 1));
|
||||
}
|
||||
|
||||
|
||||
// Pass data to view
|
||||
$this->set('seminary', $seminary);
|
||||
$this->set('groupsgroup', $groupsgroup);
|
||||
$this->set('quest', $quest);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue