Skip to content

Commit

Permalink
show info sheet count for categories
Browse files Browse the repository at this point in the history
  • Loading branch information
mrothauer committed Jul 31, 2024
1 parent edef6f5 commit c94edca
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion plugins/Admin/src/Controller/CategoriesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
1 change: 1 addition & 0 deletions plugins/Admin/templates/Categories/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down
13 changes: 13 additions & 0 deletions src/Model/Table/CategoriesTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
{

Expand Down

0 comments on commit c94edca

Please sign in to comment.