diff --git a/src/Services/ProjectSystem/ProjectBuildHelper.php b/src/Services/ProjectSystem/ProjectBuildHelper.php index 824923cb..a541c29d 100644 --- a/src/Services/ProjectSystem/ProjectBuildHelper.php +++ b/src/Services/ProjectSystem/ProjectBuildHelper.php @@ -31,9 +31,9 @@ use App\Services\Parts\PartLotWithdrawAddHelper; /** * @see \App\Tests\Services\ProjectSystem\ProjectBuildHelperTest */ -class ProjectBuildHelper +final readonly class ProjectBuildHelper { - public function __construct(private readonly PartLotWithdrawAddHelper $withdraw_add_helper) + public function __construct(private PartLotWithdrawAddHelper $withdraw_add_helper) { } @@ -79,6 +79,21 @@ class ProjectBuildHelper return $maximum_buildable_count; } + /** + * Returns the maximum buildable amount of the given project as string, based on the stock of the used parts in the BOM. + * If the maximum buildable count is infinite, the string '∞' is returned. + * @param Project $project + * @return string + */ + public function getMaximumBuildableCountAsString(Project $project): string + { + $max_count = $this->getMaximumBuildableCount($project); + if ($max_count === PHP_INT_MAX) { + return '∞'; + } + return (string) $max_count; + } + /** * Checks if the given project can be built with the current stock. * This means that the maximum buildable count is greater or equal than the requested $number_of_projects diff --git a/templates/projects/build/build.html.twig b/templates/projects/build/build.html.twig index 6489256d..a5ff3d9a 100644 --- a/templates/projects/build/build.html.twig +++ b/templates/projects/build/build.html.twig @@ -18,10 +18,9 @@ {% endif %} -
{% trans %}project.builds.no_stocked_builds{% endtrans %}: {{ project.buildPart.amountSum }}
-{% endif %} \ No newline at end of file +{% endif %} diff --git a/tests/Services/ProjectSystem/ProjectBuildHelperTest.php b/tests/Services/ProjectSystem/ProjectBuildHelperTest.php index 3b73cad1..5009f849 100644 --- a/tests/Services/ProjectSystem/ProjectBuildHelperTest.php +++ b/tests/Services/ProjectSystem/ProjectBuildHelperTest.php @@ -114,4 +114,22 @@ class ProjectBuildHelperTest extends WebTestCase $this->assertSame(0, $this->service->getMaximumBuildableCount($project)); } + + public function testGetMaximumBuildableCountEmpty(): void + { + $project = new Project(); + + $this->assertSame(0, $this->service->getMaximumBuildableCount($project)); + } + + public function testGetMaximumBuildableCountAsString(): void + { + $project = new Project(); + $bom_entry1 = new ProjectBOMEntry(); + $bom_entry1->setName("Test"); + $project->addBomEntry($bom_entry1); + + $this->assertSame('∞', $this->service->getMaximumBuildableCountAsString($project)); + + } } diff --git a/translations/messages.en.xlf b/translations/messages.en.xlf index ad618f86..4ae29e18 100644 --- a/translations/messages.en.xlf +++ b/translations/messages.en.xlf @@ -14223,7 +14223,13 @@ Please note, that you can not impersonate a disabled user. If you try you will g