Sort lists, and implement proper money type mapping

This commit is contained in:
Timothy Warren 2017-11-22 13:51:04 -05:00
parent 594d62db21
commit c9b5569316
20 changed files with 201 additions and 37 deletions

View File

@ -56,8 +56,11 @@ doctrine:
# 2. Uncomment database_path in parameters.yml.dist
# 3. Uncomment next line:
# path: '%database_path%'
types:
money: CameraBundle\Types\MoneyType
mapping_types:
bit: boolean
money: money
orm:
auto_generate_proxy_classes: '%kernel.debug%'

View File

@ -24,7 +24,12 @@ class CameraController extends Controller
{
$em = $this->getDoctrine()->getManager();
$cameras = $em->getRepository('CameraBundle:Camera')->findAll();
$cameras = $em->getRepository('CameraBundle:Camera')->findBy([], [
'received' => 'DESC',
'brand' => 'ASC',
'mount' => 'ASC',
'model' => 'ASC',
]);
return $this->render('camera/index.html.twig', array(
'cameras' => $cameras,

View File

@ -24,7 +24,9 @@ class CameraTypeController extends Controller
{
$em = $this->getDoctrine()->getManager();
$cameraTypes = $em->getRepository('CameraBundle:CameraType')->findAll();
$cameraTypes = $em->getRepository('CameraBundle:CameraType')->findBy([], [
'type' => 'ASC'
]);
return $this->render('cameratype/index.html.twig', array(
'cameraTypes' => $cameraTypes,

View File

@ -24,7 +24,11 @@ class FlashController extends Controller
{
$em = $this->getDoctrine()->getManager();
$flashes = $em->getRepository('CameraBundle:Flash')->findAll();
$flashes = $em->getRepository('CameraBundle:Flash')->findBy([], [
'received' => 'DESC',
'brand' => 'ASC',
'model' => 'ASC'
]);
return $this->render('flash/index.html.twig', array(
'flashes' => $flashes,

View File

@ -24,7 +24,14 @@ class LensesController extends Controller
{
$em = $this->getDoctrine()->getManager();
$lenses = $em->getRepository('CameraBundle:Lenses')->findAll();
$lenses = $em->getRepository('CameraBundle:Lenses')->findBy([], [
'received' => 'DESC',
'brand' => 'ASC',
'productLine' => 'ASC',
'mount' => 'ASC',
'minFocalLength' => 'ASC',
'maxFStop' => 'ASC',
]);
return $this->render('lenses/index.html.twig', array(
'lenses' => $lenses,

View File

@ -25,7 +25,11 @@ class PreviouslyOwnedCameraController extends Controller
{
$em = $this->getDoctrine()->getManager();
$previouslyOwnedCameras = $em->getRepository('CameraBundle:PreviouslyOwnedCamera')->findAll();
$previouslyOwnedCameras = $em->getRepository('CameraBundle:PreviouslyOwnedCamera')->findBy([], [
'brand' => 'ASC',
'mount' => 'ASC',
'model' => 'ASC',
]);
return $this->render('previouslyownedcamera/index.html.twig', array(
'previouslyOwnedCameras' => $previouslyOwnedCameras,

View File

@ -25,7 +25,10 @@ class PreviouslyOwnedFlashController extends Controller
{
$em = $this->getDoctrine()->getManager();
$previouslyOwnedFlashes = $em->getRepository('CameraBundle:PreviouslyOwnedFlash')->findAll();
$previouslyOwnedFlashes = $em->getRepository('CameraBundle:PreviouslyOwnedFlash')->findBy([], [
'brand' => 'ASC',
'model' => 'ASC'
]);
return $this->render('previouslyownedflash/index.html.twig', array(
'previouslyOwnedFlashes' => $previouslyOwnedFlashes,

View File

@ -25,7 +25,13 @@ class PreviouslyOwnedLensesController extends Controller
{
$em = $this->getDoctrine()->getManager();
$previouslyOwnedLenses = $em->getRepository('CameraBundle:PreviouslyOwnedLenses')->findAll();
$previouslyOwnedLenses = $em->getRepository('CameraBundle:PreviouslyOwnedLenses')->findBy([], [
'brand' => 'ASC',
'productLine' => 'ASC',
'mount' => 'ASC',
'minFocalLength' => 'ASC',
'maxFStop' => 'ASC',
]);
return $this->render('previouslyownedlenses/index.html.twig', array(
'previouslyOwnedLenses' => $previouslyOwnedLenses,

View File

@ -81,7 +81,7 @@ trait CameraTrait {
/**
* @var string
*
* @ORM\Column(name="purchase_price", type="decimal", precision=10, scale=0, nullable=true)
* @ORM\Column(name="purchase_price", type="money", nullable=true)
*/
private $purchasePrice;

View File

@ -24,4 +24,18 @@ class Flash
*/
private $id;
/**
* @var boolean
*
* @ORM\Column(name="received", type="boolean", nullable=false, options={"default" : false})
*/
private $received = false;
/**
* @var boolean
*
* @ORM\Column(name="formerly_owned", type="boolean", nullable=false, options={"default" : false})
*/
private $formerlyOwned = false;
}

View File

@ -64,7 +64,7 @@ trait FlashTrait {
/**
* @var string
*
* @ORM\Column(name="purchase_price", type="decimal", precision=10, scale=0, nullable=true)
* @ORM\Column(name="purchase_price", type="money", nullable=true)
*/
private $purchasePrice;
@ -89,15 +89,6 @@ trait FlashTrait {
*/
private $serial;
/**
* @var boolean
*
* @ORM\Column(name="formerly_owned", type="boolean", nullable=false, options={"default" : false})
*/
private $formerlyOwned = false;
/**
* Get id
*
@ -395,4 +386,28 @@ trait FlashTrait {
{
return $this->formerlyOwned;
}
/**
* Set received
*
* @param boolean $received
*
* @return Flash
*/
public function setReceived($received)
{
$this->received = $received;
return $this;
}
/**
* Get received
*
* @return boolean
*/
public function getReceived()
{
return $this->received;
}
}

View File

@ -71,7 +71,7 @@ trait LensTrait {
/**
* @var string
*
* @ORM\Column(name="purchase_price", type="decimal", precision=10, scale=0, nullable=true)
* @ORM\Column(name="purchase_price", type="money", nullable=true)
*/
private $purchasePrice;
@ -89,20 +89,6 @@ trait LensTrait {
*/
private $mount;
/**
* @var boolean
*
* @ORM\Column(name="received", type="boolean", nullable=false)
*/
private $received = false;
/**
* @var boolean
*
* @ORM\Column(name="formerly_owned", type="boolean", nullable=false)
*/
private $formerlyOwned = false;
/**
* @var string
*

View File

@ -23,4 +23,18 @@ class Lenses
* @ORM\SequenceGenerator(sequenceName="camera.lenses_id_seq", allocationSize=1, initialValue=1)
*/
private $id;
/**
* @var boolean
*
* @ORM\Column(name="received", type="boolean", nullable=false)
*/
private $received = false;
/**
* @var boolean
*
* @ORM\Column(name="formerly_owned", type="boolean", nullable=false)
*/
private $formerlyOwned = false;
}

View File

@ -23,4 +23,19 @@ class PreviouslyOwnedFlash
* @ORM\SequenceGenerator(sequenceName="camera.previously_owned_flash_id_seq", allocationSize=1, initialValue=1)
*/
private $id;
/**
* @var boolean
*
* @ORM\Column(name="received", type="boolean", nullable=false, options={"default" : true})
*/
private $received = true;
/**
* @var boolean
*
* @ORM\Column(name="formerly_owned", type="boolean", nullable=false, options={"default" : true})
*/
private $formerlyOwned = true;
}

View File

@ -22,4 +22,18 @@ class PreviouslyOwnedLenses
* @ORM\SequenceGenerator(sequenceName="camera.previously_owned_lenses_id_seq", allocationSize=1, initialValue=1)
*/
private $id;
/**
* @var boolean
*
* @ORM\Column(name="received", type="boolean", nullable=false)
*/
private $received = true;
/**
* @var boolean
*
* @ORM\Column(name="formerly_owned", type="boolean", nullable=false)
*/
private $formerlyOwned = true;
}

View File

@ -12,7 +12,7 @@ trait PurchasePriceTrait {
*/
public function setPurchasePrice($purchasePrice)
{
$this->purchasePrice = $purchasePrice ?? null;
$this->purchasePrice = $purchasePrice;
return $this;
}
@ -24,6 +24,10 @@ trait PurchasePriceTrait {
*/
public function getPurchasePrice()
{
return (double) str_replace(['$',','], '', (string)$this->purchasePrice) ?? null;
if (empty($this->purchasePrice)) {
return 0;
}
return $this->purchasePrice;
}
}

View File

@ -25,6 +25,7 @@ class FlashType extends AbstractType
->add('batteries')
->add('notes')
->add('serial')
->add('received')
->add('formerlyOwned');
}

View File

@ -13,7 +13,21 @@ class PreviouslyOwnedFlashType extends AbstractType
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('brand')->add('model')->add('isAutoFlash')->add('isTtl')->add('ttlType')->add('isPTtl')->add('pTtlType')->add('guideNumber')->add('purchasePrice')->add('batteries')->add('notes')->add('serial')->add('formerlyOwned');
$builder
->add('brand')
->add('model')
->add('isAutoFlash')
->add('isTtl')
->add('ttlType')
->add('isPTtl')
->add('pTtlType')
->add('guideNumber')
->add('purchasePrice')
->add('batteries')
->add('notes')
->add('serial')
->add('received')
->add('formerlyOwned');
}
/**

View File

@ -0,0 +1,31 @@
<?php
namespace CameraBundle\Types;
use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use CameraBundle\ValueObject\Money;
class MoneyType extends Type {
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
{
return 'MONEY';
}
public function convertToPHPValue($value, AbstractPlatform $platform)
{
return new Money($value);
}
public function convertToDatabaseValue($value, AbstractPlatform $platform)
{
return $value;
}
public function getName()
{
return 'money';
}
}

View File

@ -0,0 +1,22 @@
<?php
namespace CameraBundle\ValueObject;
class Money {
private $value;
public function __construct($value)
{
$this->value = str_replace(['$',','], '', $value);
}
public function getValue()
{
return str_replace(['$',','], '', $this->value);
}
public function __toString()
{
return (string)$this->getValue();
}
}