3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
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 +--------------------------------------------------------------------+
12 namespace Civi\Search
;
16 * @package Civi\Search
23 public static function getAdminSettings():array {
25 'operators' => \CRM_Utils_Array
::makeNonAssociative(self
::getOperators()),
26 'functions' => \CRM_Api4_Page_Api4Explorer
::getSqlFunctions(),
27 'displayTypes' => Display
::getDisplayTypes(['name', 'label', 'description', 'icon']),
34 public static function getOperators():array {
42 'CONTAINS' => ts('Contains'),
44 'NOT IN' => ts('Not In'),
45 'LIKE' => ts('Is Like'),
46 'NOT LIKE' => ts('Not Like'),
47 'BETWEEN' => ts('Is Between'),
48 'NOT BETWEEN' => ts('Not Between'),
49 'IS NULL' => ts('Is Null'),
50 'IS NOT NULL' => ts('Not Null'),
55 * Fetch all entities the current user has permission to `get`
58 public static function getSchema() {
60 $entities = \Civi\Api4\Entity
::get()
61 ->addSelect('name', 'title', 'title_plural', 'description', 'icon')
62 ->addWhere('name', '!=', 'Entity')
63 ->addOrderBy('title_plural')
65 'get' => ['$name', 'getActions', ['where' => [['name', '=', 'get']]], ['params']],
67 $getFields = ['name', 'label', 'description', 'options', 'input_type', 'input_attrs', 'data_type', 'serialize', 'fk_entity'];
68 foreach ($entities as $entity) {
69 // Skip if entity doesn't have a 'get' action or the user doesn't have permission to use get
71 $entity['fields'] = civicrm_api4($entity['name'], 'getFields', [
72 'select' => $getFields,
73 'where' => [['name', 'NOT IN', ['api_key', 'hash']]],
74 'orderBy' => ['label'],
76 $params = $entity['get'][0];
77 // Entity must support at least these params or it is too weird for search kit
78 if (!array_diff(['select', 'where', 'orderBy', 'limit', 'offset'], array_keys($params))) {
79 \CRM_Utils_Array
::remove($params, 'checkPermissions', 'debug', 'chain', 'language', 'select', 'where', 'orderBy', 'limit', 'offset');
80 unset($entity['get']);
81 $schema[] = ['params' => array_keys($params)] +
array_filter($entity);
89 * @param array $allowedEntities
92 public static function getLinks(array $allowedEntities) {
94 $keys = array_flip(['alias', 'entity', 'joinType']);
95 foreach (civicrm_api4('Entity', 'getLinks', ['where' => [['entity', 'IN', $allowedEntities]]], ['entity' => 'links']) as $entity => $links) {
97 foreach ($links as $link) {
98 if (!empty($link['entity']) && in_array($link['entity'], $allowedEntities)) {
99 // Use entity.alias as array key to avoid duplicates
100 $entityLinks[$link['entity'] . $link['alias']] = array_intersect_key($link, $keys);
103 $results[$entity] = array_values($entityLinks);
105 return array_filter($results);