Upvote/Kudos

Post

Posted
Rating:
#5878 (In Topic #1399)
Avatar
Standard member
walterhpdx is in the usergroup ‘Fan in training’

Is there a way to add upvotes/kudos to posts, links, etc?

So I posted this in Tracker, but think I should have posted it here.  Here's what I posted in Tracker:
--
I've been tasked with putting together what amounts to a "recommends" website (different than the project I attempted previously with Composr), and came back to Composr because it fits my needs. I have everything I need except one - unless I'm overlooking.

We'll be using the "Links" functionality to add lots of links to different archived stories/artwork. I have everything worked out, and will import most of what I need. However, the request is to have a community based "link ranking", meaning if there are five links listed, and a visitor comes in and likes one of the items that we link to, they can "upvote" that link. So what I need is twofold; the ability to upvote a post and the ability to sort on that.

I've looked through the custom fields, but haven't seen one that looks like it can handle upvoting. I may well be wrong. But I thought that if one isn't available yet, that I would put the request in for such functionality. Ideally, my links would look somewhat like:

Link 1 (67 upvotes)
Link 5 (45 upvotes)
Link 3 (30 upvotes)
Link 4 (12 upvotes)
Link 2 (1 upvotes)
Online now: No Back to the top

Post

Posted
Rating:
#5879
Avatar
Standard member
walterhpdx is in the usergroup ‘Fan in training’
To follow up on this, I think that it would be easy to use the "Rating" for this functionality.  I just need two things:

1) The ability to use that rating data as a sort item.  For example, if two people rate something "5" and one rates it "3", then the average is 4.33.  So if there's an entry with an average rating of 4.5, it would come before this entry.  Basically, I just need to know where that's stored in the database (I'm searching but have not found it yet) and if you can use that data to sort.

2) The ability to leave a rating on the entry itself, easily.  I've found it once, but haven't found it since.  So maybe embed the "not rated" blank stars as part of the entry, and leave the user the ability to click on the rating as part of the entry.
Online now: No Back to the top

Post

Posted
Rating:
#5881
Avatar
Site director
Chris Graham is in the usergroup ‘Administrators’
Hi,

It can be done, but it took even me a while to work through this!

You need to make template changes as follows (save into proper template overrides, not over the originals). If you don't understand the diff format then hopefully someone can step it through more clearly for you.

Code (Diff)

diff --git a/themes/default/templates/CATALOGUE_links_TABULAR_ENTRY_WRAP.tpl b/themes/default/templates/CATALOGUE_links_TABULAR_ENTRY_WRAP.tpl
index 70069923c..3cf08b8ae 100644
--- a/themes/default/templates/CATALOGUE_links_TABULAR_ENTRY_WRAP.tpl
+++ b/themes/default/templates/CATALOGUE_links_TABULAR_ENTRY_WRAP.tpl
@@ -3,5 +3,9 @@
 
 <tr class="{$CYCLE,results_table_zebra,zebra_0,zebra_1}">
        {FIELDS_TABULAR}
+
+       <td>
+               {$RATING,catalogues__links,{ID},{SUBMITTER},{$SELF_URL},{FIELD_1_PLAIN},RATING_INLINE_DYNAMIC}
+       </td>
 </tr>
 
diff --git a/themes/default/templates/CATALOGUE_links_TABULAR_WRAP.tpl b/themes/default/templates/CATALOGUE_links_TABULAR_WRAP.tpl
index c2d0d36ae..83ba46381 100644
--- a/themes/default/templates/CATALOGUE_links_TABULAR_WRAP.tpl
+++ b/themes/default/templates/CATALOGUE_links_TABULAR_WRAP.tpl
@@ -13,6 +13,19 @@
                <thead>
                        <tr>
                                {HEAD}
