Deacquire action for cameras, code reformatting

This commit is contained in:
Timothy Warren 2018-01-03 16:35:10 -05:00
parent bf4b649232
commit d8da3177e8
28 changed files with 1110 additions and 350 deletions

5
.gitignore vendored
View File

@ -5,3 +5,8 @@
/var/ /var/
/vendor/ /vendor/
###< symfony/framework-bundle ### ###< symfony/framework-bundle ###
###> symfony/phpunit-bridge ###
.phpunit
/phpunit.xml
###< symfony/phpunit-bridge ###

View File

@ -7,9 +7,11 @@
"doctrine/orm": "^2.5", "doctrine/orm": "^2.5",
"sensio/framework-extra-bundle": "^5.1", "sensio/framework-extra-bundle": "^5.1",
"symfony/console": "^4.0", "symfony/console": "^4.0",
"symfony/debug-bundle": "^4.0",
"symfony/debug-pack": "^1.0",
"symfony/form": "^4.0", "symfony/form": "^4.0",
"symfony/framework-bundle": "^4.0", "symfony/framework-bundle": "^4.0",
"symfony/monolog-bundle": "^3.1.0", "symfony/monolog-bundle": "^3.1",
"symfony/twig-bundle": "^4.0", "symfony/twig-bundle": "^4.0",
"symfony/yaml": "^4.0", "symfony/yaml": "^4.0",
"twig/twig": "^2.0 || ^3.0" "twig/twig": "^2.0 || ^3.0"

794
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -8,4 +8,6 @@ return [
Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true], Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
Symfony\Bundle\MonologBundle\MonologBundle::class => ['all' => true], Symfony\Bundle\MonologBundle\MonologBundle::class => ['all' => true],
Symfony\Bundle\TwigBundle\TwigBundle::class => ['all' => true], Symfony\Bundle\TwigBundle\TwigBundle::class => ['all' => true],
Symfony\Bundle\WebProfilerBundle\WebProfilerBundle::class => ['dev' => true, 'test' => true],
Symfony\Bundle\DebugBundle\DebugBundle::class => ['dev' => true, 'test' => true],
]; ];

View File

@ -0,0 +1,16 @@
services:
EasyCorp\EasyLog\EasyLogHandler:
public: false
arguments: ['%kernel.logs_dir%/%kernel.environment%.log']
#// FIXME: How to add this configuration automatically without messing up with the monolog configuration?
#monolog:
# handlers:
# buffered:
# type: buffer
# handler: easylog
# channels: ['!event']
# level: debug
# easylog:
# type: service
# id: EasyCorp\EasyLog\EasyLogHandler

View File

@ -0,0 +1,6 @@
web_profiler:
toolbar: true
intercept_redirects: false
framework:
profiler: { only_exceptions: false }

View File

@ -9,6 +9,7 @@ doctrine:
dbal: dbal:
# configure these for your database server # configure these for your database server
driver: 'pdo_pgsql' driver: 'pdo_pgsql'
types: types:
money: CameraBundle\Types\MoneyType money: CameraBundle\Types\MoneyType
mapping_types: mapping_types:

View File

@ -1,6 +1,6 @@
framework: framework:
secret: '%env(APP_SECRET)%' secret: '%env(APP_SECRET)%'
#default_locale: en default_locale: en
#csrf_protection: ~ #csrf_protection: ~
#http_method_override: true #http_method_override: true
#trusted_hosts: ~ #trusted_hosts: ~

View File

@ -0,0 +1,6 @@
web_profiler:
toolbar: false
intercept_redirects: false
framework:
profiler: { collect: false }

View File

@ -1,3 +1,3 @@
app: #index:
resource: '@CameraBundle/Controller/' # path: /
type: annotation # defaults: { _controller: 'App\Controller\DefaultController::index' }

View File

@ -0,0 +1,7 @@
web_profiler_wdt:
resource: '@WebProfilerBundle/Resources/config/routing/wdt.xml'
prefix: /_wdt
web_profiler_profiler:
resource: '@WebProfilerBundle/Resources/config/routing/profiler.xml'
prefix: /_profiler

