src/Export/Csv/SpecificField/SpecificFieldDateCsvExporter.php line 36

Open in your IDE?
  1. <?php
  2. namespace App\Export\Csv\SpecificField;
  3. use ApiPlatform\Core\DataProvider\CollectionDataProviderInterface;
  4. use ApiPlatform\Core\Exception\ResourceClassNotSupportedException;
  5. use App\Export\Builder\ExporterInterface;
  6. use App\Export\SpecificField\SpecificFieldExporter;
  7. use App\Model\Field\Field;
  8. use App\Model\FieldType\FieldType;
  9. use App\Model\SpecificField\SpecificField;
  10. use App\V4\Security\AuthenticationManager;
  11. use DateTime;
  12. use Exception;
  13. class SpecificFieldDateCsvExporter extends SpecificFieldExporter
  14. {
  15.     public function __construct(CollectionDataProviderInterface $collectionDataProviderAuthenticationManager $authManager)
  16.     {
  17.         parent::__construct($collectionDataProvider$authManager);
  18.     }
  19.     /**
  20.      * @return int
  21.      */
  22.     public static function getDefaultPriority(): int
  23.     {
  24.         return 2000;
  25.     }
  26.     /**
  27.      * {@inheritdoc}
  28.      *
  29.      * @throws ResourceClassNotSupportedException
  30.      */
  31.     public function supports($entitystring $fieldNamestring $exportType): bool
  32.     {
  33.         $fieldObj $this->getFieldBySfId($fieldName);
  34.         return parent::supports($entity$fieldName$exportType)
  35.             && $fieldObj instanceof Field
  36.             && FieldType::FIELD_TYPE_DATE === $fieldObj->getFieldType()->getType()
  37.             && ExporterInterface::EXPORT_TYPE_CSV === $exportType
  38.         ;
  39.     }
  40.     /**
  41.      * {@inheritdoc}
  42.      *
  43.      * @throws Exception
  44.      */
  45.     public function convert($entitystring $fieldName): ?string
  46.     {
  47.         $sfId str_replace(['sf_''specificFields_''sf.''specificFields.'], ''$fieldName);
  48.         /** @var SpecificField $specificField */
  49.         $specificField $entity->getSpecificFieldByFieldId($sfId);
  50.         return null !== $specificField->getValue() ? (new DateTime($specificField->getValue()))->format('d/m/Y') : null;
  51.     }
  52. }