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
ivyforms / backend / src / Repository / EntryField / EntryFieldNameEmailRepository.php

EntryFieldNameEmailRepository.php in The Innovative Form Builder – IvyForms 1.5, at backend/src/Repository/EntryField/EntryFieldNameEmailRepository.php

51 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace IvyForms\Repository\EntryField;
4
5 use IvyForms\Common\Exceptions\QueryExecutionException;
6 use IvyForms\Repository\AbstractRepository;
7 use IvyForms\Services\InstallActions\DB\Field\FieldsTable;
8 use IvyForms\Services\Translations\BackendStrings;
9
10 class EntryFieldNameEmailRepository extends AbstractRepository implements EntryFieldNameEmailRepositoryInterface
11 {
12 /**
13 * @param int[] $entryIds
14 * @return array<int, array<string, string>>
15 * @throws QueryExecutionException
16 */
17 public function findNameEmailValuesByEntryIds(array $entryIds): array
18 {
19 if ($entryIds === []) {
20 return [];
21 }
22
23 $fieldsTable = FieldsTable::getTableName();
24 $placeholders = implode(',', array_fill(0, count($entryIds), '%d'));
25 $sql = "SELECT ef.entryId, ef.fieldValue, CONCAT(fld.type, '_', fld.fieldIndex) AS fieldKey
26 FROM {$this->table} ef
27 INNER JOIN {$fieldsTable} fld ON fld.id = ef.fieldId
28 WHERE ef.entryId IN ({$placeholders})
29 AND (fld.parentId IS NULL OR fld.parentId = 0)
30 AND fld.type IN ('name', 'email')
31 AND ef.fieldValue <> ''";
32 $results = $this->wpdb->get_results($this->wpdb->prepare($sql, ...$entryIds), ARRAY_A);
33 if ($results === false) {
34 throw new QueryExecutionException(
35 BackendStrings::getExceptionStrings()['unable_find_by_id'] . __CLASS__
36 );
37 }
38
39 $values = [];
40 foreach ($results as $row) {
41 $entryId = (int) ($row['entryId'] ?? 0);
42 $fieldKey = (string) ($row['fieldKey'] ?? '');
43 if ($entryId > 0 && $fieldKey !== '') {
44 $values[$entryId][$fieldKey] = (string) ($row['fieldValue'] ?? '');
45 }
46 }
47
48 return $values;
49 }
50 }
51