Advertisement
Guest User

Untitled

a guest
Jan 29th, 2013
337
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.17 KB | None | 0 0
  1. <?php
  2. class myClass {
  3.     private $tids=array();
  4.     public $active_topics=array();
  5.     public function __construct() { /* removed irrelevant code */ }
  6.    
  7.     public function getTopicsScore($topics=false,$params=array()) {
  8.        
  9.         // removed irrelevant code
  10.         $results = $this->getScores($this->tids,$params);
  11.         $local_topics=array();
  12.         $start = microtime(true);
  13.        
  14.         foreach($results as $r) {
  15.             //removed irrelevant code
  16.             if(!isset($local_topics[$r['topic_id']])) {
  17.                 $local_topics[$r['topic_id']] = array_merge(array('tid' => $r['topic_id']),$this->default_values);
  18.             }
  19.            
  20.             $local_topics[$r['topic_id']] = $this->getPointsBasic($r,$local_topics[$r['topic_id']]);
  21.         }
  22.         echo round(microtime(true)-$start,4);
  23.         $this->active_topics=$local_topics;
  24.         return $this->active_topics;
  25.     }
  26.  
  27.     private function getPointsBasic($r,$t) {
  28.    
  29.         $t['d_score']       += $r['score'];
  30.         $t['d_'.$r['type']] += $r['score'];
  31.  
  32.         switch($r['type']) {
  33.             case 'likes':
  34.                 $r['score'] *= 2.3;
  35.             break;
  36.            
  37.             //  more cases with different calculations etc....
  38.         }
  39.        
  40.         $t[$r['type']]      += $r['score'];
  41.         $t['total_score']   += $r['score'];
  42.            
  43.         return $t;
  44.     }
  45.     // removed irrelevant code
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement