From f27490e192af22bc4677f446ef4b2bd530819568 Mon Sep 17 00:00:00 2001 From: Gregory Ballantine Date: Mon, 3 Jun 2024 08:32:37 -0400 Subject: [PATCH] Modified some views, routes and models to work with the new many-to-many for tests and benchmarks --- src/Controllers/TestController.php | 6 +++++- src/Models/Benchmark.php | 4 ++-- src/Models/Test.php | 4 ++-- views/test/add.twig | 4 ++-- views/test/list.twig | 6 ++---- views/test/view.twig | 11 ++++++++--- 6 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src/Controllers/TestController.php b/src/Controllers/TestController.php index c687480..589df69 100644 --- a/src/Controllers/TestController.php +++ b/src/Controllers/TestController.php @@ -47,9 +47,13 @@ class TestController extends Controller { $test = new Test; $test->title = $params['test_title']; $test->description = $params['test_description']; - $test->benchmark_id = $params['test_benchmark']; $test->component_id = $params['test_component']; + // attach benchmarks to test + foreach ($params['test_benchmarks'] as $b) { + $test->benchmarks()->attach($b); + } + $test->save(); // redirect the user back to the home page diff --git a/src/Models/Benchmark.php b/src/Models/Benchmark.php index 57f4983..ee0e9f0 100644 --- a/src/Models/Benchmark.php +++ b/src/Models/Benchmark.php @@ -13,7 +13,7 @@ class Benchmark extends Model { ]; public function tests() { - return $this->hasMany(Test::class); + return $this->belongsToMany(Test::class); } -} \ No newline at end of file +} diff --git a/src/Models/Test.php b/src/Models/Test.php index e5bc171..f862a7c 100644 --- a/src/Models/Test.php +++ b/src/Models/Test.php @@ -17,11 +17,11 @@ class Test extends Model { } public function benchmark() { - return $this->belongsTo(Benchmark::class); + return $this->belongsToMany(Benchmark::class); } public function component() { return $this->belongsTo(Component::class); } -} \ No newline at end of file +} diff --git a/views/test/add.twig b/views/test/add.twig index bda0de6..9ac7640 100644 --- a/views/test/add.twig +++ b/views/test/add.twig @@ -23,8 +23,8 @@
@@ -33,8 +38,8 @@ {% for r in test.results %} {{ test.component().name }} - {{ test.benchmark().name }} - {{ test.scoring | capitalize }} + {{ r.benchmark().name }} + {{ r.benchmark().scoring | capitalize }} {{ r.average }} {{ r.minimum ? r.minimum : 'N/a' }} {{ r.maximum ? r.maximum : 'N/a' }} @@ -43,7 +48,7 @@ {% else %} -

There are no results associated with this.

+

There are no results associated with this test.

{% endif %}