1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71:
<?php
namespace FrontBundle\Form\DataTransformer;
use FrontBundle\Utils\IriHelper;
use Symfony\Component\Form\DataTransformerInterface;
class StudentConventionTransformer implements DataTransformerInterface
{
const API_URI_PREFIX = '/api/student_conventions';
public function transform($value)
{
if (null === $value) {
return;
}
if (isset($value['@id'])) {
$value['@id'] = IriHelper::extractId($value['@id']);
}
if (isset($value['dateOfSignature'])) {
$value['dateOfSignature'] = (true === empty($value['dateOfSignature']))
? null
: new \DateTime($value['dateOfSignature'])
;
}
return $value;
}
public function reverseTransform($value)
{
if (null === $value) {
return;
}
if (isset($value['@id']) && false === empty($value['@id'])) {
$value['@id'] = sprintf('%s/%s', self::API_URI_PREFIX, IriHelper::extractId($value['@id']));
}
if (isset($value['dateOfSignature']) && $value['dateOfSignature'] instanceof \DateTime) {
$value['dateOfSignature'] = $value['dateOfSignature']->format('Y-m-d\TH:i:sP');
}
return $value;
}
}