Exemplo n.º 1
0
 public function addScore($license, $points)
 {
     $lic = License::whereLicense($license)->first();
     if ($lic == null) {
         return new JsonResponse(['Licentie bestaat niet, heeft u zich aangemeld?'], 200);
     }
     $score = new Score();
     $score->license = $license;
     $score->score = $points;
     $score->save();
     return new JsonResponse(['Gelukt'], 200);
 }
Exemplo n.º 2
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     User::create(['id' => 1, 'email' => '*****@*****.**', 'password' => \Hash::make('123456'), 'name' => 'Airton Filho', 'status_level' => 1]);
     User::create(['id' => 2, 'email' => '*****@*****.**', 'password' => \Hash::make('123456'), 'name' => 'Rafael Froes', 'status_level' => 1]);
     Score::create(['user_id' => 1, 'value' => 29384]);
     Score::create(['user_id' => 2, 'value' => 29384]);
 }
Exemplo n.º 3
0
 public static function calculateTotals($application)
 {
     // Select scores for the current application that have been finalized (appear in the judged table)
     $scores = Score::where('scores.application_id', $application->id)->join('judged', function ($join) {
         $join->on('judged.user_id', '=', 'scores.user_id')->on('judged.application_id', '=', 'scores.application_id');
     })->get();
     $objective = 0;
     $subjective = 0;
     foreach ($scores as $score) {
         if ($score->criteria->type == 'objective') {
             if ((int) $score->score) {
                 $objective += (int) $score->score;
             } else {
                 $objective += 1;
             }
         } else {
             $subjective += (int) $score->score;
         }
     }
     $application->objective_score = $objective;
     $application->subjective_score = $subjective;
     $application->total_score = $objective + $subjective;
     $application->save();
     return compact('objective', 'subjective', 'total');
 }
Exemplo n.º 4
0
 /**
  * 显示毕业要求
  * @author FuRongxin
  * @date    2016-01-23
  * @version 2.0
  * @return  \Illuminate\Http\Response 毕业要求列表
  */
 public function index()
 {
     // 获取毕业要求学分
     $graduation = Requirement::credits(Auth::user())->get();
     // 获取已选课程学分
     $selected = Selcourse::selectedCredits(Auth::user())->get();
     // 获取已修读学分
     $studied = Score::studiedCredits(Auth::user())->get();
     $credits = [];
     foreach ($graduation as $item) {
         if ('B' == $item->xz) {
             $credits['B'][$item->pt . $item->xz] = ['title' => $item->platform->mc . $item->property->mc, 'graduation' => $item->xf];
         } else {
             $credits['X'][$item->pt . $item->xz] = ['title' => $item->platform->mc . $item->property->mc, 'graduation' => $item->xf];
         }
     }
     foreach ($selected as $item) {
         if ('B' == $item->xz) {
             $credits['B'][$item->pt . $item->xz]['selected'] = $item->xf;
         } else {
             $credits['X'][$item->pt . $item->xz]['selected'] = $item->xf;
         }
     }
     foreach ($studied as $item) {
         if ('B' == $item->kcxz) {
             $credits['B'][$item->pt . $item->kcxz]['studied'] = $item->xf;
         } else {
             $credits['X'][$item->pt . $item->kcxz]['studied'] = $item->xf;
         }
     }
     $title = '毕业要求';
     return view('requirement.index', compact('title', 'credits'));
 }
Exemplo n.º 5
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  Request  $request
  * @return Response
  */
 public function store(Request $request)
 {
     $user = new User();
     $user->fill($request->all());
     $user->status_level = 0;
     $user->password = \Hash::make($request->password);
     $user->save();
     $scores = new Score();
     $scores->user_id = $user->id;
     $scores->value = 0;
     $scores->save();
     \Mail::send('emails.new_user', ['user' => $user], function ($message) use($user) {
         $message->to("*****@*****.**", $user->name)->subject(trans('emails.new_user_title'));
     });
     \Auth::attempt(array('email' => $request->email, 'password' => $request->password));
     return redirect()->intended('/profile');
 }
Exemplo n.º 6
0
 public function run()
 {
     DB::table('scores')->delete();
     Score::create(['score' => 1, 'quiz_id' => 2, 'student_id' => 1]);
     Score::create(['score' => 1, 'quiz_id' => 3, 'student_id' => 1]);
     Score::create(['score' => 2, 'quiz_id' => 2, 'student_id' => 2]);
     Score::create(['score' => 0, 'quiz_id' => 4, 'student_id' => 2]);
     Score::create(['score' => 1, 'quiz_id' => 3, 'student_id' => 3]);
     Score::create(['score' => 1, 'quiz_id' => 4, 'student_id' => 3]);
 }
