| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* @copyright © TMS-Plugins. All rights reserved. |
| 5 |
* @licence See COPYING.md for license details. |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace IvyForms\Services\Template; |
| 9 |
|
| 10 |
// phpcs:disable PSR1.Files.SideEffects |
| 11 |
if (!defined('ABSPATH')) { |
| 12 |
exit; // Exit if accessed directly |
| 13 |
} |
| 14 |
|
| 15 |
use IvyForms\Common\Exceptions\InvalidArgumentException; |
| 16 |
use IvyForms\Services\Translations\BackendStrings; |
| 17 |
|
| 18 |
/** |
| 19 |
* Class TemplateService |
| 20 |
* |
| 21 |
* @package IvyForms\Services\Template |
| 22 |
*/ |
| 23 |
class TemplateService |
| 24 |
{ |
| 25 |
/** |
| 26 |
* Get all predefined form templates |
| 27 |
* |
| 28 |
* @return array<string, array<string, mixed>> |
| 29 |
*/ |
| 30 |
public function getAllTemplates(): array |
| 31 |
{ |
| 32 |
return TemplateMapper::getAllTemplates(); |
| 33 |
} |
| 34 |
|
| 35 |
/** |
| 36 |
* Get predefined form template by ID |
| 37 |
* |
| 38 |
* @param string $templateId |
| 39 |
* @return array<string, mixed>|null |
| 40 |
*/ |
| 41 |
public function getTemplateById(string $templateId): ?array |
| 42 |
{ |
| 43 |
return TemplateMapper::getTemplate($templateId); |
| 44 |
} |
| 45 |
|
| 46 |
/** |
| 47 |
* Get form data from template by ID |
| 48 |
* |
| 49 |
* @param string $templateId |
| 50 |
* @return array<string, mixed> |
| 51 |
* @throws InvalidArgumentException |
| 52 |
*/ |
| 53 |
public function getFormDataFromTemplate(string $templateId): array |
| 54 |
{ |
| 55 |
$template = $this->getTemplateById($templateId); |
| 56 |
|
| 57 |
if (!$template) { |
| 58 |
throw new InvalidArgumentException( |
| 59 |
BackendStrings::getTemplateStrings()['template_not_found'] |
| 60 |
); |
| 61 |
} |
| 62 |
|
| 63 |
return $template['form_data']; |
| 64 |
} |
| 65 |
|
| 66 |
/** |
| 67 |
* Get template categories |
| 68 |
* |
| 69 |
* @return array<string, array<string, string>> |
| 70 |
*/ |
| 71 |
public function getTemplateCategories(): array |
| 72 |
{ |
| 73 |
return [ |
| 74 |
// 'basic' => [ |
| 75 |
// 'name' => '', |
| 76 |
// 'description' => '' |
| 77 |
// ] |
| 78 |
]; |
| 79 |
} |
| 80 |
} |
| 81 |
|