mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-13 13:54:23 +00:00
person: fix altname denormalisation
This commit is contained in:
parent
bcdddcde9b
commit
49da5fe060
@ -12,6 +12,7 @@ declare(strict_types=1);
|
|||||||
namespace Chill\PersonBundle\Entity;
|
namespace Chill\PersonBundle\Entity;
|
||||||
|
|
||||||
use Doctrine\ORM\Mapping as ORM;
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
|
use Symfony\Component\Serializer\Annotation\Groups;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PersonAltName.
|
* PersonAltName.
|
||||||
@ -34,6 +35,7 @@ class PersonAltName
|
|||||||
* @var string
|
* @var string
|
||||||
*
|
*
|
||||||
* @ORM\Column(name="key", type="string", length=255)
|
* @ORM\Column(name="key", type="string", length=255)
|
||||||
|
* @Groups({"write"})
|
||||||
*/
|
*/
|
||||||
private $key;
|
private $key;
|
||||||
|
|
||||||
@ -41,6 +43,7 @@ class PersonAltName
|
|||||||
* @var string
|
* @var string
|
||||||
*
|
*
|
||||||
* @ORM\Column(name="label", type="text")
|
* @ORM\Column(name="label", type="text")
|
||||||
|
* @Groups({"write"})
|
||||||
*/
|
*/
|
||||||
private $label;
|
private $label;
|
||||||
|
|
||||||
|
@ -138,10 +138,14 @@ class PersonJsonNormalizer implements
|
|||||||
|
|
||||||
case 'altNames':
|
case 'altNames':
|
||||||
foreach($data[$item] as $altName){
|
foreach($data[$item] as $altName){
|
||||||
$object = $this->denormalizer->denormalize($altName, PersonAltName::class, $format, $context);
|
$oldAltName = $person->getAltNames()->filter(function (PersonAltName $n) use ($altName) { return $n->getKey() === $altName['key']; })->first();
|
||||||
dump($object); //TODO not working
|
if (false === $oldAltName) {
|
||||||
if ($object instanceof PersonAltName) {
|
$newAltName = new PersonAltName();
|
||||||
$person->addAltName($object);
|
$newAltName->setKey($altName['key']);
|
||||||
|
$newAltName->setLabel($altName['label']);
|
||||||
|
$person->addAltName($newAltName);
|
||||||
|
} else {
|
||||||
|
$oldAltName->setLabel($altName['label']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user