Column.php
82 lines
| 1 | <?php |
| 2 | |
| 3 | namespace IAWP_SCOPED\IAWP\Tables\Columns; |
| 4 | |
| 5 | use IAWP_SCOPED\IAWP\Tables\Groups\Group; |
| 6 | class Column |
| 7 | { |
| 8 | private $id; |
| 9 | private $label; |
| 10 | private $visible; |
| 11 | private $type; |
| 12 | private $requires_woocommerce; |
| 13 | private $exportable; |
| 14 | private $options; |
| 15 | private $filter_placeholder; |
| 16 | private $unavailable_for; |
| 17 | public function __construct($options) |
| 18 | { |
| 19 | $this->id = $options['id']; |
| 20 | $this->label = $options['label']; |
| 21 | $this->visible = $options['visible']; |
| 22 | $this->type = $options['type']; |
| 23 | $this->requires_woocommerce = $options['requires_woocommerce'] ?? \false; |
| 24 | $this->exportable = $options['exportable'] ?? \true; |
| 25 | $this->options = $options['options'] ?? []; |
| 26 | $this->filter_placeholder = $options['filter_placeholder'] ?? ''; |
| 27 | $this->unavailable_for = $options['unavailable_for'] ?? []; |
| 28 | } |
| 29 | public function is_enabled_for_group(Group $group) : bool |
| 30 | { |
| 31 | return !\in_array($group->id(), $this->unavailable_for); |
| 32 | } |
| 33 | public function is_group_dependent() : bool |
| 34 | { |
| 35 | return \count($this->unavailable_for) > 0; |
| 36 | } |
| 37 | public function id() : string |
| 38 | { |
| 39 | return $this->id; |
| 40 | } |
| 41 | public function label() : string |
| 42 | { |
| 43 | return $this->label; |
| 44 | } |
| 45 | public function visible() : bool |
| 46 | { |
| 47 | return $this->visible; |
| 48 | } |
| 49 | public function type() : string |
| 50 | { |
| 51 | return $this->type; |
| 52 | } |
| 53 | public function sort_direction() : string |
| 54 | { |
| 55 | $descending_types = ['int']; |
| 56 | return \in_array($this->type, $descending_types) ? 'desc' : 'asc'; |
| 57 | } |
| 58 | public function set_visibility(bool $visible) : void |
| 59 | { |
| 60 | $this->visible = $visible; |
| 61 | } |
| 62 | public function requires_woocommerce() : bool |
| 63 | { |
| 64 | return $this->requires_woocommerce; |
| 65 | } |
| 66 | public function exportable() : bool |
| 67 | { |
| 68 | return $this->exportable; |
| 69 | } |
| 70 | /** |
| 71 | * @return array List of possible options for this filter such as a list of authors or list of post categories |
| 72 | */ |
| 73 | public function options() : array |
| 74 | { |
| 75 | return $this->options; |
| 76 | } |
| 77 | public function filter_placeholder() : string |
| 78 | { |
| 79 | return $this->filter_placeholder; |
| 80 | } |
| 81 | } |
| 82 |