We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 10357
    • 573 Posts
    I want like 5 ratings for different items all on one page

    could you not use something like ditto to do this? have each star rating on a separate page than use ditto to list them together.
    • Quote from: jek at Dec 02, 2006, 01:58 PM

      Hello!
      Anybody know how to null the rating?
      To null a rating, set the TV you are using for the star rating in the document to: 0:0

      If you mean something different, please post back smiley

      Quote from: g5604 at Dec 02, 2006, 02:58 PM

      I want like 5 ratings for different items all on one page

      could you not use something like ditto to do this? have each star rating on a separate page than use ditto to list them together.
      If anybody does have experience with using the star rating with Ditto, please let me know. I’m pulling together a feature list for a new version of the star rating snippet so would interested in knowing any requirements/requests that people have.

      Cheers,
      Garry
        Garry Nutting
        Senior Developer
        MODX, LLC

        Email: [email protected]
        Twitter: @garryn
        Web: modx.com
        • 10647
        • 36 Posts
        Hi, I’m in the search of a very specific ranking system. Maybe in the next version you can try to help me?

        I asked about it here.

        Quote from: ajayre at Nov 07, 2006, 07:11 PM

        Do you understand Template Variables (TVs)? It’s like adding a property to each document.

        Create a template for the documents that will be voted on.

        Create a template variable called "votes" and add it to the template. Default value is zero.

        Create documents based on the template.

        Create a snippet called "vote" that when clicked increments the value in the template variable. However you will have to add flood control so someone can’t spam the voting system. So only let a specific IP address vote once per document.

        To show the top 10 documents, use Ditto and pass:

        &sortBy=`votes`


        I hope this helps.

        Andy

        So basically, the snippit. My knowledge of coding is elementary at best. I would like it set up so that only a specific user can vote only once. grin Thanks!
          • 10666
          • 68 Posts
          Hello!
          First of all ,I have to say this is a very nice and useful snippet!

          Second, it has a bug that is pretty annoying . I have traced it down and I will try to explain(I totally suck at explaining stuff grin ) what it does:

          Say you have a ditto listing with 10 article summarys on a page , and after each summary you have:
          [!star_rating? &docID=`[+id+]` &onevote=`true`!] (included in the ditto chunk of course).You want your users to vote only once,based on the cookie option ($onevote).When you vote on an article, the only star rating that gets disabled ,is the first one on the page.

          I click the star and the
          $_GET['starvote']
          variable gets set . On the page that now loads the snippets begin to be processed. The first one on the page does
          setcookie('cssStarRating' . $docID, 'novote', time() + $ovtime);
          and is thus disabling it’s own article that should be voted , not the one we chose to vote ! ( the ID of that article is transmitted with the help of $pid if I’m not mistaken).Further on , the snippet processes it’s data, and does: unset ($_GET); . After this snippet called is finished,there are 9 more to pe processed,and there is no more $_GET data.(thus,no more $_GET[’starvote’] and no more cookies sad )

          To put it short , the cookie is set for the wrong document ID , it sets the current docID from the snippets call as read , instead of the voted one (as those the useSession option).

          I would have tried to hack the script myself, but as I am pretty much a newbie in PHP ( woot,this was actually the first php script I ever debugged tongue ) it wouldn’t have been a very good idea.


          And third, I have a feature request (well, actually more of a change of behaviour).
          After you have voted let’s say hmm... 5 out 10 article summarys that have the star_rating attached ,and disable repeated voting , half your page will have the "You may only vote once" , even if you haven’t had the intention of voting the same article summary again. (maybe this appears only in a certain situation e.g.: when the useSession , onevote paramaters gets used on at a time , or both at once - haven’t checked witch case ... smiley ).
          Thus , a say that a better aproach would that of activating $viewOnly for the articles voted instead of displaying the text. I tried to hack the script, but the code is messy and redundant:
          if($novote) {
          	$starPhArray['starRating'] = "<ul class='star-rating'>
          	<li class='current-rating' style='width:" . $width . "px;'>" . $_lang['current_1'] . $currentStarValue . $_lang['current_2'] . "</li>
          		<li class='one-star'>1</li>
          		<li class='two-stars'>2</li>
          		<li class='three-stars'>3</li>
          		<li class='four-stars'>4</li>
          		<li class='five-stars'>5</li>
          	</ul>";
          }
          else
          {
          if (!$viewOnly) {
          	$starPhArray['starRating'] = "<ul class='star-rating'>
          		<li class='current-rating' style='width:" . $width . "px;'>" . $_lang['current_1'] . $currentStarValue . $_lang['current_2'] . "</li>
          		<li><a href='" . $modx->makeUrl($modx->documentObject['id'], $modx->documentObject['alias'], 'starvote=1&pid=' . $docID) . "' title='" . $_lang['one_star'] . "' class='one-star'>1</a></li>
          		<li><a href='" . $modx->makeUrl($modx->documentObject['id'], $modx->documentObject['alias'], 'starvote=2&pid=' . $docID) . "' title='" . $_lang['two_stars'] . "' class='two-stars'>2</a></li>
          		<li><a href='" . $modx->makeUrl($modx->documentObject['id'], $modx->documentObject['alias'], 'starvote=3&pid=' . $docID) . "' title='" . $_lang['three_stars'] . "' class='three-stars'>3</a></li>
          		<li><a href='" . $modx->makeUrl($modx->documentObject['id'], $modx->documentObject['alias'], 'starvote=4&pid=' . $docID) . "' title='" . $_lang['four_stars'] . "' class='four-stars'>4</a></li>
          		<li><a href='" . $modx->makeUrl($modx->documentObject['id'], $modx->documentObject['alias'], 'starvote=5&pid=' . $docID) . "' title='" . $_lang['five_stars'] . "' class='five-stars'>5</a></li>
          	</ul>";
          } else {
          	$starPhArray['starRating'] = "<ul class='star-rating'>
          	<li class='current-rating' style='width:" . $width . "px;'>" . $_lang['current_1'] . $currentStarValue . $_lang['current_2'] . "</li>
          		<li class='one-star'>1</li>
          		<li class='two-stars'>2</li>
          		<li class='three-stars'>3</li>
          		<li class='four-stars'>4</li>
          		<li class='five-stars'>5</li>
          	</ul>";
          }
          }
          $starPhArray['totalVotes'] = $totalVotes;
          
          foreach ($starPhArray as $n => $v) {
          	$starTpl = str_replace('[+' . $n . '+]', $v, $starTpl);
          }
          	$output .= $starTpl;


          Looking forward for some feedback ,I hope that what I wrote makes sense tongue .
          • I’m aware of issues with the star rating and Ditto - it was never really designed to work with Ditto out of the box so I’m not surprised there are issues at the moment wink

            I will look into the issues (and feature requests) and get an updated version posted - thanks for the feedback! laugh
              Garry Nutting
              Senior Developer
              MODX, LLC

              Email: [email protected]
              Twitter: @garryn
              Web: modx.com
              • 10666
              • 68 Posts
              Hmm.. I’m back !

              For the Ditto issue,I found quite a simple fix .For those that can’t wait for the official updated version,just replace
              		setcookie('cssStarRating' . $docID, 'novote', time() + $ovtime);

              with:
              		setcookie('cssStarRating' . $pid, 'novote', time() + $ovtime);

              (line 67).
              I think that this change would represent the right logic in the code.


              Also , upon further testing I stumbled on another bug.
              When you have a voting snippet on a page , even if you disabled repeated voting with both useSession and onevote you can still vote repeatedly.

              To test for yourself , go on a page that has an active voting snippet and right click on one of the stars,and copy the link location.Let’s take this one for example:
              http://modxcms.com/GoogleMapMarker-723.html?starvote=4&pid=723
              After you click on the star , and vote, the snippet will be "disabled" in the sense that the stars are no longer click-able.But, if you paste in the url bar the copied link ( http://modxcms.com/GoogleMapMarker-723.html?starvote=4&pid=723 ) and go to that page, you will see that the voting choice actually took effect , and there’s one more vote ,though voting was disabled.So , the voting interface is disabled, but the actual processing is still being done.

              I think the snippet would benefit from some code logic rewrite,though the bugs can be fixed within the current structure(-but it’s somewhat difficult ,since processing and displaying code is quite mixed).

              Also , by studying this snippet , I have to say I also learned more php than I have done in quite a few months , so my study on your snippet may not be over yet grin .
              • Thanks geo88! I’ve already fixed the logic in my latest version that I’m finishing off writing now - there was a couple of issues I found around the sessions and cookies implementation. (The new version is a complete rewrite and will be objectified which should make it easier for people to integrate into other snippets etc. as well)

                Shouldn’t be too long before I can get the next version out for a beta - I’m aiming to finish the coding and do some testing over the weekend smiley
                  Garry Nutting
                  Senior Developer
                  MODX, LLC

                  Email: [email protected]
                  Twitter: @garryn
                  Web: modx.com
                  • 10666
                  • 68 Posts
                  Sounds great tongue .

                  I f you need some beta testers,I’ll be glad to participate.

                  Also , I would have another feature request embarrassed . Could this snippet be ajaxified,as in not having to reload the page after a vote, or at least have a paramater so we could control the redirection upon clicking a star link ? grin

                  Cheers !
                  • Well, here you go ... CSS Star Rating v2 beta has arrived smiley

                    This is a complete rewrite of the snippet code and should solve the problems with calling it multiple times for different documents (such as when it is used in a Ditto call). Some of the other changes:

                    • Added &webGroups parameter for restricting voting to certain web Groups - pass in a comma-separated list of group names to use.
                    • Added &redirect parameter to control the redirection once a vote has been saved - specify a valid document ID to use and make sure the voter will have access to the page (ie. page is published and voter has the correct permissions)
                    • It is now possible to call the star rating multiple times for the same document by specifying the different TV names to use.
                    • Complete rewrite of the way that Star Rating handles sessions and cookies.
                    • &onevote is now &useCookie and &ovtime is now &cookieExpiry. However, the snippet is backwards compatible so shouldn’t break any previous calls.
                    • The &cssFiles array is now deprecated but backwards compatibility is supported; if you have used this array then please remember to add your custom entries back into the array when upgrading.

                    Please remember this is a beta release, so use it with discretion. (release notes with instructions for installation are in the archive).

                    @Geo88: Ajax is next on my list of things I want to do, some of the changes in this beta release are in preparation of working on the Ajax handler for the snippet.

                    Cheers,
                    Garry
                      Garry Nutting
                      Senior Developer
                      MODX, LLC

                      Email: [email protected]
                      Twitter: @garryn
                      Web: modx.com
                      • 10666
                      • 68 Posts
                      Downloaded it yesterday,testing it today/tommorow tongue .