Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
33.33% |
25 / 75 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| AchievementsController | |
32.43% |
24 / 74 |
|
0.00% |
0 / 2 |
157.04 | |
0.00% |
0 / 1 |
| index | |
85.71% |
24 / 28 |
|
0.00% |
0 / 1 |
8.19 | |||
| view | |
0.00% |
0 / 46 |
|
0.00% |
0 / 1 |
182 | |||
| 1 | <?php |
| 2 | |
| 3 | App::uses('NotFoundException', 'Routing/Error'); |
| 4 | |
| 5 | class AchievementsController extends AppController |
| 6 | { |
| 7 | /** |
| 8 | * @return void |
| 9 | */ |
| 10 | public function index() |
| 11 | { |
| 12 | $this->set('_page', 'user'); |
| 13 | $this->set('_title', 'Tsumego Hero - Achievements'); |
| 14 | $this->loadModel('AchievementStatus'); |
| 15 | $existingAs = []; |
| 16 | $unlockedCounter2 = 0; |
| 17 | |
| 18 | $a = $this->Achievement->find('all', ['order' => 'order ASC']); |
| 19 | if (!$a) |
| 20 | $a = []; |
| 21 | |
| 22 | if (Auth::isLoggedIn()) |
| 23 | { |
| 24 | $as = $this->AchievementStatus->find('all', ['conditions' => ['user_id' => Auth::getUserID()]]); |
| 25 | if (!$as) |
| 26 | $as = []; |
| 27 | |
| 28 | foreach ($as as $item) |
| 29 | $existingAs[$item['AchievementStatus']['achievement_id']] = $item; |
| 30 | } |
| 31 | |
| 32 | $aCount = count($a); |
| 33 | for ($i = 0; $i < $aCount; $i++) |
| 34 | { |
| 35 | $a[$i]['Achievement']['unlocked'] = false; |
| 36 | $a[$i]['Achievement']['created'] = ''; |
| 37 | if (isset($existingAs[$a[$i]['Achievement']['id']])) |
| 38 | { |
| 39 | if ($a[$i]['Achievement']['id'] == 46) |
| 40 | { |
| 41 | $a[$i]['Achievement']['a46value'] = $existingAs[$a[$i]['Achievement']['id']]['AchievementStatus']['value']; |
| 42 | $unlockedCounter2 = $existingAs[$a[$i]['Achievement']['id']]['AchievementStatus']['value'] - 1; |
| 43 | } |
| 44 | $a[$i]['Achievement']['unlocked'] = true; |
| 45 | $a[$i]['Achievement']['created'] = $existingAs[$a[$i]['Achievement']['id']]['AchievementStatus']['created']; |
| 46 | $date = date_create($a[$i]['Achievement']['created']); |
| 47 | $a[$i]['Achievement']['created'] = date_format($date, 'd.m.Y H:i'); |
| 48 | } |
| 49 | } |
| 50 | $this->set('a', $a); |
| 51 | $this->set('unlockedCounter2', $unlockedCounter2); |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * @param string|int|null $id |
| 56 | * @return void |
| 57 | */ |
| 58 | public function view($id = null) |
| 59 | { |
| 60 | $this->set('_page', 'user'); |
| 61 | $this->set('_title', 'Tsumego Hero - Achievements'); |
| 62 | $this->loadModel('AchievementCondition'); |
| 63 | $this->loadModel('AchievementStatus'); |
| 64 | $this->loadModel('User'); |
| 65 | $a = $this->Achievement->findById($id); |
| 66 | if (!$a) |
| 67 | throw new NotFoundException('Achievement not found'); |
| 68 | |
| 69 | $as = []; |
| 70 | $asAll = $this->AchievementStatus->find('all', ['order' => 'created DESC', 'conditions' => ['achievement_id' => $id]]); |
| 71 | if (!$asAll) |
| 72 | $asAll = []; |
| 73 | $aCount = count($asAll); |
| 74 | if (Auth::isLoggedIn()) |
| 75 | $as = $this->AchievementStatus->find('first', ['conditions' => ['achievement_id' => $id, 'user_id' => Auth::getUserID()]]); |
| 76 | if ($as) |
| 77 | { |
| 78 | $date = date_create($as['AchievementStatus']['created']); |
| 79 | $as['AchievementStatus']['created'] = date_format($date, 'd.m.Y H:i'); |
| 80 | } |
| 81 | $asAll2 = []; |
| 82 | $count = 10; |
| 83 | if (count($asAll) < 10) |
| 84 | $count = count($asAll); |
| 85 | if (count($asAll) > 10) |
| 86 | $andMore = ' and more.'; |
| 87 | else |
| 88 | $andMore = '.'; |
| 89 | for ($i = 0; $i < $count; $i++) |
| 90 | { |
| 91 | $u = $this->User->findById($asAll[$i]['AchievementStatus']['user_id']); |
| 92 | $asAll[$i]['AchievementStatus']['name'] = $this->checkPicture($u); |
| 93 | $asAll2[] = $asAll[$i]; |
| 94 | } |
| 95 | $asAll = $asAll2; |
| 96 | |
| 97 | if (Auth::isLoggedIn()) |
| 98 | { |
| 99 | $acGolden = $this->AchievementCondition->find('all', ['conditions' => ['user_id' => Auth::getUserID(), 'category' => 'golden']]); |
| 100 | if (!$acGolden) |
| 101 | $acGolden = []; |
| 102 | if (count($acGolden) == 0) |
| 103 | $acGoldenCount = 0; |
| 104 | else |
| 105 | $acGoldenCount = $acGolden[0]['AchievementCondition']['value']; |
| 106 | if ($as) |
| 107 | $acGoldenCount = 10; |
| 108 | if ($a['Achievement']['id'] == 97) |
| 109 | $a['Achievement']['additionalDescription'] = 'Progress: ' . $acGoldenCount . '/10'; |
| 110 | } |
| 111 | |
| 112 | $this->set('a', $a); |
| 113 | $this->set('as', $as); |
| 114 | $this->set('asAll', $asAll); |
| 115 | $this->set('aCount', $aCount); |
| 116 | $this->set('andMore', $andMore); |
| 117 | } |
| 118 | |
| 119 | } |