flexible-shipping
/
src
/
WPDesk
/
FS
/
TableRate
/
Rule
/
PreconfiguredScenarios
/
PredefinedScenario.php
PredefinedScenario.php
161 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Class PredefinedScenario |
| 4 | * |
| 5 | * @package WPDesk\FS\TableRate\Rule\PreconfiguredScenarios |
| 6 | */ |
| 7 | |
| 8 | namespace WPDesk\FS\TableRate\Rule\PreconfiguredScenarios; |
| 9 | |
| 10 | /** |
| 11 | * Predefined scenario.ś |
| 12 | */ |
| 13 | class PredefinedScenario implements \JsonSerializable { |
| 14 | |
| 15 | /** |
| 16 | * @var string |
| 17 | */ |
| 18 | private $category; |
| 19 | |
| 20 | /** |
| 21 | * @var string |
| 22 | */ |
| 23 | private $name; |
| 24 | |
| 25 | /** |
| 26 | * @var string |
| 27 | */ |
| 28 | private $description; |
| 29 | |
| 30 | /** |
| 31 | * @var string |
| 32 | */ |
| 33 | private $documentation_url; |
| 34 | |
| 35 | /** |
| 36 | * @var string |
| 37 | */ |
| 38 | private $rules_json; |
| 39 | |
| 40 | /** |
| 41 | * @var bool |
| 42 | */ |
| 43 | private $available; |
| 44 | |
| 45 | /** |
| 46 | * @var string |
| 47 | */ |
| 48 | private $reason_for_unavailability; |
| 49 | |
| 50 | /** |
| 51 | * @var string |
| 52 | */ |
| 53 | private $requirements; |
| 54 | |
| 55 | /** |
| 56 | * PredefinedScenario constructor. |
| 57 | * |
| 58 | * @param string $category . |
| 59 | * @param string $name . |
| 60 | * @param string $description . |
| 61 | * @param string $documentation_url . |
| 62 | * @param string $rules_json . |
| 63 | * @param bool $available . |
| 64 | * @param string $reason_for_unavailability . |
| 65 | * @param string $requirements . |
| 66 | */ |
| 67 | public function __construct( $category, $name, $description, $documentation_url, $rules_json, $available = true, $reason_for_unavailability = '', $requirements = '' ) { |
| 68 | $this->category = $category; |
| 69 | $this->name = $name; |
| 70 | $this->description = $description; |
| 71 | $this->documentation_url = $documentation_url; |
| 72 | $this->rules_json = $rules_json; |
| 73 | $this->available = $available; |
| 74 | $this->reason_for_unavailability = $reason_for_unavailability; |
| 75 | $this->requirements = $requirements; |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * @return string |
| 80 | */ |
| 81 | public function get_category() { |
| 82 | return $this->category; |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * @return string |
| 87 | */ |
| 88 | public function get_name() { |
| 89 | return $this->name; |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * @return string |
| 94 | */ |
| 95 | public function get_description() { |
| 96 | return $this->description; |
| 97 | } |
| 98 | |
| 99 | /** |
| 100 | * @return string |
| 101 | */ |
| 102 | public function get_documentation_url() { |
| 103 | return $this->documentation_url; |
| 104 | } |
| 105 | |
| 106 | /** |
| 107 | * @return string |
| 108 | */ |
| 109 | public function get_rules_json() { |
| 110 | return $this->rules_json; |
| 111 | } |
| 112 | |
| 113 | /** |
| 114 | * @return bool |
| 115 | */ |
| 116 | public function is_available(): bool { |
| 117 | return $this->available; |
| 118 | } |
| 119 | |
| 120 | /** |
| 121 | * @return string |
| 122 | */ |
| 123 | public function get_reason_for_unavailability(): string { |
| 124 | return $this->reason_for_unavailability; |
| 125 | } |
| 126 | |
| 127 | /** |
| 128 | * @return string |
| 129 | */ |
| 130 | public function get_requirements(): string { |
| 131 | return $this->requirements; |
| 132 | } |
| 133 | |
| 134 | /** |
| 135 | * @return array |
| 136 | */ |
| 137 | public function jsonSerialize(): array { |
| 138 | return [ |
| 139 | 'category' => $this->category, |
| 140 | 'name' => $this->name, |
| 141 | 'description' => $this->description, |
| 142 | 'documentation_url' => $this->documentation_url, |
| 143 | 'rules_json' => $this->rules_json, |
| 144 | 'available' => $this->available, |
| 145 | 'reason_for_unavailability' => $this->reason_for_unavailability, |
| 146 | 'requirements' => $this->requirements, |
| 147 | 'rules_count' => $this->get_rules_count(), |
| 148 | ]; |
| 149 | } |
| 150 | |
| 151 | /** |
| 152 | * @return int |
| 153 | */ |
| 154 | private function get_rules_count() { |
| 155 | $rules = json_decode( $this->rules_json, true ); |
| 156 | |
| 157 | return count( $rules ); |
| 158 | } |
| 159 | |
| 160 | } |
| 161 |