Search kit: Rewrite input widget to support IN sets, relative dates, BETWEEN groups...
[civicrm-core.git] / ext / search / Civi / Search / Actions.php
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\Search;
13
14 /**
15 * Class Tasks
16 * @package Civi\Search
17 */
18 class Actions {
19
20 /**
21 * @return array
22 */
23 public static function getActionSettings():array {
24 return [
25 'tasks' => self::getTasks(),
26 'groupOptions' => self::getGroupOptions(),
27 'dateRanges' => \CRM_Utils_Array::makeNonAssociative(\CRM_Core_OptionGroup::values('relative_date_filters'), 'id', 'text'),
28 ];
29 }
30
31 /**
32 * @return array
33 */
34 public static function getGroupOptions():array {
35 return \Civi\Api4\Group::getFields(FALSE)
36 ->setLoadOptions(['id', 'label'])
37 ->addWhere('name', 'IN', ['group_type', 'visibility'])
38 ->execute()
39 ->indexBy('name')
40 ->column('options');
41 }
42
43 /**
44 * @return array
45 */
46 public static function getTasks():array {
47 // Note: the placeholder %1 will be replaced with entity name on the clientside
48 $tasks = [
49 'export' => [
50 'title' => ts('Export %1'),
51 'icon' => 'fa-file-excel-o',
52 'entities' => array_keys(\CRM_Export_BAO_Export::getComponents()),
53 'crmPopup' => [
54 'path' => "'civicrm/export/standalone'",
55 'query' => "{entity: entity, id: ids.join(',')}",
56 ],
57 ],
58 'update' => [
59 'title' => ts('Update %1'),
60 'icon' => 'fa-save',
61 'entities' => [],
62 'uiDialog' => ['templateUrl' => '~/crmSearchActions/crmSearchActionUpdate.html'],
63 ],
64 'delete' => [
65 'title' => ts('Delete %1'),
66 'icon' => 'fa-trash',
67 'entities' => [],
68 'uiDialog' => ['templateUrl' => '~/crmSearchActions/crmSearchActionDelete.html'],
69 ],
70 ];
71
72 // Add contact tasks which support standalone mode (with a 'url' property)
73 $contactTasks = \CRM_Contact_Task::permissionedTaskTitles(\CRM_Core_Permission::getPermission());
74 foreach (\CRM_Contact_Task::tasks() as $id => $task) {
75 if (isset($contactTasks[$id]) && !empty($task['url']) && $task['url'] !== 'civicrm/task/delete-contact') {
76 $tasks['contact.' . $id] = [
77 'title' => $task['title'],
78 'entities' => ['Contact'],
79 'icon' => $task['icon'] ?? 'fa-gear',
80 'crmPopup' => [
81 'path' => "'{$task['url']}'",
82 'query' => "{cids: ids.join(',')}",
83 ],
84 ];
85 }
86 }
87
88 return $tasks;
89 }
90
91 }