Skwoat /
ramverk-kmom10
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Seb\Home; |
||
| 4 | |||
| 5 | /** |
||
| 6 | * A sample controller to show how a controller class can be implemented. |
||
| 7 | */ |
||
| 8 | class HomeModel |
||
| 9 | { |
||
| 10 | |||
| 11 | /** |
||
| 12 | * Show all items. |
||
| 13 | * |
||
| 14 | * @return object as a response object |
||
| 15 | */ |
||
| 16 | 2 | public function recentTopics($topics) |
|
| 17 | { |
||
| 18 | 2 | $arrayRes = []; |
|
| 19 | 2 | foreach (array_reverse($topics) as $q) { |
|
| 20 | 2 | if (count($topics)-3 < $q->id) { |
|
| 21 | 2 | array_push($arrayRes, $q->topic); |
|
| 22 | } |
||
| 23 | } |
||
| 24 | 2 | return $arrayRes; |
|
| 25 | } |
||
| 26 | |||
| 27 | /** |
||
| 28 | * Show all items. |
||
| 29 | * |
||
| 30 | * @return object as a response object |
||
| 31 | */ |
||
| 32 | 2 | public function topUsers($users) |
|
| 33 | { |
||
| 34 | 2 | $arrayRes = []; |
|
| 35 | 2 | $array = []; |
|
|
0 ignored issues
–
show
Unused Code
introduced
by
Loading history...
|
|||
| 36 | 2 | foreach ($users as $u) { |
|
| 37 | 2 | $arrayRes[$u->acronym] = $u->score; |
|
| 38 | } |
||
| 39 | 2 | arsort($arrayRes); |
|
| 40 | 2 | $array = array_slice($arrayRes, 0, 3); |
|
| 41 | 2 | return $array; |
|
|
0 ignored issues
–
show
|
|||
| 42 | } |
||
| 43 | |||
| 44 | /** |
||
| 45 | * Show all items. |
||
| 46 | * |
||
| 47 | * @return object as a response object |
||
| 48 | */ |
||
| 49 | 2 | public function topTags($tags, $questions) |
|
| 50 | { |
||
| 51 | 2 | $arrayRes = []; |
|
| 52 | 2 | $tagFrequency = 0; |
|
|
0 ignored issues
–
show
|
|||
| 53 | 2 | foreach ($tags as $tag) { |
|
| 54 | 2 | $tagFrequency = 0; |
|
| 55 | 2 | foreach ($questions as $q) { |
|
| 56 | 2 | if ($tag->tag == $q->tag1 || $tag->tag == $q->tag2 || $tag->tag == $q->tag3) { |
|
| 57 | 2 | $tagFrequency += 1; |
|
| 58 | } |
||
| 59 | } |
||
| 60 | 2 | if ($tagFrequency == !0) { |
|
| 61 | 2 | $arrayRes[$tag->tag] = $tagFrequency; |
|
| 62 | } |
||
| 63 | } |
||
| 64 | 2 | arsort($arrayRes); |
|
| 65 | 2 | $arrayRes = array_slice($arrayRes, 0, 3); |
|
| 66 | 2 | return $arrayRes; |
|
|
0 ignored issues
–
show
|
|||
| 67 | } |
||
| 68 | } |
||
| 69 |