本文整理汇总了PHP中Rating::get_rating方法的典型用法代码示例。如果您正苦于以下问题:PHP Rating::get_rating方法的具体用法?PHP Rating::get_rating怎么用?PHP Rating::get_rating使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Rating
的用法示例。
在下文中一共展示了Rating::get_rating方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: rating
function rating($rating_type, $type_id, $scale = 5)
{
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);
$details = $Rating->get_rating();
if (!empty($details)) {
foreach ($details as $entity) {
$stars_count = round($entity->total_rating / $entity->total_max_rating * $scale);
$faded_stars_count = $scale - $stars_count;
$existing_rating = null;
for ($cnt = 0; $cnt < $stars_count; ++$cnt) {
$return['overall'] .= '<img src="' . PA::$theme_url . '/images/star.gif" alt="star" />';
}
for ($cnt = 0; $cnt < $faded_stars_count; ++$cnt) {
$return['overall'] .= '<img src="' . PA::$theme_url . '/images/starfaded.gif" alt="star" />';
}
}
} else {
for ($cnt = 0; $cnt < $scale; ++$cnt) {
$return['overall'] .= '<img src="' . PA::$theme_url . '/images/starfaded.gif" alt="star" />';
}
}
$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 = PA_Rating::get(null, $params);
// FIXME: this might not be set
$user_rating = @$user_rating_details[0]->rating;
}
for ($counter = 1; $counter <= $user_rating; ++$counter) {
$return['new'] .= '<img class="user_star';
if ($counter == $user_rating) {
$return['new'] .= ' current_rating';
}
$return['new'] .= '" src="' . PA::$theme_url . '/images/star.gif" alt="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 . ')" />';
}
for (; $counter <= $scale; ++$counter) {
$return['new'] .= '<img class="user_star" src="' . PA::$theme_url . '/images/starfaded.gif" alt="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 . ')" />';
}
return $return;
}
示例2: array
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;
}