Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
99.59% |
243 / 244 |
|
80.00% |
4 / 5 |
CRAP | |
0.00% |
0 / 1 |
| ModuleExtensionTabCatalog | |
99.59% |
242 / 243 |
|
80.00% |
4 / 5 |
25 | |
0.00% |
0 / 1 |
| resolveTabs | |
97.14% |
34 / 35 |
|
0.00% |
0 / 1 |
10 | |||
| appendSpecialModuleTabs | |
100.00% |
112 / 112 |
|
100.00% |
1 / 1 |
12 | |||
| appendSystemModuleTabs | |
100.00% |
30 / 30 |
|
100.00% |
1 / 1 |
1 | |||
| appendRelatedModuleTabs | |
100.00% |
36 / 36 |
|
100.00% |
1 / 1 |
1 | |||
| appendSystemUserTabs | |
100.00% |
30 / 30 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | /** @license For full copyright and license information, please see the LICENSE.md file. */ |
| 6 | |
| 7 | namespace App\Core\Engine\Domain\Model\Support; |
| 8 | |
| 9 | defined('AMMONLY_APP') || exit('Direct script access is forbidden.'); |
| 10 | |
| 11 | /** |
| 12 | * Module Extension Tab Catalog. |
| 13 | * |
| 14 | * Resolves standard extension tabs configuration (Timeline, Comments, Calendar, Work Time, Gantt, Items, etc.) |
| 15 | * based on module machine name, type, and capabilities. |
| 16 | * |
| 17 | * @package App\Core\Engine\Domain\Model\Support |
| 18 | */ |
| 19 | final readonly class ModuleExtensionTabCatalog |
| 20 | { |
| 21 | private const string GANTT_LABEL = 'Wykres Gantta'; |
| 22 | private const string GANTT_ICON = 'bi bi-bar-chart-steps'; |
| 23 | |
| 24 | private const array SUPPORTED_RELATED_TABS_MODULES = [ |
| 25 | 'companies', |
| 26 | 'partners', |
| 27 | 'contacts', |
| 28 | 'projects', |
| 29 | 'project_stages', |
| 30 | 'project_tasks', |
| 31 | 'tickets', |
| 32 | 'contracts', |
| 33 | 'products', |
| 34 | 'services', |
| 35 | 'documents', |
| 36 | ]; |
| 37 | |
| 38 | /** |
| 39 | * Resolves extension tabs configuration for the specified module. |
| 40 | * |
| 41 | * @param string $name Module machine name. |
| 42 | * @param string $type Module type (crud|dynamic). |
| 43 | * @param bool $hasInventory Whether inventory items are supported. |
| 44 | * @return array<int, array<string, mixed>> Extension tabs list. |
| 45 | */ |
| 46 | public function resolveTabs(string $name, string $type, bool $hasInventory = false): array |
| 47 | { |
| 48 | $extensionTabs = []; |
| 49 | |
| 50 | if ($hasInventory || in_array(strtolower($name), ['quotes', 'orders'], true)) { |
| 51 | $extensionTabs[] = [ |
| 52 | 'id' => 'inventory_items', |
| 53 | 'label' => 'Items', |
| 54 | 'category' => 'app', |
| 55 | 'icon' => 'bi bi-table', |
| 56 | 'partial' => 'engine/partials/inventory_table_tab.twig', |
| 57 | 'has_add' => true, |
| 58 | 'add_title' => 'Add Item', |
| 59 | 'views' => ['detail', 'edit', 'create'], |
| 60 | ]; |
| 61 | } |
| 62 | |
| 63 | $this->appendSpecialModuleTabs($extensionTabs, $name); |
| 64 | |
| 65 | if (in_array($name, self::SUPPORTED_RELATED_TABS_MODULES, true)) { |
| 66 | $this->appendRelatedModuleTabs($extensionTabs); |
| 67 | } |
| 68 | |
| 69 | if ($name === 'system_users') { |
| 70 | $this->appendSystemUserTabs($extensionTabs); |
| 71 | } |
| 72 | |
| 73 | $hasTimeline = false; |
| 74 | foreach ($extensionTabs as $tab) { |
| 75 | if (($tab['id'] ?? '') === 'timeline') { |
| 76 | $hasTimeline = true; |
| 77 | break; |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | if (!$hasTimeline && ($type === 'crud' |
| 82 | || in_array($name, ['system_modules', 'system_picklists', 'system_structure', 'structure'], true))) { |
| 83 | $extensionTabs[] = [ |
| 84 | 'id' => 'timeline', |
| 85 | 'label' => 'Timeline', |
| 86 | 'category' => 'app', |
| 87 | 'icon' => 'bi bi-clock-history', |
| 88 | 'partial' => 'engine/partials/timeline_manager.twig', |
| 89 | 'has_add' => false, |
| 90 | 'add_title' => '', |
| 91 | 'views' => ['detail'], |
| 92 | 'limit' => 20, |
| 93 | ]; |
| 94 | } |
| 95 | |
| 96 | return $extensionTabs; |
| 97 | } |
| 98 | |
| 99 | /** |
| 100 | * Appends special module tabs for templates, calendar, languages, widgets, and projects. |
| 101 | * |
| 102 | * @param array<int, array<string, mixed>> &$extensionTabs |
| 103 | * @param string $name Module name. |
| 104 | */ |
| 105 | private function appendSpecialModuleTabs(array &$extensionTabs, string $name): void |
| 106 | { |
| 107 | if (in_array($name, ['mail_templates', 'client_mail_templates'], true)) { |
| 108 | $extensionTabs[] = [ |
| 109 | 'id' => 'email_preview', |
| 110 | 'label' => 'Podgląd wiadomości', |
| 111 | 'category' => 'app', |
| 112 | 'icon' => 'bi bi-envelope-paper', |
| 113 | 'partial' => 'engine/partials/email_preview_tab.twig', |
| 114 | 'has_add' => false, |
| 115 | 'add_title' => '', |
| 116 | 'views' => ['detail'], |
| 117 | ]; |
| 118 | } |
| 119 | |
| 120 | if ($name === 'pdf_templates') { |
| 121 | $extensionTabs[] = [ |
| 122 | 'id' => 'template_builder', |
| 123 | 'label' => 'Kreator dokumentu', |
| 124 | 'category' => 'app', |
| 125 | 'icon' => 'bi bi-file-earmark-pdf', |
| 126 | 'partial' => 'engine/partials/template_builder_tab.twig', |
| 127 | 'has_add' => false, |
| 128 | 'add_title' => '', |
| 129 | 'views' => ['detail', 'edit'], |
| 130 | ]; |
| 131 | } |
| 132 | |
| 133 | if ($name === 'calendar') { |
| 134 | $extensionTabs[] = [ |
| 135 | 'id' => 'calendar_view', |
| 136 | 'label' => 'Kalendarz', |
| 137 | 'category' => 'app', |
| 138 | 'icon' => 'bi bi-calendar3', |
| 139 | 'partial' => 'engine/partials/calendar_extension_tab.twig', |
| 140 | 'has_add' => false, |
| 141 | 'add_title' => '', |
| 142 | 'views' => ['create', 'edit'], |
| 143 | ]; |
| 144 | } |
| 145 | |
| 146 | if ($name === 'system_picklists') { |
| 147 | $extensionTabs[] = [ |
| 148 | 'id' => 'values', |
| 149 | 'label' => 'Values', |
| 150 | 'category' => 'app', |
| 151 | 'icon' => 'bi bi-list-ul', |
| 152 | 'partial' => 'engine/partials/picklist_values_manager.twig', |
| 153 | 'has_add' => true, |
| 154 | 'add_title' => 'add_value', |
| 155 | 'views' => ['all'], |
| 156 | ]; |
| 157 | } |
| 158 | |
| 159 | if ($name === 'system_languages') { |
| 160 | $extensionTabs[] = [ |
| 161 | 'id' => 'translations', |
| 162 | 'label' => 'Translations', |
| 163 | 'category' => 'app', |
| 164 | 'icon' => 'bi bi-chat-left-quote', |
| 165 | 'partial' => 'engine/partials/language_translations_manager.twig', |
| 166 | 'has_add' => true, |
| 167 | 'add_title' => 'add_translation', |
| 168 | 'views' => ['detail'], |
| 169 | ]; |
| 170 | } |
| 171 | |
| 172 | if ($name === 'system_widgets') { |
| 173 | $extensionTabs[] = [ |
| 174 | 'id' => 'grid_relations', |
| 175 | 'label' => 'Usage in Modules', |
| 176 | 'category' => 'app', |
| 177 | 'icon' => 'bi bi-grid-1x2-fill', |
| 178 | 'partial' => 'engine/partials/widget_grid_relations_manager.twig', |
| 179 | 'has_add' => false, |
| 180 | 'add_title' => '', |
| 181 | 'views' => ['all'], |
| 182 | ]; |
| 183 | } |
| 184 | |
| 185 | if ($name === 'system_modules') { |
| 186 | $this->appendSystemModuleTabs($extensionTabs); |
| 187 | } |
| 188 | |
| 189 | if ($name === 'projects') { |
| 190 | $extensionTabs[] = [ |
| 191 | 'id' => 'project_gantt', |
| 192 | 'label' => self::GANTT_LABEL, |
| 193 | 'category' => 'app', |
| 194 | 'icon' => self::GANTT_ICON, |
| 195 | 'partial' => 'projects/partials/gantt_tab.twig', |
| 196 | 'has_add' => false, |
| 197 | 'add_title' => '', |
| 198 | 'views' => ['detail'], |
| 199 | ]; |
| 200 | } |
| 201 | |
| 202 | if ($name === 'project_stages') { |
| 203 | $extensionTabs[] = [ |
| 204 | 'id' => 'stage_gantt', |
| 205 | 'label' => self::GANTT_LABEL, |
| 206 | 'category' => 'app', |
| 207 | 'icon' => self::GANTT_ICON, |
| 208 | 'partial' => 'projects/partials/stage_gantt_tab.twig', |
| 209 | 'has_add' => false, |
| 210 | 'add_title' => '', |
| 211 | 'views' => ['detail'], |
| 212 | ]; |
| 213 | } |
| 214 | |
| 215 | if ($name === 'documents') { |
| 216 | $extensionTabs[] = [ |
| 217 | 'id' => 'document_files', |
| 218 | 'label' => 'Pliki dokumentu', |
| 219 | 'category' => 'app', |
| 220 | 'icon' => 'bi bi-paperclip', |
| 221 | 'partial' => 'engine/partials/related_document_files_tab.twig', |
| 222 | 'has_add' => true, |
| 223 | 'add_title' => 'Dodaj plik', |
| 224 | 'views' => ['detail', 'edit', 'create'], |
| 225 | ]; |
| 226 | } |
| 227 | |
| 228 | if (in_array($name, ['system_structure', 'structure'], true)) { |
| 229 | $extensionTabs[] = [ |
| 230 | 'id' => 'structure_map', |
| 231 | 'label' => 'Mapa obiektów', |
| 232 | 'category' => 'app', |
| 233 | 'icon' => 'bi bi-geo-alt', |
| 234 | 'partial' => 'structure/partials/structure_map_tab.twig', |
| 235 | 'has_add' => false, |
| 236 | 'add_title' => '', |
| 237 | 'views' => ['detail'], |
| 238 | ]; |
| 239 | } |
| 240 | } |
| 241 | |
| 242 | /** |
| 243 | * Appends system module builder tabs. |
| 244 | * |
| 245 | * @param array<int, array<string, mixed>> &$extensionTabs |
| 246 | */ |
| 247 | private function appendSystemModuleTabs(array &$extensionTabs): void |
| 248 | { |
| 249 | $extensionTabs[] = [ |
| 250 | 'id' => 'fields', |
| 251 | 'label' => 'Fields', |
| 252 | 'category' => 'app', |
| 253 | 'icon' => 'bi bi-input-cursor-text', |
| 254 | 'partial' => 'engine/partials/module_fields_manager.twig', |
| 255 | 'has_add' => true, |
| 256 | 'add_title' => 'add_field', |
| 257 | 'views' => ['all'], |
| 258 | ]; |
| 259 | $extensionTabs[] = [ |
| 260 | 'id' => 'filters', |
| 261 | 'label' => 'Filters', |
| 262 | 'category' => 'app', |
| 263 | 'icon' => 'bi bi-funnel', |
| 264 | 'partial' => 'engine/partials/module_filters_manager.twig', |
| 265 | 'has_add' => true, |
| 266 | 'add_title' => 'add_filter', |
| 267 | 'views' => ['all'], |
| 268 | ]; |
| 269 | $extensionTabs[] = [ |
| 270 | 'id' => 'picklists', |
| 271 | 'label' => 'Picklists', |
| 272 | 'category' => 'app', |
| 273 | 'icon' => 'bi bi-bookmark-star', |
| 274 | 'partial' => 'engine/partials/module_picklists_manager.twig', |
| 275 | 'has_add' => true, |
| 276 | 'add_title' => 'add_picklist', |
| 277 | 'views' => ['all'], |
| 278 | ]; |
| 279 | } |
| 280 | |
| 281 | /** |
| 282 | * Appends related comments, calendar, and work time tabs. |
| 283 | * |
| 284 | * @param array<int, array<string, mixed>> &$extensionTabs |
| 285 | */ |
| 286 | private function appendRelatedModuleTabs(array &$extensionTabs): void |
| 287 | { |
| 288 | $extensionTabs[] = [ |
| 289 | 'id' => 'related_comments', |
| 290 | 'label' => 'Komentarze', |
| 291 | 'category' => 'app', |
| 292 | 'icon' => 'bi bi-chat-dots', |
| 293 | 'partial' => 'engine/partials/related_comments_tab.twig', |
| 294 | 'has_add' => true, |
| 295 | 'add_title' => 'add_comment', |
| 296 | 'target_module_name' => 'comments', |
| 297 | 'views' => ['detail'], |
| 298 | 'allowed_actions' => ['create', 'refresh'], |
| 299 | ]; |
| 300 | $extensionTabs[] = [ |
| 301 | 'id' => 'related_calendar', |
| 302 | 'label' => 'Kalendarz', |
| 303 | 'category' => 'app', |
| 304 | 'icon' => 'bi bi-calendar-event', |
| 305 | 'partial' => 'engine/partials/related_calendar_tab.twig', |
| 306 | 'has_add' => true, |
| 307 | 'add_title' => 'add_event', |
| 308 | 'target_module_name' => 'calendar', |
| 309 | 'views' => ['detail'], |
| 310 | 'allowed_actions' => ['create', 'refresh'], |
| 311 | ]; |
| 312 | $extensionTabs[] = [ |
| 313 | 'id' => 'related_work_time', |
| 314 | 'label' => 'Czas pracy', |
| 315 | 'category' => 'app', |
| 316 | 'icon' => 'bi bi-stopwatch', |
| 317 | 'partial' => 'engine/partials/related_work_time_tab.twig', |
| 318 | 'has_add' => true, |
| 319 | 'add_title' => 'add_work_time', |
| 320 | 'target_module_name' => 'work_time', |
| 321 | 'views' => ['detail'], |
| 322 | 'allowed_actions' => ['create', 'refresh'], |
| 323 | ]; |
| 324 | } |
| 325 | |
| 326 | /** |
| 327 | * Appends security and impersonation tabs for system_users. |
| 328 | * |
| 329 | * @param array<int, array<string, mixed>> &$extensionTabs |
| 330 | */ |
| 331 | private function appendSystemUserTabs(array &$extensionTabs): void |
| 332 | { |
| 333 | $extensionTabs[] = [ |
| 334 | 'id' => 'access_matrix', |
| 335 | 'label' => 'Access Permission Matrix', |
| 336 | 'category' => 'app', |
| 337 | 'icon' => 'bi bi-shield-check', |
| 338 | 'partial' => 'users/partials/user_access_matrix_tab.twig', |
| 339 | 'has_add' => false, |
| 340 | 'add_title' => '', |
| 341 | 'views' => ['detail'], |
| 342 | ]; |
| 343 | $extensionTabs[] = [ |
| 344 | 'id' => 'profile_matrix', |
| 345 | 'label' => 'Profile Permission Matrix', |
| 346 | 'category' => 'app', |
| 347 | 'icon' => 'bi bi-shield-lock', |
| 348 | 'partial' => 'users/partials/user_profile_matrix_tab.twig', |
| 349 | 'has_add' => false, |
| 350 | 'add_title' => '', |
| 351 | 'views' => ['detail'], |
| 352 | ]; |
| 353 | $extensionTabs[] = [ |
| 354 | 'id' => 'impersonation_grants', |
| 355 | 'label' => 'User Impersonation', |
| 356 | 'category' => 'menu', |
| 357 | 'icon' => 'bi bi-arrow-left-right', |
| 358 | 'partial' => 'users/partials/user_impersonation_tab.twig', |
| 359 | 'has_add' => false, |
| 360 | 'add_title' => '', |
| 361 | 'views' => ['detail'], |
| 362 | ]; |
| 363 | } |
| 364 | } |