We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 32365
    • 42 Posts
    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.
      • 24860
      • 3 Posts
      Hi guys! pls a little help to put multiple rating in a single page. I try to make multiple tv-s but my ratings is collected in star_rating tv... I use evo. THX anticipated.
        • 5675
        • 120 Posts
        Doesn’t working properly with 1.0.3
        &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
          Автор благодарит алфавит за любезно предоставленные буквы
          • 37266
          • 1 Posts
          Hi, first of all thanks for such a great rating system!

          I have a question: Can the code be modified to also display the current rating as a percentage in text format?

          Thanks, Adam
            • 42671
            • 1 Posts
            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!
              • 40024
              • 72 Posts
              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.