当前位置: 首页>>代码示例>>PHP>>正文


PHP Rating::create方法代码示例

本文整理汇总了PHP中Rating::create方法的典型用法代码示例。如果您正苦于以下问题:PHP Rating::create方法的具体用法?PHP Rating::create怎么用?PHP Rating::create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Rating的用法示例。


在下文中一共展示了Rating::create方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testUserSumRating

 public function testUserSumRating()
 {
     Rating::unguard();
     $post1 = Post::find(1);
     $post2 = Post::find(2);
     $user1 = User::find(1);
     Rating::create(['id' => 5, 'rating' => 1, 'rateable_id' => $post1->id, 'rateable_type' => 'Post', 'user_id' => $user1->id]);
     Rating::create(['id' => 6, 'rating' => 1, 'rateable_id' => $post2->id, 'rateable_type' => 'Post', 'user_id' => $user1->id]);
     Rating::reguard();
     $this->assertEquals(6, Post::find(1)->userSumRating);
     $this->assertEquals(6, Post::find(1)->userSumRating());
     $this->assertEquals(2, Post::find(2)->userSumRating);
     $this->assertEquals(2, Post::find(2)->userSumRating());
 }
开发者ID:willvincent,项目名称:laravel-rateable,代码行数:14,代码来源:userRatingsTest.php

示例2: run

 public function run()
 {
     DB::table('ratings')->delete();
     $user_id = User::where('email', 'testacc@gmail.com')->first()->user_id;
     $user_1 = User::where('email', 'test_1@gmail.com')->first()->user_id;
     $user_2 = User::where('email', 'test_2@gmail.com')->first()->user_id;
     $wine_1 = Wine::where('wine_id', 1)->first()->wine_unique_id;
     $wine_2 = Wine::where('wine_id', 2)->first()->wine_unique_id;
     $wine_3 = Wine::where('wine_id', 3)->first()->wine_unique_id;
     Rating::create(array('id' => '1', 'user_id' => $user_id, 'wine_unique_id' => $wine_1, 'rate' => '0.5', 'content' => 'this is rating 1', 'like_count' => '5', 'comment_count' => '5', 'is_my_wine' => '1'));
     Rating::create(array('id' => '2', 'user_id' => $user_id, 'wine_unique_id' => $wine_2, 'rate' => '1.5', 'content' => 'this is rating 2', 'like_count' => '5', 'comment_count' => '5', 'is_my_wine' => '1'));
     Rating::create(array('id' => '3', 'user_id' => $user_id, 'wine_unique_id' => $wine_3, 'rate' => '4.5', 'content' => 'this is rating 3', 'like_count' => '8', 'comment_count' => '5', 'is_my_wine' => '1'));
     Rating::create(array('id' => '4', 'user_id' => $user_1, 'wine_unique_id' => $wine_1, 'rate' => '5', 'content' => 'this is rating 7', 'like_count' => '6', 'comment_count' => '15', 'is_my_wine' => '1'));
     Rating::create(array('id' => '5', 'user_id' => $user_2, 'wine_unique_id' => $wine_2, 'rate' => '5', 'content' => 'this is rating 8', 'like_count' => '14', 'comment_count' => '8', 'is_my_wine' => '1'));
 }
开发者ID:anht37,项目名称:winelover_server,代码行数:15,代码来源:RatingTableSeeder.php

示例3: run

 public function run()
 {
     DB::table('ratings')->delete();
     Rating::unguard();
     $post1 = Post::find(1);
     $post2 = Post::find(2);
     $post3 = Post::find(3);
     $user1 = User::find(1);
     $user2 = User::find(2);
     Rating::create(['id' => 1, 'rating' => 5, 'rateable_id' => $post1->id, 'rateable_type' => 'Post', 'user_id' => $user1->id]);
     Rating::create(['id' => 2, 'rating' => 5, 'rateable_id' => $post1->id, 'rateable_type' => 'Post', 'user_id' => $user2->id]);
     Rating::create(['id' => 3, 'rating' => 1, 'rateable_id' => $post2->id, 'rateable_type' => 'Post', 'user_id' => $user1->id]);
     Rating::create(['id' => 4, 'rating' => 5, 'rateable_id' => $post2->id, 'rateable_type' => 'Post', 'user_id' => $user2->id]);
     Rating::reguard();
 }
开发者ID:faisalmirza,项目名称:laravel-rateable,代码行数:15,代码来源:RatingsSeeder.php

