fix folder name

This commit is contained in:
2021-03-18 13:37:13 +01:00
parent a2f6773f5a
commit eaa0ad925f
1578 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,121 @@
<?php
/*
* Copyright (C) 2019 Champs Libres Cooperative <info@champs-libres.coop>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Chill\MainBundle\Form\DataMapper;
use Symfony\Component\Form\DataMapperInterface;
use Chill\MainBundle\Entity\Address;
use Chill\MainBundle\Entity\PostalCode;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\Exception\UnexpectedTypeException;
/**
* Add a data mapper to Address.
*
* If the address is incomplete, the data mapper returns null
*/
class AddressDataMapper implements DataMapperInterface
{
/**
*
* @param Address $address
* @param \Iterator $forms
*/
public function mapDataToForms($address, $forms)
{
if (NULL === $address) {
return;
}
if (!$address instanceof Address) {
throw new UnexpectedTypeException($address, Address::class);
}
foreach ($forms as $key => $form) {
/** @var FormInterface $form */
switch ($key) {
case 'streetAddress1':
$form->setData($address->getStreetAddress1());
break;
case 'streetAddress2':
$form->setData($address->getStreetAddress2());
break;
case 'postCode':
$form->setData($address->getPostcode());
break;
case 'validFrom':
$form->setData($address->getValidFrom());
break;
case 'isNoAddress':
$form->setData($address->isNoAddress());
break;
default:
break;
}
}
}
/**
*
* @param \Iterator $forms
* @param Address $address
*/
public function mapFormsToData($forms, &$address)
{
if (!$address instanceof Address) {
$address = new Address();
}
$isNoAddress = false;
foreach ($forms as $key => $form) {
if ($key === 'isNoAddress') {
$isNoAddress = $form->get('isNoAddress')->getData();
}
}
foreach ($forms as $key => $form) {
/** @var FormInterface $form */
switch($key) {
case 'postCode':
if (!$form->getData() instanceof PostalCode && !$isNoAddress) {
$address = null;
return;
}
$address->setPostcode($form->getData());
break;
case 'streetAddress1':
if (empty($form->getData()) && !$isNoAddress) {
$address = null;
return;
}
$address->setStreetAddress1($form->getData());
break;
case 'streetAddress2':
$address->setStreetAddress2($form->getData());
break;
case 'validFrom':
$address->setValidFrom($form->getData());
break;
case 'isNoAddress':
$address->setIsNoAddress($form->getData());
break;
default:
break;
}
}
}
}

View File

@@ -0,0 +1,51 @@
<?php
namespace Chill\MainBundle\Form\DataMapper;
use Chill\MainBundle\Entity\Scope;
use Symfony\Component\Form\DataMapperInterface;
use Symfony\Component\Form\FormInterface;
class ScopePickerDataMapper implements DataMapperInterface
{
/**
* @var \Chill\MainBundle\Entity\Scope
*/
private $scope;
public function __construct(Scope $scope = null)
{
$this->scope = $scope;
}
public function mapDataToForms($data, $forms)
{
$forms = iterator_to_array($forms);
if ($this->scope instanceof Scope) {
$forms['scope']->setData($this->scope);
return;
}
if (null === $data) {
return;
}
if ($data instanceof Scope) {
$forms['scope']->setData($data);
}
}
public function mapFormsToData($forms, &$data)
{
$forms = iterator_to_array($forms);
if (isset($forms['scope'])) {
if ($this->scope instanceof Scope) {
$data = $this->scope;
} else {
$data = $forms['scope']->getData();
}
}
}
}