Skip to content

Commit

Permalink
Fixes wrong order
Browse files Browse the repository at this point in the history
  • Loading branch information
frostieDE committed Nov 24, 2024
1 parent 66e1ac7 commit 2a0af26
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
22 changes: 22 additions & 0 deletions src/Book/Grade/CategoryStrategy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace App\Book\Grade;

use App\Sorting\SortingStrategyInterface;
use App\Sorting\TuitionGradeCategoryStrategy;

class CategoryStrategy implements SortingStrategyInterface {

public function __construct(private readonly TuitionGradeCategoryStrategy $strategy) {

}

/**
* @param Category $objectA
* @param Category $objectB
* @return int
*/
public function compare($objectA, $objectB): int {
return $this->strategy->compare($objectA->getCategory(), $objectB->getCategory());
}
}
4 changes: 2 additions & 2 deletions src/Book/Grade/GradeOverviewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ public function computeOverviewForStudent(Student $student, Section $section): G

foreach($tuitions as $tuition) {
$gradeCategories = $tuition->getGradeCategories()->toArray();
$this->sorter->sort($gradeCategories, TuitionGradeCategoryStrategy::class);

foreach($gradeCategories as $category) {
$categories[$category->getId()] = new Category($tuition, $category);
}
}

$this->sorter->sort($categories, CategoryStrategy::class);

$grades = ArrayUtils::createArrayWithKeys(
$this->tuitionGradeRepository->findAllByStudent($student, $section),
fn(TuitionGrade $grade) => sprintf('%s_%s', $grade->getTuition()->getId(), $grade->getCategory()->getId())
Expand Down

0 comments on commit 2a0af26

Please sign in to comment.