Skip to content

Commit

Permalink
Merge pull request #643 from gravityview/develop
Browse files Browse the repository at this point in the history
1.16.2.2
  • Loading branch information
zackkatz committed Feb 17, 2016
2 parents 1ca2d37 + fb16b30 commit 2adc18e
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 27 deletions.
4 changes: 2 additions & 2 deletions gravityview.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* Plugin Name: GravityView
* Plugin URI: http://gravityview.co
* Description: Create directories based on a Gravity Forms form, insert them using a shortcode, and modify how they output.
* Version: 1.16.2.1
* Version: 1.16.2.2
* Author: Katz Web Services, Inc.
* Author URI: http://www.katzwebservices.com
* Text Domain: gravityview
Expand Down Expand Up @@ -89,7 +89,7 @@
*/
final class GravityView_Plugin {

const version = '1.16.2.1';
const version = '1.16.2.2';

private static $instance;

Expand Down
96 changes: 84 additions & 12 deletions includes/extensions/edit-entry/class-edit-entry-render.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class GravityView_Edit_Entry_Render {

/**
* Gravity Forms form array (it won't get changed during this class lifecycle)
* @since 1.16.3
* @since 1.16.2.1
* @var array
*/
var $original_form;
Expand All @@ -72,6 +72,18 @@ class GravityView_Edit_Entry_Render {
*/
var $form_after_validation = null;

/**
* Hold an array of GF field objects that have calculation rules
* @var array
*/
var $fields_with_calculation = array();

/**
* Hold an array of GF field objects with type 'total'
* @var array
*/
var $total_fields = array();

/**
* Gravity Forms form id
*
Expand Down Expand Up @@ -279,7 +291,7 @@ function process_save() {
do_action('gravityview_log_debug', 'GravityView_Edit_Entry[process_save] Submission is valid.' );

/**
* @hack This step is needed to unset the adminOnly from form fields
* @hack This step is needed to unset the adminOnly from form fields, to add the calculation fields
*/
$form = $this->form_prepare_for_save();

Expand All @@ -295,6 +307,9 @@ function process_save() {
$this->maybe_update_post_fields( $form );
}

// Process calculation fields
$this->update_calculation_fields();

// Perform actions normally performed after updating a lead
$this->after_update();

Expand Down Expand Up @@ -352,7 +367,8 @@ public function modify_fileupload_settings( $plupload_init, $form_id, $instance
* @return array $form
*/
private function form_prepare_for_save() {
$form = $this->original_form;

$form = $this->form;

foreach( $form['fields'] as &$field ) {

Expand All @@ -368,6 +384,52 @@ private function form_prepare_for_save() {
return $form;
}

private function update_calculation_fields() {

$form = $this->original_form;
$update = false;

// get the most up to date entry values
$entry = GFAPI::get_entry( $this->entry['id'] );

if( !empty( $this->fields_with_calculation ) ) {
$update = true;
foreach ( $this->fields_with_calculation as $calc_field ) {
$inputs = $calc_field->get_entry_inputs();
if ( is_array( $inputs ) ) {
foreach ( $inputs as $input ) {
$input_name = 'input_' . str_replace( '.', '_', $input['id'] );
$entry[ strval( $input['id'] ) ] = RGFormsModel::prepare_value( $form, $calc_field, '', $input_name, $entry['id'], $entry );
}
} else {
$input_name = 'input_' . str_replace( '.', '_', $calc_field->id);
$entry[ strval( $calc_field->id ) ] = RGFormsModel::prepare_value( $form, $calc_field, '', $input_name, $entry['id'], $entry );
}
}

}

//saving total field as the last field of the form.
if ( ! empty( $this->total_fields ) ) {
$update = true;
foreach ( $this->total_fields as $total_field ) {
$input_name = 'input_' . str_replace( '.', '_', $total_field->id);
$entry[ strval( $total_field->id ) ] = RGFormsModel::prepare_value( $form, $total_field, '', $input_name, $entry['id'], $entry );
}
}

if( $update ) {

$return_entry = GFAPI::update_entry( $entry );

if( is_wp_error( $return_entry ) ) {
do_action( 'gravityview_log_error', 'Updating the entry calculation and total fields failed', $return_entry );
} else {
do_action( 'gravityview_log_debug', 'Updating the entry calculation and total fields succeeded' );
}
}
}


/**
* Loop through the fields being edited and if they include Post fields, update the Entry's post object
Expand All @@ -390,7 +452,10 @@ function maybe_update_post_fields( $form ) {

$updated_post = $original_post = get_post( $post_id );

foreach ( $this->entry as $field_id => $value ) {
// get the most up to date entry values
$entry = GFAPI::get_entry( $this->entry['id'] );

foreach ( $entry as $field_id => $value ) {

//todo: only run through the edit entry configured fields

Expand Down Expand Up @@ -426,11 +491,11 @@ function maybe_update_post_fields( $form ) {
if( isset( $value[ strval( $field_id ) ] ) ) {
foreach( $value as $input_id => $val ) {
$input_name = 'input_' . str_replace( '.', '_', $input_id );
$this->entry[ strval( $input_id ) ] = RGFormsModel::prepare_value( $form, $field, $val, $input_name, $this->entry['id'] );
$entry[ strval( $input_id ) ] = RGFormsModel::prepare_value( $form, $field, $val, $input_name, $entry['id'], $entry );
}
} else {
$input_name = 'input_' . str_replace( '.', '_', $field_id );
$this->entry[ strval( $field_id ) ] = RGFormsModel::prepare_value( $form, $field, $value, $input_name, $this->entry['id'] );
$entry[ strval( $field_id ) ] = RGFormsModel::prepare_value( $form, $field, $value, $input_name, $entry['id'], $entry );
}

break;
Expand Down Expand Up @@ -462,7 +527,7 @@ function maybe_update_post_fields( $form ) {

// We have a new image

$value = RGFormsModel::prepare_value( $form, $field, $value, $input_name, $this->entry['id'] );
$value = RGFormsModel::prepare_value( $form, $field, $value, $input_name, $entry['id'] );

// is this field set as featured image, if not, leave
if ( ! $field->postFeaturedImage ) {
Expand Down Expand Up @@ -500,7 +565,7 @@ function maybe_update_post_fields( $form ) {

// Same image although the image title, caption or description might have changed

$ary = ! empty( $this->entry[ $field_id ] ) ? explode( '|:|', $this->entry[ $field_id ] ) : array();
$ary = ! empty( $entry[ $field_id ] ) ? explode( '|:|', $entry[ $field_id ] ) : array();
$img_url = rgar( $ary, 0 );

// is this really the same image or something went wrong ?
Expand Down Expand Up @@ -542,13 +607,13 @@ function maybe_update_post_fields( $form ) {
}

//ignore fields that have not changed
if ( $value === rgget( (string) $field_id, $this->entry ) ) {
if ( $value === rgget( (string) $field_id, $entry ) ) {
continue;
}

// update entry
if( 'post_category' !== $field->type ) {
$this->entry[ strval( $field_id ) ] = $value;
$entry[ strval( $field_id ) ] = $value;
}

$update_entry = true;
Expand All @@ -559,7 +624,7 @@ function maybe_update_post_fields( $form ) {

if( $update_entry ) {

$return_entry = GFAPI::update_entry( $this->entry );
$return_entry = GFAPI::update_entry( $entry );

if( is_wp_error( $return_entry ) ) {
do_action( 'gravityview_log_error', 'Updating the entry post fields failed', $return_entry );
Expand Down Expand Up @@ -1382,9 +1447,16 @@ private function filter_fields( $fields, $configured_fields ) {
// First, remove blacklist or calculation fields
foreach ( $fields as $key => $field ) {

// Remove the fields that have calculation properties
// Remove the fields that have calculation properties and keep them to be used later
// @since 1.16.2
if( $field->has_calculation() ) {
$this->fields_with_calculation[] = $field;
unset( $fields[ $key ] );
}

// process total field after all fields have been saved
if ( $field->type == 'total' ) {
$this->total_fields[] = $field;
unset( $fields[ $key ] );
}

Expand Down
26 changes: 13 additions & 13 deletions languages/gravityview.pot
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# This file is distributed under the GPLv2 or later.
msgid ""
msgstr ""
"Project-Id-Version: GravityView 1.16.3\n"
"Project-Id-Version: GravityView 1.16.2.2\n"
"Report-Msgid-Bugs-To: https://gravityview.co/support/\n"
"POT-Creation-Date: 2015-04-10 17:11-0700\n"
"MIME-Version: 1.0\n"
Expand Down Expand Up @@ -282,7 +282,7 @@ msgstr ""
#: includes/class-gravityview-entry-link-shortcode.php:205
#: includes/extensions/edit-entry/class-edit-entry-admin.php:58
#: includes/extensions/edit-entry/class-edit-entry-admin.php:116
#: includes/extensions/edit-entry/class-edit-entry-render.php:640
#: includes/extensions/edit-entry/class-edit-entry-render.php:705
#: includes/extensions/edit-entry/fields/edit_link.php:14
msgid "Edit Entry"
msgstr ""
Expand Down Expand Up @@ -1641,43 +1641,43 @@ msgstr ""
msgid "Make field editable to:"
msgstr ""

#: includes/extensions/edit-entry/class-edit-entry-render.php:687
#: includes/extensions/edit-entry/class-edit-entry-render.php:752
msgid "There was a problem with your submission."
msgstr ""

#: includes/extensions/edit-entry/class-edit-entry-render.php:687
#: includes/extensions/edit-entry/class-edit-entry-render.php:752
msgid "Errors have been highlighted below."
msgstr ""

#: includes/extensions/edit-entry/class-edit-entry-render.php:693
#: includes/extensions/edit-entry/class-edit-entry-render.php:758
msgid "Entry Updated. %sReturn to Entry%s"
msgstr ""

#: includes/extensions/edit-entry/class-edit-entry-render.php:819
#: includes/extensions/edit-entry/class-edit-entry-render.php:884
msgid "You don’t have permission to edit this post."
msgstr ""

#: includes/extensions/edit-entry/class-edit-entry-render.php:826
#: includes/extensions/edit-entry/class-edit-entry-render.php:891
msgid "This field is not editable; the post no longer exists."
msgstr ""

#: includes/extensions/edit-entry/class-edit-entry-render.php:1191
#: includes/extensions/edit-entry/class-edit-entry-render.php:1256
msgid "Maximum number of files reached"
msgstr ""

#: includes/extensions/edit-entry/class-edit-entry-render.php:1588
#: includes/extensions/edit-entry/class-edit-entry-render.php:1660
msgid "The link to edit this entry is not valid; it may have expired."
msgstr ""

#: includes/extensions/edit-entry/class-edit-entry-render.php:1594
#: includes/extensions/edit-entry/class-edit-entry-render.php:1666
msgid "You do not have permission to edit this entry."
msgstr ""

#: includes/extensions/edit-entry/class-edit-entry-render.php:1598
#: includes/extensions/edit-entry/class-edit-entry-render.php:1670
msgid "You cannot edit the entry; it is in the trash."
msgstr ""

#: includes/extensions/edit-entry/class-edit-entry-render.php:1638
#: includes/extensions/edit-entry/class-edit-entry-render.php:1710
msgid "You do not have permission to edit this field."
msgstr ""

Expand Down Expand Up @@ -2752,7 +2752,7 @@ msgctxt "User capability"
msgid "Entry Creator"
msgstr ""

#: includes/extensions/edit-entry/class-edit-entry-render.php:1614
#: includes/extensions/edit-entry/class-edit-entry-render.php:1686
msgctxt "Link shown when invalid Edit Entry link is clicked"
msgid "Go back."
msgstr ""
Expand Down
4 changes: 4 additions & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ Beautifully display your Gravity Forms entries. Learn more on [gravityview.co](h

== Changelog ==

= 1.16.2.2 on February 17 =

* This fixes Edit Entry issues introduced by 1.16.2.1. If you are running 1.16.2.1, please update. Sorry for the inconvenience!

= 1.16.2.1 on February 16 =

* Fixed: Edit Entry calculation fields not being able to calculate values when the required fields weren't included in Edit Entry layout
Expand Down

0 comments on commit 2adc18e

Please sign in to comment.