implement position for sorting of Character groups Quests (implements #157)
This commit is contained in:
parent
412326f69a
commit
9c0b0d8d07
8 changed files with 170 additions and 14 deletions
|
@ -353,9 +353,9 @@
|
|||
array('^charactergroups/([^/]+)/([^/]+)/(create)/?$', 'charactergroups/creategroup/$1/$2/$3', true),
|
||||
array('^charactergroups/([^/]+)/([^/]+)/([^/]+)/?$', 'charactergroups/group/$1/$2/$3', true),
|
||||
array('^charactergroups/([^/]+)/([^/]+)/([^/]+)/(manage|edit|delete)/?$', 'charactergroups/$4group/$1/$2/$3', true),
|
||||
array('^charactergroupsquests/([^/]+)/([^/]+)/create/?$', 'charactergroupsquests/create/$1/$2', true),
|
||||
array('^charactergroupsquests/([^/]+)/([^/]+)/([^/]+)/?$', 'charactergroupsquests/quest/$1/$2/$3', true),
|
||||
array('^charactergroupsquests/([^/]+)/([^/]+)/([^/]+)/(edit|delete|manage)/?$', 'charactergroupsquests/$4/$1/$2/$3', true),
|
||||
array('^charactergroupsquests/([^/]+)/([^/]+)/create/?$', 'charactergroupsquests/create/$1/$2', true),
|
||||
array('^charactergroupsquests/([^/]+)/([^/]+)/([^/]+)/?$', 'charactergroupsquests/quest/$1/$2/$3', true),
|
||||
array('^charactergroupsquests/([^/]+)/([^/]+)/([^/]+)/(edit|moveup|movedown|delete|manage)/?$', 'charactergroupsquests/$4/$1/$2/$3', true),
|
||||
array('^charactergroupsqueststations/([^/]+)/([^/]+)/([^/]+)/?$', 'charactergroupsqueststations/index/$1/$2/$3?layout=ajax', true),
|
||||
array('^charactergroupsqueststations/([^/]+)/([^/]+)/([^/]+)/create/?$', 'charactergroupsqueststations/create/$1/$2/$3', true),
|
||||
array('^charactergroupsqueststations/([^/]+)/([^/]+)/([^/]+)/([^/]+)/(edit|edittask|delete)/?$', 'charactergroupsqueststations/$5/$1/$2/$3/$4', true),
|
||||
|
@ -418,9 +418,9 @@
|
|||
array('^charactergroups/creategroup/([^/]+)/([^/]+)$', 'charactergroups/$1/$2/create', true),
|
||||
array('^charactergroups/group/([^/]+)/([^/]+)/([^/]+)$', 'charactergroups/$1/$2/$3', true),
|
||||
array('^charactergroups/(manage|edit|delete)group/([^/]+)/([^/]+)/([^/]+)$', 'charactergroups/$2/$3/$4/$1', true),
|
||||
array('^charactergroupsquests/create/([^/]+)/([^/]+)/?$', 'charactergroupsquests/$1/$2/create', true),
|
||||
array('^charactergroupsquests/quest/(.*)$', 'charactergroupsquests/$1', true),
|
||||
array('^charactergroupsquests/(edit|delete|manage)/([^/]+)/([^/]+)/([^/]+)$', 'charactergroupsquests/$2/$3/$4/$1', true),
|
||||
array('^charactergroupsquests/create/([^/]+)/([^/]+)/?$', 'charactergroupsquests/$1/$2/create', true),
|
||||
array('^charactergroupsquests/quest/(.*)$', 'charactergroupsquests/$1', true),
|
||||
array('^charactergroupsquests/(edit|moveup|movedown|delete|manage)/([^/]+)/([^/]+)/([^/]+)$', 'charactergroupsquests/$2/$3/$4/$1', true),
|
||||
array('^charactergroupsqueststations/index/(.*)$', 'charactergroupsqueststations/$1', true),
|
||||
array('^charactergroupsqueststations/station/(.*)$', 'charactergroupsqueststations/$1', true),
|
||||
array('^charactergroupsqueststations/(create|edit|edittask|delete)/(.*)$', 'charactergroupsqueststations/$2/$1', true),
|
||||
|
|
|
@ -42,6 +42,8 @@
|
|||
'manage' => array('admin', 'moderator', 'user'),
|
||||
'create' => array('admin', 'moderator', 'user'),
|
||||
'edit' => array('admin', 'moderator', 'user'),
|
||||
'moveup' => array('admin', 'moderator', 'user'),
|
||||
'movedown' => array('admin', 'moderator', 'user'),
|
||||
'delete' => array('admin', 'moderator', 'user')
|
||||
);
|
||||
/**
|
||||
|
@ -54,6 +56,8 @@
|
|||
'manage' => array('admin', 'moderator'),
|
||||
'create' => array('admin', 'moderator'),
|
||||
'edit' => array('admin', 'moderator'),
|
||||
'moveup' => array('admin', 'moderator'),
|
||||
'movedown' => array('admin', 'moderator'),
|
||||
'delete' => array('admin', 'moderator')
|
||||
);
|
||||
|
||||
|
@ -672,6 +676,80 @@
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Action: moveup.
|
||||
*
|
||||
* Move a Character groups Quest up (decrement position).
|
||||
*
|
||||
* @throws \nre\exceptions\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 moveup($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);
|
||||
|
||||
// Set position
|
||||
$this->Charactergroupsquests->moveQuest($quest, true);
|
||||
|
||||
$this->redirect(
|
||||
$this->linker->link(
|
||||
array(
|
||||
'charactergroups',
|
||||
'groupsgroup',
|
||||
$seminary['url'],
|
||||
$groupsgroup['url']
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Action: movedown.
|
||||
*
|
||||
* Move a Character groups Quest down (increment position).
|
||||
*
|
||||
* @throws \nre\exceptions\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 movedown($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);
|
||||
|
||||
// Set position
|
||||
$this->Charactergroupsquests->moveQuest($quest, false);
|
||||
|
||||
$this->redirect(
|
||||
$this->linker->link(
|
||||
array(
|
||||
'charactergroups',
|
||||
'groupsgroup',
|
||||
$seminary['url'],
|
||||
$groupsgroup['url']
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Action: delete.
|
||||
*
|
||||
|
|
|
@ -502,6 +502,7 @@ CREATE TABLE `charactergroupsquests` (
|
|||
`questgroups_id` int(11) NOT NULL,
|
||||
`title` varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL,
|
||||
`url` varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL,
|
||||
`pos` int(10) unsigned NOT NULL,
|
||||
`description` text COLLATE utf8mb4_unicode_ci NOT NULL,
|
||||
`xps` int(10) unsigned NOT NULL,
|
||||
`rules` text COLLATE utf8mb4_unicode_ci NOT NULL,
|
||||
|
@ -511,6 +512,7 @@ CREATE TABLE `charactergroupsquests` (
|
|||
`public` tinyint(1) NOT NULL DEFAULT '1',
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `charactergroupsgroup_id_2` (`charactergroupsgroup_id`,`url`),
|
||||
UNIQUE KEY `charactergroupsgroup_id_3` (`charactergroupsgroup_id`,`pos`),
|
||||
KEY `created_user_id` (`created_user_id`),
|
||||
KEY `charactergroupsgroup_id` (`charactergroupsgroup_id`),
|
||||
KEY `questgroups_id` (`questgroups_id`),
|
||||
|
|
|
@ -50,10 +50,10 @@
|
|||
public function getQuestsForCharactergroupsgroup($groupsgroupId)
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT id, questgroups_id, title, url, xps, questsmedia_id, public '.
|
||||
'SELECT id, questgroups_id, title, url, pos, xps, questsmedia_id, public '.
|
||||
'FROM charactergroupsquests '.
|
||||
'WHERE charactergroupsgroup_id = ? '.
|
||||
'ORDER BY created ASC',
|
||||
'ORDER BY pos ASC',
|
||||
'i',
|
||||
$groupsgroupId
|
||||
);
|
||||
|
@ -71,7 +71,7 @@
|
|||
public function getQuestByUrl($groupsgroupId, $questUrl)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT id, questgroups_id, title, url, description, xps, rules, won_text, lost_text, questsmedia_id, public '.
|
||||
'SELECT id, questgroups_id, charactergroupsgroup_id, title, url, pos, description, xps, rules, won_text, lost_text, questsmedia_id, public '.
|
||||
'FROM charactergroupsquests '.
|
||||
'WHERE charactergroupsgroup_id = ? AND url = ?',
|
||||
'is',
|
||||
|
@ -97,7 +97,7 @@
|
|||
public function getQuestById($questId)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT id, charactergroupsgroup_id, questgroups_id, title, url, description, xps, rules, won_text, lost_text, questsmedia_id, public '.
|
||||
'SELECT id, charactergroupsgroup_id, questgroups_id, title, url, pos, description, xps, rules, won_text, lost_text, questsmedia_id, public '.
|
||||
'FROM charactergroupsquests '.
|
||||
'WHERE id = ?',
|
||||
'i',
|
||||
|
@ -320,17 +320,29 @@
|
|||
*/
|
||||
public function createQuest($userId, $groupsgroupId, $questgroupId, $title, $description, $xps, $rules, $wonText, $lostText)
|
||||
{
|
||||
// Get last position
|
||||
$pos = $this->db->query(
|
||||
'SELECT COALESCE(MAX(pos),0) AS pos '.
|
||||
'FROM charactergroupsquests '.
|
||||
'WHERE charactergroupsgroup_id = ?',
|
||||
'i',
|
||||
$groupsgroupId
|
||||
);
|
||||
$pos = intval($pos[0]['pos']);
|
||||
|
||||
// Add new Quest
|
||||
$this->db->query(
|
||||
'INSERT INTO charactergroupsquests '.
|
||||
'(created_user_id, charactergroupsgroup_id, questgroups_id, title, url, description, xps, rules, won_text, lost_text, public) '.
|
||||
'(created_user_id, charactergroupsgroup_id, questgroups_id, title, url, pos, description, xps, rules, won_text, lost_text, public) '.
|
||||
'VALUES '.
|
||||
'(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 0)',
|
||||
'(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 0)',
|
||||
'iiisssdsss',
|
||||
$userId,
|
||||
$groupsgroupId,
|
||||
$questgroupId,
|
||||
$title,
|
||||
\nre\core\Linker::createLinkParam($title),
|
||||
$pos + 1,
|
||||
$description,
|
||||
$xps,
|
||||
$rules,
|
||||
|
@ -339,6 +351,7 @@
|
|||
);
|
||||
|
||||
|
||||
// Return ID
|
||||
return $this->db->getInsertId();
|
||||
}
|
||||
|
||||
|
@ -379,6 +392,58 @@
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Move a Character groups Quest up (decrement position) or down
|
||||
* (increment position).
|
||||
*
|
||||
* @param array $quest Character groups Quest to move
|
||||
* @param boolean $up True for moving up, false for down
|
||||
*/
|
||||
public function moveQuest($quest, $up)
|
||||
{
|
||||
$this->db->setAutocommit(false);
|
||||
try {
|
||||
// Set temporary position
|
||||
$this->db->query(
|
||||
'UPDATE charactergroupsquests '.
|
||||
'SET pos = 0 '.
|
||||
'WHERE id = ?',
|
||||
'i',
|
||||
$quest['id']
|
||||
);
|
||||
|
||||
// Switch entry
|
||||
$this->db->query(
|
||||
'UPDATE charactergroupsquests '.
|
||||
'SET pos = ? '.
|
||||
'WHERE charactergroupsgroup_id = ? AND pos = ?',
|
||||
'iii',
|
||||
$quest['pos'],
|
||||
$quest['charactergroupsgroup_id'],
|
||||
$quest['pos'] + ($up ? -1 : 1)
|
||||
);
|
||||
|
||||
// Set new position
|
||||
$this->db->query(
|
||||
'UPDATE charactergroupsquests '.
|
||||
'SET pos = ? '.
|
||||
'WHERE id = ?',
|
||||
'ii',
|
||||
$quest['pos'] + ($up ? -1 : 1),
|
||||
$quest['id']
|
||||
);
|
||||
|
||||
$this->db->commit();
|
||||
}
|
||||
catch(\nre\exceptions\DatamodelException $e) {
|
||||
$this->db->rollback();
|
||||
$this->db->setAutocommit(true);
|
||||
throw $e;
|
||||
}
|
||||
$this->db->setAutocommit(true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Copy all Character groups Quests from a Seminary.
|
||||
*
|
||||
|
@ -402,8 +467,8 @@
|
|||
// Copy Quest
|
||||
$this->db->query(
|
||||
'INSERT INTO charactergroupsquests '.
|
||||
'(created_user_id, charactergroupsgroup_id, questgroups_id, title, url, description, xps, rules, won_text, lost_text, public) '.
|
||||
'SELECT ?, ?, ?, title, url, description, xps, rules, won_text, lost_text, public '.
|
||||
'(created_user_id, charactergroupsgroup_id, questgroups_id, title, url, pos, description, xps, rules, won_text, lost_text, public) '.
|
||||
'SELECT ?, ?, ?, title, url, pos, description, xps, rules, won_text, lost_text, public '.
|
||||
'FROM charactergroupsquests '.
|
||||
'WHERE id = ?',
|
||||
'iiii',
|
||||
|
|
|
@ -42,6 +42,16 @@
|
|||
<li class="cf">
|
||||
<img src="<?=$linker->link(array('media','charactergroupsquest',$seminary['url'],$groupsgroup['url'],$quest['url']))?>" />
|
||||
<p><a href="<?=$linker->link(array('charactergroupsquests','quest',$seminary['url'],$groupsgroup['url'],$quest['url']))?>"><?=$quest['title']?></a></p>
|
||||
<?php if(count(array_intersect(array('admin', 'moderator'), \hhu\z\controllers\SeminaryController::$character['characterroles'])) > 0) : ?>
|
||||
<p><small>
|
||||
<?php if($quest['pos'] > 1) : ?>
|
||||
<a href="<?=$linker->link(array('charactergroupsquests','moveup',$seminary['url'],$groupsgroup['url'],$quest['url']))?>">↑</a>
|
||||
<?php endif ?>
|
||||
<?php if($quest['pos'] < count($quests)) : ?>
|
||||
<a href="<?=$linker->link(array('charactergroupsquests','movedown',$seminary['url'],$groupsgroup['url'],$quest['url']))?>">↓</a>
|
||||
<?php endif ?>
|
||||
</small></p>
|
||||
<?php endif ?>
|
||||
</li>
|
||||
<?php endif ?>
|
||||
<?php endforeach ?>
|
||||
|
|
0
views/html/charactergroupsquests/movedown.tpl
Normal file
0
views/html/charactergroupsquests/movedown.tpl
Normal file
0
views/html/charactergroupsquests/moveup.tpl
Normal file
0
views/html/charactergroupsquests/moveup.tpl
Normal file
|
@ -276,6 +276,7 @@ span.ctitle{font-size:.75em;padding:0;margin:0}
|
|||
.cgqlist li{background:#fff;margin-bottom:5px;padding:3px}
|
||||
.cgqlist img{float:left;width:40px;height:40px;border-radius:3px;margin-right:10px}
|
||||
.cgqlist p{margin:5px 0 0}
|
||||
.cgqlist p small{float:right}
|
||||
|
||||
|
||||
/** Charactergroup Profile **/
|
||||
|
|
Loading…
Add table
Reference in a new issue