PluginProbe
The Innovative Form Builder – IvyForms / 0.9.1
The Innovative Form Builder – IvyForms v0.9.1
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 / Services / Entry / Managers / EntryManager.php

EntryManager.php in The Innovative Form Builder – IvyForms 0.9.1, at backend/src/Services/Entry/Managers/EntryManager.php

149 lines 4.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace IvyForms\Services\Entry\Managers;
4
5 // phpcs:disable PSR1.Files.SideEffects
6 if (!defined('ABSPATH')) {
7 exit; // Exit if accessed directly
8 }
9
10 use IvyForms\Common\Exceptions\InvalidArgumentException;
11 use IvyForms\Common\Exceptions\NotFoundException;
12 use IvyForms\Entity\Entry\Entry;
13 use IvyForms\Repository\Entry\EntryRepositoryInterface;
14 use IvyForms\Services\Translations\BackendStrings;
15
16 /**
17 * Manages Entry repository operations.
18 */
19 class EntryManager
20 {
21 private EntryRepositoryInterface $entryRepository;
22
23 public function __construct(EntryRepositoryInterface $entryRepository)
24 {
25 $this->entryRepository = $entryRepository;
26 }
27
28 /**
29 * Create a new entry.
30 *
31 * @param Entry $entryData
32 * @return int Entry ID
33 */
34 public function createEntry(Entry $entryData): int
35 {
36 return $this->entryRepository->add($entryData);
37 }
38
39 /**
40 * Get a specific entry by its ID.
41 *
42 * @param int $entryId
43 * @return object
44 * @throws NotFoundException If the entry is not found
45 */
46 public function getEntry(int $entryId): object
47 {
48 $entry = $this->entryRepository->getById($entryId);
49
50 if (!$entry) {
51 throw new NotFoundException(
52 BackendStrings::getExceptionStrings()['entry_not_found']
53 );
54 }
55
56 return $entry;
57 }
58
59 /**
60 * Search for entries based on parameters.
61 *
62 * @param array<string, mixed> $params
63 * @return array<mixed>
64 */
65 public function searchEntries(array $params): array
66 {
67 return $this->entryRepository->search($params);
68 }
69
70 /**
71 * Get the count of entry filters.
72 *
73 * @param array<string, mixed>|null $params
74 * @return array<mixed>
75 */
76 public function getFilterCount(?array $params = null): array
77 {
78 return $this->entryRepository->getFilterCount($params);
79 }
80
81 /**
82 * Get the count of entries for multiple form IDs.
83 *
84 * @param int[] $formIds
85 * @return array<int, int> formId => count
86 */
87 public function getEntryCountByFormIds(array $formIds): array
88 {
89 return $this->entryRepository->getEntryCountByFormIds($formIds);
90 }
91
92 /**
93 * Update the starred status of an entry.
94 *
95 * @param int $entryId
96 * @param bool $value
97 * @return void
98 */
99 public function updateEntryStarred(int $entryId, bool $value): void
100 {
101 $this->entryRepository->updateEntryStarred($entryId, $value);
102 }
103
104 /**
105 * Update the status of an entry.
106 *
107 * @param int $entryId
108 * @param string $status
109 * @return void
110 */
111 public function updateEntryStatus(int $entryId, string $status): void
112 {
113 $this->entryRepository->updateEntryStatus($entryId, $status);
114 }
115
116 /**
117 * Bulk update a column for multiple entries.
118 *
119 * @param string $column Column name to update
120 * @param mixed $value Value to set
121 * @param array<int> $ids Array of entry IDs
122 * @return int Number of updated entries
123 */
124 public function bulkUpdateColumn(string $column, $value, array $ids): int
125 {
126 return $this->entryRepository->bulkUpdateColumn($column, $value, $ids);
127 }
128
129 /**
130 * Get all possible entry columns
131 *
132 * @return array<string, string>
133 */
134 public static function getAllEntryColumns(): array
135 {
136 return [
137 'id' => BackendStrings::getEntriesStrings()['id'],
138 'formId' => BackendStrings::getEntriesStrings()['form_id'],
139 'userId' => BackendStrings::getEntriesStrings()['user_id'],
140 'dateCreated' => BackendStrings::getEntriesStrings()['date_created'],
141 'status' => BackendStrings::getEntriesStrings()['status'],
142 'ipAddress' => BackendStrings::getEntriesStrings()['ip_address'],
143 'userAgent' => BackendStrings::getEntriesStrings()['user_agent'],
144 'sourceURL' => BackendStrings::getEntriesStrings()['source_url'],
145 'starred' => BackendStrings::getEntriesStrings()['starred'],
146 ];
147 }
148 }
149