示例4: rate

 /**
  * action for rating an object
  * @return JSON
  **/
 public function rate($request)
 {
     $class = $request->param('ObjectClassName');
     $id = (int) $request->param('ObjectID');
     $score = (int) $request->getVar('score');
     // check we have all the params
     if (!class_exists($class) || !$id || !$score || !($object = $class::get()->byID($id))) {
         return Convert::raw2json(array('status' => 'error', 'message' => _t('RateableController.ERRORMESSAGE', 'Sorry, there was an error rating this item')));
     }
     // check the object exists
     if (!$object || !$object->checkRatingsEnabled()) {
         return Convert::raw2json(array('status' => 'error', 'message' => _t('RateableController.ERRORNOTFOUNT', 'Sorry, the item you are trying to rate could not be found')));
     }
     // check the user can rate the object
     $ratingRecord = $this->rateableService->userGetRating($class, $id);
     if ($ratingRecord) {
         if (!$object->canChangeRating()) {
             return Convert::raw2json(array('status' => 'error', 'message' => _t('RateableController.ERRORALREADYRATED', 'Sorry, You have already rated this item')));
         }
         // If clicked same score as before, remove rating
         if ($score == $ratingRecord->Score) {
             // Remove rating
             $ratingRecord->delete();
             // Success
             return Convert::raw2json(array('status' => 'success', 'isremovingrating' => 1, 'averagescore' => $object->getAverageScore(), 'numberofratings' => $object->getNumberOfRatings(), 'message' => _t('RateableController.RATINGREMOVED', 'Your rating has been removed!')));
         }
     }
     // check if score is valid
     $isScoreValid = false;
     $scoreOptions = $object->getRatingOptions();
     if ($scoreOptions) {
         foreach ($scoreOptions as $scoreOption) {
             $isScoreValid = $isScoreValid || $score == $scoreOption->Score;
         }
     }
     if (!$isScoreValid) {
         return Convert::raw2json(array('status' => 'error', 'message' => _t('RateableController.ERRORINVALIDRATING', 'You sent an invalid rating.')));
     }
     // create the rating
     $isRatingNew = !$ratingRecord;
     if (!$ratingRecord) {
         $ratingRecord = Rating::create(array('ObjectID' => $id, 'ObjectClass' => $class));
     }
     $ratingRecord->Score = $score;
     $ratingRecord->write();
     // success
     return Convert::raw2json(array('status' => 'success', 'isnew' => $isRatingNew, 'averagescore' => $object->getAverageScore(), 'numberofratings' => $object->getNumberOfRatings(), 'message' => $isRatingNew ? _t('RateableController.THANKYOUMESSAGE', 'Thanks for rating!') : _t('RateableController.CHANGEMESSAGE', 'Your rating has been changed!')));
 }
开发者ID:sheadawson,项目名称:silverstripe-rateable,代码行数:52,代码来源:RateableController.php

示例5: run

 public function run()
 {
     DB::table('ratings')->delete();
     // Going to randomize all our ratings for our users, so throw everything in
     // an array.
     $toRate = array(array('item' => Doctor::where('number', 9)->first(), 'type' => 'doctor'), array('item' => Doctor::where('number', 10)->first(), 'type' => 'doctor'), array('item' => Doctor::where('number', 11)->first(), 'type' => 'doctor'), array('item' => Doctor::where('number', 12)->first(), 'type' => 'doctor'), array('item' => Enemy::where('name', 'Cybermen')->first(), 'type' => 'enemy'), array('item' => Enemy::where('name', 'Daleks')->first(), 'type' => 'enemy'), array('item' => Enemy::where('name', 'Sontarans')->first(), 'type' => 'enemy'), array('item' => Enemy::where('name', 'The Silence')->first(), 'type' => 'enemy'), array('item' => Enemy::where('name', 'Weeping Angels')->first(), 'type' => 'enemy'), array('item' => Companion::where('name', 'Amy Pond')->first(), 'type' => 'companion'), array('item' => Companion::where('name', 'Captain Jack')->first(), 'type' => 'companion'), array('item' => Companion::where('name', 'Clara Oswald')->first(), 'type' => 'companion'), array('item' => Companion::where('name', 'Donna Noble')->first(), 'type' => 'companion'), array('item' => Companion::where('name', 'Martha Jones')->first(), 'type' => 'companion'), array('item' => Companion::where('name', 'Mickey Smith')->first(), 'type' => 'companion'), array('item' => Companion::where('name', 'River Song')->first(), 'type' => 'companion'), array('item' => Companion::where('name', 'Rory Williams')->first(), 'type' => 'companion'), array('item' => Companion::where('name', 'Rose Tyler')->first(), 'type' => 'companion'), array('item' => Companion::where('name', 'Wilfred Mott')->first(), 'type' => 'companion'), array('item' => Episode::where('season', 1)->where('episode', 1)->first(), 'type' => 'episode'), array('item' => Episode::where('season', 1)->where('episode', 6)->first(), 'type' => 'episode'), array('item' => Episode::where('season', 1)->where('episode', 10)->first(), 'type' => 'episode'), array('item' => Episode::where('season', 1)->where('episode', 12)->first(), 'type' => 'episode'), array('item' => Episode::where('season', 2)->where('episode', 5)->first(), 'type' => 'episode'), array('item' => Episode::where('season', 2)->where('episode', 12)->first(), 'type' => 'episode'), array('item' => Episode::where('season', 3)->where('episode', 9)->first(), 'type' => 'episode'), array('item' => Episode::where('season', 3)->where('episode', 10)->first(), 'type' => 'episode'), array('item' => Episode::where('season', 4)->where('episode', 4)->first(), 'type' => 'episode'), array('item' => Episode::where('season', 4)->where('episode', 13)->first(), 'type' => 'episode'), array('item' => Episode::where('season', 5)->where('episode', 3)->first(), 'type' => 'episode'), array('item' => Episode::where('season', 5)->where('episode', 4)->first(), 'type' => 'episode'), array('item' => Episode::where('season', 5)->where('episode', 12)->first(), 'type' => 'episode'), array('item' => Episode::where('season', 6)->where('episode', 1)->first(), 'type' => 'episode'), array('item' => Episode::where('season', 6)->where('episode', 10)->first(), 'type' => 'episode'), array('item' => Episode::where('season', 6)->where('episode', 13)->first(), 'type' => 'episode'), array('item' => Episode::where('season', 7)->where('episode', 5)->first(), 'type' => 'episode'), array('item' => Episode::where('season', 7)->where('episode', 12)->first(), 'type' => 'episode'), array('item' => Episode::where('season', 8)->where('episode', 2)->first(), 'type' => 'episode'));
     $users = User::get();
     // Loop through our users
     foreach ($users as $user) {
         // Loop through things to be rated
         foreach ($toRate as $item) {
             $rating = rand(1, 5);
             Rating::create(array('user_id' => $user->id, 'item_id' => $item['item']->id, 'item_type' => $item['type'], 'rating' => $rating));
         }
     }
 }
