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/
/vendor/
###< symfony/framework-bundle ###
###> symfony/phpunit-bridge ###
.phpunit
/phpunit.xml
###< symfony/phpunit-bridge ###

View File

@ -7,9 +7,11 @@
"doctrine/orm": "^2.5",
"sensio/framework-extra-bundle": "^5.1",
"symfony/console": "^4.0",
"symfony/debug-bundle": "^4.0",
"symfony/debug-pack": "^1.0",
"symfony/form": "^4.0",
"symfony/framework-bundle": "^4.0",
"symfony/monolog-bundle": "^3.1.0",
"symfony/monolog-bundle": "^3.1",
"symfony/twig-bundle": "^4.0",
"symfony/yaml": "^4.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\MonologBundle\MonologBundle::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:
# configure these for your database server
driver: 'pdo_pgsql'
types:
money: CameraBundle\Types\MoneyType
mapping_types:

View File

@ -1,6 +1,6 @@
framework:
secret: '%env(APP_SECRET)%'
#default_locale: en
default_locale: en
#csrf_protection: ~
#http_method_override: true
#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:
resource: '@CameraBundle/Controller/'
type: annotation
#index:
# path: /
# 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
# https://symfony.com/doc/current/service_container.html
parameters:
#parameter_name: value
locale: en
services:
# default configuration for services in *this* file

View File

@ -1,4 +1,4 @@
<?php
<?php declare(strict_types = 1);
use CameraBundle\Kernel;
use Symfony\Component\Debug\Debug;
@ -7,13 +7,13 @@ use Symfony\Component\HttpFoundation\Request;
require __DIR__ . '/../vendor/autoload.php';
// 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.');
}
// Parse env file
(new Dotenv())->load(__DIR__ . '/../.env');
}
// Set environment
$_SERVER['APP_ENV'] = 'dev';
$_SERVER['APP_DEBUG'] = true;
if ($_SERVER['APP_DEBUG'] ?? ('prod' !== ($_SERVER['APP_ENV'] ?? 'dev'))) {
umask(0000);
@ -23,7 +23,7 @@ if ($_SERVER['APP_DEBUG'] ?? ('prod' !== ($_SERVER['APP_ENV'] ?? 'dev'))) {
// 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();
$response = $kernel->handle($request);
$response->send();

View File

@ -3,10 +3,14 @@
namespace CameraBundle\Controller;
use CameraBundle\Entity\Camera;
use CameraBundle\Form\CameraType;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
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\Response;
/**
* Camera controller.
@ -46,7 +50,7 @@ class CameraController extends Controller
public function newAction(Request $request)
{
$camera = new Camera();
$form = $this->createForm('CameraBundle\Form\CameraType', $camera);
$form = $this->createForm(CameraType::class, $camera);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
@ -84,11 +88,14 @@ class CameraController extends Controller
*
* @Route("/{id}/edit", name="camera_edit")
* @Method({"GET", "POST"})
* @throws \LogicException
*/
public function editAction(Request $request, Camera $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);
if ($editForm->isSubmitted() && $editForm->isValid()) {
@ -100,6 +107,7 @@ class CameraController extends Controller
return $this->render('camera/edit.html.twig', array(
'camera' => $camera,
'edit_form' => $editForm->createView(),
'deacquire_form' => $deacquireForm->createView(),
'delete_form' => $deleteForm->createView(),
));
}
@ -109,18 +117,37 @@ class CameraController extends Controller
*
* @Route("/{id}", name="camera_delete")
* @Method("DELETE")
* @throws \LogicException
*/
public function deleteAction(Request $request, Camera $camera)
{
$form = $this->createDeleteForm($camera);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->remove($camera);
$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');
}
@ -129,13 +156,28 @@ class CameraController extends Controller
*
* @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()
->setAction($this->generateUrl('camera_delete', array('id' => $camera->getId())))
->setAction($this->generateUrl('camera_delete', ['id' => $camera->getId()]))
->setMethod('DELETE')
->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\Index(name="IDX_747C826FC54C8C93", columns={"type_id"})
})
* @ORM\Entity
* @ORM\Entity(repositoryClass="CameraBundle\Repository\CameraRepository")
*/
class Camera
{
@ -22,7 +22,6 @@ class Camera
* @ORM\Column(name="id", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="SEQUENCE")
* @ORM\SequenceGenerator(sequenceName="camera_id_seq", allocationSize=1, initialValue=1)
*/
private $id;

View File

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

View File

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

View File

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

View File

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

View File

@ -2,37 +2,57 @@
namespace CameraBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\{AbstractType, FormBuilderInterface};
use Symfony\Component\OptionsResolver\Exception\AccessException;
use Symfony\Component\OptionsResolver\OptionsResolver;
use CameraBundle\Entity\Lenses;
class LensesType extends AbstractType
{
/**
* {@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}
* @throws AccessException
*/
public function configureOptions(OptionsResolver $resolver)
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults(array(
'data_class' => 'CameraBundle\Entity\Lenses'
'data_class' => Lenses::class
));
}
/**
* {@inheritdoc}
*/
public function getBlockPrefix()
public function getBlockPrefix(): string
{
return 'camerabundle_lenses';
}
}

View File

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

View File

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

View File

@ -2,37 +2,57 @@
namespace CameraBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\{AbstractType, FormBuilderInterface};
use Symfony\Component\OptionsResolver\Exception\AccessException;
use Symfony\Component\OptionsResolver\OptionsResolver;
use CameraBundle\Entity\PreviouslyOwnedLenses;
class PreviouslyOwnedLensesType extends AbstractType
{
/**
* {@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('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');
}
/**
* {@inheritdoc}
* @throws AccessException
*/
public function configureOptions(OptionsResolver $resolver)
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults(array(
'data_class' => 'CameraBundle\Entity\PreviouslyOwnedLenses'
'data_class' => PreviouslyOwnedLenses::class
));
}
/**
* {@inheritdoc}
*/
public function getBlockPrefix()
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": {
"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 />
{{ 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) }}
<button type="submit" class="alert button">Delete</button>
{{ form_end(delete_form) }}