From 80b12dc1429214fa380ef9e206187ecd65518a86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A1ndly=20Gerg=C5=91?= Date: Thu, 20 Mar 2025 11:09:33 +0200 Subject: [PATCH] Removed LABEL_PRINTER_INCLUDE_DETAILS flag --- config-dist.php | 1 - controllers/BatteriesApiController.php | 10 +++----- controllers/ChoresApiController.php | 10 +++----- controllers/StockApiController.php | 22 ++++++------------ services/StockService.php | 32 +++++++------------------- 5 files changed, 21 insertions(+), 54 deletions(-) diff --git a/config-dist.php b/config-dist.php index ad891e91..717222ca 100644 --- a/config-dist.php +++ b/config-dist.php @@ -111,7 +111,6 @@ Setting('LABEL_PRINTER_WEBHOOK', ''); // The URI that Grocy will POST to when as Setting('LABEL_PRINTER_RUN_SERVER', true); // Whether the webhook will be called server- or client-side Setting('LABEL_PRINTER_PARAMS', ['font_family' => 'Source Sans Pro (Regular)']); // Additional parameters supplied to the webhook Setting('LABEL_PRINTER_HOOK_JSON', false); // TRUE to use JSON or FALSE to use normal POST request variables -Setting('LABEL_PRINTER_INCLUDE_DETAILS', false); // TRUE to include details for the object as well // Thermal printer options diff --git a/controllers/BatteriesApiController.php b/controllers/BatteriesApiController.php index 323b0638..8e5b2861 100644 --- a/controllers/BatteriesApiController.php +++ b/controllers/BatteriesApiController.php @@ -69,18 +69,14 @@ class BatteriesApiController extends BaseApiController { try { - $battery = $this->getDatabase()->batteries()->where('id', $args['batteryId'])->fetch(); + $batteryDetails = $this->getBatteriesService()->GetBatteryDetails($args['batteryId']); $webhookData = array_merge([ - 'battery' => $battery->name, + 'battery' => $batteryDetails->battery->name, 'grocycode' => (string)(new Grocycode(Grocycode::BATTERY, $args['batteryId'])), + 'details' => $batteryDetails, ], GROCY_LABEL_PRINTER_PARAMS); - if (GROCY_LABEL_PRINTER_INCLUDE_DETAILS) - { - $webhookData['details'] = $this->getBatteriesService()->GetBatteryDetails($battery->id); - } - if (GROCY_LABEL_PRINTER_RUN_SERVER) { (new WebhookRunner())->run(GROCY_LABEL_PRINTER_WEBHOOK, $webhookData, GROCY_LABEL_PRINTER_HOOK_JSON); diff --git a/controllers/ChoresApiController.php b/controllers/ChoresApiController.php index 9472452e..48c84ce1 100644 --- a/controllers/ChoresApiController.php +++ b/controllers/ChoresApiController.php @@ -120,18 +120,14 @@ class ChoresApiController extends BaseApiController { try { - $chore = $this->getDatabase()->chores()->where('id', $args['choreId'])->fetch(); + $choreDetails = $this->getChoresService()->GetChoreDetails($args['choreId']); $webhookData = array_merge([ - 'chore' => $chore->name, + 'chore' => $choreDetails->chore->name, 'grocycode' => (string)(new Grocycode(Grocycode::CHORE, $args['choreId'])), + 'details' => $choreDetails, ], GROCY_LABEL_PRINTER_PARAMS); - if (GROCY_LABEL_PRINTER_INCLUDE_DETAILS) - { - $webhookData['details'] = $this->getChoresService()->GetChoreDetails($chore->id); - } - if (GROCY_LABEL_PRINTER_RUN_SERVER) { (new WebhookRunner())->run(GROCY_LABEL_PRINTER_WEBHOOK, $webhookData, GROCY_LABEL_PRINTER_HOOK_JSON); diff --git a/controllers/StockApiController.php b/controllers/StockApiController.php index ff9db643..93ae29ae 100644 --- a/controllers/StockApiController.php +++ b/controllers/StockApiController.php @@ -672,18 +672,14 @@ class StockApiController extends BaseApiController { try { - $product = $this->getDatabase()->products()->where('id', $args['productId'])->fetch(); + $productDetails = $this->getStockService()->GetProductDetails($args['productId']); $webhookData = array_merge([ - 'product' => $product->name, + 'product' => $productDetails->product->name, 'grocycode' => (string)(new Grocycode(Grocycode::PRODUCT, $product->id)), + 'details' => $productDetails, ], GROCY_LABEL_PRINTER_PARAMS); - if (GROCY_LABEL_PRINTER_INCLUDE_DETAILS) - { - $webhookData['details'] = $this->getStockService()->GetProductDetails($product->id); - } - if (GROCY_LABEL_PRINTER_RUN_SERVER) { (new WebhookRunner())->run(GROCY_LABEL_PRINTER_WEBHOOK, $webhookData, GROCY_LABEL_PRINTER_HOOK_JSON); @@ -702,19 +698,15 @@ class StockApiController extends BaseApiController try { $stockEntry = $this->getDatabase()->stock()->where('id', $args['entryId'])->fetch(); - $product = $this->getDatabase()->products()->where('id', $stockEntry->product_id)->fetch(); + $productDetails = $this->getStockService()->GetProductDetails($stockEntry->product_id); $webhookData = array_merge([ - 'product' => $product->name, + 'product' => $productDetails->product->name, 'grocycode' => (string)(new Grocycode(Grocycode::PRODUCT, $stockEntry->product_id, [$stockEntry->stock_id])), + 'details' => $productDetails, + 'stock_entry' => $stockEntry, ], GROCY_LABEL_PRINTER_PARAMS); - if (GROCY_LABEL_PRINTER_INCLUDE_DETAILS) - { - $webhookData['details'] = $this->getStockService()->GetProductDetails($product->id); - $webhookData['details']['stock_entry'] = $stockEntry; - } - if (GROCY_FEATURE_FLAG_STOCK_BEST_BEFORE_DATE_TRACKING) { $webhookData['due_date'] = $this->getLocalizationService()->__t('DD') . ': ' . $stockEntry->best_before_date; diff --git a/services/StockService.php b/services/StockService.php index 8bbb9f9d..aba6ef2b 100644 --- a/services/StockService.php +++ b/services/StockService.php @@ -227,14 +227,10 @@ class StockService extends BaseService $webhookData = array_merge([ 'product' => $productDetails->product->name, 'grocycode' => (string)(new Grocycode(Grocycode::PRODUCT, $productId, [$stockId])), + 'details' => $productDetails, + 'stock_entry' => $stockRow, ], GROCY_LABEL_PRINTER_PARAMS); - if (GROCY_LABEL_PRINTER_INCLUDE_DETAILS) - { - $webhookData['details'] = $productDetails; - $webhookData['details']['stock_entry'] = $stockRow; - } - if (GROCY_FEATURE_FLAG_STOCK_BEST_BEFORE_DATE_TRACKING) { $webhookData['due_date'] = $this->getLocalizationService()->__t('DD') . ': ' . $bestBeforeDate; @@ -284,14 +280,10 @@ class StockService extends BaseService $webhookData = array_merge([ 'product' => $productDetails->product->name, 'grocycode' => (string)(new Grocycode(Grocycode::PRODUCT, $productId, [$stockId])), + 'details' => $productDetails, + 'stock_entry' => $stockRow, ], GROCY_LABEL_PRINTER_PARAMS); - if (GROCY_LABEL_PRINTER_INCLUDE_DETAILS) - { - $webhookData['details'] = $productDetails; - $webhookData['details']['stock_entry'] = $stockRow; - } - if (GROCY_FEATURE_FLAG_STOCK_BEST_BEFORE_DATE_TRACKING) { $webhookData['due_date'] = $this->getLocalizationService()->__t('DD') . ': ' . $bestBeforeDate; @@ -1021,14 +1013,10 @@ class StockService extends BaseService $webhookData = array_merge([ 'product' => $productDetails->product->name, 'grocycode' => (string)(new Grocycode(Grocycode::PRODUCT, $productId, [$stockEntry->stock_id])), + 'details' => $productDetails, + 'stock_entry' => $stockEntry, ], GROCY_LABEL_PRINTER_PARAMS); - if (GROCY_LABEL_PRINTER_INCLUDE_DETAILS) - { - $webhookData['details'] = $productDetails; - $webhookData['details']['stock_entry'] = $stockEntry; - } - if (GROCY_FEATURE_FLAG_STOCK_BEST_BEFORE_DATE_TRACKING) { $webhookData['due_date'] = $this->getLocalizationService()->__t('DD') . ': ' . $newBestBeforeDate; @@ -1339,14 +1327,10 @@ class StockService extends BaseService $webhookData = array_merge([ 'product' => $productDetails->product->name, 'grocycode' => (string)(new Grocycode(Grocycode::PRODUCT, $productId, [$stockEntry->stock_id])), + 'details' => $productDetails, + 'stock_entry' => $stockEntry, ], GROCY_LABEL_PRINTER_PARAMS); - if (GROCY_LABEL_PRINTER_INCLUDE_DETAILS) - { - $webhookData['details'] = $productDetails; - $webhookData['details']['stock_entry'] = $stockEntry; - } - if (GROCY_FEATURE_FLAG_STOCK_BEST_BEFORE_DATE_TRACKING) { $webhookData['due_date'] = $this->getLocalizationService()->__t('DD') . ': ' . $newBestBeforeDate;