|
- <?php
- namespace VPSManager;
-
- final class BackupOption
- {
- public const NAMES = ['Backup diario', 'Backup diario VPS'];
-
- // Resolve only groups linked to the product of the authorized service.
- // Definitions describe applicable options; they never prove subscription.
- public static function applicable($productId): array
- {
- $groups = \WHMCS\Database\Capsule::table('tblproductconfiglinks')->where('pid', $productId)->get();
- $seenGroups = []; $keys = [];
- foreach ($groups as $link) {
- if (isset($seenGroups[$link->gid])) continue;
- $seenGroups[$link->gid] = true;
- $options = \WHMCS\Database\Capsule::table('tblproductconfigoptions')->where('gid', $link->gid)->get();
- foreach ($options as $option) {
- if (!in_array($option->optionname, self::NAMES, true)) continue;
- // Only the confirmed Yes/No definition type is supported. This is NOT activation.
- if (!in_array($option->optiontype, [3, '3'], true) || in_array($option->optionname, $keys, true)) {
- throw new \RuntimeException('OPTION_DEFINITION');
- }
- $keys[] = $option->optionname;
- }
- }
- sort($keys, SORT_STRING);
- return $keys;
- }
-
- public static function conflict(array $options): bool
- {
- return array_key_exists(self::NAMES[0], $options) && array_key_exists(self::NAMES[1], $options)
- && $options[self::NAMES[0]] !== $options[self::NAMES[1]];
- }
-
- }
|