NOM_COLONNE (API/BDD). * * @var array */ protected array $definition = [ 'matricule' => 'MATRICULE_FIC', 'lastname' => 'NOM_FIC', 'firstname' => 'PRENOM_FIC', 'start_date' => 'DATE_DEB_FIC', 'end_date' => 'DATE_FIN_FIC', 'planned_end_date' => 'DATE_EFFET_FIC', 'establishment' => 'ETAB_FIC', 'site' => 'SITE_FIC', 'service' => 'SERVICE_FIC', 'created_at' => 'DATE_EFFET_FIC', 'updated_at' => 'DAT_MAJ', ]; public function getTable(): string { return $this->table; } public function getTableKey(): string { return $this->definition[$this->tableKey]; } public function getPropertiesMap(): array { return $this->definition; } public function getValueFor(string | SortColumn $column): string { if (is_string($column)) { return array_key_exists($column, $this->definition) ? $this->definition[$column] : throw new \InvalidArgumentException("No matching column for {$column}"); } if (! ($column instanceof EmployeeSortColumn)) { throw new \InvalidArgumentException( 'Expected ' . EmployeeSortColumn::class . ' given ' . get_class($column) ); } return $this->mapToArcadiaColumn($column); } public function toDto(array $data): Employee { $columnsMapper = $this->getPropertiesMap(); /** @var array */ $mapped = []; foreach ($columnsMapper as $modelName => $columnName) { // FIXME: Ceci devrait être ok au lieu de cela l'API ne respecte pas le contrat du select quand un champ est null. // if (! array_key_exists($columnName, $data)) { // throw new UnexpectedErrorException("Column '{$columnName}' not found in data " . json_encode($data)); // } // FIXME: Supprimer ceci quand le bug d'api aura été corrigé, et decommenter le code au dessus. if (! array_key_exists($columnName, $data)) { // NOTE: On ne devrais pas avoir a faire cela. $mapped[$modelName] = null; continue; } $mapped[$modelName] = $data[$columnName]; if (is_string($mapped[$modelName])) { $mapped[$modelName] = IncoApiStringParser::protectiveDataFilter($mapped[$modelName]); } } $employeeId = new ArcadiaEmployeeId($mapped['matricule']); $siteeId = new SiteId($mapped['site']); $serviceId = new ServiceId($mapped['service']); $establishmentCode = new EstablishmentCode($mapped['establishment']); $startDate = $this->toDateTime($mapped['start_date']); if ($startDate === null) { throw new DomainException('Missing start date'); } $createdAt = $this->toDateTime($mapped['start_date']); if ($createdAt === null) { throw new DomainException('Missing created at'); } return new Employee( $employeeId, $mapped['lastname'], $mapped['firstname'], $startDate, $this->toDateTime($mapped['end_date']), $this->toDateTime($mapped['planned_end_date']), $establishmentCode, $siteeId, $serviceId, $createdAt, $this->toDateTime($mapped['updated_at']) ); } protected function toDateTime(?string $datetime): ?\DateTimeInterface { return is_null($datetime) ? null : DateUtils::parseDateTime($datetime); } protected function mapToArcadiaColumn(EmployeeSortColumn $column): string { return match ($column) { EmployeeSortColumn::arcadiaId => $this->definition['matricule'], EmployeeSortColumn::startDate => $this->definition['start_date'], EmployeeSortColumn::endDate => $this->definition['end_date'], EmployeeSortColumn::plannedEndDate => $this->definition['planned_end_date'], EmployeeSortColumn::createdAt => $this->definition['created_at'], EmployeeSortColumn::updatedAt => $this->definition['updated_at'] }; } }