From d73974ac410b3610672ad8bd5c3bbd7cb3d1918c Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Thu, 15 Dec 2016 18:38:54 -0500 Subject: [PATCH] CRM-19769 - Add color column to civicrm_tag --- CRM/Contact/Page/View/Summary.php | 3 +- CRM/Core/BAO/Tag.php | 1 + CRM/Core/DAO/OptionValue.php | 17 ++++++- CRM/Core/DAO/Tag.php | 17 ++++++- .../Smarty/plugins/modifier.colorContrast.php | 45 +++++++++++++++++++ CRM/Tag/Form/Edit.php | 8 +++- CRM/Tag/Form/Tag.php | 6 +-- CRM/Tag/Page/Tag.php | 2 +- CRM/Upgrade/Incremental/php/FourSeven.php | 4 ++ css/contactSummary.css | 9 +++- templates/CRM/Contact/Page/View/Summary.tpl | 8 +++- templates/CRM/Tag/Form/Tag.tpl | 10 +++-- templates/CRM/Tag/Form/Tagtree.tpl | 4 +- templates/CRM/Tag/Page/Tag.tpl | 4 +- xml/schema/Core/OptionValue.xml | 9 ++++ xml/schema/Core/Tag.xml | 9 ++++ 16 files changed, 140 insertions(+), 16 deletions(-) create mode 100644 CRM/Core/Smarty/plugins/modifier.colorContrast.php diff --git a/CRM/Contact/Page/View/Summary.php b/CRM/Contact/Page/View/Summary.php index 02fe9db092..ae7c9be464 100644 --- a/CRM/Contact/Page/View/Summary.php +++ b/CRM/Contact/Page/View/Summary.php @@ -220,7 +220,8 @@ class CRM_Contact_Page_View_Summary extends CRM_Contact_Page_View { $contactTags = CRM_Core_BAO_EntityTag::getContactTags($this->_contactId); if (!empty($contactTags)) { - $defaults['contactTag'] = implode(', ', $contactTags); + $defaults['contactTag'] = $contactTags; + $defaults['allTags'] = CRM_Core_BAO_Tag::getTagsUsedFor('civicrm_contact', FALSE); } $defaults['privacy_values'] = CRM_Core_SelectValues::privacy(); diff --git a/CRM/Core/BAO/Tag.php b/CRM/Core/BAO/Tag.php index e22af2bfce..cc44df7c02 100644 --- a/CRM/Core/BAO/Tag.php +++ b/CRM/Core/BAO/Tag.php @@ -172,6 +172,7 @@ class CRM_Core_BAO_Tag extends CRM_Core_DAO_Tag { $tags[$tag->id]['parent_id'] = $tag->parent_id; $tags[$tag->id]['is_tagset'] = $tag->is_tagset; $tags[$tag->id]['used_for'] = $tag->used_for; + $tags[$tag->id]['color'] = !empty($tag->color) ? $tag->color : NULL; } } $tag->free(); diff --git a/CRM/Core/DAO/OptionValue.php b/CRM/Core/DAO/OptionValue.php index 00fdf022bd..8a27e6203a 100644 --- a/CRM/Core/DAO/OptionValue.php +++ b/CRM/Core/DAO/OptionValue.php @@ -30,7 +30,7 @@ * * Generated from xml/schema/CRM/Core/OptionValue.xml * DO NOT EDIT. Generated by CRM_Core_CodeGen - * (GenCodeChecksum:7581126bad606520292d883da2f620ca) + * (GenCodeChecksum:fdf2f62ba69b54da0567362493827448) */ require_once 'CRM/Core/DAO.php'; require_once 'CRM/Utils/Type.php'; @@ -149,6 +149,12 @@ class CRM_Core_DAO_OptionValue extends CRM_Core_DAO { * @var string */ public $icon; + /** + * Hex color value e.g. #ffffff + * + * @var string + */ + public $color; /** * class constructor * @@ -335,6 +341,15 @@ class CRM_Core_DAO_OptionValue extends CRM_Core_DAO { 'size' => CRM_Utils_Type::HUGE, 'default' => 'NULL', ) , + 'color' => array( + 'name' => 'color', + 'type' => CRM_Utils_Type::T_STRING, + 'title' => ts('Color') , + 'description' => 'Hex color value e.g. #ffffff', + 'maxlength' => 255, + 'size' => CRM_Utils_Type::HUGE, + 'default' => 'NULL', + ) , ); CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']); } diff --git a/CRM/Core/DAO/Tag.php b/CRM/Core/DAO/Tag.php index 75835d6dab..f412f0cbcf 100644 --- a/CRM/Core/DAO/Tag.php +++ b/CRM/Core/DAO/Tag.php @@ -30,7 +30,7 @@ * * Generated from xml/schema/CRM/Core/Tag.xml * DO NOT EDIT. Generated by CRM_Core_CodeGen - * (GenCodeChecksum:e62b7ed2ffb1714200328dd2b08cdc9c) + * (GenCodeChecksum:1e6ad1d5a7c05b1a7d300d2a7722ba4d) */ require_once 'CRM/Core/DAO.php'; require_once 'CRM/Utils/Type.php'; @@ -99,6 +99,12 @@ class CRM_Core_DAO_Tag extends CRM_Core_DAO { * @var int unsigned */ public $created_id; + /** + * Hex color value e.g. #ffffff + * + * @var string + */ + public $color; /** * Date and time that tag was created. * @@ -208,6 +214,15 @@ class CRM_Core_DAO_Tag extends CRM_Core_DAO { 'description' => 'FK to civicrm_contact, who created this tag', 'FKClassName' => 'CRM_Contact_DAO_Contact', ) , + 'color' => array( + 'name' => 'color', + 'type' => CRM_Utils_Type::T_STRING, + 'title' => ts('Color') , + 'description' => 'Hex color value e.g. #ffffff', + 'maxlength' => 255, + 'size' => CRM_Utils_Type::HUGE, + 'default' => 'NULL', + ) , 'created_date' => array( 'name' => 'created_date', 'type' => CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME, diff --git a/CRM/Core/Smarty/plugins/modifier.colorContrast.php b/CRM/Core/Smarty/plugins/modifier.colorContrast.php new file mode 100644 index 0000000000..b1145e193d --- /dev/null +++ b/CRM/Core/Smarty/plugins/modifier.colorContrast.php @@ -0,0 +1,45 @@ +_id) || !CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Tag', $this->_id, 'color')) { + $defaults['color'] = '#ffffff'; + } return $defaults; } @@ -166,6 +168,10 @@ class CRM_Tag_Form_Edit extends CRM_Admin_Form { $params['is_selectable'] = 0; } + if (strtolower($params['color']) == '#ffffff') { + $params['color'] = 'null'; + } + if ($this->_action == CRM_Core_Action::DELETE) { if ($this->_id > 0) { $tag = civicrm_api3('tag', 'getsingle', array('id' => $this->_id)); diff --git a/CRM/Tag/Form/Tag.php b/CRM/Tag/Form/Tag.php index a786ebe19f..7809b1f871 100644 --- a/CRM/Tag/Form/Tag.php +++ b/CRM/Tag/Form/Tag.php @@ -76,10 +76,10 @@ class CRM_Tag_Form_Tag extends CRM_Core_Form { $this->assign('tagged', $entityTag); // get the list of all the categories - $allTag = CRM_Core_BAO_Tag::getTagsUsedFor($this->_entityTable); + $allTags = CRM_Core_BAO_Tag::getTagsUsedFor($this->_entityTable, FALSE); // need to append the array with the " checked " if contact is tagged with the tag - foreach ($allTag as $tagID => $varValue) { + foreach ($allTags as $tagID => $varValue) { if (in_array($tagID, $entityTag)) { $tagAttribute = array( 'checked' => 'checked', @@ -112,7 +112,7 @@ class CRM_Tag_Form_Tag extends CRM_Core_Form { } $this->assign('tree', $tree); - $this->assign('tag', $allTag); + $this->assign('allTags', $allTags); //build tag widget $parentNames = CRM_Core_BAO_Tag::getTagSet('civicrm_contact'); diff --git a/CRM/Tag/Page/Tag.php b/CRM/Tag/Page/Tag.php index 20ed8e097e..cd02704792 100644 --- a/CRM/Tag/Page/Tag.php +++ b/CRM/Tag/Page/Tag.php @@ -165,7 +165,7 @@ WHERE t2.id IS NULL {$reservedClause}"; $usedFor = CRM_Core_OptionGroup::values('tag_used_for'); $query = "SELECT t1.name, t1.id, t2.name as parent, t1.description, t1.used_for, t1.is_tagset, - t1.is_reserved, t1.parent_id, t1.used_for + t1.is_reserved, t1.parent_id, t1.used_for, t1.color FROM civicrm_tag t1 LEFT JOIN civicrm_tag t2 ON t1.parent_id = t2.id GROUP BY t1.parent_id, t1.id"; diff --git a/CRM/Upgrade/Incremental/php/FourSeven.php b/CRM/Upgrade/Incremental/php/FourSeven.php index e51dee5950..a1e54cfd3d 100644 --- a/CRM/Upgrade/Incremental/php/FourSeven.php +++ b/CRM/Upgrade/Incremental/php/FourSeven.php @@ -284,6 +284,10 @@ class CRM_Upgrade_Incremental_php_FourSeven extends CRM_Upgrade_Incremental_Base 'civicrm_option_value', 'icon', "varchar(255) COMMENT 'crm-i icon class' DEFAULT NULL"); $this->addTask('CRM-19626 - Add min_amount column to civicrm_price_set', 'addColumn', 'civicrm_price_set', 'min_amount', "INT(10) UNSIGNED DEFAULT '0' COMMENT 'Minimum Amount required for this set.'"); + $this->addTask('CRM-19769 - Add color column to civicrm_tag', 'addColumn', + 'civicrm_tag', 'color', "varchar(255) COMMENT 'Hex color value e.g. #ffffff' DEFAULT NULL"); + $this->addTask('CRM-19779 - Add color column to civicrm_option_value', 'addColumn', + 'civicrm_option_value', 'color', "varchar(255) COMMENT 'Hex color value e.g. #ffffff' DEFAULT NULL"); $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => $rev)), 'runSql', $rev); } diff --git a/css/contactSummary.css b/css/contactSummary.css index 0c248d78bf..a62b8827cc 100644 --- a/css/contactSummary.css +++ b/css/contactSummary.css @@ -350,4 +350,11 @@ div#crm-contact-thumbnail { } #tagGroup table { color: #000; -} \ No newline at end of file +} + +.crm-tag-item { + display: inline-block; + padding: 1px 5px; + border-radius: 3px; + border: 1px solid grey; +} diff --git a/templates/CRM/Contact/Page/View/Summary.tpl b/templates/CRM/Contact/Page/View/Summary.tpl index d585acb1cf..2cd574ad5b 100644 --- a/templates/CRM/Contact/Page/View/Summary.tpl +++ b/templates/CRM/Contact/Page/View/Summary.tpl @@ -164,7 +164,13 @@ {ts}Tags{/ts} -
{$contactTag}
+
+ {foreach from=$contactTag item=tagName key=tagId} + + {$tagName} + + {/foreach} +
{ts}Contact Type{/ts}
diff --git a/templates/CRM/Tag/Form/Tag.tpl b/templates/CRM/Tag/Form/Tag.tpl index 1cf656f931..d0e929d842 100644 --- a/templates/CRM/Tag/Form/Tag.tpl +++ b/templates/CRM/Tag/Form/Tag.tpl @@ -26,7 +26,7 @@ {* this template is used for adding/editing tags *} {literal}