ManyToOnePersist

This commit is contained in:
Marc Ducobu 2014-10-08 17:20:34 +02:00
parent 3cafed3264
commit a0bacda530
2 changed files with 27 additions and 2 deletions

View File

@ -65,7 +65,12 @@ class JsonCustomFieldToArrayTransformer implements DataTransformerInterface {
if(array_key_exists($key, $this->customField)) {
$type = $this->customField[$key]->getType();
if(strpos($type,'ManyToOne') === 0) {
$entityClass = substr($type, 10, -1);
if(strpos($type,'ManyToOnePersist') ===0) {
$entityClass = substr($type, 17, -1);
} else {
$entityClass = substr($type, 10, -1);
}
$customFieldsArrayRet[$key] = $this->om
->getRepository('CLCustomFieldsBundle:' . $entityClass)
->findOneById($value);
@ -104,8 +109,24 @@ class JsonCustomFieldToArrayTransformer implements DataTransformerInterface {
if(array_key_exists($key, $this->customField)) {
$type = $this->customField[$key]->getType();
if(strpos($type,'ManyToOne') === 0) {
// pour le manytoone() faire
// un update du form en js ? : http://symfony.com/fr/doc/current/cookbook/form/form_collections.html
//
//$entityClass = substr($type, 10, -1);
//echo $entityClasss;
if(strpos($type, 'ManyToOnePersist') === 0) {
$this->om->persist($value); // pas bon ici
// LE PERSIST NE SERT QUE LA PREMIERE FOIS
// plutot le mettre dans une var temporaire de adress
// et faire le persist qd fait sur l'obj parent
// regarder : http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/events.html
// ou : http://symfony.com/doc/current/cookbook/doctrine/event_listeners_subscribers.html
// dans yml :
// lifecycleCallbacks:
// prePersist: [ doStuffOnPrePersist, doOtherStuffOnPrePersist ]
$this->om->flush(); // sinon l'id pose pbm
}
$customFieldsArrayRet[$key] = $value->getId();
$traited = true;
}

View File

@ -15,6 +15,7 @@ use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use CL\CustomFieldsBundle\Form\DataTransformer\JsonCustomFieldToArrayTransformer;
use Doctrine\Common\Persistence\ObjectManager;
use CL\CustomFieldsBundle\Form\AdressType;
class CustomFieldType extends AbstractType
{
@ -43,7 +44,10 @@ class CustomFieldType extends AbstractType
'class' => 'CLCustomFieldsBundle:Adress',
'property' => 'data',
));
} else {
} else if ($cf->getType() === 'ManyToOnePersist(Adress)') {
$builder->add($cf->getLabel(), new AdressType());
}
else {
$builder->add($cf->getLabel(), $cf->getType());
}
}