From 80b9f903247d4d05ccc80161ecbe9e6f0f2e63b6 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Sat, 30 Dec 2023 23:09:27 -0500 Subject: [PATCH] Rename ItemPriceController to ItemController. #780 --- config/packages/catalyst_auth.yaml | 14 +- config/packages/catalyst_menu.yaml | 6 +- config/routes/item.yaml | 34 ++++ config/routes/item_price.yaml | 34 ---- ...PriceController.php => ItemController.php} | 16 +- src/Entity/{ItemPrice.php => Item.php} | 19 ++- src/Entity/ItemType.php | 11 ++ src/Entity/PriceTier.php | 10 +- templates/item/form.html.twig | 142 +++++++++++++++++ templates/item/list.html.twig | 146 ++++++++++++++++++ templates/price-tier/form.html.twig | 2 +- 11 files changed, 373 insertions(+), 61 deletions(-) create mode 100644 config/routes/item.yaml delete mode 100644 config/routes/item_price.yaml rename src/Controller/{ItemPriceController.php => ItemController.php} (90%) rename src/Entity/{ItemPrice.php => Item.php} (83%) create mode 100644 templates/item/form.html.twig create mode 100644 templates/item/list.html.twig diff --git a/config/packages/catalyst_auth.yaml b/config/packages/catalyst_auth.yaml index e03cdc32..7e02d5c0 100644 --- a/config/packages/catalyst_auth.yaml +++ b/config/packages/catalyst_auth.yaml @@ -662,18 +662,18 @@ catalyst_auth: - id: item_type.delete label: Delete - - id: item_price - label: Item Price + - id: item + label: Item acls: - - id: item_price.menu + - id: item.menu label: Menu - - id: item_price.list + - id: item.list label: List - - id: item_price.add + - id: item.add label: Add - - id: item_price.update + - id: item.update label: Update - - id: item_price.delete + - id: item.delete label: Delete - id: item_pricing label: Item Pricing diff --git a/config/packages/catalyst_menu.yaml b/config/packages/catalyst_menu.yaml index 83f7e852..a6bd1583 100644 --- a/config/packages/catalyst_menu.yaml +++ b/config/packages/catalyst_menu.yaml @@ -297,7 +297,7 @@ catalyst_menu: acl: item.menu label: Item Management icon: fa fa-boxes - order: 10 + order: 10 - id: price_tier_list acl: price_tier.list label: Price Tiers @@ -306,7 +306,7 @@ catalyst_menu: acl: item_pricing.update label: Item Pricing parent: item - - id: item_price_list - acl: item_price.list + - id: item_list + acl: item.list label: Items parent: item diff --git a/config/routes/item.yaml b/config/routes/item.yaml new file mode 100644 index 00000000..89dde4d2 --- /dev/null +++ b/config/routes/item.yaml @@ -0,0 +1,34 @@ +item_list: + path: /items + controller: App\Controller\ItemController::index + methods: [GET] + +item_rows: + path: /items/rowdata + controller: App\Controller\ItemController::datatableRows + methods: [POST] + +item_add_form: + path: /items/newform + controller: App\Controller\ItemController::addForm + methods: [GET] + +item_add_submit: + path: /items + controller: App\Controller\ItemController::addSubmit + methods: [POST] + +item_update_form: + path: /items/{id} + controller: App\Controller\ItemController::updateForm + methods: [GET] + +item_update_submit: + path: /items/{id} + controller: App\Controller\ItemController::updateSubmit + methods: [POST] + +item_delete: + path: /items/{id} + controller: App\Controller\ItemController::deleteSubmit + methods: [DELETE] diff --git a/config/routes/item_price.yaml b/config/routes/item_price.yaml deleted file mode 100644 index 607dc3cd..00000000 --- a/config/routes/item_price.yaml +++ /dev/null @@ -1,34 +0,0 @@ -item_price_list: - path: /items - controller: App\Controller\ItemPriceController::index - methods: [GET] - -item_price_rows: - path: /items/rowdata - controller: App\Controller\ItemPriceController::datatableRows - methods: [POST] - -item_price_add_form: - path: /items/newform - controller: App\Controller\ItemPriceController::addForm - methods: [GET] - -item_price_add_submit: - path: /items - controller: App\Controller\ItemPriceController::addSubmit - methods: [POST] - -item_price_update_form: - path: /items/{id} - controller: App\Controller\ItemPriceController::updateForm - methods: [GET] - -item_price_update_submit: - path: /items/{id} - controller: App\Controller\ItemPriceController::updateSubmit - methods: [POST] - -item_price_delete: - path: /items/{id} - controller: App\Controller\ItemPriceController::deleteSubmit - methods: [DELETE] diff --git a/src/Controller/ItemPriceController.php b/src/Controller/ItemController.php similarity index 90% rename from src/Controller/ItemPriceController.php rename to src/Controller/ItemController.php index 0a41994c..07e66df1 100644 --- a/src/Controller/ItemPriceController.php +++ b/src/Controller/ItemController.php @@ -14,31 +14,31 @@ use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter; use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted; use App\Entity\ItemType; -use App\Entity\ItemPrice; +use App\Entity\Item; use App\Entity\Battery; use App\Entity\ServiceOffering; use Catalyst\MenuBundle\Annotation\Menu; -class ItemPriceController extends Controller +class ItemController extends Controller { /** - * @Menu(selected="item_price_list") - * @IsGranted("item_price.list") + * @Menu(selected="item_list") + * @IsGranted("item.list") */ public function index () { - return $this->render('item-price/list.html.twig'); + return $this->render('item/list.html.twig'); } /** - * @IsGranted("item_price.list") + * @IsGranted("item.list") */ public function datatableRows(Request $req) { // get query builder $qb = $this->getDoctrine() - ->getRepository(ItemPrice::class) + ->getRepository(Item::class) ->createQueryBuilder('q'); // get datatable params @@ -118,6 +118,8 @@ class ItemPriceController extends Controller protected function setQueryFilters($datatable, QueryBuilder $query) { + // TODO: add filter for item type. + // TODO: fix filter for name since name is with the associated entity if (isset($datatable['query']['data-rows-search']) && !empty($datatable['query']['data-rows-search'])) { $query->where('q.name LIKE :filter') ->setParameter('filter', '%' . $datatable['query']['data-rows-search'] . '%'); diff --git a/src/Entity/ItemPrice.php b/src/Entity/Item.php similarity index 83% rename from src/Entity/ItemPrice.php rename to src/Entity/Item.php index b9f14517..2e5ed091 100644 --- a/src/Entity/ItemPrice.php +++ b/src/Entity/Item.php @@ -6,10 +6,10 @@ use Doctrine\ORM\Mapping as ORM; /** * @ORM\Entity - * @ORM\Table(name="item_price") + * @ORM\Table(name="item") */ -class ItemPrice +class Item { // unique id /** @@ -20,14 +20,14 @@ class ItemPrice protected $id; /** - * @ORM\ManyToOne(targetEntity="PriceTier", inversedBy="item_prices") + * @ORM\ManyToOne(targetEntity="PriceTier", inversedBy="items") * @ORM\JoinColumn(name="price_tier_id", referencedColumnName="id") */ protected $price_tier; // item type /** - * @ORM\ManyToOne(targetEntity="ItemType", inversedBy="item_prices") + * @ORM\ManyToOne(targetEntity="ItemType", inversedBy="items") * @ORM\JoinColumn(name="item_type_id", referencedColumnName="id") */ protected $item_type; @@ -62,6 +62,17 @@ class ItemPrice return $this->price_tier; } + public function setItemType(ItemType $item_type) + { + $this->item_type = $item_type; + return $this; + } + + public function getItemType() + { + return $this->item_type; + } + public function setItemID($item_id) { $this->item_id = $item_id; diff --git a/src/Entity/ItemType.php b/src/Entity/ItemType.php index 204fb9b3..3ef422d8 100644 --- a/src/Entity/ItemType.php +++ b/src/Entity/ItemType.php @@ -35,6 +35,12 @@ class ItemType */ protected $code; + // items under an item type + /** + * @ORM\OneToMany(targetEntity="Item", mappedBy="item_type") + */ + protected $items; + public function __construct() { $this->code = ''; @@ -66,4 +72,9 @@ class ItemType { return $this->code; } + + public function getItems() + { + return $this->items; + } } diff --git a/src/Entity/PriceTier.php b/src/Entity/PriceTier.php index 37c8d8f8..d929fc8f 100644 --- a/src/Entity/PriceTier.php +++ b/src/Entity/PriceTier.php @@ -34,14 +34,14 @@ class PriceTier // items under a price tier /** - * @ORM\OneToMany(targetEntity="ItemPrice", mappedBy="price_tier") + * @ORM\OneToMany(targetEntity="Item", mappedBy="price_tier") */ - protected $item_prices; + protected $items; public function __construct() { $this->supported_areas = new ArrayCollection(); - $this->item_prices = new ArrayCollection(); + $this->items = new ArrayCollection(); } public function getID() @@ -80,9 +80,9 @@ class PriceTier return $this; } - public function getItemPrices() + public function getItems() { - return $this->item_prices; + return $this->items; } } diff --git a/templates/item/form.html.twig b/templates/item/form.html.twig new file mode 100644 index 00000000..97d0d9ec --- /dev/null +++ b/templates/item/form.html.twig @@ -0,0 +1,142 @@ +{% extends 'base.html.twig' %} + +{% block body %} + +
+
+
+

