From 77d0b1f8ccb0bb4a6c0d4e9ba2ce75c1946ff86b Mon Sep 17 00:00:00 2001 From: kurund Date: Sun, 9 Feb 2014 01:09:55 -0800 Subject: [PATCH] CRM-14181 fixes, deleted addDisplayEnums() and code fixes ---------------------------------------- * CRM-14181: migrate enums to varchar in schema for all tables http://issues.civicrm.org/jira/browse/CRM-14181 --- CRM/Admin/Form/RelationshipType.php | 2 -- CRM/Contact/BAO/Contact.php | 3 ++- CRM/Contact/Form/DedupeRules.php | 10 +++++----- CRM/Contact/Page/DedupeRules.php | 5 +++-- CRM/Core/Page/Basic.php | 6 +++++- CRM/Core/SelectValues.php | 15 +++++++++++++++ CRM/Custom/Page/Group.php | 3 ++- CRM/UF/Page/Field.php | 3 ++- xml/templates/dao.tpl | 18 ------------------ 9 files changed, 34 insertions(+), 31 deletions(-) diff --git a/CRM/Admin/Form/RelationshipType.php b/CRM/Admin/Form/RelationshipType.php index 76d627e0f4..7dbd708b2e 100644 --- a/CRM/Admin/Form/RelationshipType.php +++ b/CRM/Admin/Form/RelationshipType.php @@ -74,8 +74,6 @@ class CRM_Admin_Form_RelationshipType extends CRM_Admin_Form { CRM_Core_DAO::getAttribute('CRM_Contact_DAO_RelationshipType', 'description') ); - - $contactTypes = CRM_Contact_BAO_ContactType::getSelectElements(); // add select for contact type diff --git a/CRM/Contact/BAO/Contact.php b/CRM/Contact/BAO/Contact.php index fafe395c9a..90fefe0c9e 100644 --- a/CRM/Contact/BAO/Contact.php +++ b/CRM/Contact/BAO/Contact.php @@ -2381,7 +2381,8 @@ AND civicrm_openid.is_primary = 1"; $values['preferred_communication_method'] = $preffComm; $values['preferred_communication_method_display'] = CRM_Utils_Array::value('preferred_communication_method_display', $temp); - CRM_Contact_DAO_Contact::addDisplayEnums($values); + $preferredMailingFormat = CRM_Core_SelectValues::pmf(); + $values['preferred_mail_format'] = $preferredMailingFormat[$contact->preferred_mail_format]; // get preferred languages if (!empty($contact->preferred_language)) { diff --git a/CRM/Contact/Form/DedupeRules.php b/CRM/Contact/Form/DedupeRules.php index 85e21738aa..15b4014c7a 100644 --- a/CRM/Contact/Form/DedupeRules.php +++ b/CRM/Contact/Form/DedupeRules.php @@ -56,7 +56,7 @@ class CRM_Contact_Form_DedupeRules extends CRM_Admin_Form { CRM_Utils_System::permissionDenied(); CRM_Utils_System::civiExit(); } - $this->_options = array(ts('Unsupervised'), ts('Supervised'), ts('General')); + $this->_options = CRM_Core_SelectValues::getDedupeRuleTypes(); $this->_rgid = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE, 0); $this->_contactType = CRM_Utils_Request::retrieve('contact_type', 'String', $this, FALSE, 0); if ($this->_rgid) { @@ -188,16 +188,16 @@ class CRM_Contact_Form_DedupeRules extends CRM_Admin_Form { $values = $this->exportValues(); //FIXME: Handle logic to replace is_default column by usage - $used = CRM_Utils_Array::value('used', $values, FALSE); // reset used column to General (since there can only // be one 'Supervised' or 'Unsupervised' rule) - if ($this->_options[$used] != 'General') { + if ($values['used'] != 'General') { $query = " UPDATE civicrm_dedupe_rule_group SET used = 'General' WHERE contact_type = %1 AND used = %2"; - $queryParams = array(1 => array($this->_contactType, 'String'), + $queryParams = array( + 1 => array($this->_contactType, 'String'), 2 => array($this->_options[$used], 'String'), ); @@ -211,7 +211,7 @@ UPDATE civicrm_dedupe_rule_group $rgDao->title = $values['title']; $rgDao->is_reserved = CRM_Utils_Array::value('is_reserved', $values, FALSE); - $rgDao->used = $this->_options[$values['used']]; + $rgDao->used = $values['used']; $rgDao->contact_type = $this->_contactType; $rgDao->threshold = $values['threshold']; $rgDao->save(); diff --git a/CRM/Contact/Page/DedupeRules.php b/CRM/Contact/Page/DedupeRules.php index 4ea6369a92..629d992367 100644 --- a/CRM/Contact/Page/DedupeRules.php +++ b/CRM/Contact/Page/DedupeRules.php @@ -148,6 +148,7 @@ class CRM_Contact_Page_DedupeRules extends CRM_Core_Page_Basic { $dao->orderBy('contact_type,used ASC'); $dao->find(); + $dedupeRuleTypes = CRM_Core_SelectValues::getDedupeRuleTypes(); while ($dao->fetch()) { $ruleGroups[$dao->contact_type][$dao->id] = array(); CRM_Core_DAO::storeValues($dao, $ruleGroups[$dao->contact_type][$dao->id]); @@ -174,9 +175,9 @@ class CRM_Contact_Page_DedupeRules extends CRM_Core_Page_Basic { 'DedupeRule', $dao->id ); - CRM_Dedupe_DAO_RuleGroup::addDisplayEnums($ruleGroups[$dao->contact_type][$dao->id]); - } + $ruleGroups[$dao->contact_type][$dao->id]['used_display'] = $dedupeRuleTypes[$ruleGroups[$dao->contact_type][$dao->id]['used']]; + } $this->assign('brows', $ruleGroups); } diff --git a/CRM/Core/Page/Basic.php b/CRM/Core/Page/Basic.php index 65c7684623..bce480ba86 100644 --- a/CRM/Core/Page/Basic.php +++ b/CRM/Core/Page/Basic.php @@ -242,6 +242,7 @@ abstract class CRM_Core_Page_Basic extends CRM_Core_Page { } + $contactTypes = CRM_Contact_BAO_ContactType::getSelectElements(); // find all objects $object->find(); while ($object->fetch()) { @@ -257,7 +258,10 @@ abstract class CRM_Core_Page_Basic extends CRM_Core_Page { $values[$object->id] = array(); CRM_Core_DAO::storeValues($object, $values[$object->id]); - CRM_Contact_DAO_RelationshipType::addDisplayEnums($values[$object->id]); + if (is_a($object, 'CRM_Contact_DAO_RelationshipType')) { + $values[$object->id]['contact_type_a_display'] = $contactTypes[$values[$object->id]['contact_type_a']]; + $values[$object->id]['contact_type_b_display'] = $contactTypes[$values[$object->id]['contact_type_b']]; + } // populate action links $this->action($object, $action, $values[$object->id], $links, $permission); diff --git a/CRM/Core/SelectValues.php b/CRM/Core/SelectValues.php index 6c4ddbd2f2..36127993dd 100644 --- a/CRM/Core/SelectValues.php +++ b/CRM/Core/SelectValues.php @@ -866,5 +866,20 @@ class CRM_Core_SelectValues { } return $barcodeTypes; } + + /** + * dedupe rule types + */ + static function getDedupeRuleTypes() { + static $dedupeRuleTypes = NULL; + if (!$dedupeRuleTypes) { + $dedupeRuleTypes = array( + 'Unsupervised' => ts('Unsupervised'), + 'Supervised' => ts('Supervised'), + 'General' => ts('General'), + ); + } + return $dedupeRuleTypes; + } } diff --git a/CRM/Custom/Page/Group.php b/CRM/Custom/Page/Group.php index b26cea535d..b1874f37dc 100644 --- a/CRM/Custom/Page/Group.php +++ b/CRM/Custom/Page/Group.php @@ -235,8 +235,9 @@ class CRM_Custom_Page_Group extends CRM_Core_Page { } $customGroupExtends = CRM_Core_SelectValues::customGroupExtends(); + $customGroupStyle = CRM_Core_SelectValues::customGroupStyle(); foreach ($customGroup as $key => $array) { - CRM_Core_DAO_CustomGroup::addDisplayEnums($customGroup[$key]); + $customGroup[$key]['style_display'] = $customGroupStyle[$customGroup[$key]['style']]; $customGroup[$key]['extends_display'] = $customGroupExtends[$customGroup[$key]['extends']]; } diff --git a/CRM/UF/Page/Field.php b/CRM/UF/Page/Field.php index 37b6701798..f1fa6bd3ef 100644 --- a/CRM/UF/Page/Field.php +++ b/CRM/UF/Page/Field.php @@ -143,11 +143,12 @@ class CRM_UF_Page_Field extends CRM_Core_Page { $select['group'] = ts('Group(s)'); $select['tag'] = ts('Tag(s)'); + $visibility = CRM_Core_SelectValues::ufVisibility(); while ($ufFieldBAO->fetch()) { $ufField[$ufFieldBAO->id] = array(); $phoneType = $locType = ''; CRM_Core_DAO::storeValues($ufFieldBAO, $ufField[$ufFieldBAO->id]); - CRM_Core_DAO_UFField::addDisplayEnums($ufField[$ufFieldBAO->id]); + $ufField[$ufFieldBAO->id]['visibility_display'] = $visibility[$ufFieldBAO->visibility]; $ufField[$ufFieldBAO->id]['label'] = $ufFieldBAO->label; diff --git a/xml/templates/dao.tpl b/xml/templates/dao.tpl index 1f3240c29e..3d4d29e3dd 100644 --- a/xml/templates/dao.tpl +++ b/xml/templates/dao.tpl @@ -357,24 +357,6 @@ class {$table.className} extends CRM_Core_DAO {ldelim} return self::$_export; {rdelim} -{if $table.hasEnum} - - /** - * adds $value['foo_display'] for each $value['foo'] enum from {$table.name} - * - * @param array $values (reference) the array up for enhancing - * @return void - */ - static function addDisplayEnums(&$values) {ldelim} - $enumFields =& {$table.className}::getEnums(); - foreach ($enumFields as $enum) {ldelim} - if (isset($values[$enum])) {ldelim} - $values[$enum.'_display'] = {$table.className}::tsEnum($enum, $values[$enum]); - {rdelim} - {rdelim} - {rdelim} -{/if} - {rdelim} -- 2.25.1