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