diff --git a/src/Controllers/Metrics/Controller.php b/src/Controllers/Metrics/Controller.php index 8be03d0c..c5cbf736 100644 --- a/src/Controllers/Metrics/Controller.php +++ b/src/Controllers/Metrics/Controller.php @@ -139,6 +139,8 @@ class Controller extends BaseController 'locales' => ['type' => 'gauge', 'help' => 'The locales users have configured'] + $userLocales, 'themes' => ['type' => 'gauge', 'help' => 'The themes users have configured'] + $userThemes, 'locations' => ['type' => 'gauge', $this->stats->locations()], + 'angeltypes' => ['type' => 'gauge', $this->stats->angeltypes()], + 'shifttypes' => ['type' => 'gauge', $this->stats->shifttypes()], 'shifts' => ['type' => 'gauge', $this->stats->shifts()], 'announcements' => [ 'type' => 'gauge', diff --git a/src/Controllers/Metrics/Stats.php b/src/Controllers/Metrics/Stats.php index 86b50ca9..1f4f9936 100644 --- a/src/Controllers/Metrics/Stats.php +++ b/src/Controllers/Metrics/Stats.php @@ -6,6 +6,7 @@ namespace Engelsystem\Controllers\Metrics; use Carbon\Carbon; use Engelsystem\Database\Database; +use Engelsystem\Models\AngelType; use Engelsystem\Models\EventConfig; use Engelsystem\Models\Faq; use Engelsystem\Models\LogEntry; @@ -16,6 +17,7 @@ use Engelsystem\Models\OAuth; use Engelsystem\Models\Question; use Engelsystem\Models\Location; use Engelsystem\Models\Shifts\Shift; +use Engelsystem\Models\Shifts\ShiftType; use Engelsystem\Models\User\License; use Engelsystem\Models\User\PasswordReset; use Engelsystem\Models\User\PersonalData; @@ -297,6 +299,18 @@ class Stats ->count(); } + public function shifttypes(): int + { + return ShiftType::query() + ->count(); + } + + public function angeltypes(): int + { + return AngelType::query() + ->count(); + } + public function shifts(): int { return Shift::count(); diff --git a/tests/Unit/Controllers/Metrics/StatsTest.php b/tests/Unit/Controllers/Metrics/StatsTest.php index 3f4a8ea1..fcfbcc08 100644 --- a/tests/Unit/Controllers/Metrics/StatsTest.php +++ b/tests/Unit/Controllers/Metrics/StatsTest.php @@ -6,6 +6,7 @@ namespace Engelsystem\Test\Unit\Controllers\Metrics; use Carbon\Carbon; use Engelsystem\Controllers\Metrics\Stats; +use Engelsystem\Models\AngelType; use Engelsystem\Models\Faq; use Engelsystem\Models\LogEntry; use Engelsystem\Models\Message; @@ -16,6 +17,7 @@ use Engelsystem\Models\Question; use Engelsystem\Models\Location; use Engelsystem\Models\Shifts\Shift; use Engelsystem\Models\Shifts\ShiftEntry; +use Engelsystem\Models\Shifts\ShiftType; use Engelsystem\Models\User\License; use Engelsystem\Models\User\PasswordReset; use Engelsystem\Models\User\PersonalData; @@ -200,6 +202,34 @@ class StatsTest extends TestCase $this->assertEquals(4, $stats->locations()); } + /** + * @covers \Engelsystem\Controllers\Metrics\Stats::angeltypes + */ + public function testAngeltypes(): void + { + (new AngelType(['name' => 'AngelType 1']))->save(); + (new AngelType(['name' => 'Second AngelType']))->save(); + (new AngelType(['name' => 'Another AngelType']))->save(); + (new AngelType(['name' => 'Old AngelType']))->save(); + + $stats = new Stats($this->database); + $this->assertEquals(4, $stats->angeltypes()); + } + + /** + * @covers \Engelsystem\Controllers\Metrics\Stats::shifttypes + */ + public function testShifttypes(): void + { + (new ShiftType(['name' => 'ShiftType 1', 'description' => 'rtfm']))->save(); + (new ShiftType(['name' => 'Second ShiftType', 'description' => 'pebkac']))->save(); + (new ShiftType(['name' => 'Another ShiftType', 'description' => 'id10t error']))->save(); + (new ShiftType(['name' => 'Old ShiftType', 'description' => 'layer 8']))->save(); + + $stats = new Stats($this->database); + $this->assertEquals(4, $stats->shifttypes()); + } + /** * @covers \Engelsystem\Controllers\Metrics\Stats::shifts */