+
+                               <th>
+                                       Upvotes
+
+                                       <span class="table_header_sorting">
+                                               {+START,IF,{$NEQ,{$PAGE},search}}
+                                               <a target="_self" href="{$SELF_URL*,0,0,0,module_order=compound_rating ASC}"><img src="{$IMG*,results/{$?,{$EQ,{$_GET,module_order},compound_rating ASC},sortablefield_asc,sortablefield_asc_nonselected}}" title="{!SORT_BY} Upvotes, {!ASCENDING}" alt="{!SORT_BY} Upvotes, {!ASCENDING}" /></a>
+                                               {+END}
+                                               {+START,IF,{$NEQ,{$PAGE},search}}
+                                               <a target="_self" href="{$SELF_URL*,0,0,0,module_order=compound_rating DESC}"><img src="{$IMG*,results/{$?,{$EQ,{$_GET,module_order},compound_rating DESC},sortablefield_desc,sortablefield_desc_nonselected}}" title="{!SORT_BY} Upvotes, {!DESCENDING}" alt="{!SORT_BY} Upvotes, {!DESCENDING}" /></a>
+                                               {+END}
+                                       </span>
+                               </th>
                        </tr>
                </thead>
 
diff --git a/themes/default/templates/RATING_DISPLAY_SHARED.tpl b/themes/default/templates/RATING_DISPLAY_SHARED.tpl
index 3deceed13..3dc190f64 100755
--- a/themes/default/templates/RATING_DISPLAY_SHARED.tpl
+++ b/themes/default/templates/RATING_DISPLAY_SHARED.tpl
@@ -8,12 +8,5 @@
                <strong>{TITLE*}:</strong>
        {+END}
 
-       {$,Visually show results}
-       {$SET,rating_loop,0}
-       {+START,SET,rating_stars}{$ROUND,{$DIV_FLOAT,{RATING},2}}{+END}
-       {+START,WHILE,{$LT,{$GET,rating_loop},{$GET,rating_stars}}}<img src="{$IMG*,icons/14x14/rating}" srcset="{$IMG*,icons/28x28/rating} 2x" {$?,{$EQ,{$GET,rating_loop},0},alt="{!HAS_RATING,{$GET,rating_stars}}" title="{!HAS_RATING,{$GET,rating_stars}}",alt=""} />{$INC,rating_loop}{+END}
-       {+START,IF_NON_PASSED_OR_FALSE,NO_PEOPLE_SHOWN}{+START,IF,{LIKES}}{+START,IF_PASSED,LIKED_BY}{+START,IF_NON_EMPTY,{LIKED_BY}}
-               {$SET,done_one_liker,0}
-               {+START,LOOP,LIKED_BY}{+START,IF_NON_EMPTY,{$AVATAR,{MEMBER_ID}}}{+START,IF,{$NOT,{$GET,done_one_liker,0}}}({+END}<a href="{$MEMBER_PROFILE_URL*,{MEMBER_ID}}"><img width="10" height="10" style="width: 10px; height: 10px"{$,LEGACY- fixes display issues on Mac OS Mail app} src="{$ENSURE_PROTOCOL_SUITABILITY*,{$AVATAR,{MEMBER_ID}}}" title="{!LIKED_BY} {USERNAME*}" alt="{!LIKED_BY} {$DISPLAYED_USERNAME*,{USERNAME}}" /></a>{$SET,done_one_liker,1}{+END}{+END}{+START,IF,{$GET,done_one_liker,0}}){+END}
-       {+END}{+END}{+END}{+END}
+       {NUM_RATINGS}
 {+END}
diff --git a/themes/default/templates/RATING_INLINE_DYNAMIC.tpl b/themes/default/templates/RATING_INLINE_DYNAMIC.tpl
index 3be89b2e3..2dd6299ed 100755
--- a/themes/default/templates/RATING_INLINE_DYNAMIC.tpl
+++ b/themes/default/templates/RATING_INLINE_DYNAMIC.tpl
@@ -1,7 +1,7 @@
-{+START,IF,{$OR,{HAS_RATINGS},{$IS_NON_EMPTY,{$TRIM,{RATING_FORM}}}}}
+{+START,IF,{$OR,{HAS_RATINGS},{LIKES},{$IS_NON_EMPTY,{$TRIM,{RATING_FORM}}}}}
        <div class="RATING_INLINE RATING_INLINE_DYNAMIC" itemscope="itemscope" itemtype="http://schema.org/AggregateRating">
                {$,Show the current result (nothing shows if nobody voted yet; by default RATING_DISPLAY_SHARED nothing shows if RATING_FORM is not blank either, as the rating stars will show the current rating too)}