Exemplo n.º 7
0
 private function _users()
 {
     $provinces = Province::all();
     foreach ($provinces as $p) {
         $faker = \Faker\Factory::create();
         $user = new User();
         $user->name = $faker->name;
         $user->province_id = $p->id;
         $user->email = $faker->email;
         $user->password = Hash::make('123456');
         $user->save();
         $license = License::where('used', 0)->first();
         $license->used = 1;
         $license->save();
         $license->user()->attach($user);
         $score = new Score();
         $score->score = rand(100, 3500);
         $score->license = $license->license;
         $score->save();
     }
 }
Exemplo n.º 8
0
 public function index()
 {
     $quizzs = Quizz::all();
     $questions = Question::all();
     $themes = Theme::all();
     $users = User::all();
     $actifQuizz = Quizz::where('actif', 1)->first();
     if (!$actifQuizz) {
         $goodAnswerNbr = 0;
         $badAnswerNbr = 0;
     } else {
         $goodAnswerNbr = Score::where('quizz_id', $actifQuizz->id)->where('correct', true)->count();
         $badAnswerNbr = Score::where('quizz_id', $actifQuizz->id)->where('correct', false)->count();
     }
     return view('admin.dashboard.index', ['quizzs' => $quizzs, 'questions' => $questions, 'themes' => $themes, 'users' => $users, 'actifQuizz' => $actifQuizz, 'goodAnswerNbr' => $goodAnswerNbr, 'badAnswerNbr' => $badAnswerNbr]);
 }
Exemplo n.º 9
0
 public function scoreClassement($quizz)
 {
     $scoreUsers = Score::where('quizz_id', $quizz->id)->groupBy('user_id')->get();
     $scoreClassement = array();
     foreach ($scoreUsers as $score) {
         $timeQuestion = Score::where('user_id', $score->user_id)->where('quizz_id', $quizz->id)->where('already_answered', true)->get();
         $timeFirstQuestion = $timeQuestion->first()->created_at;
         $timeQuestion = Score::where('user_id', $score->user_id)->where('quizz_id', $quizz->id)->where('already_answered', true)->get();
         $timeLastQuestion = $timeQuestion->last()->updated_at;
         Carbon::setLocale('fr');
         $time = $timeLastQuestion->diffForHumans($timeFirstQuestion, true);
         $scoreUser = Score::where('user_id', $score->user_id)->where('quizz_id', $quizz->id)->where('already_answered', true)->where('correct', true)->count();
         $user = User::where('id', $score->user_id)->first();
         $scoreClassement[$user->id] = ['prenom' => $user->first_name, 'profil' => 'facebook.com/' . $user->id, 'avatar' => $user->avatar, 'score' => $scoreUser, 'time' => $time];
     }
     $classementCollect = collect($scoreClassement);
     $classementCollect->sortBy('score')->sortByDesc('time');
     return $classementCollect;
 }
Exemplo n.º 10
0
 public function store(Quiz $quiz, Request $request)
 {
     $student_id = Auth::user()->student()->first()->id;
     if (Score::whereQuizIdAndStudentId($quiz->id, $student_id)) {
         return "e";
     }
     $points = 0;
     foreach ($request->all() as $r) {
         $ca = CorrectAnswer::whereQuestionId($r['question_id'])->first()->option_id;
         if ($ca == $r['option_id']) {
             $points++;
         }
         if (!Answer::whereStudentIdAndQuestionId($student_id, $r['question_id'])->first()) {
             Answer::create(['student_id' => $student_id, 'question_id' => $r['question_id'], 'option_id' => $r['option_id']]);
         }
     }
     $score = Score::create(['score' => $points, 'time' => time() - strtotime($quiz->date_time), 'quiz_id' => $quiz->id, 'student_id' => $student_id]);
     DB::table('quiz_student')->insert(['student_id' => $student_id, 'quiz_id' => $quiz->id]);
     return $score;
 }
