Sort lists, and implement proper money type mapping
This commit is contained in:
parent
594d62db21
commit
c9b5569316
@ -56,8 +56,11 @@ doctrine:
|
|||||||
# 2. Uncomment database_path in parameters.yml.dist
|
# 2. Uncomment database_path in parameters.yml.dist
|
||||||
# 3. Uncomment next line:
|
# 3. Uncomment next line:
|
||||||
# path: '%database_path%'
|
# path: '%database_path%'
|
||||||
|
types:
|
||||||
|
money: CameraBundle\Types\MoneyType
|
||||||
mapping_types:
|
mapping_types:
|
||||||
bit: boolean
|
bit: boolean
|
||||||
|
money: money
|
||||||
|
|
||||||
orm:
|
orm:
|
||||||
auto_generate_proxy_classes: '%kernel.debug%'
|
auto_generate_proxy_classes: '%kernel.debug%'
|
||||||
|
@ -24,7 +24,12 @@ class CameraController extends Controller
|
|||||||
{
|
{
|
||||||
$em = $this->getDoctrine()->getManager();
|
$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(
|
return $this->render('camera/index.html.twig', array(
|
||||||
'cameras' => $cameras,
|
'cameras' => $cameras,
|
||||||
|
@ -24,7 +24,9 @@ class CameraTypeController extends Controller
|
|||||||
{
|
{
|
||||||
$em = $this->getDoctrine()->getManager();
|
$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(
|
return $this->render('cameratype/index.html.twig', array(
|
||||||
'cameraTypes' => $cameraTypes,
|
'cameraTypes' => $cameraTypes,
|
||||||
|
@ -24,7 +24,11 @@ class FlashController extends Controller
|
|||||||
{
|
{
|
||||||
$em = $this->getDoctrine()->getManager();
|
$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(
|
return $this->render('flash/index.html.twig', array(
|
||||||
'flashes' => $flashes,
|
'flashes' => $flashes,
|
||||||
|
@ -24,7 +24,14 @@ class LensesController extends Controller
|
|||||||
{
|
{
|
||||||
$em = $this->getDoctrine()->getManager();
|
$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(
|
return $this->render('lenses/index.html.twig', array(
|
||||||
'lenses' => $lenses,
|
'lenses' => $lenses,
|
||||||
|
@ -25,7 +25,11 @@ class PreviouslyOwnedCameraController extends Controller
|
|||||||
{
|
{
|
||||||
$em = $this->getDoctrine()->getManager();
|
$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(
|
return $this->render('previouslyownedcamera/index.html.twig', array(
|
||||||
'previouslyOwnedCameras' => $previouslyOwnedCameras,
|
'previouslyOwnedCameras' => $previouslyOwnedCameras,
|
||||||
|
@ -25,7 +25,10 @@ class PreviouslyOwnedFlashController extends Controller
|
|||||||
{
|
{
|
||||||
$em = $this->getDoctrine()->getManager();
|
$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(
|
return $this->render('previouslyownedflash/index.html.twig', array(
|
||||||
'previouslyOwnedFlashes' => $previouslyOwnedFlashes,
|
'previouslyOwnedFlashes' => $previouslyOwnedFlashes,
|
||||||
|
@ -25,7 +25,13 @@ class PreviouslyOwnedLensesController extends Controller
|
|||||||
{
|
{
|
||||||
$em = $this->getDoctrine()->getManager();
|
$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(
|
return $this->render('previouslyownedlenses/index.html.twig', array(
|
||||||
'previouslyOwnedLenses' => $previouslyOwnedLenses,
|
'previouslyOwnedLenses' => $previouslyOwnedLenses,
|
||||||
|
@ -81,7 +81,7 @@ trait CameraTrait {
|
|||||||
/**
|
/**
|
||||||
* @var string
|
* @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;
|
private $purchasePrice;
|
||||||
|
|
||||||
|
@ -24,4 +24,18 @@ class Flash
|
|||||||
*/
|
*/
|
||||||
private $id;
|
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;
|
||||||
}
|
}
|
||||||
|
@ -64,7 +64,7 @@ trait FlashTrait {
|
|||||||
/**
|
/**
|
||||||
* @var string
|
* @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;
|
private $purchasePrice;
|
||||||
|
|
||||||
@ -89,15 +89,6 @@ trait FlashTrait {
|
|||||||
*/
|
*/
|
||||||
private $serial;
|
private $serial;
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var boolean
|
|
||||||
*
|
|
||||||
* @ORM\Column(name="formerly_owned", type="boolean", nullable=false, options={"default" : false})
|
|
||||||
*/
|
|
||||||
private $formerlyOwned = false;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get id
|
* Get id
|
||||||
*
|
*
|
||||||
@ -395,4 +386,28 @@ trait FlashTrait {
|
|||||||
{
|
{
|
||||||
return $this->formerlyOwned;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
@ -71,7 +71,7 @@ trait LensTrait {
|
|||||||
/**
|
/**
|
||||||
* @var string
|
* @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;
|
private $purchasePrice;
|
||||||
|
|
||||||
@ -89,20 +89,6 @@ trait LensTrait {
|
|||||||
*/
|
*/
|
||||||
private $mount;
|
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
|
* @var string
|
||||||
*
|
*
|
||||||
|
@ -23,4 +23,18 @@ class Lenses
|
|||||||
* @ORM\SequenceGenerator(sequenceName="camera.lenses_id_seq", allocationSize=1, initialValue=1)
|
* @ORM\SequenceGenerator(sequenceName="camera.lenses_id_seq", allocationSize=1, initialValue=1)
|
||||||
*/
|
*/
|
||||||
private $id;
|
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;
|
||||||
}
|
}
|
||||||
|
@ -23,4 +23,19 @@ class PreviouslyOwnedFlash
|
|||||||
* @ORM\SequenceGenerator(sequenceName="camera.previously_owned_flash_id_seq", allocationSize=1, initialValue=1)
|
* @ORM\SequenceGenerator(sequenceName="camera.previously_owned_flash_id_seq", allocationSize=1, initialValue=1)
|
||||||
*/
|
*/
|
||||||
private $id;
|
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;
|
||||||
}
|
}
|
||||||
|
@ -22,4 +22,18 @@ class PreviouslyOwnedLenses
|
|||||||
* @ORM\SequenceGenerator(sequenceName="camera.previously_owned_lenses_id_seq", allocationSize=1, initialValue=1)
|
* @ORM\SequenceGenerator(sequenceName="camera.previously_owned_lenses_id_seq", allocationSize=1, initialValue=1)
|
||||||
*/
|
*/
|
||||||
private $id;
|
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;
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ trait PurchasePriceTrait {
|
|||||||
*/
|
*/
|
||||||
public function setPurchasePrice($purchasePrice)
|
public function setPurchasePrice($purchasePrice)
|
||||||
{
|
{
|
||||||
$this->purchasePrice = $purchasePrice ?? null;
|
$this->purchasePrice = $purchasePrice;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
@ -24,6 +24,10 @@ trait PurchasePriceTrait {
|
|||||||
*/
|
*/
|
||||||
public function getPurchasePrice()
|
public function getPurchasePrice()
|
||||||
{
|
{
|
||||||
return (double) str_replace(['$',','], '', (string)$this->purchasePrice) ?? null;
|
if (empty($this->purchasePrice)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->purchasePrice;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -25,6 +25,7 @@ class FlashType extends AbstractType
|
|||||||
->add('batteries')
|
->add('batteries')
|
||||||
->add('notes')
|
->add('notes')
|
||||||
->add('serial')
|
->add('serial')
|
||||||
|
->add('received')
|
||||||
->add('formerlyOwned');
|
->add('formerlyOwned');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,7 +13,21 @@ class PreviouslyOwnedFlashType extends AbstractType
|
|||||||
*/
|
*/
|
||||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
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');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
31
src/CameraBundle/Types/MoneyType.php
Normal file
31
src/CameraBundle/Types/MoneyType.php
Normal 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';
|
||||||
|
}
|
||||||
|
}
|
22
src/CameraBundle/ValueObject/Money.php
Normal file
22
src/CameraBundle/ValueObject/Money.php
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user