<?php /** ! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * [filename] is a part of PeopleAggregator. * [description including history] * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * @author [creator, or "Original Author"] * @license http://bit.ly/aVWqRV PayAsYouGo License * @copyright Copyright (c) 2010 Broadband Mechanics * @package PeopleAggregator */ $login_required = TRUE; //including necessary files $use_theme = 'Beta'; //TODO : Remove this when new UI is completely implemented. include_once "web/includes/page.php"; require 'api/Rating/Rating.php'; $Rating = new Rating(); if (!empty($_POST)) { $Rating->set_rating_type(@$_POST['rating_type']); $Rating->set_type_id(@(int) $_POST['type_id']); $Rating->set_rating(@(int) $_POST['rating']); $Rating->set_max_rating(@(int) $_POST['max_rating']); $Rating->set_user_id(@(int) $login_uid); $Rating->rate(); $rating = rating(@$_POST['rating_type'], @(int) $_POST['type_id']); print $rating['overall']; }
function get_most_rated_video() { // first find that video_id after that load that video Logger::log("Enter: TekVideo::get_most_rated_video()"); global $path_prefix; require_once "{$path_prefix}/api/Rating/Rating.php"; $rating = new Rating(); $rating->set_rating_type('content'); $param['limit'] = 1; $data = $rating->get_max_rated_content($this->type, $param, NULL, time()); if ($data[0]->type_id) { $video_data = $this->load($data[0]->type_id); Logger::log("Exit: TekVideo::get_most_rated_video()"); return $video_data; } Logger::log("Exit: TekVideo::get_most_rated_video()"); return null; }
function thumbs_rating($rating_type, $type_id, $scale = 1) { // User can rate any entity . An entity can be User, content, comments etc require_once 'api/Rating/Rating.php'; require_once 'api/PA_Rating/PA_Rating.php'; $return = array('overall' => null, 'new' => null); $Rating = new Rating(); $Rating->set_rating_type($rating_type); $Rating->set_type_id((int) $type_id); $condition = " rating_type = '{$rating_type}' AND rating = -1 AND type_id = {$type_id} "; $thumb_down = Rating::get($condition); $condition = " rating_type = '{$rating_type}' AND rating = 1 AND type_id = {$type_id} "; $thumb_up = Rating::get($condition); $total = count($thumb_up) + count($thumb_down); if ($total > 0) { $recommended = count($thumb_up) / (count($thumb_up) + count($thumb_down)) * 100; $not_recommended = count($thumb_down) / (count($thumb_up) + count($thumb_down)) * 100; //Over all rating is showing count of thumb_up rating . Done for Radio-one pages. $overall = 'Recommended:' . count($thumb_up) . '<br />'; $return['overall'] = $overall; } else { $overall = 'Recommended: 0<br />'; $return['overall'] = $overall; } $user_rating = 0; if (!empty(PA::$login_uid)) { $params = array('rating_type' => $rating_type, 'user_id' => PA::$login_uid, 'type_id' => $type_id); $user_rating_details = Rating::get(NULL, $params); $user_rating = @$user_rating_details[0]->rating; if (!empty($user_rating)) { // user give the rating to that content if ($user_rating == 1) { $return['new'] = 'Your Recommendation:<img src="' . PA::$theme_url . '/images/rec_yes1.png" alt="star" />'; } else { $return['new'] = 'Your Recommendation:<img src="' . PA::$theme_url . '/images/rec_no1.png" alt="star" />'; } return $return; } } // image of thumbs up $counter = 1; $return['new'] = 'Make Recommendation:<b><img src="' . PA::$theme_url . '/images/rec_yes1.png" alt="star" id="star_' . $type_id . '_' . $counter . '" onclick="javascript:thumbs_rating.click(' . $counter . ', ' . $type_id . ', \'' . $rating_type . '\', ' . $scale . ',' . PA::$login_uid . ')" style="cursor:pointer" /></b>'; // image of thumbs down $counter = -1; $return['new'] .= '<b><img src="' . PA::$theme_url . '/images/rec_no1.png" alt="star" id="star_' . $type_id . '_' . $counter . '" onclick="javascript:thumbs_rating.click(' . $counter . ', ' . $type_id . ', \'' . $rating_type . '\', ' . $scale . ',' . PA::$login_uid . ')" style="cursor:pointer" /></b>'; return $return; }
function get_ratings($rating_type, $type_id) { $scale = 5; $return = array('overall' => null, 'new' => null); $this->rating_cnt = 0; $this->avg_rating = 0; $Rating = new Rating(); $Rating->set_rating_type($rating_type); $Rating->set_type_id($type_id); $this->details = $details = $Rating->get_rating(); if (!empty($details)) { foreach ($details as $entity) { $avg_rating = $entity->total_rating / $entity->total_max_rating * $scale; $stars_count = round($avg_rating); $this->rating_cnt = $entity->ratings; $this->avg_rating = round($avg_rating, 1); $faded_stars_count = $scale - $stars_count; for ($cnt = 0; $cnt < $stars_count; ++$cnt) { $return['overall'] .= '<div class="star"></div>'; } for ($cnt = 0; $cnt < $faded_stars_count; ++$cnt) { $return['overall'] .= '<div class="starfaded"></div>'; } } } else { for ($cnt = 0; $cnt < $scale; ++$cnt) { $return['overall'] .= '<div class="starfaded"></div>'; } } if (!empty(PA::$login_user->user_id)) { $params = array('rating_type' => $rating_type, 'user_id' => PA::$login_user->user_id, 'type_id' => $type_id); $user_rating_details = PA_Rating::get($params); } $user_rating = @$user_rating_details[0]->rating ? $user_rating_details[0]->rating : 0; for ($counter = 1; $counter <= $user_rating; ++$counter) { $return['new'] .= '<div class="user_star'; if ($counter == $user_rating) { $return['new'] .= ' current_rating'; } $return['new'] .= ' star" id="star_' . $type_id . '_' . $counter . '" onmouseover="javascript:toggle_stars.mouseover(' . $counter . ', \'' . $type_id . '\')" onmouseout="javascript:toggle_stars.mouseout(' . $counter . ', \'' . $type_id . '\')" onclick="javascript:toggle_stars.click(' . $counter . ', \'' . $type_id . '\', \'' . $rating_type . '\', ' . $scale . ')" ></div>'; } for (; $counter <= $scale; ++$counter) { $return['new'] .= '<div class="user_star starfaded" id="star_' . $type_id . '_' . $counter . '" onmouseover="javascript:toggle_stars.mouseover(' . $counter . ', \'' . $type_id . '\')" onmouseout="javascript:toggle_stars.mouseout(' . $counter . ', \'' . $type_id . '\')" onclick="javascript:toggle_stars.click(' . $counter . ', \'' . $type_id . '\', \'' . $rating_type . '\', ' . $scale . ')" ></div>'; } return $return; }