base-table-box.php
88 lines
| 1 | <?php |
| 2 | |
| 3 | |
| 4 | namespace Jet_Form_Builder\Admin\Single_Pages\Meta_Boxes; |
| 5 | |
| 6 | use Jet_Form_Builder\Admin\Table_Advanced_Record_Prepare_Trait; |
| 7 | |
| 8 | abstract class Base_Table_Box extends Base_Meta_Box { |
| 9 | |
| 10 | use Table_Advanced_Record_Prepare_Trait; |
| 11 | |
| 12 | protected $editable_table = false; |
| 13 | protected $show_overflow = false; |
| 14 | protected $show_overflow_control = false; |
| 15 | protected $offset = 0; |
| 16 | protected $limit = 8; |
| 17 | |
| 18 | final public function get_values(): array { |
| 19 | return $this->prepare_list(); |
| 20 | } |
| 21 | |
| 22 | public function get_list(): array { |
| 23 | return $this->get_raw_list( |
| 24 | array( |
| 25 | 'offset' => $this->offset, |
| 26 | 'limit' => $this->limit, |
| 27 | ) |
| 28 | ); |
| 29 | } |
| 30 | |
| 31 | public function get_total(): int { |
| 32 | return 0; |
| 33 | } |
| 34 | |
| 35 | public function get_receive_endpoint(): array { |
| 36 | return array(); |
| 37 | } |
| 38 | |
| 39 | public function after_prepare_record( $prepared, array $record, $column_name ) { |
| 40 | $is_editable = $prepared['editable'] ?? false; |
| 41 | |
| 42 | if ( $is_editable ) { |
| 43 | $this->set_editable_table( true ); |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * @param bool $editable_table |
| 49 | */ |
| 50 | public function set_editable_table( bool $editable_table ) { |
| 51 | $this->editable_table = $editable_table; |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * @return bool |
| 56 | */ |
| 57 | public function is_editable_table(): bool { |
| 58 | return $this->editable_table; |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * @return bool |
| 63 | */ |
| 64 | public function is_show_overflow(): bool { |
| 65 | return $this->show_overflow; |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * @return bool |
| 70 | */ |
| 71 | public function is_show_overflow_control(): bool { |
| 72 | return $this->show_overflow_control; |
| 73 | } |
| 74 | |
| 75 | public function to_array(): array { |
| 76 | return parent::to_array() + array( |
| 77 | 'columns' => $this->get_columns_headings(), |
| 78 | 'render_type' => self::TYPE_TABLE, |
| 79 | 'is_editable_table' => $this->is_editable_table(), |
| 80 | 'total' => $this->get_total(), |
| 81 | 'receive_url' => $this->get_receive_endpoint(), |
| 82 | 'show_overflow' => $this->is_show_overflow(), |
| 83 | 'show_overflow_control' => $this->is_show_overflow_control(), |
| 84 | ); |
| 85 | } |
| 86 | |
| 87 | } |
| 88 |