Example #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;
 }
Example #2
0
 public static function getTags(Slay_Song $song)
 {
     return Slay_TagVote::getTags($song);
 }
Example #3
0
 private function onTag(Slay_Song $song)
 {
     $form = $this->formTag($song);
     if (false !== ($error = $form->validateCSRF_WeakS())) {
         return $error;
     }
     $tags = array();
     $errors = array();
     foreach ($_POST as $k => $v) {
         if (Common::startsWith($k, 'tag_')) {
             $k = substr($k, 4);
             if (Slay_Tag::getByName($k) === false) {
                 $errors[] = $this->module->lang('err_tag_uk');
             } else {
                 $tags[] = $k;
             }
         }
     }
     if (count($errors) > 0) {
         return GWF_HTML::error('Slaytags', $errors);
     }
     $user = GWF_Session::getUser();
     if (false === Slay_TagVote::clearVotes($song, $user)) {
         return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
     }
     if (false === Slay_TagVote::addVotes($song, $user, $tags)) {
         return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
     }
     if (false === $song->computeTags()) {
         return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
     }
     return $this->module->message('msg_tagged');
 }
Example #4
0
 public function computeTags()
 {
     $taggers = Slay_TagVote::countTaggers($this);
     if (false === $this->saveVar('ss_taggers', $taggers)) {
         return false;
     }
     if (false === Slay_SongTag::computeVotes($this, $taggers)) {
         return false;
     }
     $this->votes = NULL;
     return true;
 }