New Snippet: AJAX Star Rating Snippet

crnogorac081

I played a little with this snippet, and made a top rated list  :-D

This code should be included in include.php file just before ?> tag
Code (include.php) Select

function Show_Top_Rating($count = 5, $title = "Top rated:", $show_title = 1, $show_totals = 0, $ShowRatingStars = 1, $ShowOutOfFive = 1, $ShowRating = 1, $ShowVotes = 1 ) {
   global $database;
   $tbl_counter = TABLE_PREFIX ."mod_ajaxsurvey_question";
   $tbl_pages = TABLE_PREFIX ."pages";
   $pagelist = $database->query("SELECT sum(question_id) as total, r.page_id, p.page_title, p.menu_title, p.link, question_id as question
       FROM $tbl_counter r
       INNER JOIN $tbl_pages p on (p.page_id = r.page_id)
       GROUP BY page_id
       ORDER BY total ASC");
   $inner_count = 0;
   if ($pagelist->numRows() > 0){
       echo "<div class=\"ajaxTopRatingTitle\"><h3>$title</h3></div><div class=\"ajaxTopRatingBox\"><ul>";
       while(($res = $pagelist->fetchRow()) && ($inner_count++ < $count)) {
   
       if ($ShowOutOfFive == 1) { $OutOfFiveEcho = ' ,Rated <span id="outOfFive_'.$res['question'].'" class="out5Class">'.outOfFiveSnip($res['question']).'</span>/5'; } else { $OutOfFiveEcho = ''; }
       if ($ShowVotes == 1) { $ShowVotesEcho = ' ,<span id="percentage_'.$res['question'].'" class="percentClass">'.getVotesSnip($res['question']).'</span>'; } else { $ShowVotesEcho = ''; }
       if ($ShowRating == 1) { $ShowRatingEcho = ' (<span id="showvotes_'.$res['question'].'" class="votesClass">'.getRatingSnip($res['question']).'</span>)'; } else { $ShowRatingEcho = ''; }
       if ($ShowRatingStars == 1) { $ShowRatingStarsEcho = pullRating($res['question']); } else { $ShowRatingStarsEcho = ''; }

           if ($show_title == 1) {
               $TopRatedTitle = showQuestionTitle($res['question']); }           
           else if ( $show_title == 2) {
           $TopRatedTitle = $res['menu_title']; }
           else if ( $show_title == 3) {
           $TopRatedTitle = $res['page_title']; }


           echo "<li><a href=\"".page_link($res['link'])."\"";
           echo ">".$TopRatedTitle.$ShowRatingStarsEcho.$OutOfFiveEcho.$ShowRatingEcho.$ShowVotesEcho."</a></li>" ;
       }
       echo "</ul></div>";
   }
}



You can call the snippet with simple Show_Top_Rating(); or advanced call:  Show_Top_Rating(5,"Top rated pages:",2,1,1,1,1);

the parametars in snippet are:


$count = 5                    ---- shows number of items in list
$title = "Top rated:"       ---- Title text
$show_title = 1              ---- Shows title for list item: 1 = Question title, 2 = Menu title, 3 = Page title
$ShowRatingStars = 1      ---- Displays stars
$ShowOutOfFive = 1        ---  Shows: Rated 5/5
$ShowRating = 1             ---- Shows: (100%)
$ShowVotes = 1             ----  Shows: 1 time vodet


Also there are two css classes: ajaxTopRatingTitle and ajaxTopRatingBox which you can style in your template css file..

cheers
Web developer

crnogorac081

#13
Hi,

just followed your instructions and page rating was working, but the snippet didn't. I examined the code from the snipped as Error I mentioned above appeared again, and find that it was wrong table name to call:


mod_ajaxstarratting_question
mod_ajaxstarratting_rating

instead

mod_ajaxsurvey_question
mod_ajaxsurvey_rating


It must be some older version :)

Also in page rating, I added an extra line in backend (see attached picture) for Id (it will be handy if you have much questions to rate, when you call the snippet..)

I also zipped "fixed" page rating (includes new rating_functions.php ), and the snippet..

cheers




[gelöscht durch Administrator]
Web developer

SourDough

This snippet works in conjunction with the module in my first post here:  https://forum.websitebaker.org/index.php/topic,10332.0.html.  You need to install the module before AND the snippet for the snippet to work. 

Nick

crnogorac081

#11
Hi Nick,

I downloaded and instaled the snippet from the first post (version 1.0). Then added

pullRatingSnip();

in a code section on some page. Here is error:

Fatal error: Call to a member function fetchRow() on a non-object in I:\WebsiteBaker Portable1_2\htdocs\inf\modules\AJAX_Star_Rating_Snippet\include.php on line 36

al best,
ivan
Web developer

SourDough

Which version of Ajax Star Rating are you using?  What errors are you seeing?  Set error reporting to E_ALL.  Additionally, this snippet was written by me to work with the original release of this module.  I suspect you are using the version of the module re-released by JohnP (aka cnwb).

Nick

crnogorac081

#9
not working with wb 2.8 rc1 :(
Web developer

crnogorac081

I created  a new page, and in code module inserted pullRatingSnip(); and nothing happened ??

what am I doing wrong?
Web developer

webslaav

Love the snippet! Here's a new question for you all:
I have a bunch of pages and all can be rated.
Now, on the homepage I want links to the 5 pages with the highest scores. Just the highest, not through difficult math of how many people voted versus scores..just plain scores.

Can anyone help?
Regards,
Alex
For a moment, nothing happened. Then, after a second or so, nothing continued to happen.

Vlob

anyone already made a droplet from the snippet?  would be very handy

SourDough

FYI, this snippet only works with the original version of the AJAX Star Rating, not with the "improved" version by Johnp.

Nick


erpe0812

#4
There is another one listed at AMASP.

rgds

erpe

anjelo

Hey this is THE solution I was looking for so long. I didn't know if I was going to find it till the end of the new year in. :mrgreen:

Hopefully I did. Thanks anyway!

soki


SourDough

#1
This was at the request of user Soki in thread https://forum.WebsiteBaker.org/index.php/topic,10332.msg64477.html#msg64477

This snippet provides a way to display just one of the questions/ratings from the AJAX Star Rating module on a page type code, or from the template index.php file.  This snippet does not allow voting to take place, it is for display purposes only.  If there is enough interest, I can rewrite to allow voting. 

There is a readme included, but basic usage follows:

From template index.php:
<?php pullRatingSnip(); ?>

From a code module:
pullRatingSnip();

For a more customized output, you can pass over serveral parameters to the function explained below.

<?php pullRatingSnip($question_id,$showfive,$showperc,$showtotal,$showdetail); ?>

Options:
//question_id    id of the question (defaults to 1)
//showfive       shows how many votes out of five, 0 for no, 1 for yes (default yes)
//showperc       shows vote percentage, 0 for no, 1 for yes (default yes)
//showtotal      shows total votes, 0 for no, 1 for yes (default yes)
//showdetail         whether to show question detail, 0 for no, 1 for yes (default no)


Hope this is useful.

Nick



[gelöscht durch Administrator]