public function rate() { if ($this->check()) { $rating = Rating::find("tag", self::TAG)->find("valueType", self::VALUE_TYPE)->find("value", self::VALUE); $rating = $rating->find("entityId", $this->entityId)->find("entityType", $this->entityType)->find("userId", $this->userId); $rating = $rating->first(); if ($rating == null) { $rating = new Rating(); $rating->tag = self::TAG; $rating->valueType = self::VALUE_TYPE; $rating->value = self::VALUE; $rating->host = $this->host; $rating->entityId = $this->entityId; $rating->entityType = $this->entityType; $rating->userId = $this->userId; $rating->timestamp = date('Y-m-d H:i:s'); $rating->save(); if (isset($rating->id) && $rating->id) { $this->updatePlusCounter(); return true; } } } return false; }
public function save() { if (!isset($this->timestamp) || $this->timestamp == '') { $this->timestamp = date('Y-m-d H:i:s'); } return parent::save(); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function addRate($rating_score, $bus_Id) { $rateMod = new Rating(); $rateMod->rating_score = $rating_score; $rateMod->product_id = $bus_Id; $rateMod->rating_type = 1; if ($rateMod->save()) { return $rateMod->rating_id; } return 0; }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Rating(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Rating'])) { $model->attributes = $_POST['Rating']; if ($model->save()) { $this->redirect(array('view', 'id' => $model->id)); } } $this->render('create', array('model' => $model)); }
/** * Store a newly created rating in storage. * * @return Response */ public function store() { $validator = Validator::make($data = Input::all(), Rating::$rules); if ($validator->fails()) { dd($validator->messages()); return Redirect::back()->withErrors($validator)->withInput(); } $rating = new Rating(); $rating->stars = Input::get('stars'); $rating->comment = Input::get('comment'); $rating->recommended = Input::get('recommended'); $rating->parking_lot_id = Input::get('parking_lot_id'); $rating->user_id = Auth::user()->id; $rating->save(); return Redirect::route('ratings.index'); }
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)); } }
public function executeRate() { $params = explode('.', $this->getRequestParameter('object_id')); $type = $params[0]; $object_id = $params[1]; $value = $this->getRequestParameter('value'); $rating = null; if ($type == Rating::APPLICATION) { $object = Doctrine::getTable('Application')->find($object_id); $q = new Doctrine_Query(); $rating = $q->select('r.*')->from('Rating r')->where('application_id = ? and user_id = ?', array($object_id, $this->getUser()->getId()))->fetchOne(); if (!$rating) { $rating = new Rating(); $rating->setUserId($this->getUser()->getId()); $rating->setApplicationId($object_id); } } elseif ($type == Rating::MODULE) { $object = Doctrine::getTable('Madule')->find($object_id); $q = new Doctrine_Query(); $rating = $q->select('r.*')->from('Rating r')->where('madule_id = ? and user_id = ?', array($object_id, $this->getUser()->getId()))->fetchOne(); if (!$rating) { $rating = new Rating(); $rating->setUserId($this->getUser()->getId()); $rating->setMaduleId($object_id); } } elseif ($type == Rating::THEME) { $object = Doctrine::getTable('Theme')->find($object_id); $q = new Doctrine_Query(); $rating = $q->select('r.*')->from('Rating r')->where('theme_id = ? and user_id = ?', array($object_id, $this->getUser()->getId()))->fetchOne(); if (!$rating) { $rating = new Rating(); $rating->setUserId($this->getUser()->getId()); $rating->setThemeId($object_id); } } $this->forward404Unless($value <= 5); $this->forward404Unless($value >= 1); if ($rating) { $rating->setValue($value); $rating->save(); $this->my_rating = $value; $this->rating = $object->getRating(); } }
public function run() { $faker = Faker::create(); $parking_lot = ParkingLot::all()->random(); $user = User::firstOrFail(); foreach (range(1, 10) as $index) { $rating = new Rating(); $rating->stars = $faker->numberBetween($min = 1, $max = 5); $rating->comment = 'Great Parking Lot'; $rating->recommended = $faker->boolean; $rating->parking_lot_id = $parking_lot->id; $rating->user_id = $user->id; $rating->save(); $parking_lot = ParkingLot::all()->random(); $rating2 = new Rating(); $rating2->stars = $faker->numberBetween($min = 1, $max = 5); $rating2->comment = 'Excellent Service'; $rating2->recommended = $faker->boolean; $rating2->parking_lot_id = $parking_lot->id; $rating2->user_id = $user->id; $rating2->save(); $parking_lot = ParkingLot::all()->random(); $rating3 = new Rating(); $rating3->stars = $faker->numberBetween($min = 1, $max = 5); $rating3->comment = 'Average Parking Lot'; $rating3->recommended = $faker->boolean; $rating3->parking_lot_id = $parking_lot->id; $rating3->user_id = $user->id; $rating3->save(); $parking_lot = ParkingLot::all()->random(); $rating4 = new Rating(); $rating4->stars = $faker->numberBetween($min = 1, $max = 5); $rating4->comment = 'Bad Customer Service'; $rating4->recommended = $faker->boolean; $rating4->parking_lot_id = $parking_lot->id; $rating4->user_id = $user->id; $rating4->save(); } }
public function actionAddcandidate() { if (!isset(Yii::app()->user->userProfileID)) { $this->redirect('/user/login'); } // renders the view file 'protected/views/site/index.php' // using the default layout 'protected/views/layouts/main.php' $candidateModel = new Candidate(); $performanceModel = new Performance(); $ratingModel = new Rating(); $planningModel = new Planning(); if (isset($_POST['Candidate'])) { $candidateModel->attributes = $_POST['Candidate']; $candidateModel->IsActive = 1; //$candidateModel->UserProfileID = Yii::app()->user->userProfileID; $candidateModel->CompanyID = Yii::app()->user->companyID; if ($candidateModel->validate()) { if ($candidateModel->save()) { $currentYear = date('Y'); // insert new record $performanceModel->CandidateID = $candidateModel->CandidateID; $performanceModel->PerformanceYear = $currentYear; $ratingModel->CandidateID = $candidateModel->CandidateID; $ratingModel->RatingYear = $currentYear; $planningModel->CandidateID = $candidateModel->CandidateID; $planningModel->PlanningYear = $currentYear; $planningModel->CurrentPositionLevel = $_POST['Candidate']['CompanyPositionID']; if ($_POST['Candidate']['CompanyPositionID'] == 5) { $planningModel->NextStepPositionLevel = 5; $planningModel->LongTermPositionLevel = 5; } else { $planningModel->NextStepPositionLevel = $_POST['Candidate']['CompanyPositionID']; $planningModel->LongTermPositionLevel = $_POST['Candidate']['CompanyPositionID']; } $performanceModel->save(); $ratingModel->save(); $planningModel->save(); $this->redirect(Yii::app()->createUrl('company/candidates')); } } } $criteria3 = new CDbCriteria(); $criteria3->condition = 'companyID = :companyID'; $criteria3->params = array(':companyID' => Yii::app()->user->companyID); $criteria3->order = 'Email'; $userManagers = UserProfile::model()->findAllByAttributes(array(), $criteria3); $managersArray = array(); foreach ($userManagers as $UserManager) { $managersArray[$UserManager->UserProfileID] = $UserManager->Email; } $managerArray = $managersArray; $companyPositions = Helper::getCompanyPositions(Yii::app()->user->companyID); $this->render('candidate-form', array('candidateModel' => $candidateModel, 'planningModel' => $planningModel, 'companyPositionSelect' => $companyPositions, 'managerArray' => $managerArray)); }
public function saveDatabase() { $buyer1 = Input::get('buyer'); $seller = Input::get('seller'); $review = Input::get('review'); $urls = Input::get('urls'); $rating_num = Input::get('rating'); $rating = new Rating(); //$rating->rating_id = 2; $rating->seller = $seller; $rating->buyer = $buyer1; $rating->review = $review; $rating->rating_number = $rating_num; $rating->save(); return Redirect::away("http://localhost/authentication/secure/dashboard/modules/problem_sharing/donors"); // return Response::json(array('status'=>'done')); }
/** * Rate */ public function rate($data) { App::uses('Rating', 'Ratings.Model'); // load Ratings Model $Rating = new Rating(); //create Object $Rating return $Rating->save($data); //return data and save }
function update($item_id, $rating_value) { if (!AMP_SYSTEM_UNIQUE_VISITOR_ID) { return false; } $session = AMP_SYSTEM_UNIQUE_VISITOR_ID; $articles_rated = AMP_lookup('article_ids_rated_by_session', $session); if (!isset($articles_rated[$item_id])) { return ArticleRating::create($item_id, $rating_value); } $rating_id = $articles_rated[$item_id]; $rating = new Rating(AMP_Registry::getDbcon(), $rating_id); if (!$rating->hasData()) { return false; } $rating->mergeData(array('rating' => $rating_value, 'updated_at' => date('Y-m-d h:i:s'))); $result = $rating->save(); AMP_lookup_clear_cached('article_ids_rated_by_session', $session); AMP_lookup_clear_cached('article_ratings_by_session', $session); AMP_lookup_clear_cached('article_ratings'); AMP_lookup_clear_cached('article_ratings_last_week'); AMP_lookup_clear_cached('article_ratings_last_month'); return $result; }
/** * 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'; } } }
public function setUpRating() { $rating = new Rating(); $rating->id = 1; $rating->user_id = $this->_user_id; $rating->wine_unique_id = '1_2009'; $rating->rate = '3.5'; $rating->comment_count = '8'; $rating->like_count = '6'; $rating->save(); $rating = new Rating(); $rating->id = 2; $rating->user_id = '3620a42d-fcbb-45eb-b3a5-36cada1b77b7'; $rating->wine_unique_id = '1_2009'; $rating->rate = '2'; $rating->comment_count = '18'; $rating->like_count = '7'; $rating->save(); $rating = new Rating(); $rating->id = 3; $rating->user_id = '1803a4fd-0e90-45ae-ad75-d8d3d2448d5e'; $rating->wine_unique_id = '1_2009'; $rating->rate = '5'; $rating->comment_count = '3'; $rating->like_count = '4'; $rating->save(); }
public function actionCreate() { // check permissions // if (!Yii::app()->user->checkAccess('manageUser')) { // Helper::authException(); // } // models $UserLogin = new UserLogin(); $UserProfile = new UserProfile(); $criteria3 = new CDbCriteria(); $criteria3->condition = '(companyID = :companyID AND IsActive=1)'; $criteria3->params = array(':companyID' => Yii::app()->user->companyID); $criteria3->order = 'Email'; $userManagers = UserProfile::model()->with('userLogin')->findAllByAttributes(array(), $criteria3); $managersArray = array(); $managersArray[0] = "Please Select..."; foreach ($userManagers as $UserManager) { //if ($UserManager->ManagerEmail == '') { //$managersArray[$UserManager->Email] = $UserManager->Email; $managersArray[$UserManager->Email] = $UserManager->Email; //} elseif (Helper::hasRole('lacekAdministrator')) { // $rolesArray[$UserRole->UserRoleID] = $UserRole->RoleDesc; // } } // add default (empty value) to front of array $managerArray = $managersArray; // role array for select $userRoles = UserRole::model()->findAll(); $rolesArray = array(); foreach ($userRoles as $UserRole) { if ($UserRole->RoleType != 'lacekAdministrator') { $rolesArray[$UserRole->UserRoleID] = $UserRole->RoleDesc; } elseif (Helper::hasRole('lacekAdministrator')) { $rolesArray[$UserRole->UserRoleID] = $UserRole->RoleDesc; } } // add default (empty value) to front of array $rolesArray = $rolesArray; // form processing if (isset($_POST['UserLogin'], $_POST['UserProfile'])) { // redirect to the dashboard if 'Cancel' button clicked if (isset($_POST['button-cancel'])) { $this->redirect($this->createUrl('user/dashboard')); } // set UserLogin attributes and scenario $UserLogin->attributes = $_POST['UserLogin']; $UserLogin->IsPasswordReset = 1; // force password reset on first login $UserLogin->IsActive = 1; $UserLogin->scenario = 'create'; $UserLogin->UserRoleID = 1; // set UserProfile attributes $UserProfile->attributes = $_POST['UserProfile']; $UserProfile->CompanyID = Yii::app()->user->companyID; $UserProfile->Email = $UserLogin->LoginEmail; // validate form submission $valid = $UserLogin->validate(); $valid = $UserProfile->validate() && $valid; if ($valid) { // save UserLogin if (!$UserLogin->save(false)) { throw new CHttpException(400, 'Error when trying to create user.'); } // save UserProfile $UserProfile->UserLoginID = $UserLogin->UserLoginID; // set newly generated EventID if (!$UserProfile->save(false)) { throw new CHttpException(400, 'Error when trying to create user.'); } if ($UserProfile->ManagerEmail) { $UserProfilex = UserProfile::model()->findByAttributes(array('Email' => $UserProfile->ManagerEmail)); $candidateModel = new Candidate(); $candidateModel->CompanyID = $UserProfile->CompanyID; $candidateModel->EmployeeID = $UserProfile->EmployeeID; $candidateModel->FirstName = $UserProfile->FirstName; $candidateModel->MiddleName = $UserProfile->MiddleName; $candidateModel->LastName = $UserProfile->LastName; $candidateModel->Title = $UserProfile->Title; $candidateModel->Email = $UserProfile->Email; $candidateModel->CompanyPositionID = 1; $candidateModel->HireDate = date("Y-m-d"); $candidateModel->PositionDate = date("Y-m-d"); $candidateModel->IsActive = 1; $candidateModel->UserProfileID = $UserProfilex->UserProfileID; //$candidateModel->UserProfileId=2; //print_r($candidateModel); // die($UserProfilex->UserProfileID); // if ($candidateModel->validate()) { // if ($candidateModel->save()) { $candidateModel->save(); $performanceModel = new Performance(); $ratingModel = new Rating(); $planningModel = new Planning(); $currentYear = date('Y'); // insert new record $performanceModel->CandidateID = $candidateModel->CandidateID; $performanceModel->PerformanceYear = $currentYear; $ratingModel->CandidateID = $candidateModel->CandidateID; $ratingModel->RatingYear = $currentYear; $planningModel->CandidateID = $candidateModel->CandidateID; $planningModel->PlanningYear = $currentYear; $planningModel->CurrentPositionLevel = 3; $planningModel->NextStepPositionLevel = 3; $planningModel->LongTermPositionLevel = 3; $performanceModel->save(); $ratingModel->save(); $planningModel->save(); //} //} // else //{ // $errores = $candidateModel->getErrors(); // print_r($errores); // die(); // } } // set success message for user Yii::app()->user->setFlash('success', 'A new user was successfully created.'); // return to empty create user form if adding another, else go to user dashboard if (isset($_POST['button-submit-add'])) { $this->redirect($this->createUrl('user/create')); } else { $this->redirect($this->createUrl('user/dashboard')); } } } // clear password $UserLogin->UserPassword = null; // render view $this->render('create', array('UserLogin' => $UserLogin, 'UserProfile' => $UserProfile, 'rolesArray' => $rolesArray, 'managersArray' => $managerArray)); }
public function saveDatabase() { $buyer1 = Input::get('buyer'); $seller = Input::get('seller'); $review = Input::get('review'); $urls = Input::get('urls'); $rating_num = Input::get('rating'); $rating = new Rating(); //$rating->rating_id = 2; $rating->seller = $seller; $rating->buyer = $buyer1; $rating->review = $review; $rating->rating_number = $rating_num; $rating->save(); $actual_link = "http://{$_SERVER['HTTP_HOST']}"; return Redirect::away($actual_link . "/authentication"); }
public static function createNewRating($input) { $rating = new Rating(); $error_code = ApiResponse::OK; $rating->user_id = Session::get('user_id'); if (!empty($input['wine_unique_id'])) { if (Wine::where('wine_unique_id', $input['wine_unique_id'])->first()) { $rating_old = Rating::where('wine_unique_id', $input['wine_unique_id'])->where('user_id', $rating->user_id)->first(); if ($rating_old) { $result = Rating::updateRatingDetail($rating_old->id, $input); return $result; } else { $rating->wine_unique_id = $input['wine_unique_id']; if (!empty($input['rate'])) { $rating->rate = $input['rate']; } if (!empty($input['content'])) { $rating->content = $input['content']; } if (!empty($input['like_count'])) { $rating->like_count = $input['like_count']; } if (!empty($input['comment_count'])) { $rating->comment_count = $input['comment_count']; } if (!empty($input['is_my_wine'])) { $rating->is_my_wine = $input['is_my_wine']; } // Validation and Filtering is sorely needed!! // Seriously, I'm a bad person for leaving that out. $check = Rating::check_validator($input); if ($check !== false) { $rating_profile = Profile::where('user_id', $rating->user_id)->first(); if ($rating_profile != null) { $rating_profile->rate_count = $rating_profile->rate_count + 1; $rating_profile->save(); } $rating_wine = Wine::where('wine_unique_id', $rating->wine_unique_id)->first(); if ($rating_wine != null) { $rating_rate = $rating_wine->average_rate * $rating_wine->rate_count; $rating_wine->rate_count = $rating_wine->rate_count + 1; $rating_wine->average_rate = ($rating_rate + $rating->rate) / $rating_wine->rate_count; $rating_wine->save(); } $rating->save(); $data = $rating->toArray(); } else { $error_code = ApiResponse::UNAVAILABLE_RATING; $data = ApiResponse::getErrorContent(ApiResponse::UNAVAILABLE_RATING); } } } else { $error_code = ApiResponse::UNAVAILABLE_WINE; $data = ApiResponse::getErrorContent(ApiResponse::UNAVAILABLE_WINE); } } else { $error_code = ApiResponse::MISSING_PARAMS; $data = $input; } return array("code" => $error_code, "data" => $data); }
/** * Handles the saving of ratings against a user's ID * @return unknown_type */ protected function saveRatings() { $friendRatings = $this->getUser()->getAttribute("friendRatings"); $friendID = $this->getUser()->getAttribute("selectedFriend"); foreach ($friendRatings as $skillID => $ratingValue) { $rating = new Rating(); $rating->uid = $friendID; $rating->by_uid = $this->facebook->user; $rating->skill_id = $skillID; $rating->rating = $ratingValue; $rating->save(); } }
public function run() { $rating = new Rating(); $rating->user_id = 1; $rating->beer_id = 63; $rating->rating = '5'; $rating->comment = 'Great Beer!'; $rating->save(); $rating = new Rating(); $rating->user_id = 2; $rating->beer_id = 63; $rating->rating = '5'; $rating->comment = 'Great Beer!'; $rating->save(); $rating = new Rating(); $rating->user_id = 3; $rating->beer_id = 63; $rating->rating = '5'; $rating->comment = 'Great Beer!'; $rating->save(); $rating = new Rating(); $rating->user_id = 4; $rating->beer_id = 63; $rating->rating = '5'; $rating->comment = 'Great Beer!'; $rating->save(); $rating = new Rating(); $rating->user_id = 5; $rating->beer_id = 63; $rating->rating = '5'; $rating->comment = 'Great Beer!'; $rating->save(); $rating = new Rating(); $rating->user_id = 6; $rating->beer_id = 63; $rating->rating = '1'; $rating->comment = 'Great Beer!'; $rating->save(); $rating = new Rating(); $rating->user_id = 7; $rating->beer_id = 63; $rating->rating = '1'; $rating->comment = 'Great Beer!'; $rating->save(); $rating = new Rating(); $rating->user_id = 8; $rating->beer_id = 63; $rating->rating = '4'; $rating->comment = 'Great Beer!'; $rating->save(); $rating = new Rating(); $rating->user_id = 9; $rating->beer_id = 63; $rating->rating = '4'; $rating->comment = 'Great Beer!'; $rating->save(); $rating = new Rating(); $rating->user_id = 10; $rating->beer_id = 63; $rating->rating = '5'; $rating->comment = 'Great Beer!'; $rating->save(); $rating = new Rating(); $rating->user_id = 11; $rating->beer_id = 63; $rating->rating = '5'; $rating->comment = 'Great Beer!'; $rating->save(); $rating = new Rating(); $rating->user_id = 12; $rating->beer_id = 63; $rating->rating = '5'; $rating->comment = 'Great Beer!'; $rating->save(); $rating = new Rating(); $rating->user_id = 13; $rating->beer_id = 63; $rating->rating = '5'; $rating->comment = 'Great Beer!'; $rating->save(); $rating = new Rating(); $rating->user_id = 14; $rating->beer_id = 63; $rating->rating = '5'; $rating->comment = 'Great Beer!'; $rating->save(); $rating = new Rating(); $rating->user_id = 15; $rating->beer_id = 63; $rating->rating = '5'; $rating->comment = 'Great Beer!'; $rating->save(); $rating = new Rating(); $rating->user_id = 16; $rating->beer_id = 63; $rating->rating = '5'; $rating->comment = 'Great Beer!'; $rating->save(); $rating = new Rating(); $rating->user_id = 17; $rating->beer_id = 73; $rating->rating = '5'; $rating->comment = 'Great Beer!'; $rating->save(); $rating = new Rating(); $rating->user_id = 18; $rating->beer_id = 73; $rating->rating = '5'; $rating->comment = 'Great Beer!'; $rating->save(); $rating = new Rating(); $rating->user_id = 2; $rating->beer_id = 9; $rating->rating = '5'; $rating->comment = 'Great Beer!'; $rating->save(); $rating = new Rating(); $rating->user_id = 18; $rating->beer_id = 9; $rating->rating = '5'; $rating->comment = 'Great Beer!'; $rating->save(); $rating = new Rating(); $rating->user_id = 17; $rating->beer_id = 9; $rating->rating = '5'; $rating->comment = 'Great Beer!'; $rating->save(); $rating = new Rating(); $rating->user_id = 15; $rating->beer_id = 9; $rating->rating = '5'; $rating->comment = 'Great Beer!'; $rating->save(); $rating = new Rating(); $rating->user_id = 14; $rating->beer_id = 9; $rating->rating = '5'; $rating->comment = 'Great Beer!'; $rating->save(); $rating = new Rating(); $rating->user_id = 10; $rating->beer_id = 9; $rating->rating = '5'; $rating->comment = 'Great Beer!'; $rating->save(); }
<? require_once('classes/Rating.php'); require_once('classes/Text.php'); $recipe_id = $_REQUEST['recipe_id']; $value = $_REQUEST['rating']; $comment = $_REQUEST['comment']; $rating = Rating::getForRecipeAndUser($recipe_id); if ($rating == NULL && $value > 0) { $rating = new Rating(); $rating->recipe_id = $recipe_id; } if ($value < 0 && $rating != NULL) { $rating->delete(); } if ($value > 0) { $rating->value = $value; $rating->comment = $comment; $rating->save(); } echo 'OK';//Text::getText('ThankYou'); ?>
/** * Fill good rating by random data * @return void */ public function actionRandomData() { $users = array(1, 2, 3); $all_goods = Good::model()->findAll(); foreach ($all_goods as $good) { $sum = 0; $count = 0; foreach ($users as $user) { if (rand(1, 5) == 5) { continue; } $count++; $user_mark = rand(1, 5); $sum += $user_mark; $user_rating = new Rating(); $user_rating->good_id = $good->id; $user_rating->user_id = $user; $user_rating->value = $user_mark; $user_rating->save(); } if ($count != 0) { $good->rating = round($sum / $count * 100); $good->update(array('rating')); } echo $good->id . '<br>'; flush(); } }