We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 30277
    • 75 Posts
    Hello again

    Wohooo It worked ,it count my vote .

    One thing i dont sure if it works like that, it shows all 5 stars after i voted yellow ( when i mouse over it goes orange) ( it was grey/white before i vote) ) i tryed to vote again since i didnt set any like 1 vote browser session and it count my vote again is this normal ?

    Thank you for your fast responses and soleved it smoothly laugh
      • 10487 MODX Staff
      • 1,535 Posts
      One thing i dont sure if it works like that, it shows all 5 stars after i voted yellow ( when i mouse over it goes orange) ( it was grey/white before i vote) ) i tryed to vote again since i didnt set any like 1 vote browser session and it count my vote again is this normal ?
      Sounds like it working to me smiley (It’s actually my fault that it didn’t work to start with, this bug got reported earlier in the thread and I forgot to update the Repository package with the updated code - will do that now embarrassed)

      It’s normal for it to allow multiple voting if you don’t set any of the voting restrictions (session or cookie snippet parameters). Please be aware that the voting restrictions can be a bit buggy in the Version 1 release and will be corrected in Version 2.

      Glad to help,
      Garry



        Garry Nutting
        Senior Developer
        MODX, LLC

        Email: [email protected]
        Twitter: @garryn
        Web: modx.com
        • 30277
        • 75 Posts
        Thank you Garry for all fast responses & help to this noob smiley
          • 14796
          • 59 Posts
          Hey Garry,

          I updated my snippet to the 2beta and I’m having problems with the &webGroups. I just want it to recognize the ’Registered Users’ which from my understanding is a built in group.

          After entering this it still allows me to vote while I’m logged out.

          Any suggestions?

          Thanks,

          Josh
            • 14796
            • 59 Posts
            Another question:

            Garry: From reading the previous posts I understand that you are working on the sessions and cookies. Would it be difficult to add an option to save the cookie on the server side as well if webgroups is turned on?

            This would be a great option because it’s very easy to delete a cookie on the user side and then just vote again, but if the code did it on the server side or the option for either or both that would be great.

            Or if anyone knows how this might be possible, I would really appreciate it smiley

            Thanks,

            Josh
              • 24731 ☆ A M B ☆
              • 211 Posts
              Hi, I am having a little problem with the view only option. I am trying to display the rating for a given document using this code:

              [!star_rating? &docID=`[+id+]` &tvName=`star_rating` &starTpl=`StarRatingDisp` &cssFile=`2` &imgWidth=`16px` &viewOnly=`true`!]

              It works fine, except it still lets me vote. Even if I try:

              [!star_rating? &docID=`[+id+]` &tvName=`star_rating` &starTpl=`StarRatingDisp` &cssFile=`2` &imgWidth=`16px` &useSession=`true` &useCookie=`true` &viewOnly=`true`!]

              It will give me view only for the documents I have already voted, but those I have never voted gives me the option to vote regardless where all I want is to display its rating score.

              Any ideas?

              Jose R. Lopez
                • 24731 ☆ A M B ☆
                • 211 Posts
                Hi Again, I am sorry if this looks stupid, I am not a programmer, but by tracking down the functions in the php files, I found this:

                	/*
                	 * Checks permissions and properties to see if voting is disallowed
                	 */
                	function __disallowVoting() {
                		if ($this->webGroups !== false && $this->__checkMembership() == false) {
                			return true;
                		}
                		if (!$this->_keysObtained) {
                			$this->__getKeys();
                		}
                		if ($this->useCookie == true && array_key_exists($this->_tvId, $this->_cookieDKey)) {
                			$this->viewOnly = true;
                			return true;
                		}
                		elseif ($this->useSession == true && array_key_exists($this->_tvId, $this->_sessionDKey)) {
                			$this->viewOnly = true;
                			return true;
                		} else {
                			$this->viewOnly = $this->viewOnly ? $this->viewOnly : false;
                			return false;
                		}
                	}


                This is the function based on which it formats the output with or without links for allowed voting or not. I just added the lines between Jose Lopez edit and it appears to be working correctly now.

                /*
                	 * Checks permissions and properties to see if voting is disallowed
                	 */
                	function __disallowVoting() {
                		if ($this->webGroups !== false && $this->__checkMembership() == false) {
                			return true;
                		}
                		if (!$this->_keysObtained) {
                			$this->__getKeys();
                		}
                		if ($this->useCookie == true && array_key_exists($this->_tvId, $this->_cookieDKey)) {
                			$this->viewOnly = true;
                			return true;
                		}
                		// Jose Lopez Edit
                		if ($this->viewOnly == true) {
                			return true;
                		}
                		// Jose Lopez Edit
                		elseif ($this->useSession == true && array_key_exists($this->_tvId, $this->_sessionDKey)) {
                			$this->viewOnly = true;
                			return true;
                		} else {
                			$this->viewOnly = $this->viewOnly ? $this->viewOnly : false;
                			return false;
                		}
                	}


                Regards,
                Jose R. Lopez
                  • 593
                  • 56 Posts
                  Hi all, I have a problem with using of this snippet (2beta)
                  When I am opening the page ModX show the next error:

                  « MODx Parse Error »
                  MODx encountered the following error while attempting to parse the requested resource:
                  « PHP Parse Error »

                  PHP error debug
                  Error: array_key_exists() [function.array-key-exists]: The second argument should be either an array or an object
                  Error type/ Nr.: Warning - 2
                  File: /home/u23547/kalugaonline.ru/www/assets/snippets/star_rating/rating.class.php
                  Line: 297
                  Line 297 source: if (array_key_exists($this->passedId, $cArray)) {

                  Parser timing
                  MySQL: [^qt^] ([^q^] Requests)
                  PHP: [^p^]
                  Total: [^t^]


                  As far as I understand, $cArray is empty.
                  Anybody knows how to solve this problem? Thanks.

                  Modx version 0.9.5

                    • 9053
                    • 18 Posts
                    Here is described how to make ajaxed star rater. It can be easily implemented in CSS Star Rating (version 1. Not sure about v2 - it doesn’t work for me - same problem as afizikov described above).

                    Here is quick example of axajed CSS Star Rating in work.

                    You can ajaxify your rating in 2 easy steps:

                    1. Change your template so it looks like this:

                    <ul class='star-rating'>
                    	<li id='current-rating' style='width:" . $width . "px;'>" . $_lang['current_1'] . $currentStarValue . $_lang['current_2'] . "</li>
                    	<span id=" . $quote . "ratelinks" . $quote . ">
                    		<li><a  href='javascript:rate(1," . $docID . ")' title='" . $_lang['one_star'] . "' class='one-star'>1</a></li>
                    		<li><a  href='javascript:rate(2," . $docID . ")' title='" . $_lang['two_stars'] . "' class='two-stars'>2</a></li>
                    		<li><a  href='javascript:rate(3," . $docID . ")' title='" . $_lang['three_stars'] . "' class='three-stars'>3</a></li>
                    		<li><a  href='javascript:rate(4," . $docID . ")' title='" . $_lang['four_stars'] . "' class='four-stars'>4</a></li>
                    		<li><a  href='javascript:rate(5," . $docID . ")' title='" . $_lang['five_stars'] . "' class='five-stars'>5</a></li>
                    	</span>
                    	</ul>
                    <div id="ratingtext">Votes: [+totalVotes+]</div>
                    


                    Last div can be span or smth else, doesn’t matter. Please note what i’ve changed class=’current-rating’ to id=’current-rating’, so you need to change your css file a little bit (.current-rating to #current-rating).

                    2. Next, we must have some ajax requests handler and "rate" function. You may use mootools, but me isn’t familiar with that framework, so I use plain js:

                    function datosServidor() {
                    };
                    datosServidor.prototype.iniciar = function() {
                    	try {
                    		// Mozilla / Safari
                    		this._xh = new XMLHttpRequest();
                    	} catch (e) {
                    		// Explorer
                    		var _ieModelos = new Array(
                    		'MSXML2.XMLHTTP.5.0',
                    		'MSXML2.XMLHTTP.4.0',
                    		'MSXML2.XMLHTTP.3.0',
                    		'MSXML2.XMLHTTP',
                    		'Microsoft.XMLHTTP'
                    		);
                    		var success = false;
                    		for (var i=0;i < _ieModelos.length && !success; i++) {
                    			try {
                    				this._xh = new ActiveXObject(_ieModelos[i]);
                    				success = true;
                    			} catch (e) {
                    				// Implementar manejo de excepciones
                    			}
                    		}
                    		if ( !success ) {
                    			// Implementar manejo de excepciones, mientras alerta.
                    			return false;
                    		}
                    		return true;
                    	}
                    }
                    
                    datosServidor.prototype.ocupado = function() {
                    	estadoActual = this._xh.readyState;
                    	return (estadoActual && (estadoActual < 4));
                    }
                    
                    datosServidor.prototype.enviar = function(urlget,datos) {
                    	if (!this._xh) {
                    		this.iniciar();
                    	}
                    	if (!this.ocupado()) {
                    		this._xh.open("GET",urlget,false);
                    		this._xh.send(datos);
                    		if (this._xh.readyState == 4 && this._xh.status == 200) {
                    			return this._xh.responseText;
                    		}
                    		
                    	}
                    	return false;
                    }
                    
                    function rate(rating,pid)  {
                    		document.getElementById('ratelinks').style.display = 'none';
                    		document.getElementById('ratingtext').innerHTML = 'Please wait...';
                    		remotos = new datosServidor;
                    		nt = remotos.enviar('?starvote='+rating+'&pid='+pid);
                    		rating = rating * 25;
                    		document.getElementById('current-rating').style.width = rating + 'px';
                    		document.getElementById('ratingtext').innerHTML = 'Thanks for voting!';
                    }
                    


                    Code is borrowed from the link above.

                    This is all what we need to be done in order to have nice ajaxed rating. It has one great advantage - links aren’t grabbed by search engines, so rating isn’t affected by non-humans. Add to this some economy in traffic and users time to load updated page.
                    Of course, there are some disadvantages:
                    1) Links are not accessible for visitors with JS turned off.
                    2) If request fails, user won’t know - he’ll see "Please wait..." message. This can be eliminated by adding fail handler.

                    There is also much more sophisticated ajax rater to try use it with MODx.

                    Cheers
                      "Sorry for my english"
                      • 33273
                      • 60 Posts
                      Hello, Errant!
                      I make 2 easy steps to ajaxify my star rating, but almost everytime my browser gets down...(Mozilla)
                      Cursor becomes hand on forever...
                      Sometimes all ok.
                      What’s the matter?