Example php file needed for querying ratings

iMinnesotan

Joined: 2008-10-23
Posts: 27
Posted: Wed, 2008-12-24 14:46

I have a new web site (http://www.isobap.com) for a photo club and each month members contribute their photos to the album. We then use the rating system to cast votes to pick the winners. I was logging into phpMyAdmin and querying the results but I would prefer to have a php page that takes the id of the album from the request and generates html results.

Can anyone point me to a sample php file that queries the g2 tables and shows the results? I have the query figured out but I need an example php file that does something similar to what I'm looking to do. I am a Java programmer and have used Oracle and MS SQL Server but I haven't yet done any php programming and limited MySQL. I figure that I could start with an example and just alter it until I get the results that I'm looking for.

Thanks you for your help.

Barry

 
iMinnesotan

Joined: 2008-10-23
Posts: 27
Posted: Wed, 2008-12-24 16:35

In case anyone is interested, I basically want to produce a web page of the following query, as opposed to the manual steps that I'm taking now:

SELECT g2_User.g_userName, g2_Item.g_id as itemid, g2_Item.g_title, g2_Item.g_description, sum(g2_RatingMap.g_rating = 5) AS five,
sum(g2_RatingMap.g_rating = 4) AS four,
sum(g2_RatingMap.g_rating = 3) AS three,
sum(g2_RatingMap.g_rating = 2) AS two,
sum(g2_RatingMap.g_rating = 1) AS one
FROM g2_User, g2_ChildEntity, g2_Item, g2_RatingMap
WHERE (g2_Item.g_id = g2_ChildEntity.g_id)
AND (g2_ChildEntity.g_parentID = 149)
AND (g2_Item.g_ownerId = g2_User.g_id)
AND (g2_RatingMap.g_itemId = g2_Item.g_id)
GROUP BY g2_Item.g_id
ORDER BY g2_User.g_userName

 
suprsidr
suprsidr's picture

Joined: 2005-04-17
Posts: 8339
Posted: Wed, 2008-12-24 18:45

Or let gallery do the query:

    function getRating($itemId) {
	    global $gallery;
	    GalleryCoreApi::requireOnce('modules/rating/classes/RatingHelper.class');
	    list ($ret, $Ratings) = RatingHelper::fetchRatings($itemId, '');
	    if($ret){
	        return false;
	    }else{
	        return $Ratings[$itemId]['rating']
	    }
    }

-s
FlashYourWeb and Your Gallery with The E2 XML Media Player for Gallery2

 
iMinnesotan

Joined: 2008-10-23
Posts: 27
Posted: Wed, 2008-12-24 19:06

Great, I'll look more into using RatingHelper. But for scoring we award points (***** = 10pts, **** = 7pts, *** = 5 pts, ** = 2pts, * = 1pt). I don't want one photo with 5,5,1 to score the same as 5,4,2 or is the rating system already giving more weight to 5s than 4s?

A also don't know how to wrap it all up as a php file.

 
suprsidr
suprsidr's picture

Joined: 2005-04-17
Posts: 8339
Posted: Wed, 2008-12-24 19:49
<?php

/* Connect to gallery */
function init() {
require_once ('embed.php');
$ret = GalleryEmbed::init( array ('fullInit'=>true, 'embedUri'=>'/gallery2/main.php', 'g2Uri'=>'/gallery2/'));
if ($ret) {
    print 'GalleryEmbed::init failed, here is the error message: '.$ret->getAsHtml();
    exit ;
}
GalleryEmbed::done();
}

function getRating($itemId) {
global $gallery;
GalleryCoreApi::requireOnce('modules/rating/classes/RatingHelper.class');
list ($ret, $ratings) = RatingHelper::fetchRatings($itemId, '');
if ($ret) {
    return 'Sorry, no rating for item: '.$itemId;
} else {
    return 'The item rating is: '.$ratings[$itemId]['rating'];
}
}

if ( isset ($_REQUEST['g2_itemId'])) {
    init();
    echo getRating($_REQUEST['g2_itemId']);
}

?>

http://www.flashyourweb.com/gallery2/rating_sample.php?g2_itemId=8693

-s
FlashYourWeb and Your Gallery with The E2 XML Media Player for Gallery2

 
iMinnesotan

Joined: 2008-10-23
Posts: 27
Posted: Wed, 2008-12-24 20:47

Awesome suprsidr! I uploaded it to my site (testme.php) and tried one of my photos with a rating and it worked! This is exactly the start I was looking for.

Thanks!