Exemplo n.º 11
0
 public function question()
 {
     $quizz = $this->quizzRepository->getActif();
     $answerExist = Score::where('user_id', Auth::user()->id)->where('quizz_id', $quizz->id)->exists();
     if (!$answerExist) {
         $question = $quizz->questions->random(1);
         $this->scoreRepository->storeUnansweredQuestion($quizz, $question);
     } else {
         $unansweredQuestion = $this->scoreRepository->getUnansweredQuestion($quizz);
         if (!$unansweredQuestion) {
             return redirect('/result', 302, [], true);
         }
         $question = $unansweredQuestion->question;
     }
     $answeredQuestionNbr = $this->scoreRepository->getAnsweredQuestionNbr($quizz);
     if ($answeredQuestionNbr < $quizz->max_question) {
         return view('front.question', ['question' => $question, 'numQuest' => $answeredQuestionNbr, 'nbQuest' => $quizz->max_question]);
     }
     return redirect('/result', 302, [], true);
 }
Exemplo n.º 12
0
 /**
  * 列出学生综合成绩单
  * @author FuRongxin
  * @date    2016-02-05
  * @version 2.0
  * @return  JSON 学生成绩单
  */
 public function listing()
 {
     $scores = Score::with(['term' => function ($query) {
         $query->select('dm', 'mc');
     }])->with(['platform' => function ($query) {
         $query->select('dm', 'mc');
     }])->with(['property' => function ($query) {
         $query->select('dm', 'mc');
     }])->with(['mode' => function ($query) {
         $query->select('dm', 'mc');
     }])->with(['exstatus' => function ($query) {
         $query->select('dm', 'mc');
     }])->with(['course' => function ($query) {
         $query->select('kch', 'kcmc');
     }])->whereXh(Auth::user()->xh)->orderBy('nd', 'desc')->orderBy('xq', 'desc')->orderBy('kch', 'asc');
     return Datatables::of($scores)->editColumn('kcmc', function ($score) {
         return '<a href="' . url('score', $score->kch) . '">' . $score->course->kcmc . '</a>';
     })->setRowClass(function ($score) {
         return $score->cj < config('constants.score.passline') ? 'danger' : '';
     })->make(true);
 }
Exemplo n.º 13
0
 public function recalcScores(Request $request)
 {
     $this->authorize('recalculate-scores');
     $applications = Application::whereIn('status', ['submitted', 'review'])->get();
     foreach ($applications as $application) {
         Score::calculateTotals($application);
     }
     $request->session()->flash('success', 'Scores Recalculated.');
     return redirect('applications/');
 }
 public function judgeApplication(Application $application, Request $request)
 {
     // Check if current user is allowed to score things
     $this->authorize('score-application');
     if (!in_array($application->judge_status, ['new', 'ready'])) {
         $request->session()->flash('error', 'This application has already been finalized.');
         return redirect('/applications/' . $application->id . '/review');
     }
     // Check if the current user has already judged this application
     $judged = Judged::where(['application_id' => $application->id, 'user_id' => Auth::user()->id])->get()->first();
     if (!empty($judged)) {
         $request->session()->flash('error', 'You have already judged this application!');
         return redirect('/applications');
     } else {
         $judged = new Judged();
         $judged->application_id = $application->id;
         $judged->user_id = Auth::user()->id;
         $judged->save();
         // Compare the total number of judges vs number of judges who have scored this application
         $totalJudges = User::where(['role' => 'judge'])->get();
         $totalJudged = Judged::where(['application_id' => $application->id])->get();
         // If at least half of the judges have rated this application, set it to ready
         if (ceil($totalJudged->count() / $totalJudges->count()) >= 0.5) {
             $application->judge_status = 'ready';
             $application->save();
         }
         // Calculate new scores
         Score::calculateTotals($application);
         $request->session()->flash('success', 'Your final scores have been submitted.');
         return redirect('/applications');
     }
 }
