header("location:comments.php"); } else { header("location:guest.php"); } } else { if ($_SESSION['accesslevel'] == 1) { echo "<script>alert('There was an error updating this item');window.location = 'comments.php' </script>"; } else { echo "<script>alert('There was an error updating this item');window.location = 'guest.php' </script>"; } } } if (isset($_POST['delete'])) { $updatedOption = new Rating($db); $updatedOption->Id = $_POST['id']; if ($updatedOption->delete() == true) { if ($_SESSION['accesslevel'] == 1) { header("location:comments.php"); } else { header("location:guest.php"); } } else { if ($_SESSION['accesslevel'] == 1) { echo "<script>alert('There was an error deleting this item');window.location = 'comments.php' </script>"; } else { echo "<script>alert('There was an error deleting this item');window.location = 'guest.php' </script>"; } } } ?>
/** * Set mark for the good by user * @param $good_id * @param $rate mark (1-5) */ public function actionSetMark($good_id, $rate) { if (Yii::app()->user->isGuest) { echo 'you are not registered user'; return; } $user = Yii::app()->user->id; $rating = Rating::model()->with(array('good', 'good.marksCount'))->findByAttributes(array('good_id' => $good_id, 'user_id' => $user)); if (empty($rating)) { if ($rate == 'undefined') { return; } $rating = new Rating(); $rating->good_id = $good_id; $rating->user_id = $user; $rating->value = $rate; if ($rating->save()) { $good = $rating->good; $good->rating = round($good->rating + ($rate * 100 - $good->rating) / ($good->marksCount + 1)); $good->save(); echo 'success'; } else { echo 'fail saving'; } } else { if ($rating->value != $rate) { if ($rate == 'undefined') { echo 'rate deleted'; $rating->delete(); return; } $old_mark = $rating->value; $rating->value = $rate; if ($rating->save()) { $good = $rating->good; $good->rating = round($good->rating + ($rate * 100 - $old_mark * 100) / $good->marksCount); $good->save(); echo 'success'; } else { echo 'fail saving'; } } else { echo 'no need to change'; } } }
/** * test creating a rating then deleting it */ public function testDeleteValidRating() { $numRows = $this->getConnection()->getRowCount("rating"); // create a new rating and insert it into mySQL $rating = new Rating($this->trail->getTrailId(), $this->user->getUserId(), $this->VALID_RATINGVALUE); $rating->insert($this->getPDO()); // delete the user from mysql $this->assertSame($numRows + 1, $this->getConnection()->getRowCount("rating")); $rating->delete($this->getPDO()); // grab the data from mysql and enforce the fields meet expectation; $pdoRating = Rating::getRatingByTrailIdAndUserId($this->getPDO(), $this->trail->getTrailId(), $this->user->getUserId()); $this->assertNull($pdoRating); $this->assertSame($numRows, $this->getConnection()->getRowCount("rating")); }
<? require_once('classes/Rating.php'); require_once('classes/Text.php'); $recipe_id = $_REQUEST['recipe_id']; $value = $_REQUEST['rating']; $comment = $_REQUEST['comment']; $rating = Rating::getForRecipeAndUser($recipe_id); if ($rating == NULL && $value > 0) { $rating = new Rating(); $rating->recipe_id = $recipe_id; } if ($value < 0 && $rating != NULL) { $rating->delete(); } if ($value > 0) { $rating->value = $value; $rating->comment = $comment; $rating->save(); } echo 'OK';//Text::getText('ThankYou'); ?>
public function vote($userId, $photoId, $rating) { $oldRating = Rating::loadRating($userId, $photoId); if ($oldRating != null) { $oldRating->delete(); } if ($rating > 0) { $newRating = new Rating(array('user_id' => $userId, 'photo_id' => $photoId, 'rating' => $rating)); $newRating->store(); $votes = $this->userRatings($userId); if ($votes['total_votes'] > $this->numberVotes) { $newRating->delete(); if ($oldRating != null) { $oldRating->store(); } return false; } else { return true; } } else { return true; } }
$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"}'; }); $app->delete('/rating', function () { $request = \Slim\Slim::getInstance()->request(); $rating = json_decode($request->getBody()); $ratingDAO = new Rating(); $ratingDAO->delete($rating); echo '{"result":"ok"}'; }); $app->get('/state', function () { $stateDAO = new State(); $result = $stateDAO->get(); echo json_encode($result); }); $app->post('/state', function () { $request = \Slim\Slim::getInstance()->request(); $state = json_decode($request->getBody()); $stateDAO = new State(); $stateDAO->insert($state); echo '{"result":"ok"}'; }); $app->put('/state', function () {