<![CDATA[ Support/Comments for CSS Star Rating - My Forums]]> https://forums.modx.com/thread/?thread=38274 <![CDATA[Re: Support/Comments for CSS Star Rating]]> https://forums.modx.com/thread/38274/support-comments-for-css-star-rating?page=16#dis-post-495207 Quick question regarding the viewing format from a ditto call.

I got the star rating working fine, the votes are being counted and showed in the ditto call for each page, but the format is in text.

4:1 (a rating of 4 with 1 vote) for example.

What parameter can I add to the ditto template chunk to get a more visually friendly vote rating/count to be displayed, but not voted on?

The parameters on the snippet download page don’t seem to be what I need. Sorry for coming a little late to the party(like 4 years late tongue),but only recently i found myself in a similar situation and i kinda found a soloution. Not a preferable one,but it works.
1)First, create a snippet called Rating
2)Paste the following code:
<?php
$myVar = $modx->getTemplateVarOutput(array("star_rating"),$docID,$published=1);
$explode = $myVar['star_rating'];
$rating = explode(":", $explode);
if($rating[1]!=0){
$unrounded=$rating[0]/$rating[1];
}
else{
$unrounded=null;
}
$output=round($unrounded,2);

return $output;
?>

3)On your articles, call it like this where you want the rating value to display
[!Rating!]


The steps above are only for displaying a rating on your articles. If you want ditto to take this rating and display it on another page(like where you display all articles for example on a news page),you will need to do the following:

4)Download and install the PHx plugin:http://modx.com/extras/package/phx
5)Go inside your phx directory-->modifiers and make a custom modifier called tv.phx.php (originally from natalino) and paste this code:
<?php
    if(strlen($options )>0) {
    $data = explode("?",trim($options),2);
    $id= (!empty($data[0]) && is_numeric($data[0])) ? $data[0]: '';
    $tv= (!empty($data[1])) ? $data[1]: '';
    $result = $modx->getTemplateVar($tv, 'name', $id, 1);
	$rating=explode(":",$result['value']);
	if($rating[1]!=0){
	$unrounded=$rating[0]/$rating[1];
	}
	else{
	$unrounded=null;
	}
	$output=round($unrounded,2);
    return $output;
    }
?>


6)Make the page where you will have your ditto call uncacheable(in the manager, edit the page,press settings and then untick the "Cacheable" checkbox).

7)In your ditto tpl call the tv like this:
[+phx:tv=`[+id+]?star_rating`+]

8)
star_rating
is the default tv used by the css rating snippet.If you have changed the name of your tv, then you should replace all instances of
star_rating
with the name of your tv(both in the tv.phx.php modifier and the rating snippet).

Final thoughts: If someone manages to do that with all-in one snippet,then that will be the best option. PHx itself is slower than a snippet and having to make the page, where you have the ditto call, uncacheable will take its toll on loading times. Especially in the event that you have a lot of articles to display.]]>
dinpapa Apr 16, 2014, 07:59 AM https://forums.modx.com/thread/38274/support-comments-for-css-star-rating?page=16#dis-post-495207
<![CDATA[Re: Support/Comments for CSS Star Rating]]> https://forums.modx.com/thread/38274/support-comments-for-css-star-rating?page=16#dis-post-453978 Quote from: garryn at Sep 09, 2009, 06:45 PM
For item 1, I've attached a Ditto extender that I coded up for one of our clients ...

Note: The extender assumes that your star rating TV is called ‘star_rating’ - if it's different, then the reference will need to be updated in the extender file.

To use the extender, please follow these steps:

  • Copy the attached extender file (remove the .txt extension first) into: assets/snippets/ditto/extenders/
  • In your snippet call for Ditto, add: &extenders=`star_rating`

The extender does two things. Firstly, it does the sorting and secondly, it sets a star_rating_val placeholder to use in your Ditto template. For example, you could have this in your Ditto template:
([+star_rating_val+] out of 5 stars)


For item 2, your best bet is to create a wrapper snippet that checks the logged-in user's group and then, using $modx->runSnippet(), either renders the full voting output or the read-only output depending on if they're allowed to vote or not.