35
config/services-orig.yaml Normal file
View File

@ -0,0 +1,35 @@
# Learn more about services, parameters and containers at
# https://symfony.com/doc/current/service_container.html
parameters:
#parameter_name: value
services:
# default configuration for services in *this* file
_defaults:
# automatically injects dependencies in your services
autowire: true
# automatically registers your services as commands, event subscribers, etc.
autoconfigure: true
# this means you cannot fetch services directly from the container via $container->get()
# if you need to do this, you can override this setting on individual services
public: false
# makes classes in src/CameraBundle available to be used as services
# this creates a service per class whose id is the fully-qualified class name
CameraBundle\:
resource: '../src/*'
# you can exclude directories or files
# but if a service is unused, it's removed anyway
exclude: '../src/{Entity,Repository,Tests}'
# controllers are imported separately to make sure they're public
# and have a tag that allows actions to type-hint services
CameraBundle\Controller\:
resource: '../src/Controller'
public: true
tags: ['controller.service_arguments']
# add more services, or override services that need manual wiring
# CameraBundle\Service\ExampleService:
# arguments:
# $someArgument: 'some_value'

View File

@ -1,7 +1,7 @@
# Learn more about services, parameters and containers at # Learn more about services, parameters and containers at
# https://symfony.com/doc/current/service_container.html # https://symfony.com/doc/current/service_container.html
parameters: parameters:
#parameter_name: value locale: en
services: services:
# default configuration for services in *this* file # default configuration for services in *this* file

View File

@ -1,29 +1,29 @@
<?php <?php declare(strict_types = 1);
use CameraBundle\Kernel; use CameraBundle\Kernel;
use Symfony\Component\Debug\Debug; use Symfony\Component\Debug\Debug;
use Symfony\Component\Dotenv\Dotenv; use Symfony\Component\Dotenv\Dotenv;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
require __DIR__.'/../vendor/autoload.php'; require __DIR__ . '/../vendor/autoload.php';
// Parse env file
(new Dotenv())->load(__DIR__ . '/../.env');
// Set environment
$_SERVER['APP_ENV'] = 'dev';
$_SERVER['APP_DEBUG'] = true;
// The check is to ensure we don't use .env in production
if (!isset($_SERVER['APP_ENV'])) {
if (!class_exists(Dotenv::class)) {
throw new \RuntimeException('APP_ENV environment variable is not defined. You need to define environment variables for configuration or add "symfony/dotenv" as a Composer dependency to load variables from a .env file.');
}
(new Dotenv())->load(__DIR__.'/../.env');
}
if ($_SERVER['APP_DEBUG'] ?? ('prod' !== ($_SERVER['APP_ENV'] ?? 'dev'))) { if ($_SERVER['APP_DEBUG'] ?? ('prod' !== ($_SERVER['APP_ENV'] ?? 'dev'))) {
umask(0000); umask(0000);
Debug::enable(); Debug::enable();
} }
// Request::setTrustedProxies(['0.0.0.0/0'], Request::HEADER_FORWARDED); // Request::setTrustedProxies(['0.0.0.0/0'], Request::HEADER_FORWARDED);
$kernel = new Kernel($_SERVER['APP_ENV'] ?? 'dev', $_SERVER['APP_DEBUG'] ?? ('prod' !== ($_SERVER['APP_ENV'] ?? 'dev'))); $kernel = new Kernel($_SERVER['APP_ENV'], $_SERVER['APP_DEBUG']);
$request = Request::createFromGlobals(); $request = Request::createFromGlobals();
$response = $kernel->handle($request); $response = $kernel->handle($request);
$response->send(); $response->send();

View File

