Commit | Line | Data |
---|---|---|
0501e0ea CW |
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 | namespace Civi\Api4; | |
12 | ||
13 | /** | |
14 | * Recent Items API. | |
15 | * | |
16 | * Lists the most recently viewed entities by the current user. | |
17 | * | |
18 | * The list is stored in the user's session. | |
19 | * The number of items stored is determined by the setting `recentItemsMaxCount`. | |
20 | * | |
21 | * @searchable secondary | |
22 | * @since 5.49 | |
23 | * @package Civi\Api4 | |
24 | */ | |
25 | class RecentItem extends Generic\BasicEntity { | |
26 | ||
27 | protected static $idField = ['entity_id', 'entity_type']; | |
28 | ||
29 | protected static $getter = ['CRM_Utils_Recent', 'get']; | |
30 | protected static $setter = ['CRM_Utils_Recent', 'create']; | |
31 | protected static $deleter = ['CRM_Utils_Recent', 'del']; | |
32 | ||
33 | /** | |
34 | * @param bool $checkPermissions | |
35 | * @return Generic\BasicGetFieldsAction | |
36 | */ | |
37 | public static function getFields($checkPermissions = TRUE) { | |
38 | return (new Generic\BasicGetFieldsAction('RecentItem', __FUNCTION__, function() { | |
39 | return [ | |
40 | [ | |
41 | 'name' => 'entity_id', | |
42 | 'data_type' => 'Integer', | |
43 | 'required' => TRUE, | |
44 | ], | |
45 | [ | |
46 | 'name' => 'entity_type', | |
47 | 'title' => 'Entity Type', | |
48 | 'options' => \CRM_Utils_Recent::getProviders(), | |
49 | 'required' => TRUE, | |
50 | ], | |
51 | [ | |
52 | 'name' => 'title', | |
53 | ], | |
54 | [ | |
55 | 'name' => 'is_deleted', | |
56 | 'data_type' => 'Boolean', | |
57 | ], | |
58 | [ | |
59 | 'name' => 'icon', | |
60 | ], | |
61 | [ | |
62 | 'name' => 'view_url', | |
63 | 'title' => 'View URL', | |
64 | ], | |
65 | [ | |
66 | 'name' => 'edit_url', | |
67 | 'title' => 'Edit URL', | |
68 | ], | |
69 | [ | |
70 | 'name' => 'delete_url', | |
71 | 'title' => 'Delete URL', | |
72 | ], | |
73 | ]; | |
74 | }))->setCheckPermissions($checkPermissions); | |
75 | } | |
76 | ||
77 | /** | |
78 | * @return array | |
79 | */ | |
80 | public static function permissions() { | |
81 | return [ | |
82 | 'default' => ['access CiviCRM'], | |
83 | ]; | |
84 | } | |
85 | ||
86 | } |