correctly set Achievements count (Issue #286)
This commit is contained in:
parent
bca58c4c61
commit
67af12a3cf
3 changed files with 41 additions and 7 deletions
|
|
@ -70,8 +70,11 @@
|
|||
// Get Characters with the most Achievements
|
||||
$successfulCharacters = $this->Characters->getCharactersWithMostAchievements($seminary['id'], \nre\configs\AppConfig::$misc['achievements_range'], false);
|
||||
|
||||
// Get total count of Achievements for Seminary
|
||||
$achievementsCount = $this->Achievements->getAchievementsCountForSeminary($seminary['id'], false);
|
||||
|
||||
// Get achieved Achievements
|
||||
$achievedAchievements = $this->Achievements->getAchievedAchievementsForCharacter($character['id'], false);
|
||||
$achievedAchievements = $this->Achievements->getAchievedAchievementsForCharacter($character['id']);
|
||||
|
||||
// Get unachieved Achievements
|
||||
$unachievedAchievements = array_merge(
|
||||
|
|
@ -176,6 +179,7 @@
|
|||
$this->set('character', $character);
|
||||
$this->set('seldomAchievements', $seldomAchievements);
|
||||
$this->set('successfulCharacters', $successfulCharacters);
|
||||
$this->set('achievementsCount', $achievementsCount);
|
||||
$this->set('achievedAchievements', $achievedAchievements);
|
||||
$this->set('unachievedAchievements', $unachievedAchievements);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -156,9 +156,11 @@
|
|||
/**
|
||||
* Get all not yet achieved Achievements for a Character.
|
||||
*
|
||||
* @param int $seminaryId ID of Seminary
|
||||
* @param int $characterId ID of Character
|
||||
* @return array Achievements data
|
||||
* @param int $seminaryId ID of Seminary
|
||||
* @param int $characterId ID of Character
|
||||
* @param boolean $includeOnlyOnce Include Achievements that can only be achieved by one Character
|
||||
* @param boolean $alsoWithDeadline Include milestone Achievements
|
||||
* @return array Achievements data
|
||||
*/
|
||||
public function getUnachhievedAchievementsForCharacter($seminaryId, $characterId, $includeOnlyOnce=false, $alsoWithDeadline=true)
|
||||
{
|
||||
|
|
@ -183,6 +185,34 @@
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the amount of Achievement for a Seminary.
|
||||
*
|
||||
* @param int $seminaryId ID of Seminary
|
||||
* @param boolean $includeOnlyOnce Include Achievements that can only be achieved by one Character
|
||||
* @param boolean $alsoWithDeadline Include milestone Achievements
|
||||
* @return int Count of Achievements
|
||||
*/
|
||||
public function getAchievementsCountForSeminary($seminaryId, $includeOnlyOnce=false, $alsoWithDeadline=true)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT count(id) AS c '.
|
||||
'FROM achievements '.
|
||||
'WHERE seminary_id = ? AND only_once <= ?'.
|
||||
(!$alsoWithDeadline ? ' AND achievements.deadline IS NULL ' : null),
|
||||
'ii',
|
||||
$seminaryId,
|
||||
$includeOnlyOnce
|
||||
);
|
||||
if(!empty($data)) {
|
||||
return $data[0]['c'];
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the rank for the number of achieved Achievements.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -50,12 +50,12 @@
|
|||
</div>
|
||||
<h2><?=_('Personal Achievements')?></h2>
|
||||
<div class="libindxpr cf">
|
||||
<p><small><?=sprintf(_('Own progress: %d %%'), round(count($achievedAchievements) / (count($achievedAchievements)+count($unachievedAchievements)) * 100))?></small></p>
|
||||
<p><small><?=sprintf(_('Own progress: %d %%'), round(count($achievedAchievements) / $achievementsCount * 100))?></small></p>
|
||||
<div class="xpbar">
|
||||
<span style="width:<?=round(count($achievedAchievements) / (count($achievedAchievements)+count($unachievedAchievements)) * 100)?>%"></span>
|
||||
<span style="width:<?=round(count($achievedAchievements) / $achievementsCount * 100)?>%"></span>
|
||||
</div>
|
||||
</div>
|
||||
<p><small><b><?=$character['rank']?>. <?=_('Rank')?>:</b> <?=sprintf(_('You achieved %d of %d Achievements so far'), count($achievedAchievements), count($achievedAchievements)+count($unachievedAchievements))?>.</small></p>
|
||||
<p><small><b><?=$character['rank']?>. <?=_('Rank')?>:</b> <?=sprintf(_('You achieved %d of %d Achievements so far'), count($achievedAchievements), $achievementsCount)?>.</small></p>
|
||||
<ul class="achmnts">
|
||||
<?php foreach($achievedAchievements as &$achievement) : ?>
|
||||
<li class="cf">
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue