本文整理汇总了PHP中Rating::model方法的典型用法代码示例。如果您正苦于以下问题:PHP Rating::model方法的具体用法?PHP Rating::model怎么用?PHP Rating::model使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Rating
的用法示例。
在下文中一共展示了Rating::model方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
public function run()
{
if (isset($this->model->rating)) {
$rating = $this->model->rating;
} else {
$rating = Rating::getValue($this->model);
$rating = Rating::getHtml($rating);
}
$model_id = get_class($this->model);
$value = null;
if (!Yii::app()->user->isGuest) {
$value = Rating::model()->fetchScalarByAttributes(array('user_id' => Yii::app()->user->id, 'object_id' => $this->model->id, 'model_id' => $model_id), 'value');
}
$this->render('RatingWidget', array('object_id' => $this->model->id, 'user_id' => $this->model->getUserId(), 'model_id' => $model_id, 'rating' => $rating, 'value' => $value));
}
示例2: actionCreate
public function actionCreate()
{
if (!isset($_POST['Rating'])) {
$this->badRequest();
}
$rating = Rating::model()->findByAttributes(array('user_id' => Yii::app()->user->id, 'object_id' => $_POST['Rating']['object_id'], 'model_id' => $_POST['Rating']['model_id']));
if (!$rating) {
$rating = new Rating();
}
$rating->attributes = $_POST['Rating'];
if ($rating->save()) {
$rating = Rating::getValue($rating->model_id, $rating->object_id);
echo Rating::getHtml($rating);
} else {
echo CJSON::encode(array('errors' => $rating->errors_flat_array));
}
}
示例3: GetUserRating
/**
* Return user mark for the good
* @return string user mark for the good
*/
public function GetUserRating()
{
$value = Rating::model()->findByAttributes(array('good_id' => $this->id, 'user_id' => Yii::app()->user->id));
//echo $value;
if (isset($value)) {
return sprintf("%d", $value->value);
} else {
return '0';
}
}
示例4: actionSetMark
/**
* 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';
}
}
}
示例5: loadModel
/**
* Returns the data model based on the primary key given in the GET variable.
* If the data model is not found, an HTTP exception will be raised.
* @param integer the ID of the model to be loaded
*/
public function loadModel($id)
{
$model = Rating::model()->findByPk($id);
if ($model === null) {
throw new CHttpException(404, 'The requested page does not exist.');
}
return $model;
}
示例6: afterSave
public function afterSave()
{
$criteria = new CDbCriteria();
$criteria->select = new CDbExpression('AVG(rating_score) as avg_rating');
$criteria->condition = 'product_id=:product_id';
$criteria->params = array(':product_id' => $this->product_id);
$model = Rating::model()->find($criteria);
//echo $model->avg_rating ;//die();//var_dump($model); die();
//$modelProduct=Product::model()->with('rates')->findByPk($bid); //findByPk($bid);
$values = array('rating_score' => $model->avg_rating);
$modelProduct = Product::model()->updateByPk($this->product_id, $values);
return parent::afterSave();
}
示例7: afterSave
/**
* Save rating if need
* @return void
*/
public function afterSave()
{
$rating = Rating::model()->findByAttributes(array('good_id' => $this->good_id, 'user_id' => $this->user_id));
if ($rating == null) {
$rating = new Rating();
$rating->value = $this->rating;
$rating->good_id = $this->good_id;
$rating->user_id = $this->user_id;
$rating->Save();
} elseif ($rating->value != $this->rating) {
$rating->value = $this->rating;
$rating->Save();
}
}