feat(reference-auto) : extend auto-reference to composants + formula builder UI
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -4,20 +4,23 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use App\Entity\Composant;
|
||||
use App\Entity\CustomFieldValue;
|
||||
use App\Entity\Piece;
|
||||
|
||||
class ReferenceAutoGenerator
|
||||
{
|
||||
public function generate(Piece $piece): ?string
|
||||
public function generate(Composant|Piece $entity): ?string
|
||||
{
|
||||
$modelType = $piece->getTypePiece();
|
||||
$modelType = $entity instanceof Piece
|
||||
? $entity->getTypePiece()
|
||||
: $entity->getTypeComposant();
|
||||
|
||||
if (!$modelType || !$modelType->getReferenceFormula()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$valueMap = $this->buildValueMap($piece);
|
||||
$valueMap = $this->buildValueMap($entity);
|
||||
|
||||
$requiredFields = $modelType->getRequiredFieldsForReference();
|
||||
|
||||
@@ -35,16 +38,16 @@ class ReferenceAutoGenerator
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a map of fieldName → normalized value from the Piece's CustomFieldValues.
|
||||
* Build a map of fieldName → normalized value from the entity's CustomFieldValues.
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
private function buildValueMap(Piece $piece): array
|
||||
private function buildValueMap(Composant|Piece $entity): array
|
||||
{
|
||||
$map = [];
|
||||
|
||||
/** @var CustomFieldValue $cfv */
|
||||
foreach ($piece->getCustomFieldValues() as $cfv) {
|
||||
foreach ($entity->getCustomFieldValues() as $cfv) {
|
||||
$normalized = mb_strtoupper(trim($cfv->getValue()));
|
||||
$map[$cfv->getCustomField()->getName()] = $normalized;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user