示例#1
0
function peopleaggregator_getItems($args)
{
    global $_PA;
    require_once PA::$path . "/api/Item/Item.php";
    $remote_user = @$args['remoteUser'];
    if ($remote_user) {
        if (!$_PA->enable_widgetization_server) {
            throw new PAException(OPERATION_NOT_PERMITTED, "Widgetization disabled; you cannot use remote user functions");
        }
        require_once PA::$path . "/api/User/ShadowUser.php";
        require_once PA::$path . "/api/Rating/Rating.php";
        require_once PA::$path . "/ext/PA_Rating/PA_Rating.php";
        $remote_id = explode(":", $remote_user);
        if (count($remote_id) == 1) {
            throw new PAException(INVALID_ID, "Remote user IDs must be of the form 'namespace:id'");
        }
        $u = new ShadowUser($remote_id[0]);
        $u->load($remote_id[1]);
        if (!$u->user_id) {
            throw new PAException(USER_NOT_FOUND, "Failed to locate user '" . $remote_id[1] . "' in namespace '" . $remote_id[0] . "'");
        }
    } else {
        $u = NULL;
    }
    $items_out = array();
    foreach (explode(",", $args['ids']) as $packed_id) {
        $item_id = explode(":", $packed_id);
        if (count($item_id) == 1) {
            throw new PAException(INVALID_ID, "Individual item IDs must be of the form 'type:id'");
        }
        $item = Item::find_by_subject($item_id[0], $item_id[1]);
        if ($item == NULL) {
            continue;
        }
        // ignore IDs that don't exist
        $item_out = item_to_array($item);
        if ($u) {
            $params = array('rating_type' => $item_id[0], 'user_id' => $u->user_id, 'type_id' => $item_id[1]);
            $user_rating_details = PA_Rating::get($params);
            if (count($user_rating_details)) {
                $item_out['userRating'] = (int) $user_rating_details[0]->rating;
            }
        }
        $items_out[] = $item_out;
    }
    return array("success" => TRUE, "msg" => "Retrieved " . count($items_out) . " item(s)", "items" => $items_out);
}
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;
}
示例#3
0
 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;
 }