Skip to content

Commit 99a2aff

Browse files
committed
Resolved comments from github.
1 parent 47aedfb commit 99a2aff

File tree

3 files changed

+120
-103
lines changed

3 files changed

+120
-103
lines changed

includes/class-form-entry-manager.php

Lines changed: 93 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -7,98 +7,97 @@
77
*/
88
class WeForms_Form_Entry_Manager {
99

10-
/**
11-
* The form id
12-
*
13-
* @var int
14-
*/
15-
private $id = 0;
16-
17-
/**
18-
* The form object
19-
*
20-
* @var \WeForms_Form
21-
*/
22-
private $form;
23-
24-
/**
25-
* The constructor
26-
*
27-
* @param int $form_id
28-
* @param \WeForms_Form $form
29-
*/
30-
public function __construct( $form_id, $form ) {
31-
$this->id = $form_id;
32-
$this->form = $form;
33-
}
34-
35-
/**
36-
* Get all the form entries
37-
*
38-
* @return array
39-
*/
40-
public function all() {
41-
return weforms_get_form_entries( $this->id );
42-
}
43-
44-
/**
45-
* Get a single entry
46-
*
47-
* @param int $entry_id
48-
*
49-
* @return mixed
50-
*/
51-
public function get( $entry_id ) {
52-
return new WeForms_Form_Entry( $entry_id, $this->form );
53-
}
54-
55-
/**
56-
* Format Entry Value.
57-
*
58-
* @static
59-
* @param array $field
60-
*
61-
* @return array $field
62-
*/
63-
public static function format_entry_value( $field ) {
64-
switch ( $field['template'] ) {
65-
66-
case 'radio_field':
67-
$value = array_search( $field['value'], $field['options'] );
68-
$field['value'] = esc_html( 'Option: ' . $field['value'] . ' - ' . 'Value: ' . $value );
69-
70-
break;
71-
72-
case 'checkbox_field':
73-
$field_formatted = array();
74-
foreach ( $field['value'] as $option ) {
75-
$value = array_search( $option, $field['options'] );
76-
$field_formatted[] = esc_html( 'Option: ' . $option . ' - ' . 'Value: ' . $value );
77-
}
78-
$field['value'] = array_replace( $field['value'], $field_formatted );
79-
80-
break;
81-
82-
case 'multiple_select':
83-
$field_formatted = array();
84-
foreach ( $field['value'] as $option ) {
85-
$value = array_search( $option, $field['options'] );
86-
$field_formatted[] = esc_html( 'Option: ' . $option . ' - ' . 'Value: ' . $value );
87-
}
88-
$field['value'] = array_replace( $field['value'], $field_formatted );
89-
90-
break;
91-
92-
case 'dropdown_field':
93-
$value = array_search( $field['value'], $field['options'] );
94-
$field['value'] = esc_html( 'Option: ' . $field['value'] . ' - ' . 'Value: ' . $value );
95-
96-
break;
97-
98-
default:
99-
// Do nothing if value format does not need to be changed.
100-
break;
101-
}
102-
return $field;
103-
}
10+
/**
11+
* The form id
12+
*
13+
* @var int
14+
*/
15+
private $id = 0;
16+
17+
/**
18+
* The form object
19+
*
20+
* @var \WeForms_Form
21+
*/
22+
private $form;
23+
24+
/**
25+
* The constructor
26+
*
27+
* @param int $form_id
28+
* @param \WeForms_Form $form
29+
*/
30+
public function __construct( $form_id, $form ) {
31+
$this->id = $form_id;
32+
$this->form = $form;
33+
}
34+
35+
/**
36+
* Get all the form entries
37+
*
38+
* @return array
39+
*/
40+
public function all() {
41+
return weforms_get_form_entries( $this->id );
42+
}
43+
44+
/**
45+
* Get a single entry
46+
*
47+
* @param int $entry_id
48+
*
49+
* @return mixed
50+
*/
51+
public function get( $entry_id ) {
52+
return new WeForms_Form_Entry( $entry_id, $this->form );
53+
}
54+
55+
/**
56+
* Format Entry Value.
57+
*
58+
* @param array $field Form Field data.
59+
*
60+
* @return array $field Formatted field data values.
61+
*/
62+
public static function format_entry_value( $field ) {
63+
switch ( $field['template'] ) {
64+
65+
case 'radio_field':
66+
$value = array_search( $field['value'], $field['options'], true );
67+
$field['value'] = esc_html( 'Option: ' . $field['value'] . ' - ' . 'Value: ' . $value );
68+
69+
break;
70+
71+
case 'checkbox_field':
72+
$field_formatted = array();
73+
foreach ( $field['value'] as $option ) {
74+
$value = array_search( $option, $field['options'], true );
75+
$field_formatted[] = esc_html( 'Option: ' . $option . ' - ' . 'Value: ' . $value );
76+
}
77+
$field['value'] = array_replace( $field['value'], $field_formatted );
78+
79+
break;
80+
81+
case 'multiple_select':
82+
$field_formatted = array();
83+
foreach ( $field['value'] as $option ) {
84+
$value = array_search( $option, $field['options'], true );
85+
$field_formatted[] = esc_html( 'Option: ' . $option . ' - ' . 'Value: ' . $value );
86+
}
87+
$field['value'] = array_replace( $field['value'], $field_formatted );
88+
89+
break;
90+
91+
case 'dropdown_field':
92+
$value = array_search( $field['value'], $field['options'], true );
93+
$field['value'] = esc_html( 'Option: ' . $field['value'] . ' - ' . 'Value: ' . $value );
94+
95+
break;
96+
97+
default:
98+
// Do nothing if value format does not need to be changed.
99+
break;
100+
}
101+
return $field;
102+
}
104103
}

