store the total amount of achievable XPs for a Questgroup in the database instead of calculating it every time (Issue #281)
This commit is contained in:
parent
53a968d644
commit
ea828a88dc
10 changed files with 211 additions and 209 deletions
|
|
@ -208,7 +208,7 @@
|
||||||
array('^users/([^/]+)/(edit|delete)/?$', 'users/$2/$1', true),
|
array('^users/([^/]+)/(edit|delete)/?$', 'users/$2/$1', true),
|
||||||
array('^users/(?!(index|login|register|logout|manage|create|edit|delete))/?', 'users/user/$1', true),
|
array('^users/(?!(index|login|register|logout|manage|create|edit|delete))/?', 'users/user/$1', true),
|
||||||
array('^seminaries/([^/]+)/(edit|delete)/?$', 'seminaries/$2/$1', true),
|
array('^seminaries/([^/]+)/(edit|delete)/?$', 'seminaries/$2/$1', true),
|
||||||
array('^seminaries/(?!(index|create|edit|delete))/?', 'seminaries/seminary/$1', true),
|
array('^seminaries/(?!(index|create|edit|delete|calculatexps))/?', 'seminaries/seminary/$1', true),
|
||||||
array('^questgroups/([^/]+)/(create)/?$', 'questgroups/$2/$1', true),
|
array('^questgroups/([^/]+)/(create)/?$', 'questgroups/$2/$1', true),
|
||||||
array('^questgroups/([^/]+)/([^/]+)/?$', 'questgroups/questgroup/$1/$2', true),
|
array('^questgroups/([^/]+)/([^/]+)/?$', 'questgroups/questgroup/$1/$2', true),
|
||||||
array('^quests/([^/]+)/?$', 'quests/index/$1', true),
|
array('^quests/([^/]+)/?$', 'quests/index/$1', true),
|
||||||
|
|
|
||||||
|
|
@ -113,10 +113,8 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get cumulated data
|
// Get Character XPs
|
||||||
$data = $this->Questgroups->getCumulatedDataForQuestgroup($group['id'], $character['id']);
|
$group['character_xps'] = $this->Questgroups->getAchievedXPsForQuestgroup($group['id'], $character['id']);
|
||||||
$group['xps'] = $data['xps'];
|
|
||||||
$group['character_xps'] = $data['character_xps'];
|
|
||||||
|
|
||||||
// Attach related Questgroups
|
// Attach related Questgroups
|
||||||
$group['relatedQuestgroups'] = array();
|
$group['relatedQuestgroups'] = array();
|
||||||
|
|
@ -125,6 +123,7 @@
|
||||||
if($this->Questgroups->hasCharacterEnteredQuestgroup($relatedQuestgroup['id'], $character['id'])) {
|
if($this->Questgroups->hasCharacterEnteredQuestgroup($relatedQuestgroup['id'], $character['id'])) {
|
||||||
$group['relatedQuestgroups'][] = $this->Questgroups->getQuestgroupById($relatedQuestgroup['id']);
|
$group['relatedQuestgroups'][] = $this->Questgroups->getQuestgroupById($relatedQuestgroup['id']);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -133,9 +132,6 @@
|
||||||
// Get texts
|
// Get texts
|
||||||
$questgroupTexts = $this->Questgroups->getQuestgroupTexts($questgroup['id']);
|
$questgroupTexts = $this->Questgroups->getQuestgroupTexts($questgroup['id']);
|
||||||
|
|
||||||
// Get Character XPs
|
|
||||||
$questgroup['character_xps'] = $this->Questgroups->getAchievedXPsForQuestgroup($questgroup['id'], $character['id']);
|
|
||||||
|
|
||||||
// Media
|
// Media
|
||||||
$picture = null;
|
$picture = null;
|
||||||
if(!is_null($questgroup['questgroupspicture_id']))
|
if(!is_null($questgroup['questgroupspicture_id']))
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,8 @@
|
||||||
'seminary' => array('admin', 'moderator', 'user'),
|
'seminary' => array('admin', 'moderator', 'user'),
|
||||||
'create' => array('admin', 'moderator'),
|
'create' => array('admin', 'moderator'),
|
||||||
'edit' => array('admin', 'moderator', 'user'),
|
'edit' => array('admin', 'moderator', 'user'),
|
||||||
'delete' => array('admin', 'moderator', 'user')
|
'delete' => array('admin', 'moderator', 'user'),
|
||||||
|
'calculatexps' => array('admin', 'moderator', 'user')
|
||||||
);
|
);
|
||||||
/**
|
/**
|
||||||
* User seminary permissions
|
* User seminary permissions
|
||||||
|
|
@ -45,7 +46,8 @@
|
||||||
public $seminaryPermissions = array(
|
public $seminaryPermissions = array(
|
||||||
'seminary' => array('admin', 'moderator', 'user', 'guest'),
|
'seminary' => array('admin', 'moderator', 'user', 'guest'),
|
||||||
'edit' => array('admin'),
|
'edit' => array('admin'),
|
||||||
'delete' => array('admin')
|
'delete' => array('admin'),
|
||||||
|
'calculatexps' => array('admin', 'moderator')
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -134,10 +136,8 @@
|
||||||
$questgroup['text'] = \hhu\z\Utils::shortenString($text, 100, 120).' …';
|
$questgroup['text'] = \hhu\z\Utils::shortenString($text, 100, 120).' …';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get cumulated data
|
// Get Character XPs
|
||||||
$data = $this->Questgroups->getCumulatedDataForQuestgroup($questgroup['id'], $character['id']);
|
$questgroup['character_xps'] = $this->Questgroups->getAchievedXPsForQuestgroup($questgroup['id'], $character['id']);
|
||||||
$questgroup['xps'] = $data['xps'];
|
|
||||||
$questgroup['character_xps'] = $data['character_xps'];
|
|
||||||
|
|
||||||
// Get Media
|
// Get Media
|
||||||
$questgroup['picture'] = null;
|
$questgroup['picture'] = null;
|
||||||
|
|
@ -264,6 +264,38 @@
|
||||||
$this->set('seminary', $seminary);
|
$this->set('seminary', $seminary);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Action: calculatexps.
|
||||||
|
*
|
||||||
|
* (Re-) Calculate the amount of achievable XPs for a Seminary.
|
||||||
|
*
|
||||||
|
* @throws IdNotFoundException
|
||||||
|
* @param string $seminaryUrl URL-Title of a Seminary
|
||||||
|
*/
|
||||||
|
public function calculatexps($seminaryUrl)
|
||||||
|
{
|
||||||
|
// Get Seminary
|
||||||
|
$seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
|
||||||
|
|
||||||
|
// Questgrouphierarchy and Questgroups
|
||||||
|
$questgroupshierarchy = $this->Questgroupshierarchy->getHierarchyOfSeminary($seminary['id']);
|
||||||
|
foreach($questgroupshierarchy as &$hierarchy)
|
||||||
|
{
|
||||||
|
// Get Questgroups
|
||||||
|
$hierarchy['questgroups'] = $this->Questgroups->getQuestgroupsForHierarchy($hierarchy['id']);
|
||||||
|
foreach($hierarchy['questgroups'] as &$questgroup)
|
||||||
|
{
|
||||||
|
// Calculate achievable XPs
|
||||||
|
$this->Questgroups->calculateXPsForQuestgroup($questgroup['id']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Redirect to Questgroup
|
||||||
|
$this->redirect($this->linker->link(array('seminary', $seminary['url']), 1));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
|
||||||
Binary file not shown.
|
|
@ -1,8 +1,8 @@
|
||||||
msgid ""
|
msgid ""
|
||||||
msgstr ""
|
msgstr ""
|
||||||
"Project-Id-Version: The Legend of Z\n"
|
"Project-Id-Version: The Legend of Z\n"
|
||||||
"POT-Creation-Date: 2014-05-07 21:52+0100\n"
|
"POT-Creation-Date: 2014-05-15 18:15+0100\n"
|
||||||
"PO-Revision-Date: 2014-05-07 21:52+0100\n"
|
"PO-Revision-Date: 2014-05-15 18:15+0100\n"
|
||||||
"Last-Translator: \n"
|
"Last-Translator: \n"
|
||||||
"Language-Team: \n"
|
"Language-Team: \n"
|
||||||
"Language: de_DE\n"
|
"Language: de_DE\n"
|
||||||
|
|
@ -143,7 +143,7 @@ msgstr "Leider falsch!"
|
||||||
msgid "Error"
|
msgid "Error"
|
||||||
msgstr "Fehler"
|
msgstr "Fehler"
|
||||||
|
|
||||||
#: views/html/achievements/index.tpl:9 views/html/seminarymenu/index.tpl:5
|
#: views/html/achievements/index.tpl:9 views/html/seminarymenu/index.tpl:6
|
||||||
msgid "Achievements"
|
msgid "Achievements"
|
||||||
msgstr "Achievements"
|
msgstr "Achievements"
|
||||||
|
|
||||||
|
|
@ -193,7 +193,7 @@ msgstr "Persönlicher Fortschritt: %d%%"
|
||||||
#: views/html/achievements/index.tpl:58
|
#: views/html/achievements/index.tpl:58
|
||||||
#: views/html/charactergroups/group.tpl:32
|
#: views/html/charactergroups/group.tpl:32
|
||||||
#: views/html/charactergroups/managegroup.tpl:20
|
#: views/html/charactergroups/managegroup.tpl:20
|
||||||
#: views/html/characters/character.tpl:46 views/html/seminarybar/index.tpl:7
|
#: views/html/characters/character.tpl:46 views/html/seminarybar/index.tpl:8
|
||||||
msgid "Rank"
|
msgid "Rank"
|
||||||
msgstr "Platz"
|
msgstr "Platz"
|
||||||
|
|
||||||
|
|
@ -202,7 +202,7 @@ msgstr "Platz"
|
||||||
msgid "You achieved %d of %d Achievements so far"
|
msgid "You achieved %d of %d Achievements so far"
|
||||||
msgstr "Du hast bislang %d von insgesamt %d Achievements erreicht"
|
msgstr "Du hast bislang %d von insgesamt %d Achievements erreicht"
|
||||||
|
|
||||||
#: views/html/achievements/index.tpl:65 views/html/seminarybar/index.tpl:28
|
#: views/html/achievements/index.tpl:65 views/html/seminarybar/index.tpl:29
|
||||||
#, php-format
|
#, php-format
|
||||||
msgid "achieved at: %s"
|
msgid "achieved at: %s"
|
||||||
msgstr "erhalten am: %s"
|
msgstr "erhalten am: %s"
|
||||||
|
|
@ -226,7 +226,7 @@ msgstr "Spiele weiter, um diesen geheimen Erfolg freizuschalten"
|
||||||
#: views/html/charactergroupsquests/edit.tpl:8
|
#: views/html/charactergroupsquests/edit.tpl:8
|
||||||
#: views/html/charactergroupsquests/manage.tpl:8
|
#: views/html/charactergroupsquests/manage.tpl:8
|
||||||
#: views/html/charactergroupsquests/quest.tpl:8
|
#: views/html/charactergroupsquests/quest.tpl:8
|
||||||
#: views/html/characters/character.tpl:95 views/html/seminarymenu/index.tpl:4
|
#: views/html/characters/character.tpl:95 views/html/seminarymenu/index.tpl:5
|
||||||
msgid "Character Groups"
|
msgid "Character Groups"
|
||||||
msgstr "Gruppen"
|
msgstr "Gruppen"
|
||||||
|
|
||||||
|
|
@ -428,8 +428,8 @@ msgstr "%s-Gruppe verwalten"
|
||||||
#: views/html/characters/character.tpl:83
|
#: views/html/characters/character.tpl:83
|
||||||
#: views/html/characters/character.tpl:89
|
#: views/html/characters/character.tpl:89
|
||||||
#: views/html/characters/character.tpl:103 views/html/quests/index.tpl:37
|
#: views/html/characters/character.tpl:103 views/html/quests/index.tpl:37
|
||||||
#: views/html/seminaries/index.tpl:29 views/html/seminarybar/index.tpl:6
|
#: views/html/seminaries/index.tpl:29 views/html/seminarybar/index.tpl:7
|
||||||
#: views/html/seminarybar/index.tpl:42
|
#: views/html/seminarybar/index.tpl:43
|
||||||
#, php-format
|
#, php-format
|
||||||
msgid "%d XPs"
|
msgid "%d XPs"
|
||||||
msgstr "%d XP"
|
msgstr "%d XP"
|
||||||
|
|
@ -450,13 +450,13 @@ msgstr "Mitglied"
|
||||||
#: views/html/characters/character.tpl:13 views/html/characters/delete.tpl:10
|
#: views/html/characters/character.tpl:13 views/html/characters/delete.tpl:10
|
||||||
#: views/html/characters/edit.tpl:11 views/html/characters/edit.tpl:13
|
#: views/html/characters/edit.tpl:11 views/html/characters/edit.tpl:13
|
||||||
#: views/html/characters/index.tpl:9 views/html/characters/manage.tpl:8
|
#: views/html/characters/index.tpl:9 views/html/characters/manage.tpl:8
|
||||||
#: views/html/characters/register.tpl:8 views/html/seminarymenu/index.tpl:3
|
#: views/html/characters/register.tpl:8 views/html/seminarymenu/index.tpl:4
|
||||||
#: views/html/users/user.tpl:27
|
#: views/html/users/user.tpl:27
|
||||||
msgid "Characters"
|
msgid "Characters"
|
||||||
msgstr "Charaktere"
|
msgstr "Charaktere"
|
||||||
|
|
||||||
#: views/html/charactergroups/group.tpl:53
|
#: views/html/charactergroups/group.tpl:53
|
||||||
#: views/html/charactergroups/groupsgroup.tpl:35
|
#: views/html/charactergroups/groupsgroup.tpl:36
|
||||||
#, php-format
|
#, php-format
|
||||||
msgid "%s-Quests"
|
msgid "%s-Quests"
|
||||||
msgstr "%squests"
|
msgstr "%squests"
|
||||||
|
|
@ -476,7 +476,7 @@ msgstr "XP"
|
||||||
msgid "Create new %s Character group"
|
msgid "Create new %s Character group"
|
||||||
msgstr "Neue %s-Gruppe"
|
msgstr "Neue %s-Gruppe"
|
||||||
|
|
||||||
#: views/html/charactergroups/groupsgroup.tpl:38
|
#: views/html/charactergroups/groupsgroup.tpl:39
|
||||||
#, php-format
|
#, php-format
|
||||||
msgid "Create new %s-Quest"
|
msgid "Create new %s-Quest"
|
||||||
msgstr "Neue %s-Quest erstellen"
|
msgstr "Neue %s-Quest erstellen"
|
||||||
|
|
@ -664,7 +664,7 @@ msgstr "Fortschritt"
|
||||||
#: views/html/characters/character.tpl:38
|
#: views/html/characters/character.tpl:38
|
||||||
#: views/html/characters/character.tpl:77
|
#: views/html/characters/character.tpl:77
|
||||||
#: views/html/characters/character.tpl:83
|
#: views/html/characters/character.tpl:83
|
||||||
#: views/html/characters/character.tpl:89 views/html/seminarybar/index.tpl:42
|
#: views/html/characters/character.tpl:89 views/html/seminarybar/index.tpl:43
|
||||||
#: views/html/users/user.tpl:41
|
#: views/html/users/user.tpl:41
|
||||||
msgid "Level"
|
msgid "Level"
|
||||||
msgstr "Level"
|
msgstr "Level"
|
||||||
|
|
@ -677,7 +677,7 @@ msgstr "Meilensteine"
|
||||||
msgid "Ranking"
|
msgid "Ranking"
|
||||||
msgstr "Ranking"
|
msgstr "Ranking"
|
||||||
|
|
||||||
#: views/html/characters/character.tpl:112 views/html/seminarybar/index.tpl:14
|
#: views/html/characters/character.tpl:112 views/html/seminarybar/index.tpl:15
|
||||||
msgid "Last Quest"
|
msgid "Last Quest"
|
||||||
msgstr "Letzter Speicherpunkt"
|
msgstr "Letzter Speicherpunkt"
|
||||||
|
|
||||||
|
|
@ -843,7 +843,7 @@ msgid "Introduction"
|
||||||
msgstr "Einführung"
|
msgstr "Einführung"
|
||||||
|
|
||||||
#: views/html/library/index.tpl:9 views/html/library/topic.tpl:8
|
#: views/html/library/index.tpl:9 views/html/library/topic.tpl:8
|
||||||
#: views/html/seminarymenu/index.tpl:6
|
#: views/html/seminarymenu/index.tpl:7
|
||||||
msgid "Library"
|
msgid "Library"
|
||||||
msgstr "Bibliothek"
|
msgstr "Bibliothek"
|
||||||
|
|
||||||
|
|
@ -957,7 +957,7 @@ msgstr "Quest"
|
||||||
msgid "Go on"
|
msgid "Go on"
|
||||||
msgstr "Fortfahren"
|
msgstr "Fortfahren"
|
||||||
|
|
||||||
#: views/html/quests/quest.tpl:134 views/html/seminaries/seminary.tpl:35
|
#: views/html/quests/quest.tpl:134 views/html/seminaries/seminary.tpl:36
|
||||||
msgid "Let’s go"
|
msgid "Let’s go"
|
||||||
msgstr "Auf ins Abenteuer!"
|
msgstr "Auf ins Abenteuer!"
|
||||||
|
|
||||||
|
|
@ -1013,11 +1013,15 @@ msgstr "Dein Charakter „%s“ wurde noch nicht aktiviert"
|
||||||
msgid "Show Quests"
|
msgid "Show Quests"
|
||||||
msgstr "Quests anzeigen"
|
msgstr "Quests anzeigen"
|
||||||
|
|
||||||
#: views/html/seminarybar/index.tpl:21
|
#: views/html/seminaries/seminary.tpl:12
|
||||||
|
msgid "Recalculate XPs"
|
||||||
|
msgstr "XP neuberechnen"
|
||||||
|
|
||||||
|
#: views/html/seminarybar/index.tpl:22
|
||||||
msgid "Last Achievement"
|
msgid "Last Achievement"
|
||||||
msgstr "Letztes Achievement"
|
msgstr "Letztes Achievement"
|
||||||
|
|
||||||
#: views/html/seminarybar/index.tpl:46
|
#: views/html/seminarybar/index.tpl:47
|
||||||
#, php-format
|
#, php-format
|
||||||
msgid "Show %s-Profile"
|
msgid "Show %s-Profile"
|
||||||
msgstr "%s-Profil anzeigen"
|
msgstr "%s-Profil anzeigen"
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,7 @@
|
||||||
if(is_null($parentQuestgroupId))
|
if(is_null($parentQuestgroupId))
|
||||||
{
|
{
|
||||||
$questgroups = $this->db->query(
|
$questgroups = $this->db->query(
|
||||||
'SELECT questgroups.id, questgroups_questgroupshierarchy.questgroupshierarchy_id, questgroups_questgroupshierarchy.pos, questgroups.title, questgroups.url, questgroups.questgroupspicture_id '.
|
'SELECT questgroups.id, questgroups_questgroupshierarchy.questgroupshierarchy_id, questgroups_questgroupshierarchy.pos, questgroups.title, questgroups.url, questgroups.questgroupspicture_id, questgroups.achievable_xps '.
|
||||||
'FROM questgroups_questgroupshierarchy '.
|
'FROM questgroups_questgroupshierarchy '.
|
||||||
'INNER JOIN questgroups ON questgroups.id = questgroups_questgroupshierarchy.questgroup_id '.
|
'INNER JOIN questgroups ON questgroups.id = questgroups_questgroupshierarchy.questgroup_id '.
|
||||||
'WHERE questgroups_questgroupshierarchy.questgroupshierarchy_id = ? AND questgroups_questgroupshierarchy.parent_questgroup_id IS NULL '.
|
'WHERE questgroups_questgroupshierarchy.questgroupshierarchy_id = ? AND questgroups_questgroupshierarchy.parent_questgroup_id IS NULL '.
|
||||||
|
|
@ -73,7 +73,7 @@
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$questgroups = $this->db->query(
|
$questgroups = $this->db->query(
|
||||||
'SELECT questgroups.id, questgroups_questgroupshierarchy.questgroupshierarchy_id, questgroups_questgroupshierarchy.pos, questgroups.title, questgroups.url, questgroups.questgroupspicture_id '.
|
'SELECT questgroups.id, questgroups_questgroupshierarchy.questgroupshierarchy_id, questgroups_questgroupshierarchy.pos, questgroups.title, questgroups.url, questgroups.questgroupspicture_id, questgroups.achievable_xps '.
|
||||||
'FROM questgroups_questgroupshierarchy '.
|
'FROM questgroups_questgroupshierarchy '.
|
||||||
'INNER JOIN questgroups ON questgroups.id = questgroups_questgroupshierarchy.questgroup_id '.
|
'INNER JOIN questgroups ON questgroups.id = questgroups_questgroupshierarchy.questgroup_id '.
|
||||||
'WHERE questgroups_questgroupshierarchy.questgroupshierarchy_id = ? AND questgroups_questgroupshierarchy.parent_questgroup_id = ? '.
|
'WHERE questgroups_questgroupshierarchy.questgroupshierarchy_id = ? AND questgroups_questgroupshierarchy.parent_questgroup_id = ? '.
|
||||||
|
|
@ -98,7 +98,7 @@
|
||||||
public function getQuestgroupsForSeminary($seminaryId)
|
public function getQuestgroupsForSeminary($seminaryId)
|
||||||
{
|
{
|
||||||
return $this->db->query(
|
return $this->db->query(
|
||||||
'SELECT id, title, url '.
|
'SELECT id, title, url, achievable_xps '.
|
||||||
'FROM questgroups '.
|
'FROM questgroups '.
|
||||||
'WHERE seminary_id = ? '.
|
'WHERE seminary_id = ? '.
|
||||||
'ORDER BY title ASC',
|
'ORDER BY title ASC',
|
||||||
|
|
@ -118,7 +118,7 @@
|
||||||
public function getQuestgroupById($questgroupId)
|
public function getQuestgroupById($questgroupId)
|
||||||
{
|
{
|
||||||
$data = $this->db->query(
|
$data = $this->db->query(
|
||||||
'SELECT id, title, url, questgroupspicture_id '.
|
'SELECT id, title, url, questgroupspicture_id, achievable_xps '.
|
||||||
'FROM questgroups '.
|
'FROM questgroups '.
|
||||||
'WHERE questgroups.id = ?',
|
'WHERE questgroups.id = ?',
|
||||||
'i',
|
'i',
|
||||||
|
|
@ -144,7 +144,7 @@
|
||||||
public function getQuestgroupByUrl($seminaryId, $questgroupUrl)
|
public function getQuestgroupByUrl($seminaryId, $questgroupUrl)
|
||||||
{
|
{
|
||||||
$data = $this->db->query(
|
$data = $this->db->query(
|
||||||
'SELECT id, title, url, questgroupspicture_id '.
|
'SELECT id, title, url, questgroupspicture_id, achievable_xps '.
|
||||||
'FROM questgroups '.
|
'FROM questgroups '.
|
||||||
'WHERE seminary_id = ? AND url = ?',
|
'WHERE seminary_id = ? AND url = ?',
|
||||||
'is',
|
'is',
|
||||||
|
|
@ -428,113 +428,6 @@
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculate cumulated data for a Questgroup, its
|
|
||||||
* sub-Questgroups and all its Quests.
|
|
||||||
*
|
|
||||||
* @param int $questgroupId ID of Questgroup
|
|
||||||
* @param int $characterId ID of Character
|
|
||||||
* @param array $calculatedQuests IDs of already calculated Quests
|
|
||||||
* @return array Cumulated data for Questgroup
|
|
||||||
*/
|
|
||||||
public function getCumulatedDataForQuestgroup($questgroupId, $characterId=null, &$calculatedQuests=array())
|
|
||||||
{
|
|
||||||
// Cumulated data
|
|
||||||
$data = array(
|
|
||||||
'xps' => 0,
|
|
||||||
'character_xps' => 0
|
|
||||||
);
|
|
||||||
|
|
||||||
// Current Questgroup
|
|
||||||
$questgroup = $this->getQuestgroupById($questgroupId);
|
|
||||||
|
|
||||||
// Quests of current Questgroup
|
|
||||||
$quest = $this->Quests->getFirstQuestOfQuestgroup($questgroup['id']);
|
|
||||||
if(!is_null($quest))
|
|
||||||
{
|
|
||||||
$questData = $this->getCumulatedDataForQuest($quest, $characterId, $calculatedQuests);
|
|
||||||
$data['xps'] += $questData['xps'];
|
|
||||||
$data['character_xps'] += $questData['character_xps'];
|
|
||||||
}
|
|
||||||
|
|
||||||
// XPs of child Questgroups
|
|
||||||
$questgroupHierarchy = $this->Questgroupshierarchy->getHierarchyForQuestgroup($questgroup['id']);
|
|
||||||
if(!empty($questgroupHierarchy))
|
|
||||||
{
|
|
||||||
$childQuestgroupshierarchy = $this->Questgroupshierarchy->getChildQuestgroupshierarchy($questgroupHierarchy['id']);
|
|
||||||
foreach($childQuestgroupshierarchy as &$hierarchy)
|
|
||||||
{
|
|
||||||
$questgroups = $this->getQuestgroupsForHierarchy($hierarchy['id'], $questgroup['id']);
|
|
||||||
foreach($questgroups as &$questgroup)
|
|
||||||
{
|
|
||||||
$childData = $this->getCumulatedDataForQuestgroup($questgroup['id'], $characterId, $calculatedQuests);
|
|
||||||
$data['xps'] += $childData['xps'];
|
|
||||||
$data['character_xps'] += $childData['character_xps'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Return cumulated data
|
|
||||||
return $data;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Calculate cumulated data of the given Quest, its following
|
|
||||||
* Quests and its related Questgroups.
|
|
||||||
*
|
|
||||||
* @param array $quest Quest data
|
|
||||||
* @param int $characterId ID of Character
|
|
||||||
* @param array $calculatedQuests IDs of already calculated Quests
|
|
||||||
* @return array Cumulated data for Quest
|
|
||||||
*/
|
|
||||||
public function getCumulatedDataForQuest($quest, $characterId=null, &$calculatedQuests=array())
|
|
||||||
{
|
|
||||||
// Cumulated data
|
|
||||||
$data = array(
|
|
||||||
'xps' => $quest['xps'],
|
|
||||||
'character_xps' => (!is_null($characterId) && $this->Quests->hasCharacterSolvedQuest($quest['id'], $characterId)) ? $quest['xps'] : 0
|
|
||||||
);
|
|
||||||
|
|
||||||
// Related Questgroups
|
|
||||||
$relatedQuestgroups = $this->getRelatedQuestsgroupsOfQuest($quest['id']);
|
|
||||||
foreach($relatedQuestgroups as &$relatedQuestgroup)
|
|
||||||
{
|
|
||||||
$relatedData = $this->getCumulatedDataForQuestgroup($relatedQuestgroup['id'], $characterId, $calculatedQuests);
|
|
||||||
$data['xps'] += $relatedData['xps'];
|
|
||||||
$data['character_xps'] += $relatedData['character_xps'];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Next Quests
|
|
||||||
$nextQuests = $this->Quests->getNextQuests($quest['id']);
|
|
||||||
$allNextData = array(
|
|
||||||
'xps' => array(0),
|
|
||||||
'character_xps' => array(0),
|
|
||||||
);
|
|
||||||
foreach($nextQuests as &$nextQuest)
|
|
||||||
{
|
|
||||||
if(!array_key_exists($nextQuest['id'], $calculatedQuests))
|
|
||||||
{
|
|
||||||
$nextData = $this->getCumulatedDataForQuest($nextQuest, $characterId, $calculatedQuests);
|
|
||||||
$calculatedQuests[$nextQuest['id']] = array(
|
|
||||||
'xps' => $nextData['xps'],
|
|
||||||
'character_xps' => $nextData['character_xps']
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
$allNextData['xps'][] = $calculatedQuests[$nextQuest['id']]['xps'];
|
|
||||||
$allNextData['character_xps'][] = $calculatedQuests[$nextQuest['id']]['character_xps'];
|
|
||||||
}
|
|
||||||
$data['xps'] += max($allNextData['xps']);
|
|
||||||
$data['character_xps'] += max($allNextData['character_xps']);
|
|
||||||
|
|
||||||
|
|
||||||
// Return cumulated data
|
|
||||||
return $data;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Summarize XPs of all Quests for a Questgroup and its
|
* Summarize XPs of all Quests for a Questgroup and its
|
||||||
* sub-Questgroups solved by a Character.
|
* sub-Questgroups solved by a Character.
|
||||||
*
|
*
|
||||||
|
|
@ -544,75 +437,29 @@
|
||||||
*/
|
*/
|
||||||
public function getAchievedXPsForQuestgroup($questgroupId, $characterId)
|
public function getAchievedXPsForQuestgroup($questgroupId, $characterId)
|
||||||
{
|
{
|
||||||
// Sum of XPs
|
// Questgroup
|
||||||
$xps = 0;
|
$xps = $this->_getAchievedXPsForQuestgroup($questgroupId, $characterId);
|
||||||
|
|
||||||
// Current Questgroup
|
// Related Questgroups
|
||||||
$questgroup = $this->getQuestgroupById($questgroupId);
|
foreach($this->getRelatedQuestsgroupsOfQuestgroup($questgroupId) as $relatedQuestgroup) {
|
||||||
|
$xps += $this->getAchievedXPsForQuestgroup($relatedQuestgroup['id'], $characterId);
|
||||||
// Quests of current Questgroup
|
|
||||||
$quest = $this->Quests->getFirstQuestOfQuestgroup($questgroup['id']);
|
|
||||||
if(!is_null($quest)) {
|
|
||||||
$xps += $this->getAchievedXPsForQuest($quest, $characterId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// XPs of child Questgroups
|
// XPs of child Questgroups
|
||||||
$questgroupHierarchy = $this->Questgroupshierarchy->getHierarchyForQuestgroup($questgroup['id']);
|
$questgroupHierarchy = $this->Questgroupshierarchy->getHierarchyForQuestgroup($questgroupId);
|
||||||
if(empty($questgroupHierarchy)) {
|
if(!empty($questgroupHierarchy))
|
||||||
return $xps;
|
|
||||||
}
|
|
||||||
$childQuestgroupshierarchy = $this->Questgroupshierarchy->getChildQuestgroupshierarchy($questgroupHierarchy['id']);
|
|
||||||
foreach($childQuestgroupshierarchy as &$hierarchy)
|
|
||||||
{
|
{
|
||||||
$questgroups = $this->getQuestgroupsForHierarchy($hierarchy['id'], $questgroup['id']);
|
$childQuestgroupshierarchy = $this->Questgroupshierarchy->getChildQuestgroupshierarchy($questgroupHierarchy['id']);
|
||||||
foreach($questgroups as &$questgroup) {
|
foreach($childQuestgroupshierarchy as &$hierarchy)
|
||||||
$xps += $this->getAchievedXPsForQuestgroup($questgroup['id'], $characterId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Return summarized XPs
|
|
||||||
return $xps;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Summarize XPs of the given Quest, its following Quests and
|
|
||||||
* its related Questgroups solved by a Character.
|
|
||||||
*
|
|
||||||
* @param int $quest Quest to summarize XPs for
|
|
||||||
* @param int $characterId ID of Character
|
|
||||||
* @return int Sum of XPs
|
|
||||||
*/
|
|
||||||
public function getAchievedXPsForQuest($quest, $characterId)
|
|
||||||
{
|
|
||||||
$xps = 0;
|
|
||||||
|
|
||||||
// XPs for the given Quest
|
|
||||||
if($this->Quests->hasCharacterSolvedQuest($quest['id'], $characterId))
|
|
||||||
{
|
|
||||||
$xps += $quest['xps'];
|
|
||||||
|
|
||||||
// Next Quests
|
|
||||||
$nextQuests = $this->Quests->getNextQuests($quest['id']);
|
|
||||||
foreach($nextQuests as &$nextQuest)
|
|
||||||
{
|
{
|
||||||
if($this->Quests->hasCharacterEnteredQuest($nextQuest['id'], $characterId))
|
$childQuestgroups = $this->getQuestgroupsForHierarchy($hierarchy['id'], $questgroupId);
|
||||||
{
|
foreach($childQuestgroups as &$childQuestgroup) {
|
||||||
$xps += $this->getAchievedXPsForQuest($nextQuest, $characterId);
|
$xps += $this->getAchievedXPsForQuestgroup($childQuestgroup['id'], $characterId);
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Related Questgroups
|
|
||||||
$relatedQuestgroups = $this->getRelatedQuestsgroupsOfQuest($quest['id']);
|
|
||||||
foreach($relatedQuestgroups as &$relatedQuestgroup) {
|
|
||||||
$xps += $this->getAchievedXPsForQuestgroup($relatedQuestgroup['id'], $characterId);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Return summarized XPs
|
|
||||||
return $xps;
|
return $xps;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -766,6 +613,130 @@
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calculate the total amount of achievable XPs for a
|
||||||
|
* Questgroup, its sub-Questgroups, related Questgroups etc. and
|
||||||
|
* store this value in the database.
|
||||||
|
*
|
||||||
|
* @param int $questgroupId ID of Questgroup
|
||||||
|
* @param array $calculatedQuests Already calculated Quests
|
||||||
|
* @return int Sum of calculated XPs
|
||||||
|
*/
|
||||||
|
public function calculateXPsForQuestgroup($questgroupId, &$calculatedQuests=array())
|
||||||
|
{
|
||||||
|
$xps = 0;
|
||||||
|
|
||||||
|
// Quests
|
||||||
|
$quest = $this->Quests->getFirstQuestOfQuestgroup($questgroupId);
|
||||||
|
if(!is_null($quest)) {
|
||||||
|
$xps = $this->_calculateXPsForQuestgroup($quest);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Child Questgroups
|
||||||
|
$questgroupHierarchy = $this->Questgroupshierarchy->getHierarchyForQuestgroup($questgroupId);
|
||||||
|
if(!empty($questgroupHierarchy))
|
||||||
|
{
|
||||||
|
$childQuestgroupshierarchy = $this->Questgroupshierarchy->getChildQuestgroupshierarchy($questgroupHierarchy['id']);
|
||||||
|
foreach($childQuestgroupshierarchy as &$hierarchy)
|
||||||
|
{
|
||||||
|
$questgroups = $this->getQuestgroupsForHierarchy($hierarchy['id'], $questgroupId);
|
||||||
|
foreach($questgroups as &$questgroup) {
|
||||||
|
$xps += $this->calculateXPsForQuestgroup($questgroup['id'], $calculatedQuests);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save XPs
|
||||||
|
$this->setXPsForQuestgroup($questgroupId, $xps);
|
||||||
|
|
||||||
|
|
||||||
|
return $xps;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the sum of XPs of Quests for a Questgroup solved by a
|
||||||
|
* Character.
|
||||||
|
*
|
||||||
|
* @param int $questgroupId ID of Questgroup
|
||||||
|
* @param int $characterId ID of Character
|
||||||
|
* @return int Sum of XPs of Quests
|
||||||
|
*/
|
||||||
|
private function _getAchievedXPsForQuestgroup($questgroupId, $characterId)
|
||||||
|
{
|
||||||
|
$data = $this->db->query(
|
||||||
|
'SELECT COALESCE(SUM(quests.xps),0) AS xps '.
|
||||||
|
'FROM quests '.
|
||||||
|
'INNER JOIN quests_characters ON quests_characters.quest_id = quests.id AND quests_characters.character_id = ? AND quests_characters.status = ? '.
|
||||||
|
'WHERE quests.questgroup_id = ?',
|
||||||
|
'iii',
|
||||||
|
$characterId,
|
||||||
|
\hhu\z\models\QuestsModel::QUEST_STATUS_SOLVED,
|
||||||
|
$questgroupId
|
||||||
|
);
|
||||||
|
if(!empty($data)) {
|
||||||
|
return $data[0]['xps'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Calculate the total amount of achievable XPs for a Quest and
|
||||||
|
* its following Quests by choosing the path with the highest
|
||||||
|
* amount of XPs.
|
||||||
|
*
|
||||||
|
* @param int $quest Quest data
|
||||||
|
* @param array $calculatedQuests Already calculated Quests
|
||||||
|
* @return int Sum of calculated XPs
|
||||||
|
*/
|
||||||
|
private function _calculateXPsForQuestgroup($quest, &$calculatedQuests=array())
|
||||||
|
{
|
||||||
|
$xps = $quest['xps'];
|
||||||
|
|
||||||
|
// Related Questgroups
|
||||||
|
$relatedQuestgroups = $this->getRelatedQuestsgroupsOfQuest($quest['id']);
|
||||||
|
foreach($relatedQuestgroups as &$relatedQuestgroup) {
|
||||||
|
$xps += $this->calculateXPsForQuestgroup($relatedQuestgroup['id'], $calculatedQuests);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Next Quests
|
||||||
|
$nextQuests = $this->Quests->getNextQuests($quest['id']);
|
||||||
|
$allNextXPs = array(0);
|
||||||
|
foreach($nextQuests as &$nextQuest)
|
||||||
|
{
|
||||||
|
if(!array_key_exists($nextQuest['id'], $calculatedQuests)) {
|
||||||
|
$calculatedQuests[$nextQuest['id']] = $this->_calculateXPsForQuestgroup($nextQuest, $calculatedQuests);
|
||||||
|
}
|
||||||
|
$allNextXPs[] = $calculatedQuests[$nextQuest['id']];
|
||||||
|
}
|
||||||
|
$xps += max($allNextXPs);
|
||||||
|
|
||||||
|
|
||||||
|
return $xps;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set achievable XPs for a Questgroup.
|
||||||
|
*
|
||||||
|
* @param int $questgroupId ID of Questgroup
|
||||||
|
* @param int $xps XPs to set
|
||||||
|
*/
|
||||||
|
private function setXPsForQuestgroup($questgroupId, $xps)
|
||||||
|
{
|
||||||
|
$this->db->query(
|
||||||
|
'UPDATE questgroups '.
|
||||||
|
'SET achievable_xps = ? '.
|
||||||
|
'WHERE id = ?',
|
||||||
|
'ii',
|
||||||
|
$xps,
|
||||||
|
$questgroupId
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
|
||||||
|
|
@ -122,10 +122,8 @@
|
||||||
{
|
{
|
||||||
// Get Questgroups
|
// Get Questgroups
|
||||||
$questgroups = $this->Questgroups->getQuestgroupsForHierarchy($hierarchy['id']);
|
$questgroups = $this->Questgroups->getQuestgroupsForHierarchy($hierarchy['id']);
|
||||||
foreach($questgroups as &$questgroup)
|
foreach($questgroups as &$questgroup) {
|
||||||
{
|
$xps += $questgroup['achievable_xps'];
|
||||||
$data = $this->Questgroups->getCumulatedDataForQuestgroup($questgroup['id']);
|
|
||||||
$xps += $data['xps'];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -36,9 +36,9 @@
|
||||||
<div class="qgprogress cf">
|
<div class="qgprogress cf">
|
||||||
<p class="xpinfo">Fortschritt:</p>
|
<p class="xpinfo">Fortschritt:</p>
|
||||||
<div class="xpbar">
|
<div class="xpbar">
|
||||||
<span style="width:<?=round($group['character_xps']/$group['xps']*100)?>%"></span>
|
<span style="width:<?=round($group['character_xps']/$group['achievable_xps']*100)?>%"></span>
|
||||||
</div>
|
</div>
|
||||||
<p class="xpnumeric"><?=$group['character_xps']?> / <?=$group['xps']?> XP</p>
|
<p class="xpnumeric"><?=$group['character_xps']?> / <?=$group['achievable_xps']?> XP</p>
|
||||||
</div>
|
</div>
|
||||||
<?php foreach($group['relatedQuestgroups'] as &$relatedGroup) : ?>
|
<?php foreach($group['relatedQuestgroups'] as &$relatedGroup) : ?>
|
||||||
<div class="qghidden">
|
<div class="qghidden">
|
||||||
|
|
|
||||||
0
views/html/seminaries/calculatexps.tpl
Normal file
0
views/html/seminaries/calculatexps.tpl
Normal file
|
|
@ -9,6 +9,7 @@
|
||||||
<?php if(in_array('admin', \hhu\z\controllers\SeminaryController::$character['characterroles'])) : ?><li><a href="<?=$linker->link('edit', 3)?>"><?=_('Edit seminary')?></a></li><?php endif ?>
|
<?php if(in_array('admin', \hhu\z\controllers\SeminaryController::$character['characterroles'])) : ?><li><a href="<?=$linker->link('edit', 3)?>"><?=_('Edit seminary')?></a></li><?php endif ?>
|
||||||
<?php if(in_array('admin', \hhu\z\controllers\SeminaryController::$character['characterroles'])) : ?><li><a href="<?=$linker->link('delete', 3)?>"><?=_('Delete seminary')?></a></li><?php endif ?>
|
<?php if(in_array('admin', \hhu\z\controllers\SeminaryController::$character['characterroles'])) : ?><li><a href="<?=$linker->link('delete', 3)?>"><?=_('Delete seminary')?></a></li><?php endif ?>
|
||||||
<?php if(count(array_intersect(array('admin','moderator'), \hhu\z\controllers\SeminaryController::$character['characterroles'])) > 0) : ?><li><a href="<?=$linker->link(array('quests','index',$seminary['url']))?>"><?=_('Show Quests')?></a></li><?php endif ?>
|
<?php if(count(array_intersect(array('admin','moderator'), \hhu\z\controllers\SeminaryController::$character['characterroles'])) > 0) : ?><li><a href="<?=$linker->link(array('quests','index',$seminary['url']))?>"><?=_('Show Quests')?></a></li><?php endif ?>
|
||||||
|
<?php if(count(array_intersect(array('admin','moderator'), \hhu\z\controllers\SeminaryController::$character['characterroles'])) > 0) : ?><li><a href="<?=$linker->link(array('calculatexps',$seminary['url']),1)?>"><?=_('Recalculate XPs')?></a></li><?php endif ?>
|
||||||
</nav>
|
</nav>
|
||||||
<?php endif ?>
|
<?php endif ?>
|
||||||
<p><?=\hhu\z\Utils::t($seminary['description'])?></p>
|
<p><?=\hhu\z\Utils::t($seminary['description'])?></p>
|
||||||
|
|
@ -25,9 +26,9 @@
|
||||||
<a href="<?=$linker->link(array('questgroups','questgroup',$seminary['url'],$group['url']))?>"><?=$group['title']?></a></p>
|
<a href="<?=$linker->link(array('questgroups','questgroup',$seminary['url'],$group['url']))?>"><?=$group['title']?></a></p>
|
||||||
<div class="cf">
|
<div class="cf">
|
||||||
<div class="xpbar">
|
<div class="xpbar">
|
||||||
<span style="width:<?=round($group['character_xps']*100/$group['xps'])?>%"></span>
|
<span style="width:<?=round($group['character_xps']*100/$group['achievable_xps'])?>%"></span>
|
||||||
</div>
|
</div>
|
||||||
<p class="xpnumeric"><?=$group['character_xps']?> / <?=$group['xps']?> XP</p>
|
<p class="xpnumeric"><?=$group['character_xps']?> / <?=$group['achievable_xps']?> XP</p>
|
||||||
</div>
|
</div>
|
||||||
<?php if(array_key_exists('text', $group)) : ?>
|
<?php if(array_key_exists('text', $group)) : ?>
|
||||||
<p><?=$group['text']?></p>
|
<p><?=$group['text']?></p>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue