/** * Insert a song into the play history. * @param Slay_Song $song * @param int $time_end */ public static function insertPlayed(Slay_Song $song, $time_end) { if (self::getLastID() === $song->getID()) { return true; } $date = GWF_Time::getDate(GWF_Date::LEN_SECOND, $time_end - $song->getVar('ss_duration')); if (false === $song->saveVar('ss_last_played', $date)) { return false; } return self::table(__CLASS__)->insertAssoc(array('sph_id' => 0, 'sph_sid' => $song->getID(), 'sph_date' => $date), false); }
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; }