/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new PropertyRating(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['PropertyRating'])) { $model->attributes = $_POST['PropertyRating']; if ($model->save()) { $this->redirect(array('view', 'id' => $model->id)); } } $this->render('create', array('model' => $model)); }
/** * This method accepts property id , user id and rate and adds the record. * Returns model if successfully created. * Returns the error validated model if validation fails. * * * @param string $user_id,$propertyId,$rate * @return model || model with errors */ public static function addRating($propertyId, $userId, $rate) { $criteria = new CDbCriteria(); $criteria->condition = 'property_id=:propertyId AND user_id=:userId'; $criteria->params = array(':propertyId' => $propertyId, ':userId' => $userId); $propertyRatingCheck = PropertyRating::model()->find($criteria); if ($propertyRatingCheck) { self::removeRating($propertyId, $userId); $property_rating = new PropertyRating(); $property_rating->user_id = $userId; $property_rating->property_id = $propertyId; $property_rating->rate = $rate; $property_rating->save(); return $property_rating; } else { $property_rating = new PropertyRating(); $property_rating->user_id = $userId; $property_rating->property_id = $propertyId; $property_rating->rate = $rate; $property_rating->save(); return $property_rating; } }