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