includes/class-form-entry.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,9 +422,31 @@ public function get_payment_data() {
422422
return $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}weforms_payments WHERE entry_id = {$this->id} " );
423423
}
424424

425+
/**
426+
* Get Form from entry id.
427+
*
428+
* @param int $entry_id The entry id.
429+
*
430+
* @return object The form object.
431+
*/
432+
public static function get_form( $entry_id ) {
433+
$form_id = self::get_form_id( $entry_id );
434+
435+
return ! empty( $form_id ) ? weforms()->form->get( $form_id ) : null;
436+
}
437+
438+
/**
439+
* Get form id from entry id.
440+
*
441+
* @param int $entry_id The entry id.
442+
*
443+
* @return int The form id.
444+
*/
425445
public static function get_form_id( $entry_id ) {
426446
global $wpdb;
427447

428-
return $wpdb->get_results( "SELECT form_id FROM {$wpdb->prefix}weforms_entries WHERE id = {$entry_id} " );
448+
$results = $wpdb->get_results( "SELECT form_id FROM {$wpdb->prefix}weforms_entries WHERE id = {$entry_id} " );
449+
450+
return ! empty( $results[0]->form_id ) ? $results[0]->form_id : null;
429451
}
430452
}

includes/class-notification.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -474,10 +474,10 @@ public function get_merge_value( $tag ) {
474474
* Users need the ability to pass {field:department} and get "Support",
475475
* and {value:department} to get [email protected]
476476
*
477-
* @param string $text
478-
* @param int $entry_id
477+
* @param string $text The text to parse.
478+
* @param int $entry_id The entry ID.
479479
*
480-
* @return string
480+
* @return string $text The parsed text.
481481
*/
482482
public static function replace_field_tags( $text, $entry_id ) {
483483
// Validate data.
@@ -498,11 +498,8 @@ public static function replace_field_tags( $text, $entry_id ) {
498498
// $text may include HTML tags, only replace tag that was matched.
499499
$text = str_replace( $matches_field[0], $meta_value, $text );
500500
} elseif ( $is_value ) {
501-
$form_object = WeForms_Form_Entry::get_form_id( $entry_id);
502501
$meta_key = $matches_value[1];
503-
$form = weforms()->form->get( $form_object[0]->form_id );
504-
$form_field = $form->get_field_values();
505-
$form_field_values = $form_field[ $meta_key ]['options'];
502+
$form_field_values = WeForms_Form_Entry::get_form( $entry_id )->get_field_values()[ $meta_key ]['options'];
506503
$meta_value = weforms_get_entry_meta( $entry_id, $meta_key, true );
507504
$modified_value = array_search( $meta_value, $form_field_values );
508505
if ( is_array( $modified_value ) ) {
@@ -511,7 +508,6 @@ public static function replace_field_tags( $text, $entry_id ) {
511508
// $text may include HTML tags, only replace tag that was matched.
512509
$text = str_replace( $matches_value[0], $modified_value, $text );
513510
}
514-
515511
return $text;
516512
}
517513

0 commit comments

Comments
 (0)