mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-07-01 22:46:13 +00:00
ManyToOnePersist
This commit is contained in:
parent
3cafed3264
commit
a0bacda530
@ -65,7 +65,12 @@ class JsonCustomFieldToArrayTransformer implements DataTransformerInterface {
|
|||||||
if(array_key_exists($key, $this->customField)) {
|
if(array_key_exists($key, $this->customField)) {
|
||||||
$type = $this->customField[$key]->getType();
|
$type = $this->customField[$key]->getType();
|
||||||
if(strpos($type,'ManyToOne') === 0) {
|
if(strpos($type,'ManyToOne') === 0) {
|
||||||
|
if(strpos($type,'ManyToOnePersist') ===0) {
|
||||||
|
$entityClass = substr($type, 17, -1);
|
||||||
|
} else {
|
||||||
$entityClass = substr($type, 10, -1);
|
$entityClass = substr($type, 10, -1);
|
||||||
|
}
|
||||||
|
|
||||||
$customFieldsArrayRet[$key] = $this->om
|
$customFieldsArrayRet[$key] = $this->om
|
||||||
->getRepository('CLCustomFieldsBundle:' . $entityClass)
|
->getRepository('CLCustomFieldsBundle:' . $entityClass)
|
||||||
->findOneById($value);
|
->findOneById($value);
|
||||||
@ -104,8 +109,24 @@ class JsonCustomFieldToArrayTransformer implements DataTransformerInterface {
|
|||||||
if(array_key_exists($key, $this->customField)) {
|
if(array_key_exists($key, $this->customField)) {
|
||||||
$type = $this->customField[$key]->getType();
|
$type = $this->customField[$key]->getType();
|
||||||
if(strpos($type,'ManyToOne') === 0) {
|
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);
|
//$entityClass = substr($type, 10, -1);
|
||||||
//echo $entityClasss;
|
//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();
|
$customFieldsArrayRet[$key] = $value->getId();
|
||||||
$traited = true;
|
$traited = true;
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,7 @@ use Symfony\Component\Form\AbstractType;
|
|||||||
use Symfony\Component\Form\FormBuilderInterface;
|
use Symfony\Component\Form\FormBuilderInterface;
|
||||||
use CL\CustomFieldsBundle\Form\DataTransformer\JsonCustomFieldToArrayTransformer;
|
use CL\CustomFieldsBundle\Form\DataTransformer\JsonCustomFieldToArrayTransformer;
|
||||||
use Doctrine\Common\Persistence\ObjectManager;
|
use Doctrine\Common\Persistence\ObjectManager;
|
||||||
|
use CL\CustomFieldsBundle\Form\AdressType;
|
||||||
|
|
||||||
class CustomFieldType extends AbstractType
|
class CustomFieldType extends AbstractType
|
||||||
{
|
{
|
||||||
@ -43,7 +44,10 @@ class CustomFieldType extends AbstractType
|
|||||||
'class' => 'CLCustomFieldsBundle:Adress',
|
'class' => 'CLCustomFieldsBundle:Adress',
|
||||||
'property' => 'data',
|
'property' => 'data',
|
||||||
));
|
));
|
||||||
} else {
|
} else if ($cf->getType() === 'ManyToOnePersist(Adress)') {
|
||||||
|
$builder->add($cf->getLabel(), new AdressType());
|
||||||
|
}
|
||||||
|
else {
|
||||||
$builder->add($cf->getLabel(), $cf->getType());
|
$builder->add($cf->getLabel(), $cf->getType());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user