add option to select Character properties to show for listing and managing Characters
This commit is contained in:
parent
7792c48a77
commit
d077aa026a
4 changed files with 135 additions and 54 deletions
|
|
@ -69,20 +69,40 @@
|
||||||
// Get Seminary
|
// Get Seminary
|
||||||
$seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
|
$seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
|
||||||
|
|
||||||
|
// Set default properties to show
|
||||||
|
$properties = array(
|
||||||
|
'username',
|
||||||
|
'xps'
|
||||||
|
);
|
||||||
|
|
||||||
|
// Select proprties to show
|
||||||
|
if($this->request->getRequestMethod() == 'POST')
|
||||||
|
{
|
||||||
|
$properties = $this->request->getPostParam('properties');
|
||||||
|
if(!is_array($properties)) {
|
||||||
|
$properties = array();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Get registered Characters
|
// Get registered Characters
|
||||||
$characters = $this->Characters->getCharactersForSeminary($seminary['id']);
|
$characters = $this->Characters->getCharactersForSeminary($seminary['id']);
|
||||||
|
|
||||||
// Additional Character information
|
|
||||||
foreach($characters as &$character)
|
foreach($characters as &$character)
|
||||||
{
|
{
|
||||||
// Level
|
|
||||||
$character['xplevel'] = $this->Characters->getXPLevelOfCharacters($character['id']);
|
$character['xplevel'] = $this->Characters->getXPLevelOfCharacters($character['id']);
|
||||||
|
$character['characterroles'] = array_map(function($r) { return $r['name']; }, $this->Characterroles->getCharacterrolesForCharacterById($character['id']));
|
||||||
|
$character['user'] = $this->Users->getUserById($character['user_id']);
|
||||||
|
$character['characterfields'] = $this->Seminarycharacterfields->getFieldsForCharacter($character['id']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get Seminarycharacterfields
|
||||||
|
$characterfields = $this->Seminarycharacterfields->getFieldsForSeminary($seminary['id']);
|
||||||
|
|
||||||
|
|
||||||
// Pass data to view
|
// Pass data to view
|
||||||
$this->set('seminary', $seminary);
|
$this->set('seminary', $seminary);
|
||||||
$this->set('characters', $characters);
|
$this->set('characters', $characters);
|
||||||
|
$this->set('characterfields', $characterfields);
|
||||||
|
$this->set('properties', $properties);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -107,9 +127,6 @@
|
||||||
$character['xplevel'] = $this->Characters->getXPLevelOfCharacters($character['id']);
|
$character['xplevel'] = $this->Characters->getXPLevelOfCharacters($character['id']);
|
||||||
$character['rank'] = $this->Characters->getXPRank($seminary['id'], $character['xps']);
|
$character['rank'] = $this->Characters->getXPRank($seminary['id'], $character['xps']);
|
||||||
|
|
||||||
// Get Seminarycharacterfields
|
|
||||||
$characterfields = $this->Seminarycharacterfields->getFieldsForCharacter($character['id']);
|
|
||||||
|
|
||||||
// Get User
|
// Get User
|
||||||
$user = $this->Users->getUserById($character['user_id']);
|
$user = $this->Users->getUserById($character['user_id']);
|
||||||
|
|
||||||
|
|
@ -153,7 +170,6 @@
|
||||||
// Pass data to view
|
// Pass data to view
|
||||||
$this->set('seminary', $seminary);
|
$this->set('seminary', $seminary);
|
||||||
$this->set('character', $character);
|
$this->set('character', $character);
|
||||||
$this->set('characterfields', $characterfields);
|
|
||||||
$this->set('user', $user);
|
$this->set('user', $user);
|
||||||
$this->set('groups', $groups);
|
$this->set('groups', $groups);
|
||||||
$this->set('achievements', $achievements);
|
$this->set('achievements', $achievements);
|
||||||
|
|
@ -289,56 +305,72 @@
|
||||||
// Get seminary
|
// Get seminary
|
||||||
$seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
|
$seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
|
||||||
|
|
||||||
// Do action
|
// Set default properties to show
|
||||||
|
$properties = array(
|
||||||
|
'username',
|
||||||
|
'xps',
|
||||||
|
'roles'
|
||||||
|
);
|
||||||
|
|
||||||
$selectedCharacters = array();
|
$selectedCharacters = array();
|
||||||
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)
|
if($this->request->getRequestMethod() == 'POST')
|
||||||
{
|
{
|
||||||
$actions = $this->request->getPostParam('actions');
|
// Do action
|
||||||
$action = array_keys($actions)[0];
|
if(!is_null($this->request->getPostParam('actions')) && count($this->request->getPostParam('actions')) > 0 && !is_null($this->request->getPostParam('characters')) && count($this->request->getPostParam('characters')) > 0)
|
||||||
$selectedCharacters = $this->request->getPostParam('characters');
|
|
||||||
|
|
||||||
switch($action)
|
|
||||||
{
|
{
|
||||||
// Add/remove role to/from Characters
|
$actions = $this->request->getPostParam('actions');
|
||||||
case 'addrole':
|
$action = array_keys($actions)[0];
|
||||||
case 'removerole':
|
$selectedCharacters = $this->request->getPostParam('characters');
|
||||||
// Determine role and check permissions
|
|
||||||
$role = null;
|
switch($action)
|
||||||
switch($actions[$action])
|
{
|
||||||
{
|
// Add/remove role to/from Characters
|
||||||
case _('Admin'):
|
case 'addrole':
|
||||||
if(count(array_intersect(array('admin', 'moderator'), \hhu\z\controllers\IntermediateController::$user['roles'])) <= 0 && !in_array('admin', \hhu\z\controllers\SeminaryController::$character['characterroles'])) {
|
case 'removerole':
|
||||||
throw new \nre\exceptions\AccessDeniedException();
|
// Determine role and check permissions
|
||||||
}
|
$role = null;
|
||||||
$role = 'admin';
|
switch($actions[$action])
|
||||||
break;
|
{
|
||||||
case _('Moderator'):
|
case _('Admin'):
|
||||||
if(count(array_intersect(array('admin', 'moderator'), \hhu\z\controllers\IntermediateController::$user['roles'])) <= 0 && !in_array('admin', \hhu\z\controllers\SeminaryController::$character['characterroles'])) {
|
if(count(array_intersect(array('admin', 'moderator'), \hhu\z\controllers\IntermediateController::$user['roles'])) <= 0 && !in_array('admin', \hhu\z\controllers\SeminaryController::$character['characterroles'])) {
|
||||||
throw new \nre\exceptions\AccessDeniedException();
|
throw new \nre\exceptions\AccessDeniedException();
|
||||||
}
|
}
|
||||||
$role = 'moderator';
|
$role = 'admin';
|
||||||
break;
|
break;
|
||||||
case _('User'):
|
case _('Moderator'):
|
||||||
if(count(array_intersect(array('admin', 'moderator'), \hhu\z\controllers\IntermediateController::$user['roles'])) <= 0 && count(array_intersect(array('admin', 'moderator'), \hhu\z\controllers\SeminaryController::$character['characterroles'])) <= 0) {
|
if(count(array_intersect(array('admin', 'moderator'), \hhu\z\controllers\IntermediateController::$user['roles'])) <= 0 && !in_array('admin', \hhu\z\controllers\SeminaryController::$character['characterroles'])) {
|
||||||
throw new \nre\exceptions\AccessDeniedException();
|
throw new \nre\exceptions\AccessDeniedException();
|
||||||
}
|
}
|
||||||
$role = 'user';
|
$role = 'moderator';
|
||||||
break;
|
break;
|
||||||
}
|
case _('User'):
|
||||||
|
if(count(array_intersect(array('admin', 'moderator'), \hhu\z\controllers\IntermediateController::$user['roles'])) <= 0 && count(array_intersect(array('admin', 'moderator'), \hhu\z\controllers\SeminaryController::$character['characterroles'])) <= 0) {
|
||||||
|
throw new \nre\exceptions\AccessDeniedException();
|
||||||
|
}
|
||||||
|
$role = 'user';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
// Add role
|
// Add role
|
||||||
if($action == 'addrole') {
|
if($action == 'addrole') {
|
||||||
foreach($selectedCharacters as &$characterId) {
|
foreach($selectedCharacters as &$characterId) {
|
||||||
$this->Characterroles->addCharacterroleToCharacter($characterId, $role);
|
$this->Characterroles->addCharacterroleToCharacter($characterId, $role);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
// Remove role
|
||||||
// Remove role
|
else {
|
||||||
else {
|
foreach($selectedCharacters as &$characterId) {
|
||||||
foreach($selectedCharacters as &$characterId) {
|
$this->Characterroles->removeCharacterroleFromCharacter($characterId, $role);
|
||||||
$this->Characterroles->removeCharacterroleFromCharacter($characterId, $role);
|
}
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
break;
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Properties to show
|
||||||
|
$properties = $this->request->getPostParam('properties');
|
||||||
|
if(!is_array($properties)) {
|
||||||
|
$properties = array();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -348,12 +380,19 @@
|
||||||
{
|
{
|
||||||
$character['xplevel'] = $this->Characters->getXPLevelOfCharacters($character['id']);
|
$character['xplevel'] = $this->Characters->getXPLevelOfCharacters($character['id']);
|
||||||
$character['characterroles'] = array_map(function($r) { return $r['name']; }, $this->Characterroles->getCharacterrolesForCharacterById($character['id']));
|
$character['characterroles'] = array_map(function($r) { return $r['name']; }, $this->Characterroles->getCharacterrolesForCharacterById($character['id']));
|
||||||
|
$character['user'] = $this->Users->getUserById($character['user_id']);
|
||||||
|
$character['characterfields'] = $this->Seminarycharacterfields->getFieldsForCharacter($character['id']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get Seminarycharacterfields
|
||||||
|
$characterfields = $this->Seminarycharacterfields->getFieldsForSeminary($seminary['id']);
|
||||||
|
|
||||||
|
|
||||||
// Pass data to view
|
// Pass data to view
|
||||||
$this->set('seminary', $seminary);
|
$this->set('seminary', $seminary);
|
||||||
$this->set('characters', $characters);
|
$this->set('characters', $characters);
|
||||||
|
$this->set('characterfields', $characterfields);
|
||||||
|
$this->set('properties', $properties);
|
||||||
$this->set('selectedCharacters', $selectedCharacters);
|
$this->set('selectedCharacters', $selectedCharacters);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -63,7 +63,7 @@
|
||||||
public function getFieldsForCharacter($characterId)
|
public function getFieldsForCharacter($characterId)
|
||||||
{
|
{
|
||||||
return $this->db->query(
|
return $this->db->query(
|
||||||
'SELECT seminarycharacterfields.title, characters_seminarycharacterfields.value '.
|
'SELECT seminarycharacterfields.id, seminarycharacterfields.title, seminarycharacterfields.url, seminarycharacterfields.regex, seminarycharacterfields.required, seminarycharacterfieldtypes.id AS type_id, seminarycharacterfieldtypes.title AS type_title, seminarycharacterfieldtypes.url AS type_url, characters_seminarycharacterfields.value '.
|
||||||
'FROM characters_seminarycharacterfields '.
|
'FROM characters_seminarycharacterfields '.
|
||||||
'LEFT JOIN seminarycharacterfields ON seminarycharacterfields.id = characters_seminarycharacterfields.seminarycharacterfield_id '.
|
'LEFT JOIN seminarycharacterfields ON seminarycharacterfields.id = characters_seminarycharacterfields.seminarycharacterfield_id '.
|
||||||
'LEFT JOIN seminarycharacterfieldtypes ON seminarycharacterfieldtypes.id = seminarycharacterfields.seminarycharacterfieldtype_id '.
|
'LEFT JOIN seminarycharacterfieldtypes ON seminarycharacterfieldtypes.id = seminarycharacterfields.seminarycharacterfieldtype_id '.
|
||||||
|
|
|
||||||
|
|
@ -14,12 +14,36 @@
|
||||||
</nav>
|
</nav>
|
||||||
<?php endif ?>
|
<?php endif ?>
|
||||||
|
|
||||||
|
<form method="post">
|
||||||
|
<fieldset>
|
||||||
|
<legend><?=_('Properties')?></legend>
|
||||||
|
<input type="checkbox" id="username" name="properties[]" value="username" <?php if(in_array('username', $properties)) : ?>checked="checked"<?php endif ?> /><label for="username"><?=_('Username')?></label><br />
|
||||||
|
<input type="checkbox" id="xps" name="properties[]" value="xps" <?php if(in_array('xps', $properties)) : ?>checked="checked"<?php endif ?> /><label for="xps"><?=_('XPs')?></label><br />
|
||||||
|
<input type="checkbox" id="roles" name="properties[]" value="roles" <?php if(in_array('roles', $properties)) : ?>checked="checked"<?php endif ?> /><label for="roles"><?=_('Roles')?></label><br />
|
||||||
|
<?php foreach($characterfields as &$characterfield) : ?>
|
||||||
|
<input type="checkbox" id="characterfield-<?=$characterfield['url']?>" name="properties[characterfields][]" value="<?=$characterfield['url']?>" <?php if(array_key_exists('characterfields', $properties) && in_array($characterfield['url'], $properties['characterfields'])) : ?>checked="checked"<?php endif ?> /><label for="characterfield-<?=$characterfield['url']?>"><?=$characterfield['url']?></label><br />
|
||||||
|
<?php endforeach ?>
|
||||||
|
<input type="submit" name="set-properties" value="<?=_('Set properties')?>" />
|
||||||
|
</fieldset>
|
||||||
|
</form>
|
||||||
|
|
||||||
<ul class="gchars cf">
|
<ul class="gchars cf">
|
||||||
<?php foreach($characters as &$character) : ?>
|
<?php foreach($characters as &$character) : ?>
|
||||||
<li>
|
<li>
|
||||||
<p><img src="<?=$linker->link(array('media','avatar',$seminary['url'],$character['charactertype_url'],$character['xplevel']['level'],'portrait'))?>"></p>
|
<p><img src="<?=$linker->link(array('media','avatar',$seminary['url'],$character['charactertype_url'],$character['xplevel']['level'],'portrait'))?>"></p>
|
||||||
<p><a href="<?=$linker->link(array('characters','character',$seminary['url'],$character['url']))?>"><?=$character['name']?></a></p>
|
<p><a href="<?=$linker->link(array('characters','character',$seminary['url'],$character['url']))?>"><?=$character['name']?></a></p>
|
||||||
<p><small><?=$character['xps']?> XP</small></p>
|
<?php if(in_array('username', $properties)) : ?><p><small><a href="<?=$linker->link(array('users','user',$character['user']['url']))?>"><?=$character['user']['username']?></a></small></p><?php endif ?>
|
||||||
|
<?php if(in_array('xps', $properties)) : ?><p><small><?=$character['xps']?> XP</small></p><?php endif ?>
|
||||||
|
<?php if(in_array('roles', $properties)) : ?>
|
||||||
|
<?php if(in_array('admin', $character['characterroles'])) : ?><p><small><?=_('Admin')?></small></p><?php endif ?>
|
||||||
|
<?php if(in_array('moderator', $character['characterroles'])) : ?><p><small><?=_('Moderator')?></small></p><?php endif ?>
|
||||||
|
<?php if(in_array('user', $character['characterroles'])) : ?><p><small><?=_('User')?></small></p><?php endif ?>
|
||||||
|
<?php endif ?>
|
||||||
|
<?php foreach($character['characterfields'] as &$characterfield) : ?>
|
||||||
|
<?php if(array_key_exists('characterfields', $properties) && in_array($characterfield['url'], $properties['characterfields'])) : ?>
|
||||||
|
<p><small><?=$characterfield['value']?></small></p>
|
||||||
|
<?php endif ?>
|
||||||
|
<?php endforeach ?>
|
||||||
</li>
|
</li>
|
||||||
<?php endforeach ?>
|
<?php endforeach ?>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,16 @@
|
||||||
<h1><?=_('Manage')?></h1>
|
<h1><?=_('Manage')?></h1>
|
||||||
|
|
||||||
<form method="post">
|
<form method="post">
|
||||||
|
<fieldset>
|
||||||
|
<legend><?=_('Properties')?></legend>
|
||||||
|
<input type="checkbox" id="username" name="properties[]" value="username" <?php if(in_array('username', $properties)) : ?>checked="checked"<?php endif ?> /><label for="username"><?=_('Username')?></label><br />
|
||||||
|
<input type="checkbox" id="xps" name="properties[]" value="xps" <?php if(in_array('xps', $properties)) : ?>checked="checked"<?php endif ?> /><label for="xps"><?=_('XPs')?></label><br />
|
||||||
|
<input type="checkbox" id="roles" name="properties[]" value="roles" <?php if(in_array('roles', $properties)) : ?>checked="checked"<?php endif ?> /><label for="roles"><?=_('Roles')?></label><br />
|
||||||
|
<?php foreach($characterfields as &$characterfield) : ?>
|
||||||
|
<input type="checkbox" id="characterfield-<?=$characterfield['url']?>" name="properties[characterfields][]" value="<?=$characterfield['url']?>" <?php if(array_key_exists('characterfields', $properties) && in_array($characterfield['url'], $properties['characterfields'])) : ?>checked="checked"<?php endif ?> /><label for="characterfield-<?=$characterfield['url']?>"><?=$characterfield['url']?></label><br />
|
||||||
|
<?php endforeach ?>
|
||||||
|
<input type="submit" name="set-properties" value="<?=_('Set properties')?>" />
|
||||||
|
</fieldset>
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<legend><?=_('Selection')?>:</legend>
|
<legend><?=_('Selection')?>:</legend>
|
||||||
<ul class="gchars cf">
|
<ul class="gchars cf">
|
||||||
|
|
@ -19,10 +29,18 @@
|
||||||
<label for="characters-<?=$character['id']?>">
|
<label for="characters-<?=$character['id']?>">
|
||||||
<p><img src="<?=$linker->link(array('media','avatar',$seminary['url'],$character['charactertype_url'],$character['xplevel']['level'],'portrait'))?>"></p>
|
<p><img src="<?=$linker->link(array('media','avatar',$seminary['url'],$character['charactertype_url'],$character['xplevel']['level'],'portrait'))?>"></p>
|
||||||
<p><a href="<?=$linker->link(array('characters','character',$seminary['url'],$character['url']))?>"><?=$character['name']?></a></p>
|
<p><a href="<?=$linker->link(array('characters','character',$seminary['url'],$character['url']))?>"><?=$character['name']?></a></p>
|
||||||
<p><small><?=$character['xps']?> XP</small></p>
|
<?php if(in_array('username', $properties)) : ?><p><small><a href="<?=$linker->link(array('users','user',$character['user']['url']))?>"><?=$character['user']['username']?></a></small></p><?php endif ?>
|
||||||
|
<?php if(in_array('xps', $properties)) : ?><p><small><?=$character['xps']?> XP</small></p><?php endif ?>
|
||||||
|
<?php if(in_array('roles', $properties)) : ?>
|
||||||
<?php if(in_array('admin', $character['characterroles'])) : ?><p><small><?=_('Admin')?></small></p><?php endif ?>
|
<?php if(in_array('admin', $character['characterroles'])) : ?><p><small><?=_('Admin')?></small></p><?php endif ?>
|
||||||
<?php if(in_array('moderator', $character['characterroles'])) : ?><p><small><?=_('Moderator')?></small></p><?php endif ?>
|
<?php if(in_array('moderator', $character['characterroles'])) : ?><p><small><?=_('Moderator')?></small></p><?php endif ?>
|
||||||
<?php if(in_array('user', $character['characterroles'])) : ?><p><small><?=_('User')?></small></p><?php endif ?>
|
<?php if(in_array('user', $character['characterroles'])) : ?><p><small><?=_('User')?></small></p><?php endif ?>
|
||||||
|
<?php endif ?>
|
||||||
|
<?php foreach($character['characterfields'] as &$characterfield) : ?>
|
||||||
|
<?php if(array_key_exists('characterfields', $properties) && in_array($characterfield['url'], $properties['characterfields'])) : ?>
|
||||||
|
<p><small><?=$characterfield['value']?></small></p>
|
||||||
|
<?php endif ?>
|
||||||
|
<?php endforeach ?>
|
||||||
</label>
|
</label>
|
||||||
</li>
|
</li>
|
||||||
<?php endforeach ?>
|
<?php endforeach ?>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue