public function testCreateRatingSuccess()
 {
     $_params = $this->_params;
     $_params['user_id'] = $this->_user_id;
     $response = $this->_getAuth($_params);
     //get created login information
     $rating_infor = Rating::get(array('user_id', 'wine_unique_id', 'rate', 'comment_count', 'like_count', 'is_my_wine', 'updated_at', 'created_at', 'id'))->last();
     $this->assertNotNull($rating_infor);
     $this->assertEquals(array("code" => ApiResponse::OK, "data" => $rating_infor->toArray()), json_decode($response->getContent(), true));
 }
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;
}
 /**
  * gets the rating objects for an object
  * @param String $class DataObject ClassName
  * @param Int $id DataObject ID
  * @return DataList
  **/
 public function getRatingsFor($class, $id)
 {
     return Rating::get()->filter(array('ObjectClass' => $class, 'ObjectID' => $id));
 }
示例#4
0
 public function getRating()
 {
     if ($this->_ratingId !== null && $this->_rating === null) {
         $this->_rating = Rating::get($this->_ratingId);
     }
     return $this->_rating;
 }
示例#5
0
    $request = \Slim\Slim::getInstance()->request();
    $place = json_decode($request->getBody());
    $placeDAO = new Place();
    $placeDAO->update($place);
    echo '{"result":"ok"}';
});
$app->delete('/place', function () {
    $request = \Slim\Slim::getInstance()->request();
    $place = json_decode($request->getBody());
    $placeDAO = new Place();
    $placeDAO->delete($place);
    echo '{"result":"ok"}';
});
$app->get('/rating', function () {
    $ratingDAO = new Rating();
    $result = $ratingDAO->get();
    echo json_encode($result);
});
$app->post('/rating', function () {
    $request = \Slim\Slim::getInstance()->request();
    $rating = json_decode($request->getBody());
    $ratingDAO = new Rating();
    $ratingDAO->insert($rating);
    echo '{"result":"ok"}';
});
$app->put('/rating', function () {
    $request = \Slim\Slim::getInstance()->request();
    $rating = json_decode($request->getBody());
    $ratingDAO = new Rating();
    $ratingDAO->update($rating);
    echo '{"result":"ok"}';