Item Types

+
+
+
+ +
+ +
+
+
+
+
+
+ + + +

+ {% if mode == 'update' %} + Edit Item Type + {{ obj.getName() }} + {% else %} + New Item Type + {% endif %} +

+
+
+
+
+
+
+ +
+ + +
+
+
+ +
+ + +
+
+
+
+
+
+
+ + Back +
+
+
+
+
+
+
+
+
+{% endblock %} + +{% block scripts %} + +{% endblock %} diff --git a/templates/item/list.html.twig b/templates/item/list.html.twig new file mode 100644 index 00000000..b3a36a61 --- /dev/null +++ b/templates/item/list.html.twig @@ -0,0 +1,146 @@ +{% extends 'base.html.twig' %} + +{% block body %} + +
+
+
+

+ Items +

+
+
+
+ +
+ +
+
+
+
+
+
+
+
+
+
+ + + + +
+
+
+
+ +
+
+ +
+ +
+
+
+
+
+{% endblock %} + +{% block scripts %} + +{% endblock %} diff --git a/templates/price-tier/form.html.twig b/templates/price-tier/form.html.twig index 105d7ec2..0056cdc8 100644 --- a/templates/price-tier/form.html.twig +++ b/templates/price-tier/form.html.twig @@ -49,7 +49,7 @@
{% if sets.areas is empty %} - No supported areas. + No available supported areas. {% else %}
{% for id, label in sets.areas %}