project = $args['project']; } else { wp_die( __( 'ERROR: Wrong arguments', 'wp-data-access' ) ); } $args['allow_import'] = 'off'; parent::__construct( $args ); $this->message_confirm_delete = __( "Delete current item and all its relationships?\\nThis action cannot be undone.\\n\'Cancel\' to stop, \'OK\' to delete.", 'wp-data-access' ); if ( isset( $args['where_clause'] ) && '' !== $args['where_clause'] ) { $this->where = $args['where_clause']; } if ( isset( $args['orderby_clause'] ) && '' !== $args['orderby_clause'] ) { $this->orderby = $args['orderby_clause']; } } /** * Overwrites method bind_action_buttons to set message_confirm_delete */ protected function bind_action_buttons() { ?> project->get_mode() ) { unset( $actions['edit'] ); unset( $actions['delete'] ); ?> allow_delete ) { $title = __( 'Delete parent row and its child rows', 'wp-data-access' ); $actions['delete'] = sprintf( ' %s ', $this->message_confirm_delete, '#delete_form_' . strval( self::$list_number - 1 ), __( 'Delete', 'wp-data-access' ) ); } } } /** * Overwrite method * * @param array $item * * @return string */ protected function add_parent_args_as_string( $item ) { $parent_args = ''; if ( isset( $this->project ) ) { $parents = $this->project->get_parent(); if ( isset( $parents['key'] ) && is_array( $parents['key'] ) ) { foreach ( $parents['key'] as $key ) { $value = null; if ( isset( $item[ $key ] ) ) { $value = $item[ $key ]; } $parent_args .= ""; } } } return $parent_args; } /** * Overwrite method get_bulk_actions to add action 'Delete Permanently' * * @return array */ public function get_bulk_actions() { if ( 'view' === $this->project->get_mode() ) { return ''; } if ( ! $this->bulk_actions_enabled ) { // Bulk actions disabled. return ''; } if ( empty( $this->wpda_list_columns->get_table_primary_key() ) ) { // Tables has no primary key: no bulk actions allowed! // Primary key is neccesary to ensure uniqueness. return ''; } if ( 'off' !== $this->allow_delete ) { $actions = parent::get_bulk_actions(); } else { $actions = array(); } return $actions; } /** * Overwrites method delete_row to delete child rows on parent delete * * @param string $where where clause * @param string $engine connect or empty * * @return mixed */ public function delete_row( $where, $engine = '' ) { foreach ( $this->project->get_children() as $child ) { if ( isset( $child['relation_nm'] ) ) { $table_name = $child['relation_nm']['child_table']; $row_to_be_deleted = array(); $i = 0; foreach ( $where as $key ) { $row_to_be_deleted[ $child['relation_nm']['child_table_where'][ $i ] ] = $key; $i ++; } $this->delete_row_relationship( $table_name, $row_to_be_deleted ); } elseif ( isset( $child['relation_1n'] ) ) { $table_name = $child['table_name']; $row_to_be_deleted = array(); $i = 0; foreach ( $where as $key ) { $row_to_be_deleted[ $child['relation_1n']['child_key'][ $i ] ] = $key; $i ++; } $this->delete_row_relationship( $table_name, $row_to_be_deleted ); } } return parent::delete_row( $where, $engine ); } /** * Delete relationship * * @param string $table_name Database table name * @param string $where SQL where clause * * @return mixed Return value of SQL delete */ public function delete_row_relationship( $table_name, $where ) { $wpdadb = WPDADB::get_db_connection( $this->schema_name ); if ( null === $wpdadb ) { wp_die( sprintf( __( 'ERROR - Remote database %s not available', 'wp-data-access' ), esc_attr( $this->schema_name ) ) ); } $cannot_delete_from_view = new WPDA_Dictionary_Exist( $this->schema_name, $table_name ); if ( $cannot_delete_from_view->is_view() ) { // Cannot delete rows from view return; } return $wpdadb->delete( $table_name, $where ); // db call ok; no-cache ok. } /** * Overwrites method add_header_button to add arguments */ protected function add_header_button() { if ( 'edit' === $this->project->get_mode() && 'off' !== $this->allow_insert ) { if ( is_admin() ) { $url = "?page={$this->page}"; } else { $url = ''; } ?>
wpda_import ) { $this->wpda_import->add_button( __( 'Import', 'wp-data-access' ) ); } } } } }