PluginProbe
The Innovative Form Builder – IvyForms / 0.8
The Innovative Form Builder – IvyForms v0.8
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 1.2 1.3
ivyforms / backend / src / Services / Entry / Managers / EntryManager.php

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

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