form_id = $form_id; $fusion_forms = new Fusion_Form_DB_Forms(); $this->form_fields = $fusion_forms->get_form_fields( $this->form_id ); // Get all field names and not empty labels. foreach ( $this->form_fields as $key => $field_object ) { $this->field_names[] = $field_object->field_name; // Use field name if label is empty, for example hidden fields. if ( isset( $field_object->field_label ) && '' !== $field_object->field_label ) { $this->field_labels[] = $field_object->field_label; } } // Use labels if all fields have unique labels, otherwise use field names. $labels = $this->are_labels_valid() ? $this->field_labels : map_deep( $this->field_names, 'Fusion_Builder_Form_Helper::fusion_name_to_label' ); // We don't need all. $labels = array_slice( $labels, 0, 7 ); // Add actions column at the end. if ( 0 !== count( $this->form_fields ) ) { array_push( $labels, 'Actions' ); } if ( current_user_can( apply_filters( 'awb_role_manager_access_capability', 'moderate_comments', 'fusion_form' ) ) ) { $this->columns = [ 'cb' => '', ]; } foreach ( $labels as $key => $label ) { $this->columns[] = $label; } $this->no_entries_text = __( 'No form entries submitted yet.', 'fusion-builder' ); } /** * * Set bulk actions dropdown. * * @since 1.0 * @access public * @return array */ public function get_bulk_actions() { $actions = []; if ( current_user_can( apply_filters( 'awb_role_manager_access_capability', 'moderate_comments', 'fusion_form' ) ) ) { $actions = [ 'awb_bulk_delete_entries' => esc_html__( 'Delete Entries', 'fusion-builder' ), ]; } return $actions; } /** * Set checkbox for bulk selection and actions. * * @since 1.0 * @access public * @param array $item Data. * @return string */ public function column_cb( $item ) { if ( current_user_can( apply_filters( 'awb_role_manager_access_capability', 'moderate_comments', 'fusion_form' ) ) ) { return ""; } return ''; } /** * Prepare the items for the table to process. * * @since 3.1 * @access public * @param int $per_page number of items per page. * @param int $current_page Current page. * @return void */ public function prepare_items( $per_page = 15, $current_page = 0 ) { $submissions = new Fusion_Form_DB_Submissions(); $columns = $this->get_columns(); if ( 0 === $current_page ) { $current_page = $this->get_pagenum(); } $submission_args = [ 'where' => [ 'form_id' => (int) $this->form_id ], 'order by' => 'id DESC', ]; // If we want small section, limit query. if ( 1 < $per_page ) { $submission_args['limit'] = $per_page; $submission_args['offset'] = absint( ( $current_page - 1 ) * $per_page ); } // Get submissions. $this->form_submissions = $submissions->get( $submission_args ); $data = $this->table_data(); $hidden = $this->get_hidden_columns(); $sortable = $this->get_sortable_columns(); // Check the form submission type. $fusion_forms = new Fusion_Form_DB_Forms(); $forms = $fusion_forms->get_formatted(); // Count number of entries. $result = $submissions->get( [ 'what' => 'COUNT(id) AS count', 'where' => [ 'form_id' => (int) $this->form_id ], ] ); $total_items = isset( $result[0] ) ? $result[0]->count : 0; $this->set_pagination_args( [ 'total_items' => $total_items, 'per_page' => $per_page, ] ); $this->_column_headers = [ $columns, $hidden, $sortable ]; $this->items = $data; } /** * Override the parent columns method. Defines the columns to use in your listing table. * * @since 3.1 * @access public * @return array */ public function get_columns() { return $this->columns; } /** * Define which columns are hidden * * @since 3.1 * @access public * @return array */ public function get_hidden_columns() { return []; } /** * Define the sortable columns * * @since 3.1 * @access public * @return array */ public function get_sortable_columns() { return []; } /** * Get the table data. * * @since 3.1 * @access public * @return array */ private function table_data() { $data = []; $form_entries = []; $fusion_entries = new Fusion_Form_DB_Entries(); foreach ( $this->form_submissions as $submission ) { $form_entries[ $submission->id ] = $fusion_entries->get( [ 'where' => [ 'submission_id' => $submission->id ], ] ); } foreach ( $form_entries as $key => $entries ) { $entries = (array) $entries; foreach ( $entries as $entry ) { $entry = (array) $entry; if ( isset( $this->form_fields[ $entry['field_id'] ] ) ) { $field_label = $this->are_labels_valid() ? $this->form_fields[ $entry['field_id'] ]->field_label : Fusion_Builder_Form_Helper::fusion_name_to_label( $this->form_fields[ $entry['field_id'] ]->field_name ); $data[ $key ][ $field_label ] = esc_html( $entry['value'] ); } } if ( ! isset( $data[ $key ] ) ) { $data[ $key ] = []; } // Add actions column at the end. $data[ $key ]['Actions'] = $this->column_actions( $data[ $key ], $key ); $data[ $key ]['awb_id'] = $key; } return $data; } /** * Define what data to show on each column of the table * * @since 3.1 * @access public * @param array $item Data. * @param string $column_id - Current column id. * @return string */ public function column_default( $item, $column_id ) { $column_name = $this->columns[ $column_id ]; $value = isset( $item[ $column_name ] ) ? $item[ $column_name ] : ''; $value = $this->format_column_data( $value ); return $value; } /** * Display button with link to display all form fields in popup. * * @since 3.1 * @access public * @param array $entry Singhe entry data. * @param int $key Singhe entry key. * @return string */ public function column_actions( $entry, $key ) { $submissions_obj = new Fusion_Form_DB_Submissions(); $html = '