Esempio n. 1
0
 /**
  * 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);
 }
Esempio n. 2
0
 private function templateShowLyrics(Slay_Song $song)
 {
     $sid = $song->getID();
     $user = GWF_User::getStaticOrGuest();
     $staff = $user->isStaff();
     $table = GDO::table('Slay_Lyrics');
     $perm = $staff ? '' : ' AND ssl_options&' . Slay_Lyrics::ENABLED;
     $where = "ssl_sid={$sid}{$perm}";
     $tVars = array('song' => $song, 'lyrics' => $table->selectAll('*', $where, 'ssl_date ASC', array('user'), -1, -1, GDO::ARRAY_O), 'is_admin' => $staff);
     return $this->module->template('lyrics.tpl', $tVars);
 }
Esempio n. 3
0
 public function execute()
 {
     if (false === ($this->song = Slay_Song::getByID(Common::getGetString('song')))) {
         return $this->module->error('err_song');
     }
     return $this->templateSong();
 }
Esempio n. 4
0
 public static function onFlushTags(Slay_Song $song)
 {
     $sid = $song->getID();
     if (!GWF_User::isInGroupS(GWF_Group::STAFF)) {
         return GWF_HTML::err('ERR_NO_PERMISSION');
     }
     if (false === GDO::table('Slay_SongTag')->deleteWhere("sst_sid={$sid}")) {
         return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
     }
     if (false === GDO::table('Slay_TagVote')->deleteWhere("stv_sid={$sid}")) {
         return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
     }
     if (false === $song->saveVars(array('ss_taggers' => '0', 'ss_tag_cache' => NULL))) {
         return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
     }
     return false;
 }
Esempio n. 5
0
 public function execute()
 {
     if (false === ($song = Slay_Song::getByID(Common::getGetString('stid')))) {
         return $this->module->error('err_song');
     }
     if (isset($_POST['add'])) {
         return $this->onAddLyrics($song) . $this->templateAddLyrics($song);
     }
     return $this->templateAddLyrics($song);
 }
Esempio n. 6
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;
 }
Esempio n. 7
0
 public static function countTaggers(Slay_Song $song)
 {
     $sid = $song->getID();
     return self::table(__CLASS__)->selectVar('COUNT(DISTINCT(stv_uid))', "stv_sid={$sid}");
 }
Esempio n. 8
0
 public static function getLyricsCount(Slay_Song $song, $enabled_only = true)
 {
     $sid = $song->getID();
     $enabled = $enabled_only ? 'ssl_options&' . self::ENABLED : '1';
     return self::table(__CLASS__)->selectVar('count(ssl_uid)', "ssl_sid={$sid} AND ({$enabled})");
 }
Esempio n. 9
0
 public static function isPlaying(Slay_Song $song)
 {
     return GWF_Settings::getSetting(self::NP_KEY) === $song->getID();
 }