| 1 | <?php |
| 2 | /* |
| 3 | +--------------------------------------------------------------------+ |
| 4 | | Copyright CiviCRM LLC. All rights reserved. | |
| 5 | | | |
| 6 | | This work is published under the GNU AGPLv3 license with some | |
| 7 | | permitted exceptions and without any warranty. For full license | |
| 8 | | and copyright information, see https://civicrm.org/licensing | |
| 9 | +--------------------------------------------------------------------+ |
| 10 | */ |
| 11 | |
| 12 | namespace Civi\Api4; |
| 13 | |
| 14 | /** |
| 15 | * Search for example data. |
| 16 | * |
| 17 | * @searchable none |
| 18 | * @since 5.43 |
| 19 | * @package Civi\Api4 |
| 20 | */ |
| 21 | class ExampleData extends \Civi\Api4\Generic\AbstractEntity { |
| 22 | |
| 23 | /** |
| 24 | * @param bool $checkPermissions |
| 25 | * @return Generic\AbstractGetAction |
| 26 | */ |
| 27 | public static function get($checkPermissions = TRUE) { |
| 28 | return (new Action\ExampleData\Get(__CLASS__, __FILE__)) |
| 29 | ->setCheckPermissions($checkPermissions); |
| 30 | } |
| 31 | |
| 32 | /** |
| 33 | * @param bool $checkPermissions |
| 34 | * @return Generic\BasicGetFieldsAction |
| 35 | */ |
| 36 | public static function getFields($checkPermissions = TRUE) { |
| 37 | return (new Generic\BasicGetFieldsAction(__CLASS__, __FUNCTION__, function () { |
| 38 | return [ |
| 39 | [ |
| 40 | 'name' => 'name', |
| 41 | 'title' => 'Example Name', |
| 42 | 'data_type' => 'String', |
| 43 | ], |
| 44 | [ |
| 45 | 'name' => 'title', |
| 46 | 'title' => 'Example Title', |
| 47 | 'data_type' => 'String', |
| 48 | ], |
| 49 | [ |
| 50 | 'name' => 'workflow', |
| 51 | 'title' => 'Workflow Name', |
| 52 | 'data_type' => 'String', |
| 53 | ], |
| 54 | [ |
| 55 | 'name' => 'file', |
| 56 | 'title' => 'File Path', |
| 57 | 'data_type' => 'String', |
| 58 | 'description' => 'If the example is loaded from a file, this is the location.', |
| 59 | ], |
| 60 | [ |
| 61 | 'name' => 'tags', |
| 62 | 'title' => 'Tags', |
| 63 | 'data_type' => 'Array', |
| 64 | 'options' => [ |
| 65 | 'preview' => ts('Preview: Display as an example in the "Preview" dialog'), |
| 66 | 'phpunit' => ts('PHPUnit: Run basic sniff tests in PHPUnit using this example'), |
| 67 | ], |
| 68 | ], |
| 69 | [ |
| 70 | 'type' => 'Extra', |
| 71 | 'name' => 'data', |
| 72 | 'title' => 'Example data', |
| 73 | 'data_type' => 'String', |
| 74 | 'serialize' => \CRM_Core_DAO::SERIALIZE_JSON, |
| 75 | ], |
| 76 | [ |
| 77 | 'type' => 'Extra', |
| 78 | 'name' => 'asserts', |
| 79 | 'title' => 'Test assertions', |
| 80 | 'data_type' => 'String', |
| 81 | 'serialize' => \CRM_Core_DAO::SERIALIZE_JSON, |
| 82 | ], |
| 83 | ]; |
| 84 | }))->setCheckPermissions($checkPermissions); |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * @return array |
| 89 | */ |
| 90 | public static function permissions() { |
| 91 | return [ |
| 92 | // FIXME: Perhaps use 'edit message templates' or similar? |
| 93 | "meta" => ["access CiviCRM"], |
| 94 | "default" => ["administer CiviCRM"], |
| 95 | ]; |
| 96 | } |
| 97 | |
| 98 | /** |
| 99 | * @inheritDoc |
| 100 | */ |
| 101 | public static function getInfo() { |
| 102 | $info = parent::getInfo(); |
| 103 | $info['primary_key'] = ['name']; |
| 104 | return $info; |
| 105 | } |
| 106 | |
| 107 | } |