PluginProbe
The Innovative Form Builder – IvyForms / 1.0
The Innovative Form Builder – IvyForms v1.0
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 1.0, at backend/src/Services/Entry/Managers/EntryManager.php

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