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.
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace goals\traits;
|
||||
|
||||
trait goals_label_t
|
||||
{
|
||||
/**
|
||||
* Human-friendly label/name for the goal criteria
|
||||
* @var string|null
|
||||
*/
|
||||
public ?string $label = null;
|
||||
|
||||
/**
|
||||
* Set the label
|
||||
* @param string|null $label
|
||||
* @return void
|
||||
*/
|
||||
public function setLabel(?string $label): void
|
||||
{
|
||||
$this->label = $label;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the label
|
||||
* @return string|null
|
||||
*/
|
||||
public function getLabel(): ?string
|
||||
{
|
||||
return $this->label;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user