{$cat_info['rating_cat_name']}
\r\n"; $output .= "
{$cat_info['rating_cat_min']}
{$cat_info['rating_cat_max']}
\r\n"; } else { $classes = "rated " . Rating::ShowStars($averageStars); $cat_info = Rating::FetchCategoryInfo($varItem); // Write Output HTML for the Rating Data $output = "\r\n"; $output .= "
{$cat_info['rating_cat_name']}
"; $output .= "
{$cat_info['rating_cat_min']}
{$cat_info['rating_cat_max']}
\r\n"; } } else { $output = ""; // This is a major issue. NO information can be retrieve if an item name is not passed. Error::LogError("Variable Missing", "You must provide the item name for this function to find the average."); } return $output; } public static function OutputParentRating($varParent) { // Verify $varParent was provided if ($varParent != null && strlen(trim($varParent)) != 0) { // Check if Magic QUotes is ON if (!get_magic_quotes_gpc()) { $varParent = addslashes($varParent); } // Information for the Output $averageStars = Rating::CalculateAverageParentRating($varParent); $classes = "rated " . Rating::ShowStars($averageStars); //$parent_info = Rating::FetchParentInfo($varParent); // Write Output HTML for the Rating Data $output = "\r\n"; //$output .= "
Overall Rating
"; $output .= "
\r\n"; } else { $output = ""; // This is a major issue. NO information can be retrieve if an item name is not passed. Error::LogError("Variable Missing", "You must provide the parent name for this function to find the average."); } return $output; } // Rate an Item // Returns the name/value pair of new class names and the item name public static function RateItem($varParent, $varItem, $varRating, $varClasses) { $newClassNames = $varClasses; // Verify $varName was provided if ($varParent != null && strlen(trim($varParent)) != 0 && $varItem != null && strlen(trim($varItem)) != 0 && $varRating != null && strlen(trim($varRating)) != 0 && is_numeric($varRating) && $varClasses != null && strlen(trim($varClasses)) != 0) { // Check if Magic Quotes is ON if (!get_magic_quotes_gpc()) { $varItem = addslashes($varItem); $varParent = addslashes($varParent); } // Check to see that the user has not already rated this item if (Rating::CheckRatingsByIp($varParent, $varItem) == 0) { $ipAddress = $_SERVER['REMOTE_ADDR']; $tempTime = time(); Database::ExecuteQuery("INSERT INTO `gforum_FittersRating` (`rating_fitter_id`, `rating_category_id`, `rating_vote`, `rating_ip`, `rating_date`) VALUES ('{$varParent}', '{$varItem}', {$varRating}, '{$ipAddress}', '{$tempTime}')", "InsertRating"); Database::FetchResults("InsertRating"); Database::FreeResults("InsertRating"); Database::RemoveSavedResults("InsertRating"); // Information for the Output $averageStars = Rating::CalculateAverageRating($varParent, $varItem); $newClassNames = "rated " . Rating::ShowStars($averageStars); $averageStars = Rating::CalculateAverageParentRating($varParent); $newClassParent = "rated " . Rating::ShowStars($averageStars); } } else { // This is a major issue. NOT enough information was sent to log the item Error::LogError("Variable(s) Missing", "You must provide all of the information to log the rating of this item."); } // Build Name/Value Pair to return $nameValue = "classes={$newClassNames}&item={$varItem}&parent={$varParent}&parentClass={$newClassParent}"; return $nameValue; } ## END PUBLIC METHODS ## PRIVATE METHODS // Fetch Category Names & Min/Max Values private static function FetchCategoryInfo($varItem) { // Query Category Info for a specific Category ID Database::ExecuteQuery("SELECT * FROM `gforum_FittersRatingCategory` WHERE `rating_cat_id`='{$varItem}'", "CategoryInfo"); $results = Database::FetchResults("CategoryInfo"); Database::FreeResults("CategoryInfo"); Database::RemoveSavedResults("CategoryInfo"); return $results[0]; } // Calculate Average Rating // Returns the number of stars to show private static function CalculateAverageRating($varParent, $varItem) { $averageStars = 0; // Query Average Rating for a specific Item Database::ExecuteQuery("SELECT AVG(`rating_vote`) AS `averageRating` FROM `gforum_FittersRating` WHERE `rating_category_id`='{$varItem}' AND `rating_fitter_id`='{$varParent}'", "AverageRating"); $results = Database::FetchResults("AverageRating"); Database::FreeResults("AverageRating"); Database::RemoveSavedResults("AverageRating"); // Round the Average into a Whole Number if (sizeof($results) == 1) { if ($results[0]['averageRating'] != null) { $averageStars = round($results[0]["averageRating"], 0); } } else { // This is simply a warning, as it isn't vital if no results were found, as the item may be new. Error::LogWarning("Rating Data Missing", "No entries were found for '{$varName}', this might be the first entry."); } return $averageStars; } // Calculate Average Rating // Returns the number of stars to show private static function CalculateAverageParentRating($varParent) { $averageStars = 0; // Query Average Rating for a specific Item Database::ExecuteQuery("SELECT AVG(`rating_vote`) AS `averageRating` FROM `gforum_FittersRating` WHERE `rating_fitter_id`='{$varParent}'", "AverageRating"); $results = Database::FetchResults("AverageRating"); Database::FreeResults("AverageRating"); Database::RemoveSavedResults("AverageRating"); // Round the Average into a Whole Number if (sizeof($results) == 1) { if ($results[0]['averageRating'] != null) { $averageStars = round($results[0]["averageRating"], 0); } } else { // This is simply a warning, as it isn't vital if no results were found, as the item may be new. Error::LogWarning("Rating Data Missing", "No entries were found for '{$varName}', this might be the first entry."); } return $averageStars; } // Show Stars // Returns the class information for the number of stars to show private static function ShowStars($varStars) { // Select the Number of Stars Class switch ($varStars) { case 1: $classes .= "onestar"; break; case 2: $classes .= "twostar"; break; case 3: $classes .= "threestar"; break; case 4: $classes .= "fourstar"; break; case 5: $classes .= "fivestar"; break; default: $classes .= "nostar"; break; } return $classes; } // Check Ratings By IP Address // Returns the number of ratings for an item by an ip address private static function CheckRatingsByIp($varParent, $varItem) { $ipAddress = $_SERVER['REMOTE_ADDR']; Database::ExecuteQuery("SELECT COUNT(*) AS `totalRatings` FROM `gforum_FittersRating` WHERE `rating_category_id`='{$varItem}' AND `rating_fitter_id`='{$varParent}' AND `rating_ip`='{$ipAddress}'", "AlreadyRated"); $results = Database::FetchResults("AlreadyRated"); Database::FreeResults("AlreadyRated"); Database::RemoveSavedResults("AlreadyRated"); // Check to see that the user has not already rated this item if ($results != null && $results[0]['totalRatings'] != null) { return $results[0]['totalRatings']; } return 0; } ## END PRIVATE METHODS } ?>