PluginProbe
The Innovative Form Builder – IvyForms / 1.5
The Innovative Form Builder – IvyForms v1.5
1.5.1 1.5 1.4.1 1.4 trunk 0.1.2 0.2 0.2.1 0.3 0.3.1 0.4 0.5 0.6 0.6.1 0.6.1-backup 0.6.1.1 0.7 0.8 0.8.1 0.8.2 0.9 0.9.1 1.0 1.1 1.1.1 All 27 releases
← All changes | backend/src/Repository/Notification/NotificationRepository.php +67 -29 0.5 → 1.5 View file →
@@ -1,18 +1,13 @@
1 1 <?php
2 2
3 3 /**
4 - * @copyright © TMS-Plugins. All rights reserved.
4 + * @copyright © Melograno Venture Studio. All rights reserved.
5 5 * @licence See LICENCE.md for license details.
6 6 */
7 7
8 8 namespace IvyForms\Repository\Notification;
9 9
10 -// phpcs:disable PSR1.Files.SideEffects
11 -if (!defined('ABSPATH')) {
12 - exit; // Exit if accessed directly
13 -}
14 -
15 10 use IvyForms\Common\Exceptions\QueryExecutionException;
16 11 use IvyForms\Entity\Notification\Notification;
17 12 use IvyForms\Factory\Notification\NotificationFactory;
18 13 use IvyForms\Repository\AbstractRepository;
@@ -34,22 +29,14 @@
34 29 */
35 30 public function add($entity): int
36 31 {
37 32 $data = $entity->toArray();
33 + $row = $this->buildPersistRow($data);
38 34
39 35 $result = $this->wpdb->insert(
40 36 $this->table,
41 - [
42 - 'formId' => (int) $data['formId'],
43 - 'name' => $data['name'],
44 - 'sender' => $data['sender'],
45 - 'receiver' => $data['receiver'],
46 - 'enabled' => (int) $data['enabled'],
47 - 'subject' => $data['subject'],
48 - 'message' => $data['message'],
49 - 'smartLogic' => (int) $data['smartLogic'],
50 - ],
51 - ['%d', '%s', '%s', '%s', '%d', '%s', '%s', '%d']
37 + $row['values'],
38 + $row['formats']
52 39 );
53 40
54 41 if ($result === false) {
55 42 throw new QueryExecutionException(
@@ -72,23 +59,15 @@
72 59 */
73 60 public function update(int $id, $entity): bool
74 61 {
75 62 $data = $entity->toArray();
63 + $row = $this->buildPersistRow($data);
76 64
77 65 $result = $this->wpdb->update(
78 66 $this->table,
79 - [
80 - 'formId' => (int) $data['formId'],
81 - 'name' => $data['name'],
82 - 'sender' => $data['sender'],
83 - 'receiver' => $data['receiver'],
84 - 'enabled' => (int) $data['enabled'],
85 - 'subject' => $data['subject'],
86 - 'message' => $data['message'],
87 - 'smartLogic' => (int) $data['smartLogic'],
88 - ],
67 + $row['values'],
89 68 ['id' => $id],
90 - ['%d', '%s', '%s', '%s', '%d', '%s', '%s', '%d'],
69 + $row['formats'],
91 70 ['%d']
92 71 );
93 72
94 73 if ($result === false) {
@@ -94,9 +73,68 @@
94 73 if ($result === false) {
95 74 throw new QueryExecutionException(BackendStrings::getAllFormsStrings()['unable_to_save_data'] . __CLASS__);
96 75 }
97 76
98 - return $result;
77 + return true;
78 + }
79 +
80 + /**
81 + * Build insert/update row values and formats, allowing Pro to append columns.
82 + *
83 + * @param array<string, mixed> $data
84 + * @return array{values: array<string, mixed>, formats: string[]}
85 + */
86 + private function buildPersistRow(array $data): array
87 + {
88 + $values = [
89 + 'formId' => (int) $data['formId'],
90 + 'name' => $data['name'],
91 + 'sender' => $data['sender'],
92 + 'replyTo' => $data['replyTo'],
93 + 'receiver' => $data['receiver'],
94 + 'cc' => $data['cc'],
95 + 'bcc' => $data['bcc'],
96 + 'enabled' => (int) $data['enabled'],
97 + 'subject' => $data['subject'],
98 + 'message' => $data['message'],
99 + 'showEmptyFields' => (int) $data['showEmptyFields'],
100 + 'smartLogic' => wp_json_encode($data['smartLogic']),
101 + ];
102 + $formats = ['%d', '%s', '%s', '%s', '%s', '%s', '%s', '%d', '%s', '%s', '%d', '%s'];
103 +
104 + /**
105 + * Extend notification DB persist row (values + formats) for Pro columns.
106 + *
107 + * @since 1.2.0
108 + *
109 + * @param array<string, mixed> $row
110 + * @param array<string, mixed> $data
111 + */
112 + $filtered = apply_filters(
113 + 'ivyforms/notification/repository_row',
114 + [
115 + 'values' => $values,
116 + 'formats' => $formats,
117 + ],
118 + $data
119 + );
120 +
121 + if (
122 + !is_array($filtered)
123 + || !isset($filtered['values'], $filtered['formats'])
124 + || !is_array($filtered['values'])
125 + || !is_array($filtered['formats'])
126 + ) {
127 + return [
128 + 'values' => $values,
129 + 'formats' => $formats,
130 + ];
131 + }
132 +
133 + return [
134 + 'values' => $filtered['values'],
135 + 'formats' => $filtered['formats'],
136 + ];
99 137 }
100 138
101 139 /**
102 140 * Get all notifications by form ID.