'', // WPForms ID 'search' => '', // Flag to show search box 'show_columns' => '', // Flag to show/hide columns 'exclude_field_ids' => '', // comma separated field IDs to be exclude from table 'pagination' => '', // Flag to turn on/off pagination 'show_entry_date' => '', // Flag to show entry date ), $atts); if (empty($atts['id'])) { return; } $form_id = $atts['id']; if (strtolower($atts['search']) === 'yes') { $this->searchEnabled = true; } if (strtolower($atts['show_columns']) === 'yes') { $this->showColumns = true; } if (strtolower($atts['pagination']) === 'yes') { $this->pagination = true; } if (isset($atts['exclude_field_ids'])) { $this->excludedFieldIds = explode(',', $atts['exclude_field_ids']); } if (isset($atts['show_entry_date'])) { $fields = explode(',', $atts['show_entry_date']); if ($fields[0] === 'yes') { $this->showEntryDate = true; } $fields[1] ? $this->entryDateColumnName = $fields[1] : $this->entryDateColumnName = 'Entry Date'; } //validate if the wpform exists for selected form ID in shortcode $this->form = wpforms()->form->get(absint($form_id)); // If the form doesn't exists, abort. if (empty($this->form)) { return; } $this->form_id = $this->form->ID; $this->enqueue_scripts(); $this->set_form_fields(); $this->set_table_data(); return $this->create_entries_table(); } /** * Enqueues required CSS files and JS files (Bootstarp, fontawesome and bootstrap-table files). * * @return null * @since 1.3.0 * */ private function enqueue_scripts() { wp_enqueue_style('ank-wpforms-custom-css', ANK_WPFORM_ENTRY_BASE_URL . 'assets/css/ank-wpforms-custom-css.css', false, ANK_WPFORM_ENTRY_VERSION); wp_enqueue_style('ank-wpforms-bootstrap-css', ANK_WPFORM_ENTRY_BASE_URL . 'assets/css/bootstrap.min.css', false, ANK_WPFORM_ENTRY_VERSION); wp_enqueue_style('ank-wpforms-bootstrap-table-css', ANK_WPFORM_ENTRY_BASE_URL . 'assets/css/bootstrap-table.min.css', 'bootstrap-css', ANK_WPFORM_ENTRY_VERSION); wp_enqueue_script('ank-wpforms-bootstrap-jquery', ANK_WPFORM_ENTRY_BASE_URL . '/assets/js/bootstrap.bundle.min.js', array('jquery'), ANK_WPFORM_ENTRY_VERSION); wp_enqueue_script('ank-wpforms-bootstrap-table-js', ANK_WPFORM_ENTRY_BASE_URL . '/assets/js/bootstrap-table.min.js', array('ank-wpforms-bootstrap-jquery'), ANK_WPFORM_ENTRY_VERSION); wp_enqueue_script('ank-wpforms-fontawesome', 'https://use.fontawesome.com/d99a831dce.js', array('ank-wpforms-bootstrap-jquery'), ANK_WPFORM_ENTRY_VERSION); } /** * Get field IDs for selected WPForm ID and sets the variable. Logic of mapping table data with its columns is based on field IDs * * @return null * @since 1.3.0 * */ private function set_form_fields() { //TODO: Add option to restrict columns to certain form fields only $fields = wpforms_get_form_fields($this->form_id); $this->fields = $fields; } /** * Function to set columns and row entries of selected form ID * * @return null * @since 1.3.0 * */ private function set_table_data() { $this->columns = $this->get_table_columns(); $this->entries = $this->get_table_entries(); } /** * Gets the columns of based on field IDs of the selected form ID * This function also holds the functionality of excluding of column from the table based on field ID selected in shortcode * * @return array * @since 1.3.0 * */ private function get_table_columns() { $columns = array(); if (empty($this->fields) || !$this->fields) { return; } foreach ($this->fields as $field) { //TODO add the functionality to exclude columns based on $field['id'] . $field['type'] if (!in_array($field['id'], $this->excludedFieldIds)) { $excluded_columns = array(); array_push($this->column_keys, $field['id'] . $field['type']); //store column keys $this->column_keys = array_diff($this->column_keys, $excluded_columns); $column = array($field['id'] . $field['type'] => $field['label']); $columns = array_merge($columns, $column); } } // logic for adding entry date column if ($this->showEntryDate) { array_push($this->column_keys, 'entry_date'); $column = array('entry_date' => $this->entryDateColumnName); $columns = array_merge($columns, $column); } return apply_filters('ank_wpforms_frontend_entries_column', $columns); } /** * Gets the entries of table based on form ID selected in shortcode * * @return array * @since 1.3.0 * */ private function get_table_entries() { $entries = ank_wpforms_entry()->get_class_instance('entry-db')->get_entries($this->form_id); $data = array(); foreach ($entries as $entry) { $temp_data = array(); $json_data = array(); $temp_data = array_merge($temp_data, array('row_id' => $entry->id)); $entry_details = $entry->entry_details; foreach ($entry_details as $entry_detail) { $data_key = $entry_detail['id'] . $entry_detail['type']; $temp_data = array_merge($temp_data, array($data_key => $entry_detail['value'])); //$json_data = array_merge( $json_data, array( $this->columns[$data_key] => $entry_detail['value'] ) ); } $temp_data = array_merge($temp_data, array('entry_date' => date('m/d/Y', strtotime($entry->entry_date)))); $temp_data = array_merge($temp_data, array('viewed' => $entry->viewed)); array_push($data, $temp_data); } return $data; } /** * Generates the table based on the columns and rows set * * @return string * @since 1.3.0 * */ private function create_entries_table() { $content = ''; //$content = '