开发者ID:thechrisroberts,项目名称:thedoctor,代码行数:16,代码来源:RatingSeeder.php

示例6: rate

 /**
  * action for rating an object
  * @return JSON
  **/
 public function rate($request)
 {
     $class = $request->param('ObjectClassName');
     $id = (int) $request->param('ObjectID');
     $score = (int) $request->getVar('score');
     // check we have all the params
     if (!class_exists($class) || !$id || !$score || !($object = $class::get()->byID($id))) {
         return Convert::raw2json(array('status' => 'error', 'message' => _t('RateableController.ERRORMESSAGE', 'Sorry, there was an error rating this item')));
     }
     // check the object exists
     if (!$object && !$object->checkRatingsEnabled()) {
         return Convert::raw2json(array('status' => 'error', 'message' => _t('RateableController.ERRORNOTFOUNT', 'Sorry, the item you are trying to rate could not be found')));
     }
     // check the user can rate the object
     if ($this->rateableService->userHasRated($class, $id)) {
         return Convert::raw2json(array('status' => 'error', 'message' => _t('RateableController.ERRORALREADYRATED', 'Sorry, You have already rated this item')));
     }
     // create the rating
     $rating = Rating::create(array('Score' => $score, 'ObjectID' => $id, 'ObjectClass' => $class));
     $rating->write();
     // success
     return Convert::raw2json(array('status' => 'success', 'averagescore' => $object->getAverageScore(), 'message' => _t('RateableController.THANKYOUMESSAGE', 'Thanks for rating!')));
 }
开发者ID:helpfulrobot,项目名称:sheadawson-silverstripe-rateable,代码行数:27,代码来源:RateableController.php

示例7: issueVote

 public function issueVote()
 {
     $politician_id = Input::get('politician_id');
     $issue_id = Input::get('issue_id');
     $user_id = Auth::user()->id;
     $vote_value = Input::get('vote');
     $new_rating_array = array('politician_id' => $politician_id, 'user_id' => $user_id, 'issue_id' => $issue_id, 'value' => $vote_value);
     $rating = Rating::create($new_rating_array);
     //adjust politician rank
     $politician = Politician::find($politician_id);
     $politician->rank += $vote_value;
     $politician->save();
     $title = $politician->full_name . "'s Approval Over Last 7 Days";
     $chartController = new ChartController();
     $response = $chartController->generatePoliticianChart($politician_id, $title);
     return Response::json($response);
     //	return Response::json($new_rating_array);
 }
开发者ID:netintelpro,项目名称:laravel-app,代码行数:18,代码来源:PoliticianController.php


注:本文中的Rating::create方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。