id = $entry_id;
$this->form = $form;
$this->populate_entry_data();
}
/**
*
* Populate the class with data
*
* @TODO: Abstract this
*
* @return void
*/
public function populate_entry_data() {
global $wpdb;
// return if we populated the already, ensures single db call
if ( $this->form_id ) {
return;
}
$grid_css_added = false;
$grid_css = '';
$values = array();
$query = "SELECT * FROM {$wpdb->weforms_entries} as entry
LEFT JOIN {$wpdb->weforms_entrymeta} AS meta ON entry.id = meta.weforms_entry_id
WHERE entry.id = {$this->id}";
$results = $wpdb->get_results( $query );
if ( $results ) {
$first_row = reset( $results );
$this->form_id = (int) $first_row->form_id;
$this->user_id = (int) $first_row->user_id;
$this->ip_address = long2ip( $first_row->user_ip );
$this->device = $first_row->user_device;
$this->referer = $first_row->referer;
$this->created = $first_row->created_at;
$this->fields = $this->form->get_field_values();
$this->raw_fields = $this->fields;
foreach ( $results as $result ) {
if ( array_key_exists( $result->meta_key, $this->fields ) ) {
$field = $this->fields[ $result->meta_key ];
$value = $result->meta_value;
$this->raw_fields[ $result->meta_key ]['value'] = $value;
if ( $field['type'] == 'textarea_field' ) {
$value = weforms_format_text( $value );
} elseif ( $field['type'] == 'name_field' ) {
$value = implode( ' ', explode( WeForms::$field_separator, $value ) );
} elseif ( in_array( $field['type'], array( 'dropdown_field', 'radio_field' ) ) ) {
if ( isset( $field['options'] ) && $field['options'] ) {
if ( isset( $field['options'][ $value ] ) ) {
$value = $field['options'][ $value ];
}
}
} elseif ( in_array( $field['type'], array( 'multiple_select', 'checkbox_field' ) ) ) {
$value = explode( WeForms::$field_separator, $value );
$temp_value = $value;
if ( is_array( $value ) && $value ) {
$new_array = array();
foreach ( $value as $option_key ) {
if ( is_array( $field['options'] ) && array_key_exists( $option_key, $field['options'] ) ) {
$new_array[] = $field['options'][ $option_key ];
} else {
$new_array[] = $option_key;
}
}
$value = $new_array;
}
} elseif ( in_array( $field['type'], array( 'image_upload', 'file_upload' ) ) ) {
$file_field = '';
$value = maybe_unserialize( $value );
if ( is_array( $value ) && $value ) {
foreach ( $value as $attachment_id ) {
if ( $field['type'] == 'image_upload' ) {
$thumb = wp_get_attachment_image( $attachment_id, 'thumbnail' );
} else {
$thumb = get_post_field( 'post_title', $attachment_id );
}
$full_size = wp_get_attachment_url( $attachment_id );
$file_field .= sprintf( '%s ', $full_size, $thumb );
}
}
$value = $file_field;
} elseif ( $field['type'] == 'google_map' ) {
list( $lat, $long ) = explode( ',', $value );
$value = array(
'lat' => $lat,
'long' => $long
);
} elseif ( $field['type'] == 'multiple_product' ) {
$field_value = unserialize( $value );
$serialized_value = array();
if ( is_array( $field_value ) ) {
foreach ( $field_value as $key => $sfv ) {
if ( is_array( $sfv ) ) {
$v = array();
foreach ( $sfv as $key => $sv ) {
$sv = str_replace( array( '_', '-' ), ' ', $key ) . ': ' . $sv;
$sv = ucwords( $sv );
$v[] = $sv;
}
$serialized_value[] = implode( '
', $v );
}
}
$value = implode( '
', $serialized_value );
}
} elseif ( $field['type'] == 'checkbox_grid' ) {
$entry_value = unserialize( $value );
if ( $entry_value ) {
$return = '';
$check = '';
if ( ! $grid_css_added ) {
$return = $grid_css;
$grid_css_added = true;
}
$new_val = array();
foreach ( $entry_value as $key => $option_value ) {
$new_val[ $key ] = $option_value;
}
if ( $field['grid_rows'] && count( $field['grid_rows'] ) > 0 && $field['grid_columns'] && count( $field['grid_columns'] ) > 0 ) {
$return .= '