From 52a2f38f81bd597eb666d2dd265ded0923324948 Mon Sep 17 00:00:00 2001 From: Jeppe Bundgaard Date: Mon, 26 Jan 2026 18:58:59 +0100 Subject: [PATCH] Add `REVENUE` criteria type and `goals_label_t` trait to enhance goal labeling and criteria management - Introduce `REVENUE` as a new goal criteria type in `goals_criteria_type` enum. - Add `goals_label_t` trait for handling label properties in goal criteria. - Extend `goals_criteria` to support labels, including serialization and input validation. --- .../modules/goals/classes/goals_criteria.php | 8 ++++- .../goals/helpers/goals_criteria_type.php | 2 ++ .../modules/goals/traits/goals_label_t.php | 31 +++++++++++++++++++ 3 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 services/nginx/app/modules/goals/traits/goals_label_t.php diff --git a/services/nginx/app/modules/goals/classes/goals_criteria.php b/services/nginx/app/modules/goals/classes/goals_criteria.php index 557c46c2..2048c28d 100644 --- a/services/nginx/app/modules/goals/classes/goals_criteria.php +++ b/services/nginx/app/modules/goals/classes/goals_criteria.php @@ -7,12 +7,14 @@ use goals\interfaces\goals_criteria_i; use goals\traits\goals_result_parser_t; use goals\traits\goals_target_t; use goals\traits\goals_timeframe_t; +use goals\traits\goals_label_t; class goals_criteria implements goals_criteria_i { use goals_timeframe_t, goals_target_t, - goals_result_parser_t; + goals_result_parser_t, + goals_label_t; /** * The users criteria * @var goals_criteria_users $users @@ -60,6 +62,9 @@ class goals_criteria implements goals_criteria_i if (isset($data['target'])) { $criteria->target = $data['target']; } + if (isset($data['label'])) { + $criteria->label = is_string($data['label']) ? $data['label'] : null; + } if (isset($data['start'])) { $criteria->start = new \DateTime($data['start']); } @@ -161,6 +166,7 @@ class goals_criteria implements goals_criteria_i return [ 'type' => $this->type?->name ?? goals_criteria_type::NONE->name, 'target' => $this->target ?? 0, + 'label' => $this->label, 'start' => ($this->start instanceof \DateTimeInterface) ? $this->start->format(DATE_ATOM) : null, 'end' => ($this->end instanceof \DateTimeInterface) ? $this->end->format(DATE_ATOM) : null, 'users' => $users, diff --git a/services/nginx/app/modules/goals/helpers/goals_criteria_type.php b/services/nginx/app/modules/goals/helpers/goals_criteria_type.php index 280a6450..f096e231 100644 --- a/services/nginx/app/modules/goals/helpers/goals_criteria_type.php +++ b/services/nginx/app/modules/goals/helpers/goals_criteria_type.php @@ -5,12 +5,14 @@ namespace goals\helpers; enum goals_criteria_type { case PRODUCT; // When the goal is related to a product + case REVENUE; // When the goal is related to revenue case NONE; // When there is no specific criteria public static function tryFrom(string $param): ?goals_criteria_type { return match (strtoupper($param)) { 'PRODUCT' => goals_criteria_type::PRODUCT, + 'REVENUE' => goals_criteria_type::REVENUE, 'NONE' => goals_criteria_type::NONE, default => null, }; diff --git a/services/nginx/app/modules/goals/traits/goals_label_t.php b/services/nginx/app/modules/goals/traits/goals_label_t.php new file mode 100644 index 00000000..0e4640b5 --- /dev/null +++ b/services/nginx/app/modules/goals/traits/goals_label_t.php @@ -0,0 +1,31 @@ +label = $label; + } + + /** + * Get the label + * @return string|null + */ + public function getLabel(): ?string + { + return $this->label; + } +}