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


PHP Helper::calculate_position方法代码示例

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


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

示例1: compute_result

 /**
  * compute averages and positions for students in class
  * @param  int $class_id class id
  * @return route    redirect to route
  */
 public function compute_result($class_id)
 {
     //get all students in this class
     $students = Student::where('class_id', $class_id)->get();
     //get the number of subjects for this class
     $number_of_subjects = count(studentClass::find($class_id)->subjects);
     $result_table = 'class_results_' . \Session::get('current_session') . '_' . \Session::get('current_term');
     $positions_table = 'class_positions_' . \Session::get('current_session') . '_' . \Session::get('current_term');
     //array to hold all students total scores
     $results = [];
     foreach ($students as $student) {
         $total_score = 0;
         $offered_subjects = Helper::get_offered_subjects($class_id, $student->id);
         foreach ($offered_subjects as $subject_id) {
             $subject = \DB::table($result_table)->where(['class_id' => $class_id, 'student_id' => $student->id, 'subject_id' => $subject_id])->first();
             $total_score += $subject->subject_total;
         }
         $results[$student->id] = $total_score;
     }
     $positions = Helper::calculate_position($results);
     foreach ($positions as $student_id => $position) {
         $total_score = 0;
         $offered_subjects = Helper::get_offered_subjects($class_id, $student_id);
         foreach ($offered_subjects as $subject_id) {
             $subject = \DB::table($result_table)->where(['class_id' => $class_id, 'student_id' => $student_id, 'subject_id' => $subject_id])->first();
             $total_score += $subject->subject_total;
         }
         $average = floatVal($total_score) / floatVal(count($offered_subjects));
         try {
             \DB::table($positions_table)->where(['class_id' => $class_id, 'student_id' => $student_id])->update(['total' => $total_score, 'average' => $average, 'position' => $position, 'status_id' => 6]);
         } catch (\Illuminate\Database\QueryException $e) {
             $errorCode = $e->errorInfo[1];
             // if($errorCode == 1050){
             //     session()->flash('flash_message', 'Result table for chosen session and term already exists.');
             //     return \Redirect::back()->withInput();
             // }
         }
     }
     return redirect()->route('results.result_sheet', array($class_id));
 }
开发者ID:umahatokula,项目名称:academia,代码行数:45,代码来源:resultsController.php


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