implement manageing of Character groups (at least members)
This commit is contained in:
parent
bc1650d3cb
commit
7dcea76c86
5 changed files with 223 additions and 4 deletions
|
|
@ -156,7 +156,7 @@
|
|||
// z/<Seminary>/<Questgroup>/<Quest> ⇒ z/quests/quest/<Seminary>/<Questgroup>/<Quest>
|
||||
array('^([^/]+)/([^/]+)/([^/]+)/?$', 'quests/quest/$1/$2/3', true)*/
|
||||
array('characters/(?!(index|character|register|manage))', 'characters/index/$1', true),
|
||||
array('charactergroups/(?!(index|groupsgroup|group))', 'charactergroups/index/$1', true),
|
||||
array('charactergroups/(?!(index|groupsgroup|group|managegroup))', 'charactergroups/index/$1', true),
|
||||
array('charactergroupsquests/(?!(quest))', 'charactergroupsquests/quest/$1', true),
|
||||
array('media/(.*)', 'media/$1?layout=binary', false),
|
||||
array('uploads/(.*)', 'uploads/$1?layout=binary', false),
|
||||
|
|
|
|||
|
|
@ -24,14 +24,15 @@
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public $models = array('seminaries', 'charactergroups', 'charactergroupsquests', 'avatars', 'media');
|
||||
public $models = array('seminaries', 'charactergroups', 'charactergroupsquests', 'characters', 'avatars', 'media');
|
||||
/**
|
||||
* User permissions
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $permissions = array(
|
||||
'quest' => array('admin', 'moderator', 'user')
|
||||
'quest' => array('admin', 'moderator', 'user'),
|
||||
'manage' => array('admin', 'moderator', 'user')
|
||||
);
|
||||
/**
|
||||
* User seminary permissions
|
||||
|
|
@ -39,7 +40,8 @@
|
|||
* @var array
|
||||
*/
|
||||
public $seminaryPermissions = array(
|
||||
'quest' => array('admin', 'moderator', 'user')
|
||||
'quest' => array('admin', 'moderator', 'user'),
|
||||
'manage' => array('admin', 'moderator')
|
||||
);
|
||||
|
||||
|
||||
|
|
@ -145,6 +147,90 @@
|
|||
$this->set('quests', $quests);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Action: managegroup.
|
||||
*
|
||||
* Manage a Character group for 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 $groupUrl URL-Title of a Character group
|
||||
*/
|
||||
public function managegroup($seminaryUrl, $groupsgroupUrl, $groupUrl)
|
||||
{
|
||||
// Get seminary
|
||||
$seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
|
||||
|
||||
// Get Character groups-group
|
||||
$groupsgroup = $this->Charactergroups->getGroupsgroupByUrl($seminary['id'], $groupsgroupUrl);
|
||||
|
||||
// Get Character group
|
||||
$group = $this->Charactergroups->getGroupByUrl($groupsgroup['id'], $groupUrl);
|
||||
|
||||
// Manage
|
||||
if($this->request->getRequestMethod() == 'POST' && !is_null($this->request->getPostParam('actions')) && count($this->request->getPostParam('actions')) > 0) // && !is_null($this->request->getPostParam('characters')) && count($this->request->getPostParam('characters')) > 0)
|
||||
{
|
||||
$actions = $this->request->getPostParam('actions');
|
||||
$action = array_keys($actions)[0];
|
||||
$selectedCharacters = $this->request->getPostParam('characters');
|
||||
|
||||
switch($action)
|
||||
{
|
||||
// Add Characters to group
|
||||
case 'addcharacters':
|
||||
var_dump("hier");
|
||||
foreach($selectedCharacters as &$characterId) {
|
||||
var_dump("add ".$characterId);
|
||||
$this->Charactergroups->addCharacterToCharactergroup($group['id'], $characterId);
|
||||
}
|
||||
break;
|
||||
// Remove Characters from group
|
||||
case 'removecharacters':
|
||||
foreach($selectedCharacters as &$characterId) {
|
||||
$this->Charactergroups->removeCharacterFromCharactergroup($group['id'], $characterId);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Get additional data for group
|
||||
$group['characters'] = $this->Characters->getCharactersForGroup($group['id']);
|
||||
$group['rank'] = $this->Charactergroups->getXPRank($groupsgroup['id'], $group['xps']);
|
||||
|
||||
// Get Character avatars
|
||||
foreach($group['characters'] as &$character)
|
||||
{
|
||||
$avatar = $this->Avatars->getAvatarById($character['avatar_id']);
|
||||
if(!is_null($avatar['small_avatarpicture_id'])) {
|
||||
$character['small_avatar'] = $this->Media->getSeminaryMediaById($avatar['small_avatarpicture_id']);
|
||||
}
|
||||
}
|
||||
|
||||
// Get Character groups Quests
|
||||
$quests = $this->Charactergroupsquests->getQuestsForGroup($group['id']);
|
||||
|
||||
// Get all Characters of Seminary
|
||||
$groupCharacterIds = array_map(function($c) { return $c['id']; }, $group['characters']);
|
||||
$seminaryCharacters = $this->Characters->getCharactersForSeminary($seminary['id']);
|
||||
$characters = array();
|
||||
foreach($seminaryCharacters as &$character) {
|
||||
if(!in_array($character['id'], $groupCharacterIds)) {
|
||||
$characters[] = $character;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Pass data to view
|
||||
$this->set('seminary', $seminary);
|
||||
$this->set('groupsgroup', $groupsgroup);
|
||||
$this->set('group', $group);
|
||||
$this->set('quests', $quests);
|
||||
$this->set('characters', $characters);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -192,6 +192,44 @@
|
|||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add a Character to a Character group.
|
||||
*
|
||||
* @param int $groupId ID of Character group
|
||||
* @param int $characterId ID of Character to add
|
||||
*/
|
||||
public function addCharacterToCharactergroup($groupId, $characterId)
|
||||
{
|
||||
$this->db->query(
|
||||
'INSERT INTO characters_charactergroups '.
|
||||
'(character_id, charactergroup_id) '.
|
||||
'VALUES '.
|
||||
'(?, ?)',
|
||||
'ii',
|
||||
$characterId,
|
||||
$groupId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove a Character from a Character group.
|
||||
*
|
||||
* @param int $groupId ID of Character group
|
||||
* @param int $characterId ID of Character to remove
|
||||
*/
|
||||
public function removeCharacterFromCharactergroup($groupId, $characterId)
|
||||
{
|
||||
$this->db->query(
|
||||
'DELETE FROM characters_charactergroups '.
|
||||
'WHERE charactergroup_id = ? AND character_id = ?',
|
||||
'ii',
|
||||
$groupId,
|
||||
$characterId
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -8,6 +8,13 @@
|
|||
<li><i class="fa fa-chevron-right fa-fw"></i><a href="<?=$linker->link(array('index',$seminary['url']),1)?>"><?=_('Character Groups')?></a></li>
|
||||
<li><i class="fa fa-chevron-right fa-fw"></i><a href="<?=$linker->link(array('groupsgroup',$seminary['url'],$groupsgroup['url']),1)?>"><?=$groupsgroup['name']?></a></li>
|
||||
</ul>
|
||||
|
||||
<?php if(count(array_intersect(array('admin', 'moderator'), \hhu\z\controllers\SeminaryController::$character['characterroles'])) > 0) : ?>
|
||||
<nav class="admin">
|
||||
<li><a href="<?=$linker->link(array('managegroup',$seminary['url'],$groupsgroup['url'],$group['url']),1)?>"><?=_('Manage')?></a></li>
|
||||
</nav>
|
||||
<?php endif ?>
|
||||
|
||||
<div class="gbanner cf">
|
||||
<img src="http://s1.directupload.net/images/140325/3eqybn4i.png" class="gbanner">
|
||||
<h1><?=$group['name']?></h1>
|
||||
|
|
|
|||
88
views/html/charactergroups/managegroup.tpl
Normal file
88
views/html/charactergroups/managegroup.tpl
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
<?php if(!is_null($seminary['seminarymedia_id'])) : ?>
|
||||
<div class="moodpic">
|
||||
<img src="<?=$linker->link(array('media','seminaryheader',$seminary['url']))?>">
|
||||
</div>
|
||||
<?php endif ?>
|
||||
<ul class="breadcrumbs">
|
||||
<li><a href="<?=$linker->link(array('seminaries',$seminary['url']))?>"><?=$seminary['title']?></a></li>
|
||||
<li><i class="fa fa-chevron-right fa-fw"></i><a href="<?=$linker->link(array('index',$seminary['url']),1)?>"><?=_('Character Groups')?></a></li>
|
||||
<li><i class="fa fa-chevron-right fa-fw"></i><a href="<?=$linker->link(array('groupsgroup',$seminary['url'],$groupsgroup['url']),1)?>"><?=$groupsgroup['name']?></a></li>
|
||||
</ul>
|
||||
<div class="gbanner cf">
|
||||
<img src="http://s1.directupload.net/images/140325/3eqybn4i.png" class="gbanner">
|
||||
<h1><?=$group['name']?></h1>
|
||||
<p>"<?=$group['motto']?>"</p>
|
||||
</div>
|
||||
<ul class="gdata cf">
|
||||
<li><?=$group['rank']?>. <?=_('Rank')?></li>
|
||||
<li><?=$group['xps']?> XP</li>
|
||||
<li><?=count($group['characters'])?> <?=(count($group['characters']) > 1) ? _('Members') : _('Member')?></li>
|
||||
</ul>
|
||||
|
||||
<section>
|
||||
<h1><i class="fa fa-users fa-fw"></i><?=_('Characters')?></h1>
|
||||
<form method="post">
|
||||
<fieldset>
|
||||
<ul class="gchars cf">
|
||||
<?php foreach($group['characters'] as &$character) : ?>
|
||||
<li>
|
||||
<input type="checkbox" id="characters-<?=$character['id']?>" name="characters[]" value="<?=$character['id']?>" <?php if($character['id'] == \hhu\z\controllers\SeminaryController::$character['id']) : ?>disabled="disabled"<?php endif ?>/>
|
||||
<label for="characters-<?=$character['id']?>">
|
||||
<?php if(array_key_exists('small_avatar', $character)) : ?>
|
||||
<p><img src="<?=$linker->link(array('media','seminary',$seminary['url'],$character['small_avatar']['url']))?>"></p>
|
||||
<?php endif ?>
|
||||
<p><a href="<?=$linker->link(array('characters','character',$seminary['url'],$character['url']))?>"><?=$character['name']?></a></p>
|
||||
<p><small><?=$character['xps']?> XP</small></p>
|
||||
</label>
|
||||
</li>
|
||||
<?php endforeach ?>
|
||||
</ul>
|
||||
<input type="submit" name="actions[removecharacters]" value="<?=_('Remove Character')?>" />
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<input type="text" placeholder="<?=_('Filter Characters')?>" onkeyup="filter_characters(this)" /><br />
|
||||
<select id="characters" name="characters[]" size="5" multiple="multiple">
|
||||
<?php foreach($characters as &$character) : ?>
|
||||
<option value="<?=$character['id']?>"><?=$character['name']?></option>
|
||||
<?php endforeach ?>
|
||||
</select>
|
||||
<input type="submit" name="actions[addcharacters]" value="<?=_('Add Character')?>" />
|
||||
</fieldset>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<h1><i class="fa fa-pencil-square-o fa-fw"></i><?=_('Quests')?></h1>
|
||||
<ul class="gquests">
|
||||
<?php foreach($quests as &$quest) : ?>
|
||||
<li class="cf">
|
||||
<p>
|
||||
<span class="date"><?=$dateFormatter->format(new \DateTime($quest['created']))?></span>
|
||||
<a href="<?=$linker->link(array('charactergroupsquests','quest',$seminary['url'],$groupsgroup['url'],$quest['url']))?>" class="fwb"><?=$quest['title']?></a>
|
||||
<span class="xp"><?=$quest['group_xps']?> / <?=$quest['xps']?> XP</span>
|
||||
</p>
|
||||
</li>
|
||||
<?php endforeach ?>
|
||||
</ul>
|
||||
</section>
|
||||
|
||||
|
||||
|
||||
|
||||
<script>
|
||||
/**
|
||||
* Hide select elements that include the value string from the given input
|
||||
* element.
|
||||
*/
|
||||
function filter_characters(input)
|
||||
{
|
||||
text = input.value.toLowerCase();
|
||||
$('#characters option').each(function() {
|
||||
if(this.text.toLowerCase().indexOf(text) !== -1) {
|
||||
jQuery(this).removeAttr('hidden');
|
||||
}
|
||||
else {
|
||||
jQuery(this).attr('hidden', "hidden");
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
Loading…
Add table
Add a link
Reference in a new issue