From c94edca39a33034c9c79d736feae7d6b1b833dc8 Mon Sep 17 00:00:00 2001 From: mrothauer Date: Wed, 31 Jul 2024 09:40:28 +0200 Subject: [PATCH] show info sheet count for categories --- .../Admin/src/Controller/CategoriesController.php | 2 +- plugins/Admin/templates/Categories/index.php | 1 + src/Model/Table/CategoriesTable.php | 13 +++++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/plugins/Admin/src/Controller/CategoriesController.php b/plugins/Admin/src/Controller/CategoriesController.php index 3b625380e..e42067588 100644 --- a/plugins/Admin/src/Controller/CategoriesController.php +++ b/plugins/Admin/src/Controller/CategoriesController.php @@ -114,8 +114,8 @@ public function index() if ($object->owner_user) { $object->owner_user->revertPrivatizeData(); } + $object->info_sheet_count = $this->Category->getInfoSheetCount($object->id); } - $this->set('objects', $objects); $metaTags = [ diff --git a/plugins/Admin/templates/Categories/index.php b/plugins/Admin/templates/Categories/index.php index 6ca0807de..2101927e1 100644 --- a/plugins/Admin/templates/Categories/index.php +++ b/plugins/Admin/templates/Categories/index.php @@ -15,6 +15,7 @@ ,['name' => 'carbon_footprint', 'label' => 'CF'] ,['name' => 'material_footprint', 'label' => 'MF'] ,['name' => 'owner_user.name', 'label' => 'Owner'] + ,['name' => 'info_sheet_count', 'label' => 'LZ'] ,['name' => 'status', 'label' => 'Status'] ,['name' => 'created', 'type' => 'datetime', 'label' => 'erstellt'] ,['name' => 'modified', 'type' => 'datetime', 'label' => 'geƤndert'] diff --git a/src/Model/Table/CategoriesTable.php b/src/Model/Table/CategoriesTable.php index 423271ef2..a191e2825 100644 --- a/src/Model/Table/CategoriesTable.php +++ b/src/Model/Table/CategoriesTable.php @@ -2,6 +2,7 @@ namespace App\Model\Table; use Cake\Core\Configure; +use Cake\Datasource\FactoryLocator; use Cake\ORM\Table; use Cake\Utility\Hash; use Cake\Validation\Validator; @@ -52,6 +53,18 @@ public function validationDefault(Validator $validator): \Cake\Validation\Valida return $validator; } + public function getInfoSheetCount($categoryId) + { + $infoSheetTable = FactoryLocator::get('Table')->get('InfoSheets'); + $result = $infoSheetTable->find('all', + conditions: [ + $infoSheetTable->aliasField('category_id') => $categoryId, + $infoSheetTable->aliasField('status') => APP_ON, + ])->count(); + + return $result; + } + public function getMaterialFootprintByParentCategoryId($parentCategoryId) {