Go Back   Pligg Forum > Pligg Development > Core Development
Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-28-2007, 11:21 PM
inggenia inggenia is offline
Casual Pligger
 
Join Date: Sep 2006
Posts: 30
Downloads: 15
Uploads: 1
Thanks: 6
Thanked 11 Times in 4 Posts
user's total received votes [hack]

How to count a user's total received votes?

If a user submit, for example, 4 stories and each one have 10 votes... I want to show in the "Top Users" table his received votes' total count (40 votes)

That means that every time someone votes a story the pligg system add 1 to the author "total votes" count.

I want to show "most voted users" and "most voted stories".

How can I do that? Any Idea? Maybe editing de karma.php file?

Last edited by inggenia : 07-09-2007 at 06:31 AM.
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-09-2007, 06:36 AM
inggenia inggenia is offline
Casual Pligger
 
Join Date: Sep 2006
Posts: 30
Downloads: 15
Uploads: 1
Thanks: 6
Thanked 11 Times in 4 Posts
I´m working on a possible solution, but it is difficult.

I first think how to sum 1 every time someone click on "vote" on a user's count. But it means that you have to add a new column to the "users" table, like "karma".

How to make it without touching the database?
Reply With Quote
  #3 (permalink)  
Old 07-09-2007, 06:44 AM
inggenia inggenia is offline
Casual Pligger
 
Join Date: Sep 2006
Posts: 30
Downloads: 15
Uploads: 1
Thanks: 6
Thanked 11 Times in 4 Posts
here is my solution to this problem. I read the TopUsers.php, topusers_center.tpl, and users.php code and I looked up how "total_votes" and "published_votes" were made and I made the same for "total_received_votes"

Please, read this, use it, and tell me if it works for you and if is possible to add this to the next release



1. first go to /libs/user.php

1.1. on line 37 add a new "for stats" var for the User class

PHP Code:
var $total_received_votes 0
1.2 go to all_stats function on line 159 and add the new var after "total_comments" on line 179:

PHP Code:
$this->total_received_votes $db->get_var("SELECT sum(link_votes) FROM " table_links " WHERE link_author = $this->id and link_status != 'discard' $link_date"); 
1.3 add a new line after line 203:

PHP Code:
$main_smarty->assign('user_received_votes'$this->total_received_votes); 
1.4 now your users have a variable where you keep the total received votes



2. now the idea is to show this variable on the topusers.php page

2.1 let's add a new config var on /libs/lang.conf: go to line 618 where section "top users" vars are and add before "karma":

PHP Code:
//<SECTION>TOP USERS</SECTION><ADDED></ADDED>
PLIGG_Visual_TopUsers_TH_ReceivedVotes "Received Votes" 
2.2 go to /topusers.php and on line 32 replace:

PHP Code:
$items = array($main_smarty->get_config_vars('PLIGG_Visual_TopUsers_TH_User'), $main_smarty->get_config_vars('PLIGG_Visual_TopUsers_TH_News'), $main_smarty->get_config_vars('PLIGG_Visual_TopUsers_TH_PublishedNews'), $main_smarty->get_config_vars('PLIGG_Visual_TopUsers_TH_Comments'), $main_smarty->get_config_vars('PLIGG_Visual_TopUsers_TH_TotalVotes'), $main_smarty->get_config_vars('PLIGG_Visual_TopUsers_TH_PublishedVotes')); 
with

PHP Code:
$items = array($main_smarty->get_config_vars('PLIGG_Visual_TopUsers_TH_User'), $main_smarty->get_config_vars('PLIGG_Visual_TopUsers_TH_News'), $main_smarty->get_config_vars('PLIGG_Visual_TopUsers_TH_PublishedNews'), $main_smarty->get_config_vars('PLIGG_Visual_TopUsers_TH_Comments'), $main_smarty->get_config_vars('PLIGG_Visual_TopUsers_TH_TotalVotes'), $main_smarty->get_config_vars('PLIGG_Visual_TopUsers_TH_PublishedVotes'), $main_smarty->get_config_vars('PLIGG_Visual_TopUsers_TH_ReceivedVotes')); 
2.3 go to line 41 and replace:

PHP Code:
if(intval($sortby) < || intval($sortby) > 5
with

PHP Code:
if(intval($sortby) < || intval($sortby) > 6
2.4 go to line 75 and add a new "case" for sortby

PHP Code:
case 6// sort users by number of received votes
    
$select "SELECT user_id, sum(link_votes) as count ";
    
$from_where " FROM " table_users ", " table_links " WHERE link_author=user_id AND user_level<>'god' GROUP BY user_id";
    
$order_by " ORDER BY count DESC ";
    break; 

2.5 with this you have your topusers table and a new column "Received Votes" but you must modify your template to show it

3. add the new column to topusers table in topusers themplate .tpl

3.1 go to /templates/yget/topusers_center.tpl, go to line 32 after "user_published_links" and add this line:

PHP Code:
$main_smarty->assign('user_received_votes'$user->total_received_votes); 
3.2 go to /templates/yget/topusers_data.tpl, go to line 18 before "<td>{$user_karma}</td>" add this line:

PHP Code:
    <td>{$user_received_votes}</td

4. to show it on user profile:

4.1 go to /libs/lang.conf: and go to line 797 where section "profile" vars are and add berofe "modify profile":

PHP Code:
//<SECTION>PROFILE</SECTION><ADDED>0.5</ADDED>
PLIGG_Visual_Profile_Total_Received_Votes "Received Votes" 
4.2 go to /templates/yget/user_center.tpl and find line 375, and after "$user_published_votes" add this lines:

PHP Code:
<tr>
<
td><strong>{#PLIGG_Visual_Profile_Total_Received_Votes#}:</strong></td>
<td>{$user_received_votes}</td>
</
tr


thats all...

Last edited by inggenia : 07-09-2007 at 06:49 AM.
Reply With Quote
Reply



Thread Tools
Display Modes
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Similar Threads
Thread Thread Starter Forum Replies Last Post
How to check if a registering user's email is valid? rhythm General Help 26 01-10-2008 05:58 PM
Pligg beta 9.5 [updated] kbeeveer46 Current Version 0 04-29-2007 08:58 PM
RSS for a user's votes in a specific category? revolver General Help 6 01-18-2007 12:56 PM
Total votes sorting in top users page it is not working correctly! Nikes77 Bug Report 2 12-06-2006 05:10 PM


LinkBacks Enabled by vBSEO 3.0.0