Add blacklist support to base NameValue class, for hiding options when getting entire collection #800

This commit is contained in:
Ramon Gutierrez 2024-05-14 14:45:51 +08:00
parent d52402a2ef
commit be0e69db89
2 changed files with 22 additions and 1 deletions

View file

@ -29,4 +29,8 @@ class JORejectionReason extends NameValue
'no_credit_card' => 'NO CREDIT CARD PAYMENT / NO TERMINAL',
'discount' => 'DISCOUNT',
];
const BLACKLIST = [
self::ADMINISTRATIVE => true,
];
}

View file

@ -4,9 +4,21 @@ namespace App\Ramcar;
class NameValue
{
const BLACKLIST = [];
static public function getCollection()
{
return static::COLLECTION;
$result = [];
$blacklist = static::getBlacklist();
// filter from blacklist
foreach(static::COLLECTION as $key => $row) {
if (!isset($blacklist[$key])) {
$result[] = $row;
}
}
return $result;
}
static public function validate($value)
@ -24,4 +36,9 @@ class NameValue
return 'Unknown';
}
static public function getBlacklist()
{
return static::BLACKLIST ?? [];
}
}