mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
OneToMany via controller
This commit is contained in:
parent
f055af8228
commit
f624bce689
@ -7,6 +7,7 @@ use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
|||||||
|
|
||||||
use CL\CustomFieldsBundle\Entity\BlopEntity;
|
use CL\CustomFieldsBundle\Entity\BlopEntity;
|
||||||
use CL\CustomFieldsBundle\Form\BlopEntityType;
|
use CL\CustomFieldsBundle\Form\BlopEntityType;
|
||||||
|
use CL\CustomFieldsBundle\Form\AdressType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* BlopEntity controller.
|
* BlopEntity controller.
|
||||||
@ -15,6 +16,48 @@ use CL\CustomFieldsBundle\Form\BlopEntityType;
|
|||||||
class BlopEntityController extends Controller
|
class BlopEntityController extends Controller
|
||||||
{
|
{
|
||||||
|
|
||||||
|
public function addNewManyToOneAction($id, $key)
|
||||||
|
{
|
||||||
|
$em = $this->getDoctrine()->getManager();
|
||||||
|
|
||||||
|
$customFields = $em->getRepository('CLCustomFieldsBundle:CustomField')
|
||||||
|
->findAll();
|
||||||
|
|
||||||
|
$customFieldsLablels = array_map(
|
||||||
|
function($e) { return $e->getLabel(); },
|
||||||
|
$customFields);
|
||||||
|
|
||||||
|
$customFieldsByLabel = array_combine($customFieldsLablels, $customFields);
|
||||||
|
|
||||||
|
if (array_key_exists($key,$customFieldsByLabel)) {
|
||||||
|
$customFieldConfig = $customFieldsByLabel[$key];
|
||||||
|
if($customFieldConfig->getType() === 'OneToMany(Adress)') {
|
||||||
|
$manyToOneEntity = new AdressType();
|
||||||
|
$form = $this->createCreateForm($manyToOneEntity);
|
||||||
|
$form->handleRequest($request);
|
||||||
|
|
||||||
|
if ($form->isValid()) {
|
||||||
|
$em = $this->getDoctrine()->getManager();
|
||||||
|
$em->persist($manyToOneEntity);
|
||||||
|
$em->flush();
|
||||||
|
|
||||||
|
$blopEntity = $this->om
|
||||||
|
->getRepository('CLCustomFieldsBundle:CustomField')
|
||||||
|
->findOneById($id);
|
||||||
|
|
||||||
|
$blopEntityCustomFieldArray = json_decode($blopEntity->getCustomField());
|
||||||
|
$blopEntityCustomFieldArray[$key][] = $manyToOneEntity->getId();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// PAS MANY TO ONE
|
||||||
|
throw new Exception("Error Processing Request", 1);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// PAS RENSEIGNE COMME CF
|
||||||
|
throw new Exception("Error Processing Request", 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lists all BlopEntity entities.
|
* Lists all BlopEntity entities.
|
||||||
*
|
*
|
||||||
|
@ -35,4 +35,8 @@ blopentity_cfget:
|
|||||||
|
|
||||||
blopentity_cfset:
|
blopentity_cfset:
|
||||||
path: /{id}/cfset/{key}/{value}
|
path: /{id}/cfset/{key}/{value}
|
||||||
defaults: { _controller: "CLCustomFieldsBundle:BlopEntity:cfSet" }
|
defaults: { _controller: "CLCustomFieldsBundle:BlopEntity:cfSet" }
|
||||||
|
|
||||||
|
blopentity_addmany_to_one:
|
||||||
|
path: /{id}/add/custom/field/{key}
|
||||||
|
defaults: {_controller: "CLCustomFieldsBundle:BlopEntity:addNewManyToOne"}
|
Loading…
x
Reference in New Issue
Block a user