Пример #1
0
 public static function computeVotes(Slay_Song $song, $taggers = 0)
 {
     $sid = $song->getID();
     $cache = array();
     $table = self::table(__CLASS__);
     foreach (Slay_Tag::getAllTags() as $tag_obj) {
         $tid = $tag_obj->getID();
         if (false === ($count = Slay_TagVote::countVotes($sid, $tid))) {
             return false;
         }
         $avg = $taggers > 0 ? (int) ($count / $taggers * self::SCALE) : 0;
         if ($count > 0) {
             $cache[$tag_obj->getVar('st_name')] = array($count, $tid);
         }
         if (false === $table->insertAssoc(array('sst_sid' => $sid, 'sst_tid' => $tid, 'sst_count' => $count, 'sst_average' => $avg), true)) {
             return false;
         }
     }
     # Cleanup empties
     if (false === $table->deleteWhere("sst_count=0")) {
         return false;
     }
     # Build cache
     $cc = NULL;
     if (count($cache) > 0) {
         arsort($cache);
         foreach ($cache as $tname => $data) {
             list($count, $tid) = $data;
             $href = sprintf('/index.php?mo=Slaytags&me=Search&searchtag=%s&searchterm=&search=Search&by=ss_id&dir=ASC&page=1', $tid);
             $cc .= sprintf(', <a href="%s">%s(%.02f%%)</a>', $href, $tname, $count / $taggers * 100);
         }
         $cc = substr($cc, 2);
     }
     if (false === $song->saveVar('ss_tag_cache', $cc)) {
         return false;
     }
     return true;
 }