project_id = sanitize_text_field( wp_unslash( $args['project_id'] ) ); } elseif ( isset( $_REQUEST['tab'] ) && 'tables' === $_REQUEST['tab'] ) { $this->project_id = 'wpda_sys_tables'; } if ( isset( $args['page_id'] ) ) { $this->page_id = sanitize_text_field( wp_unslash( $args['page_id'] ) ); } $this->project = new WPDP_Project( $this->project_id, $this->page_id ); $this->title = $this->project->get_title(); $this->subtitle = $this->project->get_subtitle(); $this->mode = $this->project->get_mode(); $args['title'] = ( null === $this->title || '' === $this->title ) ? null : $this->title; $args['subtitle'] = $this->subtitle; parent::__construct( $args ); if ( 'edit' === $this->action || 'new' === $this->action || 'view' === $this->action ) { $this->label_type = 'tableform'; } // Overwrite column header text. $this->column_headers = isset( $args['column_headers'] ) ? $args['column_headers'] : ''; if ( isset( $args['where_clause'] ) && '' !== $args['where_clause'] ) { $this->where_clause = $args['where_clause']; } } /** * Overwrite method. */ public function show() { // Prepare columns for list table. Needed in get_column_headers() and handed over to list table to prevent // processing the same queries multiple times. if ( null === $this->wpda_list_columns ) { $this->wpda_list_columns = WPDP_List_Columns_Cache::get_list_columns( $this->schema_name, $this->table_name, $this->label_type ); } $wpda_repository = new WPDA_Repository(); $wpda_repository->inform_user(); switch ( $this->action ) { case 'new': // Show edit form in editing mode to create new records. case 'edit': // Show edit form in editing mode to update records. case 'view': // Show edit form in view mode to view records. $this->display_edit_form(); break; case 'create_table': // Show form to create new table. $this->display_design_menu(); break; default: // Show list (default). $this->display_list_table(); } } /** * Overwrite method. */ protected function display_list_table() { $this->wpda_list_table = new WPDP_List_Table( [ 'schema_name' => $this->schema_name, 'table_name' => $this->table_name, 'wpda_list_columns' => $this->wpda_list_columns, 'column_headers' => $this->column_headers, 'title' => $this->title, 'subtitle' => $this->subtitle, 'mode' => $this->mode, 'where_clause' => $this->where_clause, ] ); $this->wpda_list_table->show(); } /** * Overwrite method. */ public function get_column_headers() { if ( null === $this->wpda_list_columns ) { $this->wpda_list_columns = WPDP_List_Columns_Cache::get_list_columns( $this->schema_name, $this->table_name, $this->label_type ); } return $this->wpda_list_columns->get_table_column_headers(); } } }