From 7b611c343f2a7f325bdee4fc5b3694aba575396d Mon Sep 17 00:00:00 2001 From: Rich Lott / Artful Robot Date: Wed, 28 Feb 2024 17:18:46 +0000 Subject: [PATCH] Add redundant contact_id field for search kit/form builder; add index on category field... --- CRM/Contactcats/DAO/ContactCategory.php | 46 +++++++++++++++-- Civi/Api4/Action/ContactCategory/Sync.php | 4 +- ang/crmContactcats.css | 12 +++-- .../crmContactCategorySettings.html | 51 ++++++++++++++----- managed/options.mgd.php | 1 + sql/auto_install.sql | 4 +- .../CRM/Contactcats/ContactCategory.xml | 24 +++++++-- 7 files changed, 113 insertions(+), 29 deletions(-) diff --git a/CRM/Contactcats/DAO/ContactCategory.php b/CRM/Contactcats/DAO/ContactCategory.php index 2d29e2e..e8b44e5 100644 --- a/CRM/Contactcats/DAO/ContactCategory.php +++ b/CRM/Contactcats/DAO/ContactCategory.php @@ -6,7 +6,7 @@ * * Generated from contactcats/xml/schema/CRM/Contactcats/ContactCategory.xml * DO NOT EDIT. Generated by CRM_Core_CodeGen - * (GenCodeChecksum:01a6344ef3d86c080e4362dafa008d13) + * (GenCodeChecksum:222d053743f68a2678d92b8a75b46316) */ use CRM_Contactcats_ExtensionUtil as E; @@ -40,6 +40,15 @@ class CRM_Contactcats_DAO_ContactCategory extends CRM_Core_DAO { */ public $id; + /** + * Same as id but for FormBuilder + * + * @var int|string + * (SQL type: int unsigned) + * Note that values will be retrieved from the database as a string. + */ + public $contact_id; + /** * @var int|string * (SQL type: int unsigned) @@ -97,12 +106,34 @@ class CRM_Contactcats_DAO_ContactCategory extends CRM_Core_DAO { 'entity' => 'ContactCategory', 'bao' => 'CRM_Contactcats_DAO_ContactCategory', 'localizable' => 0, + 'html' => [ + 'type' => 'Number', + ], + 'readonly' => TRUE, + 'add' => NULL, + ], + 'contact_id' => [ + 'name' => 'contact_id', + 'type' => CRM_Utils_Type::T_INT, + 'title' => E::ts('Contact ID'), + 'description' => E::ts('Same as id but for FormBuilder'), + 'required' => TRUE, + 'usage' => [ + 'import' => FALSE, + 'export' => FALSE, + 'duplicate_matching' => FALSE, + 'token' => FALSE, + ], + 'where' => 'civicrm_contact_category.contact_id', + 'table_name' => 'civicrm_contact_category', + 'entity' => 'ContactCategory', + 'bao' => 'CRM_Contactcats_DAO_ContactCategory', + 'localizable' => 0, 'FKClassName' => 'CRM_Contact_DAO_Contact', 'html' => [ 'type' => 'EntityRef', 'label' => E::ts("Contact"), ], - 'readonly' => TRUE, 'add' => NULL, ], 'category' => [ @@ -192,7 +223,16 @@ class CRM_Contactcats_DAO_ContactCategory extends CRM_Core_DAO { * @return array */ public static function indices($localize = TRUE) { - $indices = []; + $indices = [ + 'index_category' => [ + 'name' => 'index_category', + 'field' => [ + 0 => 'category', + ], + 'localizable' => FALSE, + 'sig' => 'civicrm_contact_category::0::category', + ], + ]; return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables::multilingualize(__CLASS__, $indices) : $indices; } diff --git a/Civi/Api4/Action/ContactCategory/Sync.php b/Civi/Api4/Action/ContactCategory/Sync.php index 20c2c41..a7dde97 100644 --- a/Civi/Api4/Action/ContactCategory/Sync.php +++ b/Civi/Api4/Action/ContactCategory/Sync.php @@ -54,13 +54,13 @@ class Sync extends \Civi\Api4\Generic\AbstractAction { Civi::log()->debug('', ['=' => 'pop']); } - Civi::log()->debug('Resetting table', ['=' => 'timed']); + Civi::log()->debug('Resetting table', ['=' => 'start,timed']); // clear out temp space. CRM_Core_DAO::executeQuery("UPDATE civicrm_contact_category SET next_category = 0;")->free(); // ensure we have all our contacts covered. CRM_Core_DAO::executeQuery(<<free(); Civi::log()->debug('', ['=' => 'pop']); diff --git a/ang/crmContactcats.css b/ang/crmContactcats.css index c96a34f..4d043bb 100644 --- a/ang/crmContactcats.css +++ b/ang/crmContactcats.css @@ -1,18 +1,22 @@ /* Add any CSS rules for Angular module "crmContactcats" */ crm-contact-category-settings ol { - padding:0; + padding: 0; } crm-contact-category-settings ol li { display: flex; - padding:0.5em 0; + padding: 0.5em 0; + align-items: flex-end; gap: 1em; } +crm-contact-category-settings li label { + display: block; +} crm-contact-category-settings .name-input-wrapper { flex: 0 1 29ch; } crm-contact-category-settings .hint { - display:none; + display: none; } crm-contact-category-settings .name-input-wrapper:focus-within .hint { - display:block; + display: block; } diff --git a/ang/crmContactcats/crmContactCategorySettings.html b/ang/crmContactcats/crmContactCategorySettings.html index b4c596c..4885e28 100644 --- a/ang/crmContactcats/crmContactCategorySettings.html +++ b/ang/crmContactcats/crmContactCategorySettings.html @@ -2,34 +2,57 @@ Loading...
- +
  1. - -
    +
    + + +
    +
    Default
    -
    +
    - +
    {{ts('Use the Up/Down arrow keys to re-order')}}
    - +

-
Categories saved. Contacts will be updated shortly (when the next Scheduled - Job run - happens).
+
+ Categories saved. Contacts will be updated shortly (when the next Scheduled + Job run happens). +
diff --git a/managed/options.mgd.php b/managed/options.mgd.php index c026092..665d87d 100644 --- a/managed/options.mgd.php +++ b/managed/options.mgd.php @@ -19,6 +19,7 @@ return [ 'name', 'label', 'description', + 'weight', ], ], 'match' => [ diff --git a/sql/auto_install.sql b/sql/auto_install.sql index cd3b36e..420ae1a 100644 --- a/sql/auto_install.sql +++ b/sql/auto_install.sql @@ -35,9 +35,11 @@ SET FOREIGN_KEY_CHECKS=1; -- *******************************************************/ CREATE TABLE `civicrm_contact_category` ( `id` int unsigned NOT NULL AUTO_INCREMENT COMMENT 'Unique ID, corresponds to contact id', + `contact_id` int unsigned NOT NULL COMMENT 'Same as id but for FormBuilder', `category` int unsigned NOT NULL DEFAULT 0, `next_category` int unsigned NOT NULL DEFAULT 0, PRIMARY KEY (`id`), - CONSTRAINT FK_civicrm_contact_category_id FOREIGN KEY (`id`) REFERENCES `civicrm_contact`(`id`) ON DELETE CASCADE + INDEX `index_category`(category), + CONSTRAINT FK_civicrm_contact_category_contact_id FOREIGN KEY (`contact_id`) REFERENCES `civicrm_contact`(`id`) ON DELETE CASCADE ) ENGINE=InnoDB; diff --git a/xml/schema/CRM/Contactcats/ContactCategory.xml b/xml/schema/CRM/Contactcats/ContactCategory.xml index e2a4b8a..10bae2f 100644 --- a/xml/schema/CRM/Contactcats/ContactCategory.xml +++ b/xml/schema/CRM/Contactcats/ContactCategory.xml @@ -13,16 +13,26 @@ true Unique ID, corresponds to contact id - EntityRef - + Number id true + + + contact_id + int unsigned + true + Same as id but for FormBuilder + + EntityRef + + + - id + contact_id civicrm_contact
id CASCADE @@ -30,7 +40,7 @@ category - int unsigned + int unsigned true 0 @@ -40,10 +50,14 @@ Select + + index_category + category + next_category - int unsigned + int unsigned true 0