Link don`t work... Help me, please!]]>
ghostery Feb 05, 2013, 07:43 PM https://forums.modx.com/thread/38274/support-comments-for-css-star-rating?page=16#dis-post-453978
<![CDATA[Re: Support/Comments for CSS Star Rating]]> https://forums.modx.com/thread/38274/support-comments-for-css-star-rating?page=16#dis-post-396261
I have a question: Can the code be modified to also display the current rating as a percentage in text format?

Thanks, Adam]]>
adammanderson Oct 07, 2011, 04:00 PM https://forums.modx.com/thread/38274/support-comments-for-css-star-rating?page=16#dis-post-396261
<![CDATA[Re: Support/Comments for CSS Star Rating]]> https://forums.modx.com/thread/38274/support-comments-for-css-star-rating?page=16#dis-post-216174 &onevote=`1` allows to vote more than one times... but randomly voting on some items is impossible... it generates other HTML >:( only votes, not links...WHY?

ditto cal: [!Ditto? &tpl=`contestListEntry` &paginate=`0`&extenders=`star_rating` !]
in contestListEntry tpl: .........[[star_rating?&docID=`[+id+]`&onevote=`1`]] [+star_rating_val+]........

I dont use full documents, only list of photos, one photo-one document
www: http://custombar.ru/ru/contest

Thanx for advice]]>
Comicz Sep 03, 2010, 09:51 AM https://forums.modx.com/thread/38274/support-comments-for-css-star-rating?page=16#dis-post-216174
<![CDATA[Re: Support/Comments for CSS Star Rating]]> https://forums.modx.com/thread/38274/support-comments-for-css-star-rating?page=16#dis-post-216173 resetez Apr 22, 2010, 12:28 PM https://forums.modx.com/thread/38274/support-comments-for-css-star-rating?page=16#dis-post-216173 <![CDATA[Re: Support/Comments for CSS Star Rating]]> https://forums.modx.com/thread/38274/support-comments-for-css-star-rating?page=16#dis-post-216172
I got the star rating working fine, the votes are being counted and showed in the ditto call for each page, but the format is in text.

4:1 (a rating of 4 with 1 vote) for example.

What parameter can I add to the ditto template chunk to get a more visually friendly vote rating/count to be displayed, but not voted on?

The parameters on the snippet download page don’t seem to be what I need.]]>
Wickian Dec 02, 2009, 10:03 PM https://forums.modx.com/thread/38274/support-comments-for-css-star-rating?page=16#dis-post-216172
<![CDATA[Re: Support/Comments for CSS Star Rating]]> https://forums.modx.com/thread/38274/support-comments-for-css-star-rating?page=15#dis-post-216171
Commenting out all 3 lines didn’t actually work but just commenting out the last did it,

thanks allot

Paul]]>
paulp Sep 21, 2009, 11:23 AM https://forums.modx.com/thread/38274/support-comments-for-css-star-rating?page=15#dis-post-216171
<![CDATA[Re: Support/Comments for CSS Star Rating]]> https://forums.modx.com/thread/38274/support-comments-for-css-star-rating?page=15#dis-post-216170
$ditto->advSort = true;
$ditto->addField('star_rating', '*');
$orderBy['custom'][] = array('sortBy','sortByStarRating');


This should stop it sorting by the star_rating but will still allow the star_rating placeholder to be set.]]>
garryn Sep 21, 2009, 11:08 AM https://forums.modx.com/thread/38274/support-comments-for-css-star-rating?page=15#dis-post-216170
<![CDATA[Re: Support/Comments for CSS Star Rating]]> https://forums.modx.com/thread/38274/support-comments-for-css-star-rating?page=15#dis-post-216169
Example:

I have a page that is displaying a list of articles that are rated using the title, short description and star rating score ( IE: 3.8 stars out of 5 ), then you can click throught to each article and are able to read the full article and rate it.

Does that make sence ??

I only want to be able to sort by page title as I want them alphabeticley, is there another way for me to pull the star rating into the ditto call so that it displays in the output ??

Cheers]]>
paulp Sep 21, 2009, 10:56 AM https://forums.modx.com/thread/38274/support-comments-for-css-star-rating?page=15#dis-post-216169
<![CDATA[Re: Support/Comments for CSS Star Rating]]> https://forums.modx.com/thread/38274/support-comments-for-css-star-rating?page=15#dis-post-216168 Right I was using &extenders=`star_rating` in my ditto call to show the star rating for documents listed from the call, however adding this seems to stop the sortBy in the call and I have no way of sorting by page title ( had to remove &extenders=`star_rating` to be able to sort ) Well, the star_rating extender overrides the sorting to sort by the star rating average for each document. Do you mean that you want to sort by star_rating, and then by pagetitle? If you want to only sort by pagetitle, then I’m not sure why you want to use the extender in the first place undecided]]> garryn Sep 21, 2009, 08:11 AM https://forums.modx.com/thread/38274/support-comments-for-css-star-rating?page=15#dis-post-216168