示例#1
0
 /**
  * Rates the item for the given user
  *
  * @param unknown_type $app_id
  * @param unknown_type $uid
  * @param unknown_type $item_id
  * @param unknown_type $vote
  * @param unknown_type $dbCon
  * @return unknown
  */
 public static function setRating($app_id, $uid, $item_id, $vote)
 {
     $ret = false;
     if (Api_Dao_Ratings::isRated($app_id, $uid, $item_id)) {
         $ret = Api_Dao_Ratings::updateRating($app_id, $uid, $item_id, $vote);
     } else {
         $ret = Api_Dao_Ratings::createRating($app_id, $uid, $item_id, $vote);
     }
     if ($ret === false) {
         return false;
     }
     return true;
 }
示例#2
0
 /**
  * Tests getting a rating for a list of users on a list of item ids
  */
 public function testExecute()
 {
     $appId = 1;
     $app_id = 1;
     $uid = 18015;
     $uid2 = 18016;
     $iid = "RatingsTestCaseItem3";
     $iid2 = "RatingsTestCaseItem4";
     $uids = "{$uid}, {$uid2}";
     $iids = "{$iid}, {$iid2}";
     $vote = 2;
     //RingsideAppsDbRatings::setRating(uid, iid, vote, units, dbCon)
     $apiParams = array();
     $apiParams['iids'] = $iids;
     try {
         // Create our object
         $faf = $this->initRest(new RatingsGet(), $apiParams, $uid, $appId);
         $this->assertNotNull($faf, "RatingsGetRatingForUser should not be null!");
         // Set the rating for this user
         if (Api_Dao_Ratings::isRated($app_id, $uid, $iid)) {
             Api_Dao_Ratings::updateRating($app_id, $uid, $iid, $vote);
         } else {
             Api_Dao_Ratings::createRating($app_id, $uid, $iid, $vote);
         }
         $result = $faf->execute();
         $a = $result['rating'][0];
         $this->assertNotNull($a);
         $this->assertEquals($a['uid'], $uid, "UID: " . $a['uid'] . "!=" . $uid);
         $this->assertEquals($a['iid'], $iid, "iid: " . $a['iid'] . "!=" . $iid);
         $this->assertEquals($a['vote'], $vote, "Vote: " . $a['vote'] . "!=" . $vote);
     } catch (OpenFBAPIException $exception) {
         $this->fail($exception->getMessage() . "\n" . $exception->getTraceAsString());
     }
 }
 public function testExecute()
 {
     $appId = 1;
     $app_id = 1;
     $uid = 18006;
     $iid = "RatingsTestCaseItem";
     $vote = 3;
     $uids = "18006";
     //RingsideAppsDbRatings::setRating(uid, iid, vote, units, dbCon)
     $apiParams = array();
     $apiParams['iid'] = $iid;
     $apiParams['uids'] = $uids;
     try {
         // Create our object
         $faf = $this->initRest(new RatingsGetAverage(), $apiParams, $uid, $appId);
         $this->assertNotNull($faf, "RatingsGetRatingForUser should not be null!");
         // Set the rating for this user
         if (Api_Dao_Ratings::isRated($app_id, $uid, $iid)) {
             Api_Dao_Ratings::updateRating($app_id, $uid, $iid, $vote);
         } else {
             Api_Dao_Ratings::createRating($app_id, $uid, $iid, $vote);
         }
         $result = $faf->execute();
         $rating_array = $result['rating'][0];
         //$retVal[ 'rating' ][ 0 ] = array( 'iid'=>$item_id,'average_vote'=>$row[ 'average_vote' ] );
         $this->assertEquals($rating_array['iid'], $iid, "Item ids should be equal: " . $rating_array['iid'] . "!=" . $iid);
         $this->assertEquals($rating_array['average_vote'], $vote, "Average vote should be {$vote}, but is: " . $rating_array['average_vote']);
     } catch (OpenFBAPIException $exception) {
         $this->fail($exception->getMessage() . "\n" . $exception->getTraceAsString());
     }
 }
示例#4
0
 public function testExecute()
 {
     $appId = 1;
     $app_id = 1;
     $uid = 18078;
     $iid = "RatingsTestCaseItem12";
     $vote = 4;
     $uids = "18078";
     $iids = "{$iid}";
     //RingsideAppsDbRatings::setRating(uid, iid, vote, units, dbCon)
     $apiParams = array();
     $apiParams['iid'] = $iid;
     $apiParams['vote'] = $vote;
     try {
         // Create our object
         $faf = $this->initRest(new RatingsSet(), $apiParams, $uid, $appId);
         $this->assertNotNull($faf, "RatingsSetRating should not be null!");
         $result = $faf->execute();
         //$response [ 'result' ] = $ret?'1':'0';
         $this->assertEquals($result['result'], '1', "Result should be 1, but is: " . $result['result']);
         // Set the rating for this user
         $retVal = Api_Dao_Ratings::getRatings($app_id, array($iids), array($uids));
         $a = $retVal[0]->toArray();
         $this->assertNotNull($a);
         $this->assertEquals($a['uid'], $uid, "UID: " . $a['uid'] . "!=" . $uid);
         $this->assertEquals($a['item_id'], $iid, "iid: " . $a['item_id'] . "!=" . $iid);
         $this->assertEquals($a['vote'], $vote, "Vote: " . $a['vote'] . "!=" . $vote);
     } catch (OpenFBAPIException $exception) {
         $this->fail($exception->getMessage() . "\n" . $exception->getTraceAsString());
     }
 }