コード例 #1
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Frequency::create(['short_name' => 'new-challenge', 'name' => 'Every challenge']);
     Frequency::create(['short_name' => 'weekly', 'name' => 'Weekly']);
     Difficulty::create(['short_name' => 'easy', 'name' => 'Easy']);
     Difficulty::create(['short_name' => 'intermediate', 'name' => 'Intermediate']);
     Difficulty::create(['short_name' => 'hard', 'name' => 'Hard']);
     Difficulty::create(['short_name' => 'all', 'name' => 'All']);
 }
コード例 #2
0
 public function updateUserDifficulties(User $user, $difficulties)
 {
     $difficultiesId = Difficulty::where('short_name', '<>', 'all')->pluck('id');
     $difficultiesId = collect($difficultiesId);
     if ($difficultiesId->intersect($difficulties)->count() == $difficultiesId->count()) {
         // User is interested in all difficulties
         DifficultyUser::create(['user_id' => $user->id, 'difficulty_id' => Difficulty::where('short_name', 'all')->first()->id]);
     } else {
         $difficulties->each(function ($id) use($user) {
             DifficultyUser::create(['user_id' => $user->id, 'difficulty_id' => $id]);
         });
     }
 }
コード例 #3
0
 public static function saveDifficultiesForUser($difficulties, $userId)
 {
     $difficulties = collect($difficulties);
     $difficulties = $difficulties->filter(function ($item) {
         return $item != null;
     });
     $difficultyAllId = Difficulty::where('short_name', 'all')->first()->id;
     $difficultyHardId = Difficulty::where('short_name', 'hard')->first()->id;
     $difficultyIntermediateId = Difficulty::where('short_name', 'intermediate')->first()->id;
     $difficultyEasyId = Difficulty::where('short_name', 'easy')->first()->id;
     if ($difficulties->has('difficulty_all') || $difficulties->only(['difficulty_easy', 'difficulty_intermediate', 'difficulty_hard'])->count() == 3) {
         DifficultyUser::create(['user_id' => $userId, 'difficulty_id' => $difficultyAllId]);
     } else {
         if ($difficulties->has('difficulty_hard')) {
             DifficultyUser::create(['user_id' => $userId, 'difficulty_id' => $difficultyHardId]);
         }
         if ($difficulties->has('difficulty_intermediate')) {
             DifficultyUser::create(['user_id' => $userId, 'difficulty_id' => $difficultyIntermediateId]);
         }
         if ($difficulties->has('difficulty_easy')) {
             DifficultyUser::create(['user_id' => $userId, 'difficulty_id' => $difficultyEasyId]);
         }
     }
 }