/** * @var $query_restrict , will be "department,grade" * department 1 ~ 60 * grade 1 ~ 6 */ public function query($query_restrict) { $department = substr($query_restrict, 0, -2); $grade = substr($query_restrict, -1); if ($grade < 6) { return $this->course->where('course_department', 'like', "%" . $department . "%")->where('course_grade', $grade)->get(); } else { return $this->course->where('course_department', 'like', "%" . $department . "%")->get(); } }
public function testCheckCourseCommented() { $course = Course::all()->random(); $user = factory(User::class, 1)->create(); $this->assertEquals(false, $this->repository->checkCourseCommented($user->stu_id, $course->id)); factory(Comment::class, 1)->create(['course_id' => $course->id, 'commenter' => $user->stu_id]); $this->assertEquals(true, $this->repository->checkCourseCommented($user->stu_id, $course->id)); }
public function testDeleteFavorite() { $course_id = Course::all()->pluck('id')->random(); $this->repository->addFavorite($course_id); // $this->assertEquals( $course_id , $this->user->courses[0]->id ); $this->repository->deleteFavorite($course_id); $this->assertEmpty($this->user->courses); }
public function testGetCourseByDepartment() { $all_courses = Course::all()->random(10); foreach ($all_courses as $target_course) { $query_restrict = $target_course->course_department . "," . $target_course->course_grade; $course1 = $this->repository->searchCourse("department", $query_restrict)->pluck('id'); $this->assertContains($target_course->id, $course1); } }
public function testShowCourseJudgePage() { $course = Course::all()->random(); $user = factory(User::class, 1)->create(); auth()->login($user); $this->call('GET', "/course/judge/" . $course->id); $this->assertResponseOk(); $this->assertViewHas('course'); }
public function testUpdateCurrentRank() { $course = factory(Course::class, 1)->create(); $comment1 = factory(Comment::class, 1)->create(['course_id' => $course->id, 'teach_q' => 30]); $comment2 = factory(Comment::class, 1)->create(['course_id' => $course->id, 'teach_q' => 100]); $comment = factory(Comment::class, 1)->create(['course_id' => $course->id, 'teach_q' => 100]); $this->courseService->UpdateCurrentRank($course, $comment); $this->courseService->UpdateCurrentRank($course, $comment1); $this->courseService->UpdateCurrentRank($course, $comment2); $course = Course::find($course->id); $this->assertEquals($course->teach_quality, ($comment1->teach_q + $comment2->teach_q + $comment->teach_q + 50) / 4); }
public function testPinCourse() { $course_id = Course::all()->pluck('id')->random(); $result = $this->pinService->pinCourse($course_id, 1); $this->assertTrue($result); $result = $this->pinService->pinCourse($course_id, 1); $this->assertFalse($result); $result = $this->pinService->pinCourse($course_id, 0); $this->assertTrue($result); $result = $this->pinService->pinCourse($course_id, 0); $this->assertFalse($result); }
public function query($query_restrict, $extend) { $rule = $this->valid_query_string($query_restrict); if (empty($rule)) { return new \Illuminate\Database\Eloquent\Collection(); } if (isset($extend['now'])) { $this->course = $this->course->where('time1', '!=', ''); } foreach ($rule as $key => $value_array) { $column = $this->rule_mapping[$key]; $this->course = $this->course->where(function ($query) use($column, $value_array) { if ($column == 'course_department' || $column == 'time1' || $column == 'time2' || $column == 'place') { foreach ($value_array as $value) { $query->orWhere($column, 'like', '%' . $value . '%'); } } else { $query->whereIn($column, $value_array); } }); } return $this->course->get(); }
public function UpdateCurrentRank(Course $course, Comment $comment) { $c = $course->comments; $total_comment = $course->comments->count(); $teach = $comment->teach_q; $time = $comment->time_c; $sign = $comment->sign_d; $test = $comment->test_d; $homework = $comment->homework_d; $grade = $comment->grade_d; $TA = $comment->TA_r; $practical = $comment->practical_r; $roll = $comment->rollCall_r; $nutrition = $comment->nutrition_r; $Pasitive = $teach + $practical + $TA + $nutrition; $Negative = $test + $homework + $grade + $time + $roll + $sign; $test = 100 - $test; $homework = 100 - $homework; $grade = 100 - $grade; $time = 100 - $time; $roll = 100 - $roll; $sign = 100 - $sign; $total = ($Pasitive + $test + $homework + $grade + $time + $sign + $roll) / 100; // If Negative == Pasitive, current_rank won't be changed $rank = $course->current_rank; if ($Negative > $Pasitive * 1.5) { $rank -= $total; } else { if ($Negative < $Pasitive * 1.5) { $rank += $total; } } $course->current_rank = $rank; $course->teach_quality = ($c->sum('teach_q') + 50) / ($total_comment + 1); $course->time_cost = ($c->sum('time_c') + 50) / ($total_comment + 1); $course->sign_dif = ($c->sum('sign_d') + 50) / ($total_comment + 1); $course->test_dif = ($c->sum('test_d') + 50) / ($total_comment + 1); $course->homework_dif = ($c->sum('homework_d') + 50) / ($total_comment + 1); $course->grade_dif = ($c->sum('grade_d') + 50) / ($total_comment + 1); $course->TA_rank = ($c->sum('TA_r') + 50) / ($total_comment + 1); $course->practical_rank = ($c->sum('practical_r') + 50) / ($total_comment + 1); $course->roll_freq = ($c->sum('rollCall_r') + 50) / ($total_comment + 1); $course->nutrition_rank = ($c->sum('nutrition_r') + 50) / ($total_comment + 1); $course->judge_people = $total_comment; $course->save(); }
public function query($query_restrict, $extend) { return $this->course->where("course_nameCH", 'like', "%" . $query_restrict . "%")->orWhere("course_nameEN", 'like', "%" . $query_restrict . "%")->get(); }
|-------------------------------------------------------------------------- | | Here you may define all of your model factories. Model factories give | you a convenient way to create models for testing and seeding your | database. Just tell the factory how a default model should look. | */ $factory->define(User::class, function (Faker\Generator $faker) { return ['stu_id' => $faker->regexify('[BMD][0-9]{9}'), 'passwd' => sha1($faker->uuid), 'real_name' => $faker->name, 'nick_name' => $faker->name, 'grade' => $faker->numberBetween($min = 105, $max = 150), 'department' => $faker->numberBetween(0, 60), 'gender' => $faker->randomElement(array('男', '女')), 'email' => $faker->email, 'auth' => $faker->numberBetween(0, 1), 'FB_conn' => $faker->url, 'update_date' => $faker->date, 'update_time' => $faker->time, 'thecode' => $faker->word, 'remember_token' => str_random(10)]; }); $factory->define(Course::class, function (Faker\Generator $faker) { return ['course_nameCH' => $faker->name, 'course_nameEN' => $faker->name, 'course_department' => $faker->numberBetween(0, 60), 'professor' => $faker->name, 'unit' => $faker->numberBetween(0, 4), 'course_grade' => $faker->numberBetween(0, 6), 'judge_people' => $faker->numberBetween(0, 1), 'time1' => $faker->dayOfWeek, 'time2' => $faker->randomElement(['234', '567', '12', '34', '56', '78', 'CDE']), 'place' => $faker->cityPrefix, 'course_dimensions' => 1]; }); $factory->define(Comment::class, function (Faker\Generator $faker) { $courses = Course::all()->pluck('id'); $users = User::all()->pluck('stu_id'); return ['course_id' => $courses->random(), 'commenter' => $users->random(), 'teach_q' => 5 * $faker->numberBetween(0, 20), 'time_c' => 5 * $faker->numberBetween(0, 20), 'sign_d' => 5 * $faker->numberBetween(0, 20), 'test_d' => 5 * $faker->numberBetween(0, 20), 'homework_d' => 5 * $faker->numberBetween(0, 20), 'grade_d' => 5 * $faker->numberBetween(0, 20), 'TA_r' => 5 * $faker->numberBetween(0, 20), 'practical_r' => 5 * $faker->numberBetween(0, 20), 'rollCall_r' => 5 * $faker->numberBetween(0, 20), 'nutrition_r' => 5 * $faker->numberBetween(0, 20), 'date' => $faker->date(), 'time' => $faker->time(), 'description' => $faker->sentence(), 'read' => 0, 'love' => $faker->randomDigit, 'dislike' => $faker->randomDigit]; }); $factory->define(Favorite::class, function (Faker\Generator $faker) { return []; }); $factory->define(Notification::class, function (Faker\Generator $faker) { $users = User::all()->pluck('stu_id'); $courses = Course::all()->pluck('id'); return ['stu_id' => $users->random(), 'course_id' => $courses->random(), 'content' => $faker->text('50'), 'type' => $faker->numberBetween(0, 2), 'is_read' => $faker->boolean()]; }); $factory->define(Curriculum::class, function (Faker\Generator $faker) { $users = User::all()->pluck('stu_id'); $courses = Course::all()->pluck('id'); return ['stu_id' => $users->random(), 'course_id' => $courses->random()]; });