本文整理汇总了PHP中Rating::insert方法的典型用法代码示例。如果您正苦于以下问题:PHP Rating::insert方法的具体用法?PHP Rating::insert怎么用?PHP Rating::insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Rating
的用法示例。
在下文中一共展示了Rating::insert方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: sendratingsAction
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']);
}
}
示例2: Database
<?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>
示例3: testGetValidRatingByTrail
/**
* 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);
}
}