base-list-box.php
3 years ago
base-meta-box.php
3 years ago
base-table-box.php
3 years ago
meta-box-options-converter.php
3 years ago
meta-box-options.php
3 years ago
meta-box-update-callback.php
3 years ago
meta-table-options-converter.php
3 years ago
meta-table-options.php
3 years ago
base-table-box.php
134 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 | use Jet_Form_Builder\Rest_Api\Rest_Endpoint; |
| 8 | use Jet_Form_Builder\Rest_Api\Traits\Rest_Fetch_Endpoint; |
| 9 | |
| 10 | abstract class Base_Table_Box extends Base_Meta_Box implements |
| 11 | Rest_Fetch_Endpoint, |
| 12 | Meta_Table_Options { |
| 13 | |
| 14 | use Table_Advanced_Record_Prepare_Trait; |
| 15 | |
| 16 | protected $editable_table = false; |
| 17 | protected $editable_table_control = false; |
| 18 | protected $show_overflow = false; |
| 19 | protected $show_overflow_control = false; |
| 20 | protected $offset = 0; |
| 21 | protected $limit = 8; |
| 22 | protected $footer_heading = true; |
| 23 | |
| 24 | final public function get_values(): array { |
| 25 | return $this->prepare_list(); |
| 26 | } |
| 27 | |
| 28 | public function get_list(): array { |
| 29 | return $this->get_raw_list( |
| 30 | array( |
| 31 | 'offset' => $this->offset, |
| 32 | 'limit' => $this->limit, |
| 33 | ) |
| 34 | ); |
| 35 | } |
| 36 | |
| 37 | public function get_stable_limit(): int { |
| 38 | return 0; |
| 39 | } |
| 40 | |
| 41 | public function get_total(): int { |
| 42 | return 0; |
| 43 | } |
| 44 | |
| 45 | public function get_rest_methods(): string { |
| 46 | return ''; |
| 47 | } |
| 48 | |
| 49 | public function get_rest_url(): string { |
| 50 | return ''; |
| 51 | } |
| 52 | |
| 53 | public function after_prepare_record( $prepared, array $record, $column_name ) { |
| 54 | $is_editable = $prepared['editable'] ?? false; |
| 55 | |
| 56 | if ( $is_editable ) { |
| 57 | $this->set_editable_table( true ); |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * @param bool $editable_table |
| 63 | */ |
| 64 | public function set_editable_table( bool $editable_table ) { |
| 65 | $this->editable_table = $editable_table; |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * @return bool |
| 70 | */ |
| 71 | public function is_editable_table(): bool { |
| 72 | return $this->editable_table; |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * @return bool |
| 77 | */ |
| 78 | public function is_show_overflow(): bool { |
| 79 | return $this->show_overflow; |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * @return bool |
| 84 | */ |
| 85 | public function is_show_overflow_control(): bool { |
| 86 | return $this->show_overflow_control; |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * @return bool |
| 91 | */ |
| 92 | public function is_footer_heading(): bool { |
| 93 | return $this->footer_heading; |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * @param bool $footer_heading |
| 98 | */ |
| 99 | public function set_footer_heading( bool $footer_heading ) { |
| 100 | $this->footer_heading = $footer_heading; |
| 101 | } |
| 102 | |
| 103 | /** |
| 104 | * @return bool |
| 105 | */ |
| 106 | public function is_editable_table_control(): bool { |
| 107 | return $this->editable_table_control; |
| 108 | } |
| 109 | |
| 110 | /** |
| 111 | * @param bool $editable_table_control |
| 112 | */ |
| 113 | public function set_editable_table_control( bool $editable_table_control ) { |
| 114 | $this->editable_table_control = $editable_table_control; |
| 115 | } |
| 116 | |
| 117 | public function to_array(): array { |
| 118 | $stable_limit = $this->get_stable_limit(); |
| 119 | |
| 120 | return array_merge( |
| 121 | parent::to_array(), |
| 122 | ( new Meta_Table_Options_Converter( $this ) )->to_array(), |
| 123 | array( |
| 124 | 'render_type' => self::TYPE_TABLE, |
| 125 | 'columns' => $this->get_columns_headings(), |
| 126 | 'total' => $this->get_total(), |
| 127 | 'stable_limit' => $stable_limit ? $stable_limit : null, |
| 128 | 'receive_url' => ( new Rest_Endpoint( $this ) )->to_array(), |
| 129 | ) |
| 130 | ); |
| 131 | } |
| 132 | |
| 133 | } |
| 134 |