ColumnRequest
4 years ago
ListScreen
4 years ago
Middleware
4 years ago
AjaxColumnRequest.php
4 years ago
AjaxColumnValue.php
4 years ago
AjaxGeneralOptions.php
4 years ago
AjaxRequestCustomFieldKeys.php
4 years ago
AjaxScreenOptions.php
4 years ago
ColumnRequest.php
4 years ago
DefaultColumns.php
4 years ago
ListScreenRestoreColumns.php
4 years ago
RestoreSettingsRequest.php
4 years ago
TableListScreenSetter.php
4 years ago
ColumnRequest.php
70 lines
| 1 | <?php |
| 2 | |
| 3 | namespace AC\Controller; |
| 4 | |
| 5 | use AC; |
| 6 | use AC\Column\Placeholder; |
| 7 | use AC\View; |
| 8 | |
| 9 | abstract class ColumnRequest { |
| 10 | |
| 11 | /** |
| 12 | * @return AC\Column |
| 13 | */ |
| 14 | abstract protected function get_column( AC\Request $request, AC\ListScreen $list_screen ); |
| 15 | |
| 16 | public function request( AC\Request $request ) { |
| 17 | $list_screen = AC\ListScreenTypes::instance()->get_list_screen_by_key( $request->get( 'list_screen' ) ); |
| 18 | |
| 19 | if ( ! $list_screen ) { |
| 20 | exit; |
| 21 | } |
| 22 | |
| 23 | $column = $this->get_column( $request, $list_screen ); |
| 24 | |
| 25 | if ( ! $column ) { |
| 26 | wp_send_json_error( [ |
| 27 | 'type' => 'message', |
| 28 | 'error' => sprintf( __( 'Please visit the %s screen once to load all available columns', 'codepress-admin-columns' ), ac_helper()->html->link( $list_screen->get_screen_link(), $list_screen->get_label() ) ), |
| 29 | ] ); |
| 30 | } |
| 31 | |
| 32 | $current_original_columns = (array) json_decode( $request->get( 'current_original_columns', '' ), true ); |
| 33 | |
| 34 | // Not cloneable message |
| 35 | if ( in_array( $column->get_type(), $current_original_columns ) ) { |
| 36 | wp_send_json_error( [ |
| 37 | 'type' => 'message', |
| 38 | 'error' => sprintf( |
| 39 | __( '%s column is already present and can not be duplicated.', 'codepress-admin-columns' ), |
| 40 | '<strong>' . $column->get_label() . '</strong>' ), |
| 41 | ] ); |
| 42 | } |
| 43 | |
| 44 | // Placeholder message |
| 45 | if ( $column instanceof Placeholder ) { |
| 46 | wp_send_json_error( [ |
| 47 | 'type' => 'message', |
| 48 | 'error' => $column->get_message(), |
| 49 | ] ); |
| 50 | } |
| 51 | |
| 52 | wp_send_json_success( $this->render_column( $column ) ); |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * @param AC\Column $column |
| 57 | * |
| 58 | * @return string |
| 59 | */ |
| 60 | private function render_column( AC\Column $column ) { |
| 61 | $view = new View( [ |
| 62 | 'column' => $column, |
| 63 | ] ); |
| 64 | |
| 65 | $view->set_template( 'admin/edit-column' ); |
| 66 | |
| 67 | return $view->render(); |
| 68 | } |
| 69 | |
| 70 | } |