public function sendratingsAction() { echo 'foo'; $params = array('recipe_id' => $this->recipe->id, 'value' => $this->_getParam('value')); /* Try and insert them into DB */ try { $r = new Rating(); $r->insert($params); /* Incease ratings counters */ $this->db->update("users", array("ratings_count" => new Zend_Db_Expr("(ratings_count + 1)")), "id = " . $this->session->user['id']); $this->db->update("recipes", array("ratings_count" => new Zend_Db_Expr("(ratings_count + 1)")), "id = " . $params['recipe_id']); /* If successful go back to last recipe */ $this->_redirect('/recipe/view/recipe_id/' . $params['recipe_id']); exit; } catch (Exception $e) { /* Broken constraints = throws exception. Display error and return to recipe */ $this->log->debug($e->getMessage()); $this->message->setNamespace('error'); $this->message->addMessage('You have already rated this recipe.'); $this->_redirect('/recipe/view/recipe_id/' . $params['recipe_id']); } }
<?php error_reporting(0); session_start(); include "../config/database.class.php"; include "../objects/rating.class.php"; include "../objects/menuoption.class.php"; $database = new Database(); $db = $database->getConnection(); if (isset($_POST['add'])) { $updatedOption = new Rating($db); $updatedOption->Rating = $_POST['rating']; $updatedOption->Comment = $_POST['comment']; $updatedOption->Guest_Id = $_SESSION['id']; $updatedOption->MenuOption_Id = $_POST['menuitemid']; if ($updatedOption->insert() == true) { header("location:guest.php"); } else { echo "<script>alert('There was an error adding this item');window.location = 'guest.php' </script>"; } } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title></title>
/** * test inserting a Rating and grabbing it from my sql */ public function testGetValidRatingByTrail() { // count the number of rows and save it for later $numRows = $this->getConnection()->getRowCount("rating"); // create a new rating and insert it into my sql $rating = new Rating($this->trail->getTrailId(), $this->user->getUserId(), $this->VALID_RATINGVALUE); $rating->insert($this->getPDO()); //grab the data from mySQL and enforce the fields match expectations $pdoRatings = Rating::getRatingValueByTrailId($this->getPDO(), $this->trail->getTrailId()); foreach ($pdoRatings as $pdoRating) { $this->assertSame($numRows + 1, $this->getConnection()->getRowCount("rating")); $this->assertSame($pdoRating->getRatingValue(), $this->VALID_RATINGVALUE); } }
$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"}'; }); $app->delete('/rating', function () { $request = \Slim\Slim::getInstance()->request(); $rating = json_decode($request->getBody()); $ratingDAO = new Rating(); $ratingDAO->delete($rating); echo '{"result":"ok"}';