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