mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-23 08:03:49 +00:00
FEATURE [datamapper][regroupment] moved datamapper to seperate class. Still not working
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Form\DataMapper;
|
||||
|
||||
use Chill\MainBundle\Entity\Regroupment;
|
||||
use Symfony\Component\Form\DataMapperInterface;
|
||||
|
||||
class RegroupmentDataMapper implements DataMapperInterface
|
||||
{
|
||||
private $regroupment;
|
||||
|
||||
public function __construct(?Regroupment $regroupment = null)
|
||||
{
|
||||
$this->regroupment = $regroupment;
|
||||
}
|
||||
|
||||
public function mapDataToForms($data, $forms)
|
||||
{
|
||||
$forms = iterator_to_array($forms);
|
||||
|
||||
if ($this->regroupment instanceof Regroupment) {
|
||||
$forms['regroupment']->setData($this->regroupment->getCenters());
|
||||
|
||||
dump($forms['regroupment']);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (null === $data) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($data instanceof Regroupment) {
|
||||
$forms['regroupment']->setData($data);
|
||||
}
|
||||
}
|
||||
|
||||
public function mapFormsToData($forms, &$data)
|
||||
{
|
||||
$forms = iterator_to_array($forms);
|
||||
|
||||
if (isset($forms['regroupment'])) {
|
||||
if ($this->regroupment instanceof Regroupment) {
|
||||
$data = $this->regroupment;
|
||||
} else {
|
||||
$data = [];
|
||||
|
||||
foreach ($forms['regroupment']->getData() as $key => $regroupment)
|
||||
{
|
||||
dump($regroupment->getCenters());
|
||||
$data[$key] = $regroupment->getCenters();
|
||||
dump($data);
|
||||
}
|
||||
// $data = $forms['regroupment']->getData();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user