SHOW:
|
|
- or go back to the newest paste.
1 | <?php | |
2 | class myClass { | |
3 | ||
4 | private $tids=array(); | |
5 | public $active_topics=array(); | |
6 | ||
7 | public function __construct() {/* removed irrelevant code */} | |
8 | ||
9 | public function getTopicsScore($topics=false,$params=array()) { | |
10 | ||
11 | // removed irrelevant code | |
12 | $results = $this->getScores($this->tids,$params); | |
13 | $start = microtime(true); | |
14 | ||
15 | foreach($results as $r) { | |
16 | //removed irrelevant code | |
17 | - | if(!isset($local_topics[$r['topic_id']])) { |
17 | + | if(!isset($this->active_topics[$r['topic_id']])) { |
18 | $this->active_topics[$r['topic_id']] = array_merge(array('tid' => $r['topic_id']),$this->default_values); | |
19 | } | |
20 | ||
21 | $this->getPointsBasic($r); | |
22 | } | |
23 | echo round(microtime(true)-$start,4).' returned '.count(); | |
24 | ||
25 | return $this->active_topics; | |
26 | } | |
27 | ||
28 | private function getPointsBasic($r) { | |
29 | ||
30 | $this->active_topics[$r['topic_id']]['d_score'] += $r['score']; | |
31 | $this->active_topics[$r['topic_id']]['d_'.$r['type']] += $r['score']; | |
32 | ||
33 | switch($r['type']) { | |
34 | case 'likes': | |
35 | $r['score'] *= 2.3; | |
36 | break; | |
37 | ||
38 | // more cases with different calculations etc.... | |
39 | } | |
40 | ||
41 | $this->active_topics[$r['topic_id']][$r['type']] += $r['score']; | |
42 | $this->active_topics[$r['topic_id']]['total_score'] += $r['score']; | |
43 | } | |
44 | // removed irrelevant code | |
45 | } |