@ -3,10 +3,14 @@
namespace CameraBundle\Controller; namespace CameraBundle\Controller;
use CameraBundle\Entity\Camera; use CameraBundle\Entity\Camera;
use CameraBundle\Form\CameraType;
use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
/** /**
* Camera controller. * Camera controller.
@ -46,7 +50,7 @@ class CameraController extends Controller
public function newAction(Request $request) public function newAction(Request $request)
{ {
$camera = new Camera(); $camera = new Camera();
$form = $this->createForm('CameraBundle\Form\CameraType', $camera); $form = $this->createForm(CameraType::class, $camera);
$form->handleRequest($request); $form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) { if ($form->isSubmitted() && $form->isValid()) {
@ -84,11 +88,14 @@ class CameraController extends Controller
* *
* @Route("/{id}/edit", name="camera_edit") * @Route("/{id}/edit", name="camera_edit")
* @Method({"GET", "POST"}) * @Method({"GET", "POST"})
* @throws \LogicException
*/ */
public function editAction(Request $request, Camera $camera) public function editAction(Request $request, Camera $camera)
{ {
$deleteForm = $this->createDeleteForm($camera); $deleteForm = $this->createDeleteForm($camera);
$editForm = $this->createForm('CameraBundle\Form\CameraType', $camera); $deacquireForm = $this->createDeacquireForm($camera);
$editForm = $this->createForm(CameraType::class, $camera);
$editForm->handleRequest($request); $editForm->handleRequest($request);
if ($editForm->isSubmitted() && $editForm->isValid()) { if ($editForm->isSubmitted() && $editForm->isValid()) {
@ -100,6 +107,7 @@ class CameraController extends Controller
return $this->render('camera/edit.html.twig', array( return $this->render('camera/edit.html.twig', array(
'camera' => $camera, 'camera' => $camera,
'edit_form' => $editForm->createView(), 'edit_form' => $editForm->createView(),
'deacquire_form' => $deacquireForm->createView(),
'delete_form' => $deleteForm->createView(), 'delete_form' => $deleteForm->createView(),
)); ));
} }
@ -109,17 +117,36 @@ class CameraController extends Controller
* *
* @Route("/{id}", name="camera_delete") * @Route("/{id}", name="camera_delete")
* @Method("DELETE") * @Method("DELETE")
* @throws \LogicException
*/ */
public function deleteAction(Request $request, Camera $camera) public function deleteAction(Request $request, Camera $camera)
{ {
$form = $this->createDeleteForm($camera); $form = $this->createDeleteForm($camera);
$form->handleRequest($request); $form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) { $em = $this->getDoctrine()->getManager();
$em = $this->getDoctrine()->getManager(); $em->remove($camera);
$em->remove($camera); $em->flush();
$em->flush();
} return $this->redirectToRoute('camera_index');
}
/**
* Moves a camera to the previouslyOwned table
*
* @Route("/{id}/deacquire", name="camera_deacquire")
* @Method("POST")
* @param Request $request
* @param Camera $camera
* @return RedirectResponse
*/
public function deacquireAction(Request $request, Camera $camera)
{
$form = $this->createDeacquireForm($camera);
$form->handleRequest($request);
$repository = $this->getDoctrine()->getRepository(Camera::class);
$repository->deacquire($camera);
return $this->redirectToRoute('camera_index'); return $this->redirectToRoute('camera_index');
} }
@ -129,13 +156,28 @@ class CameraController extends Controller
* *
* @param Camera $camera The camera entity * @param Camera $camera The camera entity
* *
* @return \Symfony\Component\Form\Form The form * @return \Symfony\Component\Form\FormInterface The form
*/ */
private function createDeleteForm(Camera $camera) private function createDeleteForm(Camera $camera): FormInterface
{ {
return $this->createFormBuilder() return $this->createFormBuilder()
->setAction($this->generateUrl('camera_delete', array('id' => $camera->getId()))) ->setAction($this->generateUrl('camera_delete', ['id' => $camera->getId()]))
->setMethod('DELETE') ->setMethod('DELETE')
->getForm(); ->getForm();
} }
/**
* Creates a form to move
*
* @param Camera $camera The camera entity
*
* @return FormInterface
*/
private function createDeacquireForm(Camera $camera): FormInterface
{
return $this->createFormBuilder()
->setAction($this->generateUrl('camera_deacquire', ['id' => $camera->getId()]))
->setMethod('POST')
->getForm();
}
} }