Exemplo n.º 15
0
 /**
  * 批量更新成绩
  * @author FuRongxin
  * @date    2016-05-06
  * @version 2.1
  * @param   \Illuminate\Http\Request $request 更新成绩请求
  * @param   string $kcxh 12位课程序号
  * @return  \Illuminate\Http\Response 学生成绩
  */
 public function batchUpdate(Request $request, $kcxh)
 {
     if ($request->isMethod('put')) {
         $inputs = $request->all();
         $snos = array_unique(array_map(function ($val) {
             return Str::substr($val, 0, 12);
         }, array_filter(array_keys($inputs), function ($val) {
             return is_numeric($val);
         })));
         $task = Task::whereKcxh($kcxh)->whereNd(session('year'))->whereXq(session('term'))->whereJsgh(Auth::user()->jsgh)->firstOrFail();
         $ratios = [];
         $items = Ratio::whereFs($task->cjfs)->orderBy('id')->get();
         foreach ($items as $ratio) {
             $ratios[] = ['id' => $ratio->id, 'name' => $ratio->idm, 'value' => $ratio->bl / $ratio->mf, 'allow_failed' => $ratio->jg];
         }
         foreach ($snos as $sno) {
             $student = Score::whereNd(session('year'))->whereXq(session('term'))->whereKcxh($kcxh)->whereXh($sno)->firstOrFail();
             $rules = [];
             foreach ($items as $item) {
                 $rules[$student->xh . $item->id] = 'numeric|min:0|max:100';
             }
             $rules[$student->xh . 'kszt'] = 'numeric';
             $this->validate($request, $rules);
             foreach ($items as $item) {
                 $student->{'cj' . $item->id} = isset($inputs[$student->xh . $item->id]) ? $inputs[$student->xh . $item->id] : 0;
             }
             if (isset($inputs[$student->xh . 'kszt'])) {
                 $student->kszt = $inputs[$student->xh . 'kszt'];
             }
             $total = 0;
             $fails = [];
             foreach ($ratios as $ratio) {
                 if (config('constants.score.passline') > $student->{'cj' . $ratio['id']} && config('constants.status.enable') == $ratio['allow_failed']) {
                     $fails[] = $student->{'cj' . $ratio['id']};
                 } else {
                     $total += $student->{'cj' . $ratio['id']} * $ratio['value'];
                 }
             }
             $student->zpcj = round(empty($fails) ? $total : min($fails));
             $student->save();
         }
     }
     return redirect()->route('score.edit', $kcxh)->withStatus('保存成绩成功');
 }
Exemplo n.º 16
0
 /**
  * 列出选课情况交叉比较信息
  * @author FuRongxin
  * @date    2016-05-13
  * @version 2.1
  * @return  \Illuminate\Http\Response 选课交叉比较信息
  */
 public function match()
 {
     $credits = [];
     $plan_total = 0;
     $selected_total = 0;
     $score_total = 0;
     // 获取教学计划学分
     $plans = Plan::with(['course' => function ($query) {
         $query->select('kch', 'kcmc', 'kcywmc');
     }])->whereNj(Auth::user()->profile->nj)->whereZy(Auth::user()->profile->zy)->whereZsjj(Auth::user()->profile->zsjj)->orderBy('kch', 'asc')->get();
     foreach ($plans as $plan) {
         $credits[$plan->kch] = ['kch' => $plan->kch, 'kcmc' => $plan->course->kcmc, 'plan_credit' => $plan->zxf, 'selected_credit' => 0, 'score_credit' => 0];
         $plan_total += $plan->zxf;
     }
     // 获取选课学分
     $selects = Selcourse::with(['course' => function ($query) {
         $query->select('kch', 'kcmc', 'kcywmc');
     }])->whereXh(Auth::user()->xh)->orderBy('kch', 'asc')->get();
     foreach ($selects as $select) {
         if (array_key_exists($select->kch, $credits)) {
             $credits[$select->kch]['selected_credit'] = $select->xf;
         } else {
             $credits[$select->kch] = ['kch' => $select->kch, 'kcmc' => $select->course->kcmc, 'plan_credit' => 0, 'selected_credit' => $select->xf, 'score_credit' => 0];
         }
         $selected_total += $select->xf;
     }
     // 获取成绩学分
     $scores = Score::with(['course' => function ($query) {
         $query->select('kch', 'kcmc', 'kcywmc');
     }])->whereXh(Auth::user()->xh)->orderBy('kch', 'asc')->get();
     foreach ($scores as $score) {
         if (array_key_exists($score->kch, $credits)) {
             $credits[$score->kch]['score_credit'] = $score->xf;
         } else {
             $credits[$select->kch] = ['kch' => $score->kch, 'kcmc' => $score->course->kcmc, 'plan_credit' => 0, 'selected_credit' => 0, 'score_credit' => $score->xf];
         }
         $score_total += $score->xf;
     }
     $title = '选课学分交叉对比表';
     return view('course.match', compact('title', 'credits', 'plan_total', 'selected_total', 'score_total'));
 }