From 033dcbb6a8e065d4ea60c4126b58034cecf35796 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Thu, 31 Mar 2022 17:21:45 -0400 Subject: [PATCH] Add civicrm_contact_type.icon column Toward dev/user-interface#26 This adds an icon column and populates it with data but does not yet expose it in the UI. The next step is to switch the UI from using the image_URL column over to using the icon column. --- CRM/Contact/DAO/ContactType.php | 26 ++++++++++++++++++- CRM/Upgrade/Incremental/php/FiveFortyNine.php | 3 +++ .../Incremental/sql/5.49.alpha1.mysql.tpl | 4 +++ sql/test_data.mysql | 14 +++++----- .../BAO/ContactType/ContactTypeTest.php | 15 ++++++++++- xml/schema/Contact/ContactType.xml | 9 +++++++ xml/templates/civicrm_data.tpl | 8 +++--- xml/templates/civicrm_sample.tpl | 12 ++++----- 8 files changed, 72 insertions(+), 19 deletions(-) diff --git a/CRM/Contact/DAO/ContactType.php b/CRM/Contact/DAO/ContactType.php index c97ef494e9..00043c7bd9 100644 --- a/CRM/Contact/DAO/ContactType.php +++ b/CRM/Contact/DAO/ContactType.php @@ -6,7 +6,7 @@ * * Generated from xml/schema/CRM/Contact/ContactType.xml * DO NOT EDIT. Generated by CRM_Core_CodeGen - * (GenCodeChecksum:cc7d1501964e3a55b30e3df24aad8cf0) + * (GenCodeChecksum:9f3dbdc9b75770b084a6f2d6a4dfc652) */ /** @@ -75,6 +75,15 @@ class CRM_Contact_DAO_ContactType extends CRM_Core_DAO { */ public $image_URL; + /** + * crm-i icon class representing this contact type + * + * @var string|null + * (SQL type: varchar(255)) + * Note that values will be retrieved from the database as a string. + */ + public $icon; + /** * Optional FK to parent contact type. * @@ -223,6 +232,21 @@ class CRM_Contact_DAO_ContactType extends CRM_Core_DAO { 'localizable' => 0, 'add' => '3.1', ], + 'icon' => [ + 'name' => 'icon', + 'type' => CRM_Utils_Type::T_STRING, + 'title' => ts('Icon'), + 'description' => ts('crm-i icon class representing this contact type'), + 'maxlength' => 255, + 'size' => CRM_Utils_Type::HUGE, + 'where' => 'civicrm_contact_type.icon', + 'default' => NULL, + 'table_name' => 'civicrm_contact_type', + 'entity' => 'ContactType', + 'bao' => 'CRM_Contact_BAO_ContactType', + 'localizable' => 0, + 'add' => '5.49', + ], 'parent_id' => [ 'name' => 'parent_id', 'type' => CRM_Utils_Type::T_INT, diff --git a/CRM/Upgrade/Incremental/php/FiveFortyNine.php b/CRM/Upgrade/Incremental/php/FiveFortyNine.php index 269073cea2..a1270f775c 100644 --- a/CRM/Upgrade/Incremental/php/FiveFortyNine.php +++ b/CRM/Upgrade/Incremental/php/FiveFortyNine.php @@ -61,6 +61,9 @@ class CRM_Upgrade_Incremental_php_FiveFortyNine extends CRM_Upgrade_Incremental_ * The version number matching this function name */ public function upgrade_5_49_alpha1($rev): void { + $this->addTask('Add civicrm_contact_type.icon column', 'addColumn', + 'civicrm_contact_type', 'icon', "varchar(255) DEFAULT NULL COMMENT 'crm-i icon class representing this contact type'" + ); $this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev); foreach ($this->booleanColumns as $tableName => $columns) { foreach ($columns as $columnName => $defn) { diff --git a/CRM/Upgrade/Incremental/sql/5.49.alpha1.mysql.tpl b/CRM/Upgrade/Incremental/sql/5.49.alpha1.mysql.tpl index ea81d7b768..83e32307e1 100644 --- a/CRM/Upgrade/Incremental/sql/5.49.alpha1.mysql.tpl +++ b/CRM/Upgrade/Incremental/sql/5.49.alpha1.mysql.tpl @@ -1 +1,5 @@ {* file to handle db changes in 5.49.alpha1 during upgrade *} + +UPDATE `civicrm_contact_type` SET `icon` = 'fa-user' WHERE `name` = 'Individual'; +UPDATE `civicrm_contact_type` SET `icon` = 'fa-home' WHERE `name` = 'Household'; +UPDATE `civicrm_contact_type` SET `icon` = 'fa-building' WHERE `name` = 'Organization'; diff --git a/sql/test_data.mysql b/sql/test_data.mysql index 837a7a87a4..2460f7c568 100644 --- a/sql/test_data.mysql +++ b/sql/test_data.mysql @@ -1,11 +1,11 @@ INSERT INTO `civicrm_contact_type` - ( `name`, `label`,`image_URL`, `parent_id`, `is_active`,`is_reserved`) + ( `name`, `label`,`image_URL`, `parent_id`, `is_active`, `is_reserved`, `icon`) VALUES - ( 'Student' , 'Student' , NULL, 1, 1, 0), - ( 'Parent' , 'Parent' , NULL, 1, 1, 0), - ( 'Staff' , 'Staff' , NULL, 1, 1, 0), - ( 'Team' , 'Team' , NULL, 3, 1, 0), - ( 'Sponsor' , 'Sponsor' , NULL, 3, 1, 0); + ( 'Student' , 'Student' , NULL, 1, 1, 0, 'fa-graduation-cap'), + ( 'Parent' , 'Parent' , NULL, 1, 1, 0, 'fa-user-circle-o'), + ( 'Staff' , 'Staff' , NULL, 1, 1, 0, 'fa-id-badge'), + ( 'Team' , 'Team' , NULL, 3, 1, 0, 'fa-users'), + ( 'Sponsor' , 'Sponsor' , NULL, 3, 1, 0, 'fa-leaf'); + - diff --git a/tests/phpunit/CRM/Contact/BAO/ContactType/ContactTypeTest.php b/tests/phpunit/CRM/Contact/BAO/ContactType/ContactTypeTest.php index b4f15a4589..5be8e8980f 100644 --- a/tests/phpunit/CRM/Contact/BAO/ContactType/ContactTypeTest.php +++ b/tests/phpunit/CRM/Contact/BAO/ContactType/ContactTypeTest.php @@ -106,7 +106,7 @@ class CRM_Contact_BAO_ContactType_ContactTypeTest extends CiviUnitTestCase { * @throws \API_Exception */ public function testContactTypeInfo() { - $blahType = ['is_active' => 0, 'name' => 'blah', 'label' => 'blah blah', 'parent_id:name' => 'Individual']; + $blahType = ['is_active' => 0, 'name' => 'blah', 'label' => 'blah blah', 'parent_id:name' => 'Individual', 'icon' => 'fa-random']; $createdType = ContactType::create()->setValues($blahType)->execute()->first(); $activeTypes = CRM_Contact_BAO_ContactType::contactTypeInfo(); $expected = $this->getExpectedContactTypes(); @@ -123,6 +123,7 @@ class CRM_Contact_BAO_ContactType_ContactTypeTest extends CiviUnitTestCase { 'parent_label' => 'Individual', 'description' => '', 'image_URL' => '', + 'icon' => 'fa-random', ]; $this->assertEquals($expected, $allTypes); } @@ -146,6 +147,7 @@ class CRM_Contact_BAO_ContactType_ContactTypeTest extends CiviUnitTestCase { 'parent' => NULL, 'parent_label' => NULL, 'image_URL' => '', + 'icon' => 'fa-user', ], 'Household' => [ @@ -159,6 +161,7 @@ class CRM_Contact_BAO_ContactType_ContactTypeTest extends CiviUnitTestCase { 'parent' => NULL, 'parent_label' => NULL, 'image_URL' => '', + 'icon' => 'fa-home', ], 'Organization' => [ @@ -172,6 +175,7 @@ class CRM_Contact_BAO_ContactType_ContactTypeTest extends CiviUnitTestCase { 'parent' => NULL, 'parent_label' => NULL, 'image_URL' => '', + 'icon' => 'fa-building', ], 'Student' => [ @@ -185,6 +189,7 @@ class CRM_Contact_BAO_ContactType_ContactTypeTest extends CiviUnitTestCase { 'parent' => 'Individual', 'parent_label' => 'Individual', 'image_URL' => '', + 'icon' => 'fa-graduation-cap', ], 'Parent' => [ @@ -198,6 +203,7 @@ class CRM_Contact_BAO_ContactType_ContactTypeTest extends CiviUnitTestCase { 'parent' => 'Individual', 'parent_label' => 'Individual', 'image_URL' => '', + 'icon' => 'fa-user-circle-o', ], 'Staff' => [ @@ -211,6 +217,7 @@ class CRM_Contact_BAO_ContactType_ContactTypeTest extends CiviUnitTestCase { 'parent' => 'Individual', 'parent_label' => 'Individual', 'image_URL' => '', + 'icon' => 'fa-id-badge', ], 'Team' => [ @@ -224,6 +231,7 @@ class CRM_Contact_BAO_ContactType_ContactTypeTest extends CiviUnitTestCase { 'parent' => 'Organization', 'parent_label' => 'Organization', 'image_URL' => '', + 'icon' => 'fa-users', ], 'Sponsor' => [ @@ -237,6 +245,7 @@ class CRM_Contact_BAO_ContactType_ContactTypeTest extends CiviUnitTestCase { 'parent' => 'Organization', 'parent_label' => 'Organization', 'image_URL' => '', + 'icon' => 'fa-leaf', ], 'sub1_individual' => [ @@ -250,6 +259,7 @@ class CRM_Contact_BAO_ContactType_ContactTypeTest extends CiviUnitTestCase { 'parent' => 'Individual', 'parent_label' => 'Individual', 'image_URL' => '', + 'icon' => '', ], 'sub2_individual' => [ @@ -263,6 +273,7 @@ class CRM_Contact_BAO_ContactType_ContactTypeTest extends CiviUnitTestCase { 'parent' => 'Individual', 'parent_label' => 'Individual', 'image_URL' => '', + 'icon' => '', ], 'sub_organization' => [ @@ -276,6 +287,7 @@ class CRM_Contact_BAO_ContactType_ContactTypeTest extends CiviUnitTestCase { 'parent' => 'Organization', 'parent_label' => 'Organization', 'image_URL' => '', + 'icon' => '', ], 'sub_household' => [ @@ -289,6 +301,7 @@ class CRM_Contact_BAO_ContactType_ContactTypeTest extends CiviUnitTestCase { 'parent' => 'Household', 'parent_label' => 'Household', 'image_URL' => '', + 'icon' => '', ], ]; } diff --git a/xml/schema/Contact/ContactType.xml b/xml/schema/Contact/ContactType.xml index b93bcc0cc2..264da30c3d 100644 --- a/xml/schema/Contact/ContactType.xml +++ b/xml/schema/Contact/ContactType.xml @@ -68,6 +68,15 @@ URL of image if any. 3.1 + + icon + Icon + varchar + 255 + NULL + crm-i icon class representing this contact type + 5.49 + parent_id Parent ID diff --git a/xml/templates/civicrm_data.tpl b/xml/templates/civicrm_data.tpl index 12349708e6..c512269a5f 100644 --- a/xml/templates/civicrm_data.tpl +++ b/xml/templates/civicrm_data.tpl @@ -1637,11 +1637,11 @@ VALUES ( 'civicrm_contact', 'civicrm_contact', 'Date Field', 'contact_date_reminder_options', 'Annual Options', 'date_field', NULL, NULL); INSERT INTO `civicrm_contact_type` - (`id`, `name`, `label`,`image_URL`, `parent_id`, `is_active`,`is_reserved`) + (`id`, `name`, `label`,`image_URL`, `parent_id`, `is_active`,`is_reserved`, `icon`) VALUES - ( 1, 'Individual' , '{ts escape="sql"}Individual{/ts}' , NULL, NULL, 1, 1), - ( 2, 'Household' , '{ts escape="sql"}Household{/ts}' , NULL, NULL, 1, 1), - ( 3, 'Organization', '{ts escape="sql"}Organization{/ts}', NULL, NULL, 1, 1); + ( 1, 'Individual' , '{ts escape="sql"}Individual{/ts}' , NULL, NULL, 1, 1, 'fa-user'), + ( 2, 'Household' , '{ts escape="sql"}Household{/ts}' , NULL, NULL, 1, 1, 'fa-home'), + ( 3, 'Organization', '{ts escape="sql"}Organization{/ts}', NULL, NULL, 1, 1, 'fa-building'); {include file='civicrm_msg_template.tpl'} diff --git a/xml/templates/civicrm_sample.tpl b/xml/templates/civicrm_sample.tpl index 23480ffd15..c2aa3eede5 100644 --- a/xml/templates/civicrm_sample.tpl +++ b/xml/templates/civicrm_sample.tpl @@ -96,13 +96,13 @@ VALUES (@option_group_id_act, 'Interview', (SELECT @option_value_max_val := @option_value_max_val + 1), 'Interview', NULL, 0, NULL, @option_value_max_val, 'Conduct a phone or in person interview.', 0, 0, 1, 'fa-comment-o'); INSERT INTO `civicrm_contact_type` - ( `name`, `label`,`image_URL`, `parent_id`, `is_active`,`is_reserved`) + ( `name`, `label`,`image_URL`, `parent_id`, `is_active`, `is_reserved`, `icon`) VALUES - ( 'Student' , '{ts escape="sql"}Student{/ts}' , NULL, 1, 1, 0), - ( 'Parent' , '{ts escape="sql"}Parent{/ts}' , NULL, 1, 1, 0), - ( 'Staff' , '{ts escape="sql"}Staff{/ts}' , NULL, 1, 1, 0), - ( 'Team' , '{ts escape="sql"}Team{/ts}' , NULL, 3, 1, 0), - ( 'Sponsor' , '{ts escape="sql"}Sponsor{/ts}' , NULL, 3, 1, 0); + ( 'Student' , '{ts escape="sql"}Student{/ts}' , NULL, 1, 1, 0, 'fa-graduation-cap'), + ( 'Parent' , '{ts escape="sql"}Parent{/ts}' , NULL, 1, 1, 0, 'fa-user-circle-o'), + ( 'Staff' , '{ts escape="sql"}Staff{/ts}' , NULL, 1, 1, 0, 'fa-id-badge'), + ( 'Team' , '{ts escape="sql"}Team{/ts}' , NULL, 3, 1, 0, 'fa-users'), + ( 'Sponsor' , '{ts escape="sql"}Sponsor{/ts}' , NULL, 3, 1, 0, 'fa-leaf'); SELECT @domain_id := min(id) FROM civicrm_domain; SELECT @nav_indi := id FROM civicrm_navigation WHERE name = 'New Individual'; -- 2.25.1