本文整理汇总了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));
}