Last active
August 29, 2015 13:56
-
-
Save dionisos2/9276634 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Ukratio\TrouveToutBundle\Form\EventListener; | |
use Symfony\Component\Form\Exception\UnexpectedTypeException; | |
use Symfony\Component\Form\FormEvent; | |
use Symfony\Component\Form\FormFactoryInterface; | |
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | |
use Symfony\Component\Form\FormEvents; | |
use Symfony\Component\Validator\ConstraintValidatorFactory; | |
use Symfony\Component\Validator\Mapping\ClassMetadata; | |
use Symfony\Component\Validator\Constraints\MinLengthValidator; | |
use Ukratio\ToolBundle\Service\Enum; | |
use Ukratio\ToolBundle\Form\Type\EnumType; | |
use Ukratio\TrouveToutBundle\Entity\Caract; | |
use Ukratio\TrouveToutBundle\Entity\Element; | |
use Ukratio\TrouveToutBundle\Entity\CaractRepository; | |
use Ukratio\TrouveToutBundle\Entity\ConceptRepository; | |
use Ukratio\TrouveToutBundle\Entity\ElementRepository; | |
use Ukratio\TrouveToutBundle\Service\CaractTypeManager; | |
use Ukratio\TrouveToutBundle\Form\Type\ElementType; | |
use Ukratio\TrouveToutBundle\Entity\Type; | |
use Ukratio\TrouveToutBundle\Entity\Prefix; | |
use Ukratio\TrouveToutBundle\Service\Tools; | |
use Doctrine\ORM\EntityManager; | |
class AddValueSubscriber implements EventSubscriberInterface | |
{ | |
protected $factory; | |
protected $elementRepo; | |
protected $caractTypeManager; | |
protected $rootDir; | |
public function __construct(ElementRepository $elementRepo, CaractTypeManager $caractTypeManager, FormFactoryInterface $factory, $rootDir) | |
{ | |
$this->elementRepo = $elementRepo; | |
$this->caractTypeManager = $caractTypeManager; | |
$this->factory = $factory; | |
$this->rootDir = $rootDir; | |
} | |
public static function getSubscribedEvents() | |
{ | |
return array(FormEvents::PRE_SET_DATA => 'preSet', | |
FormEvents::PRE_BIND => 'preBind', | |
/* FormEvents::POST_BIND => 'postSubmit' */); | |
} | |
public function postSubmit(FormEvent $event) | |
{ | |
$caract = $event->getData(); | |
$form = $event->getForm(); | |
if (! $caract instanceof Caract) { | |
return; | |
} | |
$findPicture = false; | |
if (Type::getEnumerator($caract->getType()) === Type::$picture) { | |
$conceptConcepts = $form->getParent()->getParent()->get('moreGeneralConceptConcepts')->getData(); | |
if(count($conceptConcepts) > 0) { | |
// TODO get the current category, and don’t call a mysql request | |
$category = $conceptConcepts[0]->getMoreGeneral(); | |
$picture = $form->get('choosePicture')->getData(); | |
if(($picture != null) and (substr($picture->getMimeType(), 0, 5) == 'image')) { | |
$subDir = Tools::stripAccents($category->getName()); | |
$webPath = $this->rootDir . '/../web/img/'; | |
$picturePath = 'picture/' . $subDir . '/'; | |
$pictureName = Tools::stripAccents($picture->getClientOriginalName()); | |
$picture->move($webPath . $picturePath, $pictureName); | |
$pathElement = array($pictureName, $subDir, 'picture'); | |
$trueElement = $this->elementRepo->findByPath($pathElement, true); | |
if ($trueElement !== null) { | |
$caract->setValue($trueElement); | |
} else {//creation | |
$trueElement = $this->createElementByPath($pathElement); | |
$caract->setValue($trueElement); | |
} | |
$findPicture = true; | |
} | |
} | |
if(!$findPicture) { | |
$caract->setValue(null); | |
} | |
$event->setData($caract); | |
} | |
} | |
public function preBind(FormEvent $event) | |
{ | |
$data = $event->getData(); | |
$form = $event->getForm(); | |
if (isset($data['type'] )) { | |
echo "1"; | |
$form->add($this->factory->createNamed('value', 'TrouveTout_Element', null, array('typeOfValue' => $data['type'], 'auto_initialize' => false))); | |
echo "2"; | |
if (Type::getEnumerator($data['type']) === Type::$number) { | |
$form->add($this->factory->createNamed('imprecision', 'number', null, array('label' => 'caract.imprecision', 'auto_initialize' => false))); | |
$form->add($this->factory->createNamed('prefix', new EnumType('Ukratio\TrouveToutBundle\Entity\Prefix'), null, array('label' => 'caract.prefix', 'auto_initialize' => false))); | |
$form->add($this->factory->createNamed('unit', 'text', null, array('label' => 'caract.unit', 'auto_initialize' => false, 'required' => false))); | |
} | |
if (Type::getEnumerator($data['type']) === Type::$picture) { | |
$form->add($this->factory->createNamed('choosePicture', 'file', null, array('label' => 'caract.choose_picture', | |
'required' => false, | |
'mapped' => false, | |
'auto_initialize' => false))); | |
} | |
} | |
} | |
public function preSet(FormEvent $event) | |
{ | |
$data = $event->getData(); | |
$form = $event->getForm(); | |
if( $data == null) { | |
return; | |
} | |
if (! $data instanceof Caract) { | |
throw new UnexpectedTypeException($data, 'Caract'); | |
} | |
$valueType = $data->getType(); | |
$form->add($this->factory->createNamed('value', 'TrouveTout_Element', null, array('typeOfValue' => $valueType, 'auto_initialize' => false))); | |
if (Type::getEnumerator($valueType) === Type::$number) { | |
$form->add($this->factory->createNamed('imprecision', 'number', null, array('label' => 'caract.imprecision', 'auto_initialize' => false))); | |
$form->add($this->factory->createNamed('prefix', new EnumType('Ukratio\TrouveToutBundle\Entity\Prefix'), null, array('label' => 'caract.prefix', 'auto_initialize' => false))); | |
$form->add($this->factory->createNamed('unit', 'text', null, array('label' => 'caract.unit', 'auto_initialize' => false, 'required' => false))); | |
} | |
if (Type::getEnumerator($data->getType()) === Type::$picture) { | |
$form->add($this->factory->createNamed('choosePicture', 'file', null, array('label' => 'caract.choose_picture', | |
'required' => false, | |
'auto_initialize' => false, | |
'mapped' => false))); | |
} | |
} | |
public function createElementByPath($pathElement) | |
{ | |
$value = $pathElement[0]; | |
$pathElement = array_slice($pathElement, 1); | |
$newElement = new Element($value); | |
if (count($pathElement) != 0) { | |
$element = $this->elementRepo->findByPath($pathElement, true); | |
if ($element === null) { | |
$element = $this->createElementByPath($pathElement); | |
} | |
$newElement->setMoreGeneral($element); | |
} | |
return $newElement; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Ukratio\TrouveToutBundle\Form\Type; | |
use Symfony\Component\Form\AbstractType; | |
use Symfony\Component\Form\FormBuilderInterface; | |
use Symfony\Component\OptionsResolver\OptionsResolverInterface; | |
use Symfony\Component\Form\FormInterface; | |
use Symfony\Component\Form\FormView; | |
use Doctrine\ORM\EntityManager; | |
use Ukratio\ToolBundle\Service\Enum; | |
use Ukratio\ToolBundle\Service\DataChecking; | |
use Ukratio\ToolBundle\Form\Type\EnumType; | |
use Ukratio\TrouveToutBundle\Entity\Discriminator; | |
use Ukratio\TrouveToutBundle\Entity\ConceptRepository; | |
use Ukratio\TrouveToutBundle\Entity\CaractRepository; | |
use Ukratio\TrouveToutBundle\Entity\ElementRepository; | |
use Ukratio\TrouveToutBundle\Service\CaractTypeManager; | |
use Ukratio\TrouveToutBundle\Form\EventListener\AddValueSubscriber; | |
use Ukratio\TrouveToutBundle\Form\EventListener\SpecifyCaractSubscriber; | |
class CaractType extends AbstractType | |
{ | |
protected $conceptRepo; | |
protected $caractRepo; | |
protected $elementRepo; | |
protected $dataChecking; | |
protected $caractTypeManager; | |
public function __construct(ConceptRepository $conceptRepo, CaractRepository $caractRepo, ElementRepository $elementRepo, CaractTypeManager $caractTypeManager, DataChecking $dataChecking) | |
{ | |
$this->dataChecking = $dataChecking; | |
$this->conceptRepo = $conceptRepo; | |
$this->caractRepo = $caractRepo; | |
$this->elementRepo = $elementRepo; | |
$this->caractTypeManager = $caractTypeManager; | |
} | |
public function buildView(FormView $view, FormInterface $form, array $options) | |
{ | |
$this->caractTypeManager->buildView($view, $form, $options); | |
} | |
public function buildForm(FormBuilderInterface $builder, array $options) | |
{ | |
$this->caractTypeManager->buildCaractForm($builder, $options); | |
} | |
public function setDefaultOptions(OptionsResolverInterface $resolver) | |
{ | |
$resolver->setDefaults(array( | |
'data_class' => 'Ukratio\TrouveToutBundle\Entity\Caract', | |
'display_type' => 'show', | |
'parentType' => Discriminator::$Set, | |
)) | |
->setRequired(array('display_type')); | |
} | |
public function getName() | |
{ | |
return 'TrouveTout_Caract'; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Ukratio\TrouveToutBundle\Service; | |
use Ukratio\TrouveToutBundle\Entity\Discriminator; | |
use Ukratio\TrouveToutBundle\Entity\Type; | |
use Ukratio\TrouveToutBundle\Entity\Element; | |
use Ukratio\TrouveToutBundle\Entity\ElementRepository; | |
use Ukratio\TrouveToutBundle\Entity\Concept; | |
use Ukratio\TrouveToutBundle\Entity\ConceptRepository; | |
use Ukratio\TrouveToutBundle\Constant; | |
use Ukratio\TrouveToutBundle\Form\EventListener\AddValueSubscriber; | |
use Ukratio\TrouveToutBundle\Form\EventListener\SpecifyCaractSubscriber; | |
use Ukratio\ToolBundle\Service\DataChecking; | |
use Ukratio\ToolBundle\Form\Type\EnumType; | |
use Symfony\Component\Form\FormInterface; | |
use Symfony\Component\Form\FormView; | |
use Symfony\Component\Form\FormFactoryInterface; | |
use Symfony\Component\Form\FormBuilderInterface; | |
class CaractTypeManager | |
{ | |
private $conceptRepo; | |
private $elementRepo; | |
private $factory; | |
private $elementManager; | |
private $dataChecking; | |
private $rootDir; | |
public function __construct(FormFactoryInterface $factory, ConceptRepository $conceptRepo, ElementRepository $elementRepo, ElementManager $elementManager, DataChecking $dataChecking, $rootDir) | |
{ | |
$this->conceptRepo = $conceptRepo; | |
$this->factory = $factory; | |
$this->elementManager = $elementManager; | |
$this->elementRepo = $elementRepo; | |
$this->dataChecking = $dataChecking; | |
$this->rootDir = $rootDir; | |
} | |
public function buildView(FormView $view, FormInterface $form, array $options) | |
{ | |
$caract = $form->getData(); | |
if (($caract !== null) and ($caract->getValue() !== null)) { | |
if ($caract->getType() == 'picture') { | |
$image = implode('/', array_reverse($caract->getValue()->getPath())); | |
$view->vars['image'] = $image; | |
} | |
if ($caract->getType() == 'object') { | |
$objectNames = $caract->getValue()->getPath(); | |
$view->vars['objects'] = array(); | |
foreach ($objectNames as $objectName) { | |
if ($this->dataChecking->isNumbers($objectName)) { | |
$object = $this->conceptRepo->findOneById($objectName); | |
} else { | |
$object = $this->conceptRepo->findOneByName($objectName); | |
} | |
if ($object != null) { | |
$objectId = $object->getId(); | |
$view->vars['objects'][] = array('name' => $objectName, | |
'id' => $objectId); | |
} | |
} | |
} | |
} | |
} | |
public function buildCaractForm(FormBuilderInterface $builder, array $options) | |
{ | |
$builder->add('name', 'text', array('label' => 'caract.name')); | |
$attr = array(); | |
if ($options['parentType'] === Discriminator::$Set) { | |
$builder->add('selected', 'checkbox', array('required' => false, | |
'attr' => $attr, | |
'label' => 'caract.selected')); | |
} | |
if ($options['parentType'] === Discriminator::$Category) { | |
$builder->add('selected', 'checkbox', array('required' => false, | |
'attr' => $attr, | |
'label' => 'caract.selected')); | |
$builder->add('byDefault', 'checkbox', array('required' => false, | |
'attr' => $attr, | |
'label' => 'caract.byDefault')); | |
$builder->add('specificity', null, array('required' => false, | |
'read_only' => true, | |
'label' => 'caract.specificity')); | |
} | |
if ($options['display_type'] == 'show') { | |
$builder->add('type', 'text', array('disabled' => true, 'label' => 'caract.type')); | |
} | |
if ($options['display_type'] == 'edit') { | |
$builder->add('type', new EnumType('Ukratio\TrouveToutBundle\Entity\Type'), array('label' => 'caract.type')); | |
} | |
$builder->addEventSubscriber(new AddValueSubscriber($this->elementRepo, $this, $builder->getFormFactory(), $this->rootDir)); | |
$builder->addEventSubscriber(new SpecifyCaractSubscriber($builder->getFormFactory(), $this->elementRepo)); | |
} | |
public function addPrototypes(FormBuilderInterface $builder) | |
{ | |
$optionsTextChildValue = array('choices' => array(), | |
'label' => 'element.specify', | |
'required' => false); | |
$optionsTextValue = array('choices' => array(), | |
'label' => 'element.modify'); | |
$optionsElement = array('label' => ' ', | |
'read_only' => true, | |
'mapped' => false, | |
); | |
$optionsFor = array(); | |
$optionsFor['value'] = array(); | |
$optionsFor['value']['name'] = $optionsTextValue; | |
$optionsFor['value']['number'] = array('label' => 'element.modify'); | |
$optionsFor['value']['picture'] = $optionsTextValue; | |
$optionsFor['value']['object'] = $optionsTextValue; | |
$optionsFor['value']['text'] = array('label' => 'element.modify'); | |
$optionsFor['value']['date'] = array('label' => 'element.modify', 'input' => 'timestamp', 'widget' => 'single_text', 'required' => true, 'format' => Constant::DATEFORMAT); | |
$optionsFor['childValue'] = array(); | |
$optionsFor['childValue']['name'] = $optionsTextChildValue; | |
$optionsFor['childValue']['number'] = array('label' => 'element.modify'); | |
$optionsFor['childValue']['picture'] = $optionsTextChildValue; | |
$optionsFor['childValue']['object'] = $optionsTextChildValue; | |
$optionsFor['childValue']['text'] = array('label' => 'element.specify'); | |
$optionsFor['childValue']['date'] = array('label' => 'element.specify', 'input' => 'timestamp', 'widget' => 'single_text', 'required' => true, 'format' => Constant::DATEFORMAT); | |
$prototypeOfChildValue = array(); | |
$prototypeOfValue = array(); | |
$prototypeOfOwnerElement = $builder->create('__name__', 'text', $optionsElement); | |
$prototypeOfImprecision = $builder->create('__name__', 'number', array('label' => 'caract.imprecision')); | |
$prototypeOfPrefix = $builder->create('__name__', new EnumType('Ukratio\TrouveToutBundle\Entity\Prefix'), array('label' => 'caract.prefix')); | |
$prototypeOfUnit = $builder->create('__name__', 'text', array('label' => 'caract.unit', 'required' => false)); | |
$prototypeOfChoosePicture = $builder->create('__name__', 'file', array('label' => 'caract.choose_picture', 'required' => false)); | |
foreach(Type::getListOfElement() as $element) | |
{ | |
$prototypeOfValue[$element] = $builder->create('__name__', $this->getFormTypeFor(Type::getEnumerator($element)), $optionsFor['value'][$element]); | |
$prototypeOfChildValue[$element] = $builder->create('__name__', $this->getFormTypeFor(Type::getEnumerator($element)), $optionsFor['childValue'][$element]); | |
$elementUpper = $element; | |
$elementUpper[0] = strtoupper($elementUpper[0]); | |
$builder->setAttribute("prototypeOfChildValue$elementUpper", $prototypeOfChildValue["$element"]->getForm()); | |
$builder->setAttribute("prototypeOfValue$elementUpper", $prototypeOfValue["$element"]->getForm()); | |
} | |
$builder->setAttribute('prototypeOfOwnerElement', $prototypeOfOwnerElement->getForm()); | |
$builder->setAttribute('prototypeOfImprecision', $prototypeOfImprecision->getForm()); | |
$builder->setAttribute('prototypeOfPrefix', $prototypeOfPrefix->getForm()); | |
$builder->setAttribute('prototypeOfUnit', $prototypeOfUnit->getForm()); | |
$builder->setAttribute('prototypeOfChoosePicture', $prototypeOfChoosePicture->getForm()); | |
} | |
public function buildConceptView(FormView $view, FormInterface $form, array $options) | |
{ | |
//TODO maybe some refactorization to do | |
foreach(Type::getListOfElement() as $element) | |
{ | |
$element[0] = strtoupper($element[0]); | |
$view->vars["prototypeOfChildValue$element"] = $form->getConfig()->getAttribute("prototypeOfChildValue$element")->createView($view); | |
$view->vars["prototypeOfValue$element"] = $form->getConfig()->getAttribute("prototypeOfValue$element")->createView($view); | |
} | |
$view->vars['prototypeOfOwnerElement'] = $form->getConfig()->getAttribute('prototypeOfOwnerElement')->createView($view); | |
$view->vars['prototypeOfImprecision'] = $form->getConfig()->getAttribute('prototypeOfImprecision')->createView($view); | |
$view->vars['prototypeOfPrefix'] = $form->getConfig()->getAttribute('prototypeOfPrefix')->createView($view); | |
$view->vars['prototypeOfUnit'] = $form->getConfig()->getAttribute('prototypeOfUnit')->createView($view); | |
$view->vars['prototypeOfChoosePicture'] = $form->getConfig()->getAttribute('prototypeOfChoosePicture')->createView($view); | |
} | |
public function getFormTypeFor($type) | |
{ | |
switch ($type) { | |
case Type::$name: | |
return 'Tool_ChoiceOrText'; | |
case Type::$number: | |
return 'number'; | |
case Type::$picture: | |
return 'choice'; | |
case Type::$object: | |
return 'Tool_ChoiceOrText'; | |
case Type::$text: | |
return 'textarea'; | |
case Type::$date: | |
return 'datetime'; | |
default: | |
throw new \Exception('impossible case with type = ' . $type->getName()); | |
} | |
} | |
public function getChoicesFor(Type $type, $path, $isChildElement) | |
{ | |
if (in_array($type, array(Type::$name))) { | |
if ($path == null) { //TODO should be in the repo | |
$elementChoices = $this->elementRepo->findHeads(); | |
} else { | |
$element = $this->elementRepo->findByPath($path, true); | |
if($element !== null) { | |
$elementChoices = $this->elementRepo->findMoreSpecifics($element); | |
} else { | |
$elementChoices = array(); | |
} | |
} | |
$choices = array_map(function(Element $element) { return (string) $element->getValue();}, $elementChoices); | |
$choices = array_combine($choices, $choices); | |
} | |
switch ($type) { | |
case Type::$name: | |
if ($isChildElement) { | |
$choices = array('other' => 'other') + $choices; | |
} | |
return $choices; | |
case Type::$number: | |
return null; | |
case Type::$picture: | |
$choices = array_map(function (Element $element) {return $element->getValue();}, $this->elementManager->filesIn($path)); | |
$choices = array_combine($choices, $choices); | |
if ($isChildElement) { | |
$choices = array('' => '') + $choices; | |
} | |
return $choices; | |
case Type::$object: | |
$choices1 = array_map(function (Concept $element) {return $element->getName();}, $this->conceptRepo->findNamedSet()); | |
$choices2 = array_map(function (Concept $element) {return $element->getId();}, $this->conceptRepo->findLinkableSet()); | |
$choices1 = array_combine($choices1, $choices1); | |
$choices2 = array_combine($choices2, $choices2); | |
$choices = $choices1 + $choices2; | |
if ($isChildElement) { | |
$choices = array('other' => 'other') + $choices; | |
} | |
return $choices; | |
case Type::$text: | |
return null; | |
case Type::$date: | |
return null; | |
default: | |
throw new \Exception('impossible case with type = ' . $this->getType()); | |
} | |
} | |
public function createElementForm($name, Type $type, $path, $label = 'element.modify', $mapped = true) | |
{ | |
$options = array('label' => $label, 'mapped' => $mapped, 'required' => $mapped, 'auto_initialize' => false); | |
//TODO separate function for getting options | |
if (($label == 'element.specify') and (in_array($type, array(Type::$date, Type::$number, Type::$text)))) { | |
return null; | |
} | |
if (is_array($path)) { | |
if ($label == 'element.modify') { | |
$choices = $this->getChoicesFor($type, $path, false); | |
} else { | |
$choices = $this->getChoicesFor($type, $path, true); | |
} | |
} else { | |
if (in_array($type, array(Type::$text,Type::$number, Type::$date))) { | |
$choices = null; | |
} else { | |
$choices = array($path => $path); | |
} | |
} | |
if ($choices !== null) { | |
if(isset($choices['choices1']) and is_array($choices['choices1'])) { | |
$options = $options + array('textType' => 'choice', | |
'choices' => $choices['choices1'], | |
'options' => array('choices' => $choices['choices2'])); | |
} else { | |
$options = $options + array('choices' => $choices); | |
} | |
} | |
if ($type === Type::$date) { | |
if ($label == 'element.modify') { | |
$options = $options + array('input' => 'timestamp', 'widget' => 'single_text', 'required' => false, 'format' => Constant::DATEFORMAT); | |
} else { | |
$options = $options + array('input' => 'timestamp', 'widget' => 'single_text', 'format' => Constant::DATEFORMAT); | |
} | |
} | |
$builder = $this->factory->createNamedBuilder($name, $this->getFormTypeFor($type), null, $options); | |
return $builder->getForm(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Ukratio\TrouveToutBundle\Form\EventListener; | |
use Symfony\Component\Form\FormFactoryInterface; | |
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | |
use Symfony\Component\Form\FormEvents; | |
use Symfony\Component\Form\FormEvent; | |
use Doctrine\ORM\EntityManager; | |
use Ukratio\TrouveToutBundle\Entity\Caract; | |
use Ukratio\TrouveToutBundle\Entity\Element; | |
use Ukratio\TrouveToutBundle\Entity\ElementRepository; | |
use Ukratio\TrouveToutBundle\Entity\Type; | |
use Ukratio\ToolBundle\Debug\Message; | |
class SpecifyCaractSubscriber implements EventSubscriberInterface | |
{ | |
private $factory; | |
private $elementRepo; | |
public function __construct(FormFactoryInterface $factory, ElementRepository $elementRepo) | |
{ | |
$this->factory = $factory; | |
$this->elementRepo = $elementRepo; | |
} | |
public static function getSubscribedEvents() | |
{ | |
return array(FormEvents::POST_BIND => 'postBind'); | |
} | |
public function postBind(FormEvent $event) | |
{ | |
$caract = $event->getData(); | |
$form = $event->getForm(); | |
if (! $caract instanceof Caract) { | |
return; | |
} | |
if ((!$form->has('value')) || ($form->get('value') === null)) { | |
return; | |
} | |
//let AddValueSubscriber do the work if we have a picture | |
if (Type::getEnumerator($caract->getType()) === Type::$picture) { | |
$picture = $form->get('choosePicture')->getData(); | |
if ($picture != null) { | |
return; | |
} | |
} | |
$element = $form->get('value')->getData(); | |
$ownerElements = array(); | |
$index = 0; | |
while ($form->get('value')->has('element_'.$index)) { | |
$ownerElements['element_'.$index] = $form->get('value')->get('element_'.$index)->getData(); | |
$index++; | |
} | |
$ownerElements = array_filter($ownerElements, function ($elementValue) {return $elementValue !== null;}); | |
$pathElement = array_values($ownerElements); | |
if ($element->getValue() != null) { | |
$pathElement[] = $element->getValue(); | |
} else { | |
$caract->setValue(null); | |
return; | |
} | |
$pathElement = array_reverse($pathElement); | |
$trueElement = $this->elementRepo->findByPath($pathElement, true); | |
if ($trueElement !== null) { | |
$caract->setValue($trueElement); | |
} else {//creation | |
if ($caract->getType() == Type::$date->getName()) { | |
$pathElement = array($pathElement[0], 'date'); | |
} | |
$trueElement = $this->createElementByPath($pathElement); | |
$caract->setValue($trueElement); | |
} | |
} | |
public function createElementByPath($pathElement) | |
{ | |
$value = $pathElement[0]; | |
$pathElement = array_slice($pathElement, 1); | |
$newElement = new Element($value); | |
if (count($pathElement) != 0) { | |
$element = $this->elementRepo->findByPath($pathElement, true); | |
if ($element === null) { | |
$element = $this->createElementByPath($pathElement); | |
} | |
$newElement->setMoreGeneral($element); | |
} | |
return $newElement; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Stack Trace | |
in /home/dionisos/projet/programmation/http/public/TrouveTout/vendor/symfony/symfony/src/Symfony/Component/Form/Form.php at line 324 - | |
if ($this->lockSetData) { | |
var_dump($modelData); | |
var_dump(get_class($modelData)); | |
throw new RuntimeException('A cycle was detected. Listeners to the PRE_SET_DATA event must not call setData(). You should call setData() on the FormEvent object instead.'); | |
} | |
$this->lockSetData = true; | |
at Form ->setData (null) | |
in /home/dionisos/projet/programmation/http/public/TrouveTout/vendor/symfony/symfony/src/Symfony/Component/Form/Form.php at line 415 + | |
at Form ->getData () | |
in /home/dionisos/projet/programmation/http/public/TrouveTout/vendor/symfony/symfony/src/Symfony/Component/Form/Extension/Validator/Constraints/FormValidator.php at line 142 + | |
at FormValidator ::allowDataWalking (object(Form)) | |
in /home/dionisos/projet/programmation/http/public/TrouveTout/vendor/symfony/symfony/src/Symfony/Component/Form/Extension/Validator/Constraints/FormValidator.php at line 57 + | |
at FormValidator ->validate (object(Form), object(Form)) | |
in /home/dionisos/projet/programmation/http/public/TrouveTout/vendor/symfony/symfony/src/Symfony/Component/Validator/ExecutionContext.php at line 276 + | |
at ExecutionContext ->executeConstraintValidators (object(Form), array(object(Form))) | |
in /home/dionisos/projet/programmation/http/public/TrouveTout/vendor/symfony/symfony/src/Symfony/Component/Validator/ExecutionContext.php at line 241 + | |
at ExecutionContext ->validateValue (object(Form), array(object(Form))) | |
in /home/dionisos/projet/programmation/http/public/TrouveTout/vendor/symfony/symfony/src/Symfony/Component/Validator/ValidationVisitor.php at line 110 + | |
at ValidationVisitor ->visit (object(ClassMetadata), object(Form), 'Default', 'children[caracts].children[0].children[value].children[value]') | |
in /home/dionisos/projet/programmation/http/public/TrouveTout/vendor/symfony/symfony/src/Symfony/Component/Validator/Mapping/ClassMetadata.php at line 107 + | |
at ClassMetadata ->accept (object(ValidationVisitor), object(Form), 'Default', 'children[caracts].children[0].children[value].children[value]') | |
in /home/dionisos/projet/programmation/http/public/TrouveTout/vendor/symfony/symfony/src/Symfony/Component/Validator/ValidationVisitor.php at line 162 + | |
at ValidationVisitor ->validate (object(Form), 'Default', 'children[caracts].children[0].children[value].children[value]', false, false) | |
in /home/dionisos/projet/programmation/http/public/TrouveTout/vendor/symfony/symfony/src/Symfony/Component/Validator/ValidationVisitor.php at line 150 + | |
at ValidationVisitor ->validate (object(OrderedHashMap), 'Default', 'children[caracts].children[0].children[value].children', true, false) | |
in /home/dionisos/projet/programmation/http/public/TrouveTout/vendor/symfony/symfony/src/Symfony/Component/Validator/Mapping/MemberMetadata.php at line 50 + | |
at MemberMetadata ->accept (object(ValidationVisitor), object(OrderedHashMap), 'Default', 'children[caracts].children[0].children[value].children', null) | |
in /home/dionisos/projet/programmation/http/public/TrouveTout/vendor/symfony/symfony/src/Symfony/Component/Validator/Mapping/ClassMetadata.php at line 114 + | |
at ClassMetadata ->accept (object(ValidationVisitor), object(Form), 'Default', 'children[caracts].children[0].children[value]') | |
in /home/dionisos/projet/programmation/http/public/TrouveTout/vendor/symfony/symfony/src/Symfony/Component/Validator/ValidationVisitor.php at line 162 + | |
at ValidationVisitor ->validate (object(Form), 'Default', 'children[caracts].children[0].children[value]', false, false) | |
in /home/dionisos/projet/programmation/http/public/TrouveTout/vendor/symfony/symfony/src/Symfony/Component/Validator/ValidationVisitor.php at line 150 + | |
at ValidationVisitor ->validate (object(OrderedHashMap), 'Default', 'children[caracts].children[0].children', true, false) | |
in /home/dionisos/projet/programmation/http/public/TrouveTout/vendor/symfony/symfony/src/Symfony/Component/Validator/Mapping/MemberMetadata.php at line 50 + | |
at MemberMetadata ->accept (object(ValidationVisitor), object(OrderedHashMap), 'Default', 'children[caracts].children[0].children', null) | |
in /home/dionisos/projet/programmation/http/public/TrouveTout/vendor/symfony/symfony/src/Symfony/Component/Validator/Mapping/ClassMetadata.php at line 114 + | |
at ClassMetadata ->accept (object(ValidationVisitor), object(Form), 'Default', 'children[caracts].children[0]') | |
in /home/dionisos/projet/programmation/http/public/TrouveTout/vendor/symfony/symfony/src/Symfony/Component/Validator/ValidationVisitor.php at line 162 + | |
at ValidationVisitor ->validate (object(Form), 'Default', 'children[caracts].children[0]', false, false) | |
in /home/dionisos/projet/programmation/http/public/TrouveTout/vendor/symfony/symfony/src/Symfony/Component/Validator/ValidationVisitor.php at line 150 + | |
at ValidationVisitor ->validate (object(OrderedHashMap), 'Default', 'children[caracts].children', true, false) | |
in /home/dionisos/projet/programmation/http/public/TrouveTout/vendor/symfony/symfony/src/Symfony/Component/Validator/Mapping/MemberMetadata.php at line 50 + | |
at MemberMetadata ->accept (object(ValidationVisitor), object(OrderedHashMap), 'Default', 'children[caracts].children', null) | |
in /home/dionisos/projet/programmation/http/public/TrouveTout/vendor/symfony/symfony/src/Symfony/Component/Validator/Mapping/ClassMetadata.php at line 114 + | |
at ClassMetadata ->accept (object(ValidationVisitor), object(Form), 'Default', 'children[caracts]') | |
in /home/dionisos/projet/programmation/http/public/TrouveTout/vendor/symfony/symfony/src/Symfony/Component/Validator/ValidationVisitor.php at line 162 + | |
at ValidationVisitor ->validate (object(Form), 'Default', 'children[caracts]', false, false) | |
in /home/dionisos/projet/programmation/http/public/TrouveTout/vendor/symfony/symfony/src/Symfony/Component/Validator/ValidationVisitor.php at line 150 + | |
at ValidationVisitor ->validate (object(OrderedHashMap), 'Default', 'children', true, false) | |
in /home/dionisos/projet/programmation/http/public/TrouveTout/vendor/symfony/symfony/src/Symfony/Component/Validator/Mapping/MemberMetadata.php at line 50 + | |
at MemberMetadata ->accept (object(ValidationVisitor), object(OrderedHashMap), 'Default', 'children', null) | |
in /home/dionisos/projet/programmation/http/public/TrouveTout/vendor/symfony/symfony/src/Symfony/Component/Validator/Mapping/ClassMetadata.php at line 114 + | |
at ClassMetadata ->accept (object(ValidationVisitor), object(Form), 'Default', '') | |
in /home/dionisos/projet/programmation/http/public/TrouveTout/vendor/symfony/symfony/src/Symfony/Component/Validator/ValidationVisitor.php at line 162 + | |
at ValidationVisitor ->validate (object(Form), 'Default', '', false, false) | |
in /home/dionisos/projet/programmation/http/public/TrouveTout/vendor/symfony/symfony/src/Symfony/Component/Validator/Validator.php at line 90 + | |
at Validator ->validate (object(Form)) | |
in /home/dionisos/projet/programmation/http/public/TrouveTout/vendor/symfony/symfony/src/Symfony/Component/Form/Extension/Validator/EventListener/ValidationListener.php at line 55 + | |
at ValidationListener ->validateForm (object(FormEvent), 'form.post_bind', object(EventDispatcher)) | |
at call_user_func (array(object(ValidationListener), 'validateForm'), object(FormEvent), 'form.post_bind', object(EventDispatcher)) | |
in kernel.root_dir/cache/dev/classes.php at line 1734 + | |
at EventDispatcher ->doDispatch (array(array(object(ValidationListener), 'validateForm'), array(object(AddCaractsOfCategories), 'postBind'), array(object(DataCollectorListener), 'postSubmit')), 'form.post_bind', object(FormEvent)) | |
in kernel.root_dir/cache/dev/classes.php at line 1667 + | |
at EventDispatcher ->dispatch ('form.post_bind', object(FormEvent)) | |
in /home/dionisos/projet/programmation/http/public/TrouveTout/vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/ImmutableEventDispatcher.php at line 42 + | |
at ImmutableEventDispatcher ->dispatch ('form.post_bind', object(FormEvent)) | |
in /home/dionisos/projet/programmation/http/public/TrouveTout/vendor/symfony/symfony/src/Symfony/Component/Form/Form.php at line 659 + | |
at Form ->submit (object(Request)) | |
in /home/dionisos/projet/programmation/http/public/TrouveTout/vendor/symfony/symfony/src/Symfony/Component/Form/Form.php at line 673 + | |
at Form ->bind (object(Request)) | |
in /home/dionisos/projet/programmation/http/public/TrouveTout/src/Ukratio/TrouveToutBundle/Controller/ConceptController.php at line 146 + | |
at ConceptController ->updateAction (object(Request), object(Concept)) | |
at ReflectionMethod ->invokeArgs (object(ConceptController), array(object(Request), object(Concept))) | |
in /home/dionisos/projet/programmation/http/public/TrouveTout/vendor/jms/cg/src/CG/Proxy/MethodInvocation.php at line 63 + | |
at MethodInvocation ->proceed () | |
in /home/dionisos/projet/programmation/http/public/TrouveTout/vendor/jms/security-extra-bundle/JMS/SecurityExtraBundle/Security/Authorization/Interception/MethodSecurityInterceptor.php at line 120 + | |
at MethodSecurityInterceptor ->intercept (object(MethodInvocation)) | |
in /home/dionisos/projet/programmation/http/public/TrouveTout/vendor/jms/cg/src/CG/Proxy/MethodInvocation.php at line 58 + | |
at MethodInvocation ->proceed () | |
in kernel.root_dir/cache/dev/jms_diextra/proxies/Ukratio-TrouveToutBundle-Controller-ConceptController.php at line 21 + | |
at ConceptController ->updateAction (object(Request), object(Concept)) | |
at call_user_func_array (array(object(ConceptController), 'updateAction'), array(object(Request), object(Concept))) | |
in kernel.root_dir/bootstrap.php.cache at line 2911 + | |
at HttpKernel ->handleRaw (object(Request), '1') | |
in kernel.root_dir/bootstrap.php.cache at line 2883 + | |
at HttpKernel ->handle (object(Request), '1', true) | |
in kernel.root_dir/bootstrap.php.cache at line 3022 + | |
at ContainerAwareHttpKernel ->handle (object(Request), '1', true) | |
in kernel.root_dir/bootstrap.php.cache at line 2303 + | |
at Kernel ->handle (object(Request)) | |
in /home/dionisos/projet/programmation/http/public/TrouveTout/web/app_dev.php at line 25 + |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment