示例#1
0
 function handleRules()
 {
     global $jzSERVICES;
     if ($this->getPlType() != "dynamic") {
         return false;
     }
     $temp = array();
     $this->list = array();
     foreach ($this->rulelist as $rule) {
         $source = new jzMediaNode($rule['source']);
         $count = $rule['amount'];
         if ($rule['type'] == "track" || $rule['type'] == "tracks") {
             $type = "tracks";
             $distance = -1;
         } else {
             $type = "nodes";
             $distance = distanceTo("album", $source);
         }
         switch ($rule['function']) {
             case "exact":
                 if ($type == "tracks") {
                     $source = new jzMediaTrack($rule['source']);
                 }
                 $temp = array($source);
                 break;
             case "random":
                 $temp = $source->getSubNodes($type, $distance, true, $count);
                 break;
             case "topplayed":
                 $temp = $source->getMostPlayed($type, $distance, $count);
                 break;
             case "recentlyadded":
                 $temp = $source->getRecentlyAdded($type, $distance, $count);
                 break;
             case "similar":
                 if ($source->getPType() == "artist") {
                     $mainArray = $source->getSubNodes($type, $distance, true, $count);
                     // Now let's get the top 5 similar artists
                     $simArray = $jzSERVICES->getSimilar($source);
                     $simArray = seperateSimilar($simArray);
                     $i = 0;
                     $limit = 8;
                     // Now let's shuffle
                     $similarArray = array();
                     for ($e = 0; $e < count($simArray['matches']); $e++) {
                         if (isset($simArray['matches'][$e])) {
                             // Ok, this is one that we want, let's get it's path
                             $simArt = $simArray['matches'][$e];
                             $subArray = $simArt->getSubNodes($type, $distance, true, $count / 1.5);
                             $similarArray = array_merge($similarArray, $subArray);
                             $i++;
                             if ($limit) {
                                 if ($i > $limit) {
                                     break;
                                 }
                             }
                         }
                     }
                     $finArray = array_merge($similarArray, $mainArray);
                     shuffle($finArray);
                     $temp = array();
                     for ($i = 0; $i < $count; $i++) {
                         $temp[] = $finArray[$i];
                     }
                 } else {
                     $temp = $source->getSubNodes($type, $distance, true, $count);
                 }
                 break;
         }
         foreach ($temp as $l) {
             $this->list[] = $l;
         }
     }
     shuffle($this->list);
     if (isset($this->limit) && $this->limit > 0) {
         $this->truncate($this->limit);
     }
 }