Skip to content

Commit

Permalink
Merge pull request #20434 from colemanw/groupContact
Browse files Browse the repository at this point in the history
SearchKit - Add static groups and organize main entity selector
  • Loading branch information
colemanw authored May 31, 2021
2 parents b89ccf7 + 4736288 commit 94f5f09
Show file tree
Hide file tree
Showing 76 changed files with 203 additions and 87 deletions.
2 changes: 1 addition & 1 deletion Civi/Api4/ACL.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
*
* Creating a new ACL requires at minimum an entity table, entity ID and object_table.
*
* @searchable false
* @searchable none
* @see https://docs.civicrm.org/user/en/latest/initial-set-up/permissions-and-access-control
* @package Civi\Api4
*/
Expand Down
2 changes: 1 addition & 1 deletion Civi/Api4/ActionSchedule.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
*
* Creating a new ActionSchedule requires at minimum a title, mapping_id and entity_value.
*
* @searchable false
* @searchable none
* @see https://docs.civicrm.org/user/en/latest/email/scheduled-reminders/
* @package Civi\Api4
*/
Expand Down
1 change: 1 addition & 0 deletions Civi/Api4/Activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
* An activity is a record of some type of interaction with one or more contacts.
*
* @see https://docs.civicrm.org/user/en/latest/organising-your-data/activities/
* @searchable primary
* @package Civi\Api4
*/
class Activity extends Generic\DAOEntity {
Expand Down
5 changes: 3 additions & 2 deletions Civi/Api4/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@
/**
* Address Entity.
*
* This entity holds the address informatiom of a contact. Each contact may hold
* This entity holds the address information of a contact. Each contact may hold
* one or more addresses but must have different location types respectively.
*
* Creating a new address requires at minimum a contact's ID and location type ID
* and other attributes (although optional) like street address, city, country etc.
* and other attributes (although optional) like street address, city, country etc.
*
* @ui_join_filters location_type_id
*
* @searchable secondary
* @package Civi\Api4
*/
class Address extends Generic\DAOEntity {
Expand Down
1 change: 1 addition & 0 deletions Civi/Api4/Batch.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
/**
* Batch entity.
*
* @searchable secondary
* @see https://docs.civicrm.org/user/en/latest/pledges/everyday-tasks/#batch-entry-of-pledges
* @package Civi\Api4
*/
Expand Down
1 change: 1 addition & 0 deletions Civi/Api4/Campaign.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
* Campaign entity.
*
* @see https://docs.civicrm.org/user/en/latest/campaign/what-is-civicampaign/
* @searchable secondary
* @package Civi\Api4
*/
class Campaign extends Generic\DAOEntity {
Expand Down
1 change: 1 addition & 0 deletions Civi/Api4/CiviCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
* Note that the class for this entity is named "CiviCase" because "Case" is a keyword reserved by php.
*
* @see https://docs.civicrm.org/user/en/latest/case-management/what-is-civicase/
* @searchable primary
* @package Civi\Api4
*/
class CiviCase extends Generic\DAOEntity {
Expand Down
1 change: 1 addition & 0 deletions Civi/Api4/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
* Creating a new contact requires at minimum a name or email address.
*
* @see https://docs.civicrm.org/user/en/latest/organising-your-data/contacts/
* @searchable primary
* @package Civi\Api4
*/
class Contact extends Generic\DAOEntity {
Expand Down
1 change: 1 addition & 0 deletions Civi/Api4/Contribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
/**
* Contribution entity.
*
* @searchable primary
* @package Civi\Api4
*/
class Contribution extends Generic\DAOEntity {
Expand Down
1 change: 1 addition & 0 deletions Civi/Api4/ContributionPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
/**
* ContributionPage entity.
*
* @searchable secondary
* @package Civi\Api4
*/
class ContributionPage extends Generic\DAOEntity {
Expand Down
1 change: 1 addition & 0 deletions Civi/Api4/ContributionRecur.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
/**
* ContributionRecur entity.
*
* @searchable secondary
* @package Civi\Api4
*/
class ContributionRecur extends Generic\DAOEntity {
Expand Down
1 change: 1 addition & 0 deletions Civi/Api4/ContributionSoft.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
/**
* ContributionSoft entity.
*
* @searchable secondary
* @package Civi\Api4
*/
class ContributionSoft extends Generic\DAOEntity {
Expand Down
2 changes: 1 addition & 1 deletion Civi/Api4/CustomField.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* CustomField entity.
*
* @see https://docs.civicrm.org/user/en/latest/organising-your-data/creating-custom-fields/
* @searchable false
* @searchable none
* @package Civi\Api4
*/
class CustomField extends Generic\DAOEntity {
Expand Down
2 changes: 1 addition & 1 deletion Civi/Api4/CustomGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* CustomGroup entity.
*
* @see https://docs.civicrm.org/user/en/latest/organising-your-data/creating-custom-fields/
* @searchable false
* @searchable none
* @package Civi\Api4
*/
class CustomGroup extends Generic\DAOEntity {
Expand Down
2 changes: 1 addition & 1 deletion Civi/Api4/CustomValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public static function getInfo() {
return [
'class' => __CLASS__,
'type' => ['CustomValue'],
'searchable' => TRUE,
'searchable' => 'secondary',
'see' => [
'https://docs.civicrm.org/user/en/latest/organising-your-data/creating-custom-fields/#multiple-record-fieldsets',
'\Civi\Api4\CustomGroup',
Expand Down
2 changes: 1 addition & 1 deletion Civi/Api4/Dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* Displaying an item to a user is done with the `DashboardContact` entity.
*
* @see \Civi\Api4\DashboardContact
* @searchable false
* @searchable none
* @package Civi\Api4
*/
class Dashboard extends Generic\DAOEntity {
Expand Down
2 changes: 1 addition & 1 deletion Civi/Api4/DashboardContact.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* This places a dashboard item on a user's home screen.
*
* @see \Civi\Api4\Dashboard
* @searchable false
* @searchable none
* @package Civi\Api4
*/
class DashboardContact extends Generic\DAOEntity {
Expand Down
2 changes: 1 addition & 1 deletion Civi/Api4/Domain.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* Domains - multisite instances of CiviCRM.
*
* @see https://docs.civicrm.org/sysadmin/en/latest/setup/multisite/
* @searchable false
* @searchable none
* @package Civi\Api4
*/
class Domain extends Generic\DAOEntity {
Expand Down
1 change: 1 addition & 0 deletions Civi/Api4/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
*
* Creating a new email address requires at minimum a contact's ID and email
*
* @searchable secondary
* @package Civi\Api4
*/
class Email extends Generic\DAOEntity {
Expand Down
8 changes: 7 additions & 1 deletion Civi/Api4/Entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
*
* @see \Civi\Api4\Generic\AbstractEntity
*
* @searchable none
* @package Civi\Api4
*/
class Entity extends Generic\AbstractEntity {
Expand Down Expand Up @@ -90,7 +91,12 @@ public static function getFields($checkPermissions = TRUE) {
],
[
'name' => 'searchable',
'description' => 'Should this entity be selectable in search kit UI',
'description' => 'How should this entity be presented in search UIs',
'options' => [
'primary' => ts('Primary'),
'secondary' => ts('Secondary'),
'none' => ts('None'),
],
],
[
'name' => 'paths',
Expand Down
13 changes: 12 additions & 1 deletion Civi/Api4/EntityFinancialAccount.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,23 @@
*
* @see https://docs.civicrm.org/dev/en/latest/financial/financialentities/#financial-accounts
*
* @bridge entity_id financial_account_id
* @ui_join_filters account_relationship
*
* @package Civi\Api4
*/
class EntityFinancialAccount extends Generic\DAOEntity {
use Generic\Traits\EntityBridge;

/**
* @return array
*/
public static function getInfo() {
$info = parent::getInfo();
$info['bridge'] = [
'entity_id' => [],
'financial_account_id' => [],
];
return $info;
}

}
14 changes: 12 additions & 2 deletions Civi/Api4/EntityFinancialTrxn.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,21 @@
*
* @see https://docs.civicrm.org/dev/en/latest/financial/financialentities/
*
* @bridge entity_id financial_trxn_id
*
* @package Civi\Api4
*/
class EntityFinancialTrxn extends Generic\DAOEntity {
use Generic\Traits\EntityBridge;

/**
* @return array
*/
public static function getInfo() {
$info = parent::getInfo();
$info['bridge'] = [
'entity_id' => [],
'financial_trxn_id' => [],
];
return $info;
}

}
1 change: 1 addition & 0 deletions Civi/Api4/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
*
* @see https://docs.civicrm.org/user/en/latest/events/what-is-civievent/
*
* @searchable primary
* @package Civi\Api4
*/
class Event extends Generic\DAOEntity {
Expand Down
1 change: 1 addition & 0 deletions Civi/Api4/FinancialAccount.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
*
* @see https://docs.civicrm.org/user/en/latest/contributions/key-concepts-and-configurations/#financial-types-financial-accounts-and-accounting-codes
*
* @searchable secondary
* @package Civi\Api4
*/
class FinancialAccount extends Generic\DAOEntity {
Expand Down
1 change: 1 addition & 0 deletions Civi/Api4/FinancialTrxn.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
*
* @see https://docs.civicrm.org/dev/en/latest/financial/financialentities/#financial-transactions
*
* @searchable secondary
* @package Civi\Api4
*/
class FinancialTrxn extends Generic\DAOEntity {
Expand Down
1 change: 1 addition & 0 deletions Civi/Api4/FinancialType.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@
* @package Civi\Api4
*/
class FinancialType extends Generic\DAOEntity {
use Generic\Traits\OptionList;

}
2 changes: 1 addition & 1 deletion Civi/Api4/Generic/AbstractEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public static function getInfo() {
foreach (ReflectionUtils::getTraits(static::class) as $trait) {
$info['type'][] = self::stripNamespace($trait);
}
$info['searchable'] = !in_array('OptionList', $info['type']);
$info['searchable'] = in_array('OptionList', $info['type'], TRUE) ? 'none' : 'secondary';
$reflection = new \ReflectionClass(static::class);
$info = array_merge($info, ReflectionUtils::getCodeDocs($reflection, NULL, ['entity' => $info['name']]));
unset($info['package'], $info['method']);
Expand Down
7 changes: 3 additions & 4 deletions Civi/Api4/Generic/Traits/EntityBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,16 @@ trait EntityBridge {
/**
* Adds "bridge" info, which should specify an array of two field names from this entity
*
* This automatic function can be overridden by annotating the APIv4 entity like
* `@bridge contact_id group_id`
* This automatic function can be overridden by adding a getInfo function to the api entity class.
*
* @return array
*/
public static function getInfo() {
$info = parent::getInfo();
if (!empty($info['dao']) && empty($info['bridge'])) {
if (!empty($info['dao'])) {
foreach (($info['dao'])::fields() as $field) {
if (!empty($field['FKClassName']) || $field['name'] === 'entity_id') {
$info['bridge'][] = $field['name'];
$info['bridge'][$field['name']] = [];
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Civi/Api4/Generic/Traits/OptionList.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* The options appear in the field metadata for other entities that reference this one via pseudoconstant.
*
* Note: At time of writing, this trait does nothing except toggle the searchable flag, (and adds "OptionList" to the "type" in Entity::get() metadata).
* @searchable false (FYI annotation isn't functional because this is a trait - workaround in AbstractEntity::getInfo)
* @searchable none (FYI annotation isn't functional because this is a trait - workaround in AbstractEntity::getInfo)
*/
trait OptionList {

Expand Down
1 change: 1 addition & 0 deletions Civi/Api4/Grant.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
*
* @see https://docs.civicrm.org/user/en/latest/grants/what-is-civigrant/
*
* @searchable primary
* @package Civi\Api4
*/
class Grant extends Generic\DAOEntity {
Expand Down
1 change: 1 addition & 0 deletions Civi/Api4/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*
* @see https://docs.civicrm.org/user/en/latest/organising-your-data/groups-and-tags/#groups
*
* @searchable secondary
* @package Civi\Api4
*/
class Group extends Generic\DAOEntity {
Expand Down
16 changes: 14 additions & 2 deletions Civi/Api4/GroupContact.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
* A contact can either be "Added" "Removed" or "Pending" in a group.
* CiviCRM only considers them to be "in" a group if their status is "Added".
*
* @bridge group_id contact_id
* @ui_join_filters status
*
* @see \Civi\Api4\Group
* @searchable false
* @package Civi\Api4
*/
class GroupContact extends Generic\DAOEntity {
Expand Down Expand Up @@ -59,4 +59,16 @@ public static function update($checkPermissions = TRUE) {
->setCheckPermissions($checkPermissions);
}

/**
* @return array
*/
public static function getInfo() {
$info = parent::getInfo();
$info['bridge'] = [
'group_id' => ['description' => ts('Static (non-smart) group contacts')],
'contact_id' => ['description' => ts('Static (non-smart) group contacts')],
];
return $info;
}

}
2 changes: 1 addition & 1 deletion Civi/Api4/GroupNesting.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* GroupNesting entity.
*
* @see \Civi\Api4\Group
* @searchable false
* @searchable none
* @package Civi\Api4
*/
class GroupNesting extends Generic\DAOEntity {
Expand Down
3 changes: 3 additions & 0 deletions Civi/Api4/GroupOrganization.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
*
* Relates groups to organizations.
*
* FIXME: For now, excluding this from SearchKit because it's confusingly similar to GroupContact
* @searchable none
*
* @see \Civi\Api4\Group
* @package Civi\Api4
*/
Expand Down
1 change: 1 addition & 0 deletions Civi/Api4/IM.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
/**
* IM entity.
*
* @searchable secondary
* @package Civi\Api4
*/
class IM extends Generic\DAOEntity {
Expand Down
1 change: 1 addition & 0 deletions Civi/Api4/LineItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
/**
* LineItem entity.
*
* @searchable secondary
* @package Civi\Api4
*/
class LineItem extends Generic\DAOEntity {
Expand Down
2 changes: 1 addition & 1 deletion Civi/Api4/LocBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*
* Links addresses, emails & phones to Events.
*
* @searchable false
* @searchable none
* @package Civi\Api4
*/
class LocBlock extends Generic\DAOEntity {
Expand Down
Loading

0 comments on commit 94f5f09

Please sign in to comment.