-               {+START,IF,{HAS_RATINGS}}
+               {+START,IF,{$OR,{HAS_RATINGS},{LIKES}}}
                        {$SET,i,0}
                        {+START,LOOP,ALL_RATING_CRITERIA}
                                <div{+START,IF,{$NEQ,{$GET,i},0}} class="horiz_field_sep"{+END}>
@@ -14,7 +14,7 @@
                {$,Allow rating}
                {$SET,block_embedded_forms,1}
                {+START,IF_NON_EMPTY,{$TRIM,{RATING_FORM}}}
-                       <div{+START,IF,{$AND,{HAS_RATINGS},{LIKES},{$IS_NON_EMPTY,{ALL_RATING_CRITERIA}}}} class="horiz_field_sep"{+END}>
+                       <div{+START,IF,{$AND,{LIKES},{$IS_NON_EMPTY,{ALL_RATING_CRITERIA}}}} class="horiz_field_sep"{+END}>
                                {RATING_FORM}
                        </div>
                {+END}
diff --git a/themes/default/templates/RATING_INLINE_STATIC.tpl b/themes/default/templates/RATING_INLINE_STATIC.tpl
index 771f8e96e..9ce599c32 100755
--- a/themes/default/templates/RATING_INLINE_STATIC.tpl
+++ b/themes/default/templates/RATING_INLINE_STATIC.tpl
@@ -1,7 +1,7 @@
 {$,This is not a usual template to use, as it's for read-only ratings only. Usually we use RATING_INLINE_DYNAMIC}
 
 {$,Show the current result (nothing shows if nobody voted yet)}
-{+START,IF,{HAS_RATINGS}}
+{+START,IF,{$OR,{HAS_RATINGS},{LIKES}}}
        <div class="RATING_INLINE RATING_INLINE_STATIC" itemscope="itemscope" itemtype="http://schema.org/AggregateRating">
                {$SET,i,0}
                {+START,LOOP,ALL_RATING_CRITERIA}
 

You also need to enable a config option to get 'likes' instead of star-based rating:
Admin Zone > Setup > Configuration > Feature options > User interaction: Rating > Replace rating with ‘likes’

compound_rating is effectively a likes sorter, because a like is a 5 star rating under-the-hood, so sorting by the sum total of all those is going to be the same as sorting by the number of likes.
Actually now I think about it that won't quite work, as 5 dislikes would count the same as 1 like, which would skew things. So you will want to remove the dislike button from the templates too. Not having a dislike button is implicit in your design here anyway.


Become a fan of Composr on Facebook or add me as a friend. Add me on on Twitter. Follow me on Minds (where I am most active). Support me on Patreon

Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about Composr whenever you see the opportunity or support me on Patreon.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying Composr on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Online now: No Back to the top

Post

Posted
Rating:
#5882
Avatar
Site director
Chris Graham is in the usergroup ‘Administrators’
Actually now I think about it that won't quite work, as 5 dislikes would count the same as 1 like, which would skew things.

No, I misspoke. compound_rating sums all the ratings minus one. So a dislike will be 1 in the database, but 0 when compounded and thus will have no effect in the summation.


Become a fan of Composr on Facebook or add me as a friend. Add me on on Twitter. Follow me on Minds (where I am most active). Support me on Patreon

Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about Composr whenever you see the opportunity or support me on Patreon.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying Composr on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Online now: No Back to the top

Post

Posted
Rating:
#5883
Avatar
Standard member
walterhpdx is in the usergroup ‘Fan in training’
Awesome - thanks for this!  I'll start poking through the code and make the changes.  Once tested, I'll be able to start rolling out the solution.
Online now: No Back to the top
1 guest and 0 members have just viewed this.

Statistics

Users online:

gabriel58, mytracker, MVLipwig

Usergroups: 

Forum statistics:
  • 1,118 topics, 5,367 posts, 6,350 members
  • Our newest member is khelopcgames
Birthdays:
Back to Top