diff --git a/controllers/CharactersController.inc b/controllers/CharactersController.inc index b36de319..7be4ddcb 100644 --- a/controllers/CharactersController.inc +++ b/controllers/CharactersController.inc @@ -69,20 +69,40 @@ // Get Seminary $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 $characters = $this->Characters->getCharactersForSeminary($seminary['id']); - - // Additional Character information foreach($characters as &$character) { - // Level $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 $this->set('seminary', $seminary); $this->set('characters', $characters); + $this->set('characterfields', $characterfields); + $this->set('properties', $properties); } @@ -107,9 +127,6 @@ $character['xplevel'] = $this->Characters->getXPLevelOfCharacters($character['id']); $character['rank'] = $this->Characters->getXPRank($seminary['id'], $character['xps']); - // Get Seminarycharacterfields - $characterfields = $this->Seminarycharacterfields->getFieldsForCharacter($character['id']); - // Get User $user = $this->Users->getUserById($character['user_id']); @@ -153,7 +170,6 @@ // Pass data to view $this->set('seminary', $seminary); $this->set('character', $character); - $this->set('characterfields', $characterfields); $this->set('user', $user); $this->set('groups', $groups); $this->set('achievements', $achievements); @@ -289,56 +305,72 @@ // Get seminary $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl); - // Do action + // Set default properties to show + $properties = array( + 'username', + 'xps', + 'roles' + ); + $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'); - $action = array_keys($actions)[0]; - $selectedCharacters = $this->request->getPostParam('characters'); - - switch($action) + // Do action + 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) { - // Add/remove role to/from Characters - case 'addrole': - case 'removerole': - // Determine role and check permissions - $role = null; - switch($actions[$action]) - { - 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'])) { - throw new \nre\exceptions\AccessDeniedException(); - } - $role = 'admin'; - break; - case _('Moderator'): - 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(); - } - $role = 'moderator'; - 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; - } + $actions = $this->request->getPostParam('actions'); + $action = array_keys($actions)[0]; + $selectedCharacters = $this->request->getPostParam('characters'); + + switch($action) + { + // Add/remove role to/from Characters + case 'addrole': + case 'removerole': + // Determine role and check permissions + $role = null; + switch($actions[$action]) + { + 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'])) { + throw new \nre\exceptions\AccessDeniedException(); + } + $role = 'admin'; + break; + case _('Moderator'): + 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(); + } + $role = 'moderator'; + 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 - if($action == 'addrole') { - foreach($selectedCharacters as &$characterId) { - $this->Characterroles->addCharacterroleToCharacter($characterId, $role); + // Add role + if($action == 'addrole') { + foreach($selectedCharacters as &$characterId) { + $this->Characterroles->addCharacterroleToCharacter($characterId, $role); + } } - } - // Remove role - else { - foreach($selectedCharacters as &$characterId) { - $this->Characterroles->removeCharacterroleFromCharacter($characterId, $role); + // Remove role + else { + foreach($selectedCharacters as &$characterId) { + $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['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 $this->set('seminary', $seminary); $this->set('characters', $characters); + $this->set('characterfields', $characterfields); + $this->set('properties', $properties); $this->set('selectedCharacters', $selectedCharacters); } diff --git a/models/SeminarycharacterfieldsModel.inc b/models/SeminarycharacterfieldsModel.inc index efad3bde..e8dff611 100644 --- a/models/SeminarycharacterfieldsModel.inc +++ b/models/SeminarycharacterfieldsModel.inc @@ -63,7 +63,7 @@ public function getFieldsForCharacter($characterId) { 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 '. 'LEFT JOIN seminarycharacterfields ON seminarycharacterfields.id = characters_seminarycharacterfields.seminarycharacterfield_id '. 'LEFT JOIN seminarycharacterfieldtypes ON seminarycharacterfieldtypes.id = seminarycharacterfields.seminarycharacterfieldtype_id '. diff --git a/views/html/characters/index.tpl b/views/html/characters/index.tpl index 171d09d7..a7b7a0a2 100644 --- a/views/html/characters/index.tpl +++ b/views/html/characters/index.tpl @@ -14,12 +14,36 @@ +
+=$character['xps']?> XP
+=$character['user']['username']?>
+=$character['xps']?> XP
+ +=_('Admin')?>
+=_('Moderator')?>
+=_('User')?>
+ + + +=$characterfield['value']?>
+ +