master
ELF 4 years ago
parent 28fbbff699
commit 9b11202deb

@ -40,7 +40,7 @@ class PromoteGradeService
$config = []; $config = [];
$config['reach_level'] = $params['level']; $config['reach_level'] = $params['level'];
$config['grades'] = $params['grades']; $config['grades'] = $this->sortGrades($params['grades']);
$config['default_grade_name'] = $params['default_grade_name']; $config['default_grade_name'] = $params['default_grade_name'];
$data = []; $data = [];
@ -59,9 +59,20 @@ class PromoteGradeService
} }
} }
private function checkGrades($grades) private function sortGrades($grades)
{ {
if (count($grades) == 0) {
return $grades;
}
$values = [];
$symbols = [];
foreach ($grades as $key => $row) {
$values[$key] = $row['value'];
$symbols[$key] = $row['symbol'];
}
array_multisort($values, SORT_ASC, $symbols, SORT_ASC, $grades);
return $grades;
} }
public function getCurrentSetting($promote) public function getCurrentSetting($promote)
@ -145,7 +156,7 @@ class PromoteGradeService
$gradeName = $config['default_grade_name']; $gradeName = $config['default_grade_name'];
break; break;
} }
$nextGrade = $grade[$key + 1] ?? null; $nextGrade = $grades[$key + 1] ?? null;
if ($this->isBigger($value, $grade) && !$this->isBigger($value, $nextGrade)) { if ($this->isBigger($value, $grade) && !$this->isBigger($value, $nextGrade)) {
$gradeName = $grade['name']; $gradeName = $grade['name'];
break; break;

Loading…
Cancel
Save