diff --git a/src/Controller/LensesController.php b/src/Controller/LensesController.php
index 8edbc5e..bbccbc4 100644
--- a/src/Controller/LensesController.php
+++ b/src/Controller/LensesController.php
@@ -3,20 +3,21 @@
namespace CameraBundle\Controller;
use CameraBundle\Entity\Lenses;
+use CameraBundle\Form\LensesType;
+use Sensio\Bundle\FrameworkExtraBundle\Configuration\{Method, Route};
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
-use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
-use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
-use Symfony\Component\HttpFoundation\Request;
+use Symfony\Component\Form\FormInterface;
+use Symfony\Component\HttpFoundation\{Request, RedirectResponse};
/**
- * Lense controller.
+ * Lens controller.
*
* @Route("lens")
*/
class LensesController extends Controller
{
/**
- * Lists all lense entities.
+ * Lists all lens entities.
*
* @Route("/", name="lens_index")
* @Method("GET")
@@ -40,33 +41,33 @@ class LensesController extends Controller
}
/**
- * Creates a new lense entity.
+ * Creates a new lens entity.
*
* @Route("/new", name="lens_new")
* @Method({"GET", "POST"})
*/
public function newAction(Request $request)
{
- $lense = new Lenses();
- $form = $this->createForm('CameraBundle\Form\LensesType', $lense);
+ $lens = new Lenses();
+ $form = $this->createForm(LensesType::class, $lens);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$em = $this->getDoctrine()->getManager();
- $em->persist($lense);
+ $em->persist($lens);
$em->flush();
- return $this->redirectToRoute('lens_show', array('id' => $lense->getId()));
+ return $this->redirectToRoute('lens_show', array('id' => $lens->getId()));
}
return $this->render('lenses/new.html.twig', array(
- 'lense' => $lense,
+ 'lense' => $lens,
'form' => $form->createView(),
));
}
/**
- * Finds and displays a lense entity.
+ * Finds and displays a lens entity.
*
* @Route("/{id}", name="lens_show")
* @Method("GET")
@@ -82,44 +83,66 @@ class LensesController extends Controller
}
/**
- * Displays a form to edit an existing lense entity.
+ * Displays a form to edit an existing lens entity.
*
* @Route("/{id}/edit", name="lens_edit")
* @Method({"GET", "POST"})
*/
- public function editAction(Request $request, Lenses $lense)
+ public function editAction(Request $request, Lenses $lens)
{
- $deleteForm = $this->createDeleteForm($lense);
- $editForm = $this->createForm('CameraBundle\Form\LensesType', $lense);
+ $deleteForm = $this->createDeleteForm($lens);
+ $deacquireForm = $this->createDeacquireForm($lens);
+ $editForm = $this->createForm(LensesType::class, $lens);
$editForm->handleRequest($request);
if ($editForm->isSubmitted() && $editForm->isValid()) {
$this->getDoctrine()->getManager()->flush();
- return $this->redirectToRoute('lens_edit', array('id' => $lense->getId()));
+ return $this->redirectToRoute('lens_edit', array('id' => $lens->getId()));
}
return $this->render('lenses/edit.html.twig', array(
- 'lense' => $lense,
+ 'lense' => $lens,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
+ 'deacquire_form' => $deacquireForm->createView()
));
}
/**
- * Deletes a lense entity.
+ * Moves a camera to the previouslyOwned table
+ *
+ * @Route("/{id}/deacquire", name="lens_deacquire")
+ * @Method("POST")
+ * @param Request $request
+ * @param Lenses $lens
+ * @return RedirectResponse
+ */
+ public function deacquireAction(Request $request, Lenses $lens)
+ {
+ $form = $this->createDeacquireForm($lens);
+ $form->handleRequest($request);
+
+ $repository = $this->getDoctrine()->getRepository(Lenses::class);
+ $repository->deacquire($lens);
+
+ return $this->redirectToRoute('lens_index');
+ }
+
+ /**
+ * Deletes a lens entity.
*
* @Route("/{id}", name="lens_delete")
* @Method("DELETE")
*/
- public function deleteAction(Request $request, Lenses $lense)
+ public function deleteAction(Request $request, Lenses $lens)
{
- $form = $this->createDeleteForm($lense);
+ $form = $this->createDeleteForm($lens);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$em = $this->getDoctrine()->getManager();
- $em->remove($lense);
+ $em->remove($lens);
$em->flush();
}
@@ -127,17 +150,33 @@ class LensesController extends Controller
}
/**
- * Creates a form to delete a lense entity.
+ * Creates a form to delete a lens entity.
*
- * @param Lenses $lense The lense entity
+ * @param Lenses $lens The lens entity
*
- * @return \Symfony\Component\Form\Form The form
+ * @return FormInterface The form
*/
- private function createDeleteForm(Lenses $lense)
+ private function createDeleteForm(Lenses $lens): FormInterface
{
return $this->createFormBuilder()
- ->setAction($this->generateUrl('lens_delete', array('id' => $lense->getId())))
+ ->setAction($this->generateUrl('lens_delete', array('id' => $lens->getId())))
->setMethod('DELETE')
->getForm();
}
+
+
+ /**
+ * Creates a form to move
+ *
+ * @param Lenses $lens The lens entity
+ *
+ * @return FormInterface
+ */
+ private function createDeacquireForm(Lenses $lens): FormInterface
+ {
+ return $this->createFormBuilder()
+ ->setAction($this->generateUrl('lens_deacquire', ['id' => $lens->getId()]))
+ ->setMethod('POST')
+ ->getForm();
+ }
}
diff --git a/src/Controller/PreviouslyOwnedCameraController.php b/src/Controller/PreviouslyOwnedCameraController.php
index 91d9fe4..13ee286 100644
--- a/src/Controller/PreviouslyOwnedCameraController.php
+++ b/src/Controller/PreviouslyOwnedCameraController.php
@@ -3,6 +3,7 @@
namespace CameraBundle\Controller;
use CameraBundle\Entity\PreviouslyOwnedCamera;
+use CameraBundle\Form\PreviouslyOwnedCameraType;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
@@ -20,6 +21,7 @@ class PreviouslyOwnedCameraController extends Controller
*
* @Route("/", name="previously-owned-camera_index")
* @Method("GET")
+ * @throws \UnexpectedValueException
*/
public function indexAction()
{
@@ -54,10 +56,11 @@ class PreviouslyOwnedCameraController extends Controller
*
* @Route("/{id}/edit", name="previously-owned-camera_edit")
* @Method({"GET", "POST"})
+ * @throws \LogicException
*/
public function editAction(Request $request, PreviouslyOwnedCamera $previouslyOwnedCamera)
{
- $editForm = $this->createForm('CameraBundle\Form\PreviouslyOwnedCameraType', $previouslyOwnedCamera);
+ $editForm = $this->createForm(PreviouslyOwnedCameraType::class, $previouslyOwnedCamera);
$editForm->handleRequest($request);
if ($editForm->isSubmitted() && $editForm->isValid()) {
diff --git a/src/Entity/BatteryType.php b/src/Entity/BatteryType.php
index 2e0bd15..643fa95 100644
--- a/src/Entity/BatteryType.php
+++ b/src/Entity/BatteryType.php
@@ -17,7 +17,7 @@ class BatteryType
*
* @ORM\Column(name="id", type="integer", nullable=false)
* @ORM\Id
- * @ORM\GeneratedValue(strategy="SEQUENCE")
+ * @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
}
diff --git a/src/Entity/Camera.php b/src/Entity/Camera.php
index bdf346a..938d1a2 100644
--- a/src/Entity/Camera.php
+++ b/src/Entity/Camera.php
@@ -21,7 +21,8 @@ class Camera
*
* @ORM\Column(name="id", type="integer", nullable=false)
* @ORM\Id
- * @ORM\GeneratedValue(strategy="SEQUENCE")
+ * @ORM\GeneratedValue(strategy="IDENTITY")
+ * @ORM\SequenceGenerator(sequenceName="camera_id_seq", allocationSize=1, initialValue=1)
*/
private $id;
diff --git a/src/Entity/CameraType.php b/src/Entity/CameraType.php
index f340287..2f45e68 100644
--- a/src/Entity/CameraType.php
+++ b/src/Entity/CameraType.php
@@ -17,7 +17,8 @@ class CameraType
*
* @ORM\Column(name="id", type="integer", nullable=false)
* @ORM\Id
- * @ORM\GeneratedValue(strategy="SEQUENCE")
+ * @ORM\GeneratedValue(strategy="IDENTITY")
+ * @ORM\SequenceGenerator(sequenceName="camera.camera_type_id_seq", allocationSize=1, initialValue=1)
*/
private $id;
diff --git a/src/Entity/Flash.php b/src/Entity/Flash.php
index 0e0782c..eaa0672 100644
--- a/src/Entity/Flash.php
+++ b/src/Entity/Flash.php
@@ -19,7 +19,8 @@ class Flash
*
* @ORM\Column(name="id", type="integer", nullable=false)
* @ORM\Id
- * @ORM\GeneratedValue(strategy="SEQUENCE")
+ * @ORM\GeneratedValue(strategy="IDENTITY")
+ * @ORM\SequenceGenerator(sequenceName="camera.flash_id_seq", allocationSize=1, initialValue=1)
*/
private $id;
diff --git a/src/Entity/Lenses.php b/src/Entity/Lenses.php
index 9072f49..ca9ea62 100644
--- a/src/Entity/Lenses.php
+++ b/src/Entity/Lenses.php
@@ -8,7 +8,7 @@ use Doctrine\ORM\Mapping as ORM;
* Camera.lenses
*
* @ORM\Table(name="lenses", schema="camera")
- * @ORM\Entity
+ * @ORM\Entity(repositoryClass="CameraBundle\Repository\LensesRepository")
*/
class Lenses
{
@@ -19,7 +19,8 @@ class Lenses
*
* @ORM\Column(name="id", type="integer", nullable=false)
* @ORM\Id
- * @ORM\GeneratedValue(strategy="AUTO")
+ * @ORM\GeneratedValue(strategy="IDENTITY")
+ * @ORM\SequenceGenerator(sequenceName="camera.lenses_id_seq", allocationSize=1, initialValue=1)
*/
private $id;
diff --git a/src/Entity/PreviouslyOwnedCamera.php b/src/Entity/PreviouslyOwnedCamera.php
index 590cd20..2fb9c93 100644
--- a/src/Entity/PreviouslyOwnedCamera.php
+++ b/src/Entity/PreviouslyOwnedCamera.php
@@ -19,7 +19,7 @@ class PreviouslyOwnedCamera
*
* @ORM\Column(name="id", type="integer", nullable=false)
* @ORM\Id
- * @ORM\GeneratedValue(strategy="SEQUENCE")
+ * @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
}
diff --git a/src/Entity/PreviouslyOwnedFlash.php b/src/Entity/PreviouslyOwnedFlash.php
index 0237772..1a9e21e 100644
--- a/src/Entity/PreviouslyOwnedFlash.php
+++ b/src/Entity/PreviouslyOwnedFlash.php
@@ -19,7 +19,7 @@ class PreviouslyOwnedFlash
*
* @ORM\Column(name="id", type="integer", nullable=false)
* @ORM\Id
- * @ORM\GeneratedValue(strategy="SEQUENCE")
+ * @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
diff --git a/src/Entity/PreviouslyOwnedLenses.php b/src/Entity/PreviouslyOwnedLenses.php
index 7c35da3..82f761e 100644
--- a/src/Entity/PreviouslyOwnedLenses.php
+++ b/src/Entity/PreviouslyOwnedLenses.php
@@ -18,7 +18,7 @@ class PreviouslyOwnedLenses
*
* @ORM\Column(name="id", type="integer", nullable=false)
* @ORM\Id
- * @ORM\GeneratedValue(strategy="SEQUENCE")
+ * @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
diff --git a/src/Repository/LensesRepository.php b/src/Repository/LensesRepository.php
new file mode 100644
index 0000000..77f7042
--- /dev/null
+++ b/src/Repository/LensesRepository.php
@@ -0,0 +1,41 @@
+getEntityManager();
+
+ $currentRecord->setFormerlyOwned(true);
+
+ $newRecord = new PreviouslyOwnedLenses();
+
+ $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();
+ }
+}
diff --git a/templates/cameratype/index.html.twig b/templates/cameratype/index.html.twig
index c69175a..d3a41cc 100644
--- a/templates/cameratype/index.html.twig
+++ b/templates/cameratype/index.html.twig
@@ -17,6 +17,7 @@
Actions |
Id |
Type |
+ Description |
@@ -31,7 +32,7 @@
{{ cameraType.id }} |
{{ cameraType.type }} |
-
+ {{ cameraType.description }} |
{% endfor %}
diff --git a/templates/cameratype/show.html.twig b/templates/cameratype/show.html.twig
index 37ae79c..4d9c5e1 100644
--- a/templates/cameratype/show.html.twig
+++ b/templates/cameratype/show.html.twig
@@ -1,39 +1,43 @@
{% extends 'form.html.twig' %}
{% block form %}
- Camera Type
+ Camera Type
-
-
+
+
-
+
- {{ form_start(delete_form) }}
-
- {{ form_end(delete_form) }}
+ {{ form_start(delete_form) }}
+
+ {{ form_end(delete_form) }}
-
-
-
- Id |
- {{ cameraType.id }} |
-
-
- Type |
- {{ cameraType.type }} |
-
-
-
+
+
+
+ Id |
+ {{ cameraType.id }} |
+
+
+ Type |
+ {{ cameraType.type }} |
+
+
+ Description |
+ {{ cameraType.description }} |
+
+
+
{% endblock %}
diff --git a/templates/lenses/edit.html.twig b/templates/lenses/edit.html.twig
index c327a23..03426f2 100644
--- a/templates/lenses/edit.html.twig
+++ b/templates/lenses/edit.html.twig
@@ -19,6 +19,13 @@
+ {{ form_start(deacquire_form) }}
+ {{ form_widget(deacquire_form) }}
+
+ {{ form_end(deacquire_form) }}
+
+
+
{{ form_start(delete_form) }}
{{ form_end(delete_form) }}