View File

View File

@ -10,7 +10,7 @@ use Doctrine\ORM\Mapping as ORM;
* @ORM\Table(name="camera", schema="camera", indexes={ * @ORM\Table(name="camera", schema="camera", indexes={
@ORM\Index(name="IDX_747C826FC54C8C93", columns={"type_id"}) @ORM\Index(name="IDX_747C826FC54C8C93", columns={"type_id"})
}) })
* @ORM\Entity * @ORM\Entity(repositoryClass="CameraBundle\Repository\CameraRepository")
*/ */
class Camera class Camera
{ {
@ -22,7 +22,6 @@ class Camera
* @ORM\Column(name="id", type="integer", nullable=false) * @ORM\Column(name="id", type="integer", nullable=false)
* @ORM\Id * @ORM\Id
* @ORM\GeneratedValue(strategy="SEQUENCE") * @ORM\GeneratedValue(strategy="SEQUENCE")
* @ORM\SequenceGenerator(sequenceName="camera_id_seq", allocationSize=1, initialValue=1)
*/ */
private $id; private $id;

View File

@ -20,7 +20,6 @@ class PreviouslyOwnedCamera
* @ORM\Column(name="id", type="integer", nullable=false) * @ORM\Column(name="id", type="integer", nullable=false)
* @ORM\Id * @ORM\Id
* @ORM\GeneratedValue(strategy="SEQUENCE") * @ORM\GeneratedValue(strategy="SEQUENCE")
* @ORM\SequenceGenerator(sequenceName="camera.previously_owned_camera_id_seq", allocationSize=1, initialValue=1)
*/ */
private $id; private $id;
} }

View File

@ -2,50 +2,51 @@
namespace CameraBundle\Form; namespace CameraBundle\Form;
use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\{AbstractType, FormBuilderInterface};
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\Exception\AccessException;
use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\OptionsResolver\OptionsResolver;
use CameraBundle\Entity\Camera;
class CameraType extends AbstractType class CameraType extends AbstractType
{ {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function buildForm(FormBuilderInterface $builder, array $options) public function buildForm(FormBuilderInterface $builder, array $options): void
{ {
$builder->add('brand') $builder->add('brand')
->add('type') ->add('type')
->add('isDigital') ->add('isDigital')
->add('mount') ->add('mount')
->add('model') ->add('model')
->add('filmFormat') ->add('filmFormat')
->add('cropFactor') ->add('cropFactor')
->add('serial') ->add('serial')
->add('purchasePrice') ->add('purchasePrice')
->add('batteryType') ->add('batteryType')
->add('received') ->add('received')
->add('isWorking') ->add('isWorking')
->add('formerlyOwned') ->add('formerlyOwned')
->add('notes'); ->add('notes');
} }
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'CameraBundle\Entity\Camera'
));
}
/**
* {@inheritdoc}
*/
public function getBlockPrefix()
{
return 'camerabundle_camera';
}
/**
* {@inheritdoc}
* @throws AccessException
*/
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults(array(
'data_class' => Camera::class
));
}
/**
* {@inheritdoc}
*/
public function getBlockPrefix(): string
{
return 'camerabundle_camera';
}
} }

View File

