Skip to content

Commit

Permalink
RESOLVE #3 Include taxonomy in export
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Cannon committed Oct 24, 2014
1 parent 94d7de4 commit f541315
Showing 1 changed file with 37 additions and 21 deletions.
58 changes: 37 additions & 21 deletions includes/controllers/class.phimind_excel_export_plus.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,17 @@ private function _set_query_args() {

$array_fields = array();
$array_custom_fields = array();
if (!empty($_REQUEST['column'])) {
$count_column_name = count($_REQUEST['column']['column_name']);
for ($i = 0 ; $i < $count_column_name; $i++) {
if (!empty($_REQUEST['column']['column_name'][$i]) && $_REQUEST['column']['column_name'][$i] != 'custom_field' && empty($this->array_wp_custom_taxonomy[$_REQUEST['column']['column_name'][$i]]) && empty($this->array_wp_custom_columns[$_REQUEST['column']['column_name'][$i]]))
array_push($array_fields, $_REQUEST['column']['column_name'][$i]);
elseif (!empty($this->array_wp_custom_taxonomy[$_REQUEST['column']['column_name'][$i]]) || !empty($this->array_wp_custom_columns[$_REQUEST['column']['column_name'][$i]]))
array_push($array_custom_fields, $_REQUEST['column']['column_name'][$i]);
if ( ! empty( $_REQUEST['column'] ) ) {
$count_column_name = count( $_REQUEST['column']['column_name'] );
for ( $i = 0; $i < $count_column_name; $i++ ) {
$field = $_REQUEST['column']['column_name'][ $i ];
$is_empty_tax = false === stristr( $field, $this->custom_key );
$is_empty_col = empty( $this->array_wp_custom_columns[ $field ] );
if ( ! empty( $field ) && 'custom_field' != $field && $is_empty_tax && $is_empty_col ) {
array_push( $array_fields, $field );
} elseif ( ! $is_empty_tax || ! $is_empty_col ) {
array_push( $array_custom_fields, $field );
}
}
}

Expand Down Expand Up @@ -231,7 +235,8 @@ function _filter_query_for_fields($current_query_args) {
//FETCH ONLY THE FIELDS THAT ARE NOT EMPTY
$array_valid_fields = array();
foreach ($this->query_args['fields'] as $field)
if (!empty($field) && empty($this->array_wp_custom_taxonomy[$field]) && empty($this->array_wp_custom_columns[$field]))
$is_empty_tax = false === stristr( $field, $this->custom_key );
if (!empty($field) && $is_empty_tax && empty($this->array_wp_custom_columns[$field]))
array_push($array_valid_fields, $wpdb->posts.'.'.$field);

//CREATE THE STRING FOR THE FIELDS
Expand Down Expand Up @@ -270,6 +275,7 @@ private function _fetch_posts_records_list() {
$column_name = $_REQUEST['column']['column_name'][$i];

//FETCH META VALUES
$is_empty_tax = false === stristr( $column_name, $this->custom_key );
if ($column_name == 'custom_field') {
$meta_name = $_REQUEST['column']['column_custom_name'][$i];
if (!empty($meta_name)) {
Expand All @@ -279,9 +285,7 @@ private function _fetch_posts_records_list() {
$post->$meta_name = $column_value;
}
}
}
elseif (!empty($this->array_wp_custom_taxonomy[$column_name]) || !empty($this->array_wp_custom_columns[$column_name])) {
error_log( print_r( $column_name, true ) . ':' . __LINE__ . ':' . basename( __FILE__ ) );
} elseif ( ! $is_empty_tax || ! empty( $this->array_wp_custom_columns[$column_name] ) ) {
//FETCH CUSTOM COLUMN VALUES
foreach ($records->posts as $post) {
$field_value = 'TO-DO';
Expand Down Expand Up @@ -316,14 +320,17 @@ private function _fetch_posts_records_list() {
if ( false !== stristr( $column_name, $this->custom_key ) ) {
$parts = explode( $this->custom_separator, $column_name );
$taxonomy = array_pop( $parts );
$terms = wp_get_object_terms( $post->ID, $taxonomy );
if ( ! empty( $terms ) ) {
$holder = array();
foreach( $terms as $term ) {
$holder[] = $term->name;
}
$field_value = implode( ',', $holder );
}

global $wpdb;

$query = "
SELECT GROUP_CONCAT(t.name) as terms
FROM {$wpdb->prefix}term_relationships tr
INNER JOIN {$wpdb->prefix}term_taxonomy tt ON tr.term_taxonomy_id = tt.term_taxonomy_id
INNER JOIN {$wpdb->prefix}terms t ON t.term_id = tt.term_id
WHERE object_id = {$post->ID}
AND taxonomy = '{$taxonomy}'";
$field_value = $wpdb->get_var( $query );
}
break;
}
Expand Down Expand Up @@ -372,12 +379,21 @@ private function _generate_records_table($records) {
$array_data = array();

//SET THE HEADERS FOR THE BASIC FIELDS
foreach ($records->query_vars['fields'] as $field)
foreach ($records->query_vars['fields'] as $field) {
array_push($array_headers, $this->array_wp_columns[$field]);
}

//SET THE HEADERS FOR THE CUSTOM FIELDS
foreach ($records->query_vars['custom_fields'] as $field) {
$header = ! empty( $this->array_wp_custom_taxonomy[$field] ) ? $this->array_wp_custom_taxonomy[$field] : $this->array_wp_custom_columns[$field];
$is_empty_tax = false === stristr( $field, $this->custom_key );
if ( ! $is_empty_tax ) {
$parts = explode( $this->custom_separator, $field );
$header = array_pop( $parts );
$header = ucwords( $header );
} else {
$header = $this->array_wp_custom_columns[$field];
}

array_push( $array_headers, $header );
}

Expand Down

0 comments on commit f541315

Please sign in to comment.