Changeset 36

Show
Ignore:
Timestamp:
03/14/06 14:54:24 (2 years ago)
Author:
eadiaz
Message:

Solve Ticket #10 of trac.
Now if an user already voted for a meme the vote button is hidden.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/public_html/akarru.lib/memes.php

    r30 r36  
    4444        function get_memes($page=0, $sort='', $limit=0, $show_sql=0) 
    4545        { 
    46                 $this->memes_count = $this->db->fetch_scalar('select count(*) n from posts p where p.votes >= '.$this->promote_threshold); 
     46                $this->db->do_query('select SQL_CALC_FOUND_ROWS * from posts p where p.votes >= '.$this->promote_threshold);  
     47                $this->memes_count = $this->db->fetch_scalar('Select FOUND_ROWS()'); 
    4748                if ($this->memes_count <= 0) { 
    4849                        return array(); 
     
    5152                 
    5253                $sql =  'select p.title,p.is_micro_content,p.content,p.date_posted,p.clicks,p.category,p.url,p.submitted_user_id,p.ID,p.rank, '; 
    53                 $sql .= 'pc.cat_title,u.username, u.email, pc.ID as cat_id,votes as vote_count, count(pcom.ID) as comment_count '; 
    54                 $sql .= 'from posts p, post_cats pc, users u left join post_comments pcom on pcom.post_id=p.ID '; 
     54                $sql .= 'pc.cat_title,u.username, u.email, pc.ID as cat_id,votes as vote_count, comments as comment_count '; 
     55                $sql .= 'from posts p, post_cats pc, users u '; 
    5556                $sql .= 'where pc.ID=p.category and u.ID=p.submitted_user_id and p.votes >= '.$this->promote_threshold; 
    5657                $sql .= " group by p.title,p.content,p.date_posted,p.category,p.url,p.submitted_user_id,p.ID,pc.cat_title,u.username "; 
     
    6263                else 
    6364                { 
    64                         $sql.=" order by rank desc, vote_count desc ";  
     65                        $sql.=" order by rank desc, votes desc ";  
    6566                } 
    6667                if($page!=0) 
     
    8182        function get_meme($id) 
    8283        { 
    83                 $sql =  'select p.title,p.content,p.date_posted,p.date_promo,p.rank,p.clicks,p.category,p.url,p.submitted_user_id,p.ID,pc.cat_title,u.username, u.email, pc.ID as cat_id, p.votes as vote_count, count(pcom.ID) as comment_count from posts p, post_cats pc, users u left join post_comments pcom on pcom.post_id=p.ID where pc.ID=p.category and u.ID=p.submitted_user_id '; 
     84                $sql =  'select p.title,p.content,p.date_posted,p.date_promo,p.rank,p.clicks,p.category,p.url,p.submitted_user_id,p.ID,pc.cat_title,u.username, u.email, pc.ID as cat_id, p.votes as vote_count, comments as comment_count from posts p, post_cats pc, users u where pc.ID=p.category and u.ID=p.submitted_user_id '; 
    8485                $sql .= ' and p.ID='.$id; 
    85                 $sql .= " group by p.title,p.content,p.date_posted,p.category,p.url,p.submitted_user_id,p.ID,pc.cat_title,u.username "; 
    8686                $result = $this->db->fetch_object($sql); 
    87                 $result->small_gravatar = get_gravatar($bm_url, $comment->email, 16);  
     87                $result->small_gravatar = get_gravatar($bm_url, $result->email, 16);  
    8888                return $result; 
    8989        } 
     
    121121        { 
    122122                $sql =  'select p.title,p.is_micro_content,p.content,p.date_posted,p.rank,p.clicks,p.category,p.url,p.submitted_user_id,p.ID, '; 
    123                 $sql .=  'pc.cat_title,u.username, u.email, pc.ID as cat_id, p.votes as vote_count '; 
     123                $sql .=  'pc.cat_title,u.username, u.email, pc.ID as cat_id, p.votes as vote_count, p.comments as comment_count '; 
    124124                $sql .= ' from posts p, post_cats pc, users u where pc.ID=p.category and u.ID=p.submitted_user_id '; 
    125125                $sql .= ' and p.votes < '.$this->promote_threshold.' '; 
     
    184184        } 
    185185 
     186 
     187        // calculate gravatar and if user voted for this meme 
    186188        function filter_result($sql) 
    187189        { 
     
    192194                { 
    193195                        $meme->small_gravatar = get_gravatar($bm_url, $meme->email, 16); 
     196                        $meme_id = $meme->ID; 
     197                        $uid = $this->user_id; 
     198                        $meme->voted = $this->db->fetch_scalar("select count(*) from post_votes where post_id = $meme_id and user_id = $uid "); 
    194199                        $result[] = $meme; 
    195200                } 
     
    413418        { 
    414419                $meme = $this->get_meme($meme_id); 
    415                 $sql = "select votes from posts where ID = $meme_id "
    416                 $nv = $this->db->fetch_scalar($sql); 
     420                $nv = $this->db->fetch_scalar("select count(*) from post_votes where post_id = $meme_id ")
     421                $nc = $this->db->fetch_scalar("select count(*) from post_comments where post_id = $meme_id "); 
    417422                $now = time(); 
    418423                $hours_posted = ceil(($now - $meme->date_posted)/3600); 
     
    434439 
    435440                if ($update_promo_date) { 
    436                         $sql = "update posts set rank = $rank, date_promo = $now where ID = $meme_id"; 
     441                        $sql = "update posts set rank = $rank, date_promo = $now, votes = $nv, comments = $nc where ID = $meme_id"; 
     442 
    437443                } 
    438444                else { 
    439                         $sql = "update posts set rank = $rank where ID = $meme_id"; 
     445                        $sql = "update posts set rank = $rank, votes = $nv, comments = $nc where ID = $meme_id"; 
    440446                } 
    441447                $this->db->execute($sql); 
     
    488494        function promote_all() 
    489495        { 
    490                 $sql = 'select p.ID from posts p join post_votes pv on pv.post_id = p.ID group by p.ID'; 
     496                $sql = 'select ID from posts '; 
    491497                $memes = $this->db->fetch($sql); 
    492498                foreach ($memes as $meme) { 
  • trunk/smarty/templates/memes_grid.tpl

    r26 r36  
    1313          {$meme->vote_count} 
    1414          </h3> 
     15          {if $meme->voted <= 0} 
    1516          <p>{#votes_label#}</p> 
     17          {/if} 
    1618           <div class="vote-class"> 
    1719        {if $logged_in } 
     20        {if $meme->voted <= 0} 
    1821        <a class="vote-class" href="#vote_count_{$meme->ID}" onclick="update_vote_div('vote_count_{$meme->ID}','{$logged_userid}')"> 
    1922        <img src="styles/img/meme-votar.png" border="0" alt="{#votes_label#}" /></a> 
     23        {/if} 
    2024        {else} 
    2125        <a class="vote-class" href="#vote_count_{$meme->ID}" onclick="update_vote_div('vote_count_{$meme->ID}','0')"><img src="styles/img/meme-votar.png" border="0" alt="{#votes_label#}" /></a>