@ -2,37 +2,39 @@
namespace CameraBundle\Form; namespace CameraBundle\Form;
use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\{AbstractType, FormBuilderInterface};
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\OptionsResolver\Exception\AccessException;
use CameraBundle\Entity\CameraType;
class CameraTypeType extends AbstractType class CameraTypeType extends AbstractType
{ {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function buildForm(FormBuilderInterface $builder, array $options) public function buildForm(FormBuilderInterface $builder, array $options): void
{ {
$builder->add('type'); $builder->add('type')
->add('description');
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
* @throws AccessException
*/ */
public function configureOptions(OptionsResolver $resolver) public function configureOptions(OptionsResolver $resolver): void
{ {
$resolver->setDefaults(array( $resolver->setDefaults(array(
'data_class' => 'CameraBundle\Entity\CameraType' 'data_class' => CameraType::class
)); ));
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function getBlockPrefix() public function getBlockPrefix(): string
{ {
return 'camerabundle_cameratype'; return 'camerabundle_cameratype';
} }
} }

View File

@ -2,16 +2,18 @@
namespace CameraBundle\Form; namespace CameraBundle\Form;
use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\{AbstractType, FormBuilderInterface};
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\Exception\AccessException;
use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\OptionsResolver\OptionsResolver;
use CameraBundle\Entity\Flash;
class FlashType extends AbstractType class FlashType extends AbstractType
{ {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function buildForm(FormBuilderInterface $builder, array $options) public function buildForm(FormBuilderInterface $builder, array $options): void
{ {
$builder->add('brand') $builder->add('brand')
->add('model') ->add('model')
@ -31,21 +33,20 @@ class FlashType extends AbstractType
/** /**
* {@inheritdoc} * {@inheritdoc}
* @throws AccessException
*/ */
public function configureOptions(OptionsResolver $resolver) public function configureOptions(OptionsResolver $resolver): void
{ {
$resolver->setDefaults(array( $resolver->setDefaults(array(
'data_class' => 'CameraBundle\Entity\Flash' 'data_class' => Flash::class
)); ));
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function getBlockPrefix() public function getBlockPrefix(): string
{ {
return 'camerabundle_flash'; return 'camerabundle_flash';
} }
} }

View File

@ -2,37 +2,57 @@
namespace CameraBundle\Form; namespace CameraBundle\Form;
use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\{AbstractType, FormBuilderInterface};
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\Exception\AccessException;
use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\OptionsResolver\OptionsResolver;
use CameraBundle\Entity\Lenses;
class LensesType extends AbstractType class LensesType extends AbstractType
{ {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function buildForm(FormBuilderInterface $builder, array $options) public function buildForm(FormBuilderInterface $builder, array $options): void
{ {
$builder->add('brand')->add('coatings')->add('productLine')->add('model')->add('minFStop')->add('maxFStop')->add('minFocalLength')->add('maxFocalLength')->add('serial')->add('purchasePrice')->add('notes')->add('mount')->add('received')->add('formerlyOwned')->add('frontFilterSize')->add('rearFilterSize')->add('isTeleconverter')->add('designElements')->add('designGroups')->add('apertureBlades'); $builder->add('brand')
->add('coatings')
->add('productLine')
->add('model')
->add('mount')
->add('minFStop')
->add('maxFStop')
->add('minFocalLength')
->add('maxFocalLength')
->add('serial')
->add('purchasePrice')
->add('notes')
->add('received')
->add('formerlyOwned')
->add('frontFilterSize')
->add('rearFilterSize')
->add('isTeleconverter')
->add('designElements')
->add('designGroups')
->add('apertureBlades');
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
* @throws AccessException
*/ */
public function configureOptions(OptionsResolver $resolver) public function configureOptions(OptionsResolver $resolver): void
{ {
$resolver->setDefaults(array( $resolver->setDefaults(array(
'data_class' => 'CameraBundle\Entity\Lenses' 'data_class' => Lenses::class
)); ));
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function getBlockPrefix() public function getBlockPrefix(): string
{ {
return 'camerabundle_lenses'; return 'camerabundle_lenses';
} }
} }

View File

@ -2,37 +2,51 @@
namespace CameraBundle\Form; namespace CameraBundle\Form;
use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\{AbstractType, FormBuilderInterface};
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\Exception\AccessException;
use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\OptionsResolver\OptionsResolver;
use CameraBundle\Entity\PreviouslyOwnedCamera;
class PreviouslyOwnedCameraType extends AbstractType class PreviouslyOwnedCameraType extends AbstractType
{ {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function buildForm(FormBuilderInterface $builder, array $options) public function buildForm(FormBuilderInterface $builder, array $options): void
{ {
$builder->add('brand')->add('mount')->add('model')->add('isDigital')->add('cropFactor')->add('isWorking')->add('notes')->add('serial')->add('formerlyOwned')->add('purchasePrice')->add('batteryType')->add('filmFormat')->add('received')->add('type'); $builder->add('brand')
} ->add('mount')
->add('model')
/** ->add('isDigital')
* {@inheritdoc} ->add('cropFactor')
*/ ->add('isWorking')
public function configureOptions(OptionsResolver $resolver) ->add('notes')
{ ->add('serial')
$resolver->setDefaults(array( ->add('formerlyOwned')
'data_class' => 'CameraBundle\Entity\PreviouslyOwnedCamera' ->add('purchasePrice')
)); ->add('batteryType')
} ->add('filmFormat')
->add('received')
/** ->add('type');
* {@inheritdoc} }
*/
public function getBlockPrefix()
{
return 'camerabundle_previouslyownedcamera';
}
/**
* {@inheritdoc}
* @throws AccessException
*/
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults(array(
'data_class' => PreviouslyOwnedCamera::class
));
}
/**
* {@inheritdoc}
*/
public function getBlockPrefix(): string
{
return 'camerabundle_previouslyownedcamera';
}
} }

View File

@ -2,51 +2,52 @@
namespace CameraBundle\Form; namespace CameraBundle\Form;
use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\{AbstractType, FormBuilderInterface};
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\Exception\AccessException;
use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\OptionsResolver\OptionsResolver;
use CameraBundle\Entity\PreviouslyOwnedFlash;
class PreviouslyOwnedFlashType extends AbstractType class PreviouslyOwnedFlashType extends AbstractType
{ {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function buildForm(FormBuilderInterface $builder, array $options) public function buildForm(FormBuilderInterface $builder, array $options): void
{ {
$builder $builder
->add('brand') ->add('brand')
->add('model') ->add('model')
->add('isAutoFlash') ->add('isAutoFlash')
->add('isTtl') ->add('isTtl')
->add('ttlType') ->add('ttlType')
->add('isPTtl') ->add('isPTtl')
->add('pTtlType') ->add('pTtlType')
->add('guideNumber') ->add('guideNumber')
->add('purchasePrice') ->add('purchasePrice')
->add('batteries') ->add('batteries')
->add('notes') ->add('notes')
->add('serial') ->add('serial')
->add('received') ->add('received')
->add('formerlyOwned'); ->add('formerlyOwned');
} }
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'CameraBundle\Entity\PreviouslyOwnedFlash'
));
}
/**
* {@inheritdoc}
*/
public function getBlockPrefix()
{
return 'camerabundle_previouslyownedflash';
}
/**
* {@inheritdoc}
* @throws AccessException
*/
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults(array(
'data_class' => PreviouslyOwnedFlash::class
));
}
/**
* {@inheritdoc}
*/
public function getBlockPrefix(): string
{
return 'camerabundle_previouslyownedflash';
}
} }

View File

@ -2,37 +2,57 @@
namespace CameraBundle\Form; namespace CameraBundle\Form;
use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\{AbstractType, FormBuilderInterface};
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\Exception\AccessException;
use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\OptionsResolver\OptionsResolver;
use CameraBundle\Entity\PreviouslyOwnedLenses;
class PreviouslyOwnedLensesType extends AbstractType class PreviouslyOwnedLensesType extends AbstractType
{ {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function buildForm(FormBuilderInterface $builder, array $options) public function buildForm(FormBuilderInterface $builder, array $options): void
{ {
$builder->add('brand')->add('coatings')->add('productLine')->add('model')->add('minFStop')->add('maxFStop')->add('minFocalLength')->add('maxFocalLength')->add('serial')->add('purchasePrice')->add('notes')->add('mount')->add('received')->add('formerlyOwned')->add('frontFilterSize')->add('rearFilterSize')->add('isTeleconverter')->add('designElements')->add('designGroups')->add('apertureBlades'); $builder->add('brand')
} ->add('coatings')
->add('productLine')
/** ->add('model')
* {@inheritdoc} ->add('minFStop')
*/ ->add('maxFStop')
public function configureOptions(OptionsResolver $resolver) ->add('minFocalLength')
{ ->add('maxFocalLength')
$resolver->setDefaults(array( ->add('serial')
'data_class' => 'CameraBundle\Entity\PreviouslyOwnedLenses' ->add('purchasePrice')
)); ->add('notes')
} ->add('mount')
->add('received')
/** ->add('formerlyOwned')
* {@inheritdoc} ->add('frontFilterSize')
*/ ->add('rearFilterSize')
public function getBlockPrefix() ->add('isTeleconverter')
{ ->add('designElements')
return 'camerabundle_previouslyownedlenses'; ->add('designGroups')
} ->add('apertureBlades');
}
/**
* {@inheritdoc}
* @throws AccessException
*/
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults(array(
'data_class' => PreviouslyOwnedLenses::class
));
}
/**
* {@inheritdoc}
*/
public function getBlockPrefix(): string
{
return 'camerabundle_previouslyownedlenses';
}
} }

View File

@ -0,0 +1,41 @@
<?php
namespace CameraBundle\Repository;
use CameraBundle\Entity\{Camera, PreviouslyOwnedCamera};
use Doctrine\ORM\EntityRepository;
class CameraRepository extends EntityRepository
{
/**
* @param Camera $currentRecord
* @throws \Doctrine\ORM\OptimisticLockException
*/
public function deacquire(Camera $currentRecord)
{
$em = $this->getEntityManager();
$currentRecord->setFormerlyOwned(true);
$newRecord = new PreviouslyOwnedCamera();
$old = new \ReflectionObject($currentRecord);
$new = new \ReflectionObject($newRecord);
foreach ($old->getProperties() as $property) {
$propertyName = $property->getName();
if ($new->hasProperty($propertyName)) {
$newProperty = $new->getProperty($propertyName);
$newProperty->setAccessible(true);
$property->setAccessible(true);
$newProperty->setValue($newRecord, $property->getValue($currentRecord));
}
}
// dump($newRecord);
$em->persist($newRecord);
//$em->remove($currentRecord);
$em->flush();
}
}

View File

@ -184,5 +184,56 @@
}, },
"symfony/form": { "symfony/form": {
"version": "v4.0.0" "version": "v4.0.0"
},
"symfony/polyfill-php72": {
"version": "v1.6.0"
},
"symfony/var-dumper": {
"version": "v4.0.0"
},
"symfony/phpunit-bridge": {
"version": "3.3",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "master",
"version": "3.3",
"ref": "55a81726745b54cc6f8d845f1a094ed7d9ed2e32"
}
},
"symfony/web-profiler-bundle": {
"version": "3.3",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "master",
"version": "3.3",
"ref": "6bdfa1a95f6b2e677ab985cd1af2eae35d62e0f6"
}
},
"symfony/stopwatch": {
"version": "v4.0.0"
},
"symfony/profiler-pack": {
"version": "v1.0.2"
},
"easycorp/easy-log-handler": {
"version": "1.0",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "master",
"version": "1.0",
"ref": "70062abc2cd58794d2a90274502f81b55cd9951b"
}
},
"symfony/debug-bundle": {
"version": "3.3",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "master",
"version": "3.3",
"ref": "de31e687f3964939abd1f66817bd96ed34bc2eee"
}
},
"symfony/debug-pack": {
"version": "v1.0.3"
} }
} }

View File

@ -19,6 +19,13 @@
<hr /> <hr />
{{ form_start(deacquire_form) }}
{{ form_widget(deacquire_form) }}
<button type="submit" class="button">De-acquire</button>
{{ form_end(deacquire_form) }}
<hr />
{{ form_start(delete_form) }} {{ form_start(delete_form) }}
<button type="submit" class="alert button">Delete</button> <button type="submit" class="alert button">Delete</button>
{{ form_end(delete_form) }} {{ form_end(delete_form) }}