From e171748b9a4b13b3024321bcccaa4a78d96ad057 Mon Sep 17 00:00:00 2001 From: Olaf Buddenhagen Date: Mon, 5 Aug 2013 12:47:05 +0200 Subject: [PATCH] Introduce new `formal_title` field for contacts For Individual contacts, add a Title field along with the other name fields. This one sits between the Individual Prefix and First Name fields, which is the right place for academic and other formal titles (not only) in Germany. It is a free-form text field, as there are way too many obscure titles and possible combinations of titles for any kind of exhaustive option list. Also, this field is generally not processed, but rather just included verbatim wherever the name is used -- so there is no real need for normalisation. Note: The field is conditional in the templates, but it's added unconditionally at PHP level in this commit. That's because we don't know yet how to handle the configuration best. A followup commit implements one possible variant for the configuration. In the actual input form, the field is labled with just 'Title', as it should be clear enough in this context that it's about a formal title; and a shorter name seems more convenient... However, we are wondering whether this doesn't introduce additional confusion? This commit is mostly only covering the main contact screen. (And some other generic bits, such as exportable fields etc.) There are various other places dealing with name fields (especially for billing contacts and honoree) -- each one implementing it individually (and thus rather inconsistently...) in a hard-coded fashion. Adapting all of these will be a crazy amount of work, so we are punting this for now... (The Right Thing To Do (TM) probably would be implementing some central name handling code to use everywhere.) With this commit, the definition of the existing `prefix` field is also slightly changed regarding the import heuristics, to reflect the fact that titles are no longer supposed to be stored in the `prefix` field. --- CRM/Contact/BAO/Contact.php | 4 ++++ CRM/Contact/BAO/Individual.php | 20 ++++++++++++++++++- CRM/Contact/BAO/Query.php | 2 ++ CRM/Contact/Form/Edit/Individual.php | 2 ++ .../Incremental/sql/4.5.alpha1.mysql.tpl | 3 +++ CRM/Utils/Address.php | 1 + .../CRM/Contact/Form/Edit/Individual.tpl | 6 ++++++ .../CRM/Contact/Form/Inline/ContactName.tpl | 6 ++++++ xml/schema/Contact/Contact.xml | 9 +++++++++ 9 files changed, 52 insertions(+), 1 deletion(-) diff --git a/CRM/Contact/BAO/Contact.php b/CRM/Contact/BAO/Contact.php index 5306c580f1..57768039f5 100644 --- a/CRM/Contact/BAO/Contact.php +++ b/CRM/Contact/BAO/Contact.php @@ -1187,6 +1187,7 @@ WHERE id={$id}; "; 'first_name', 'middle_name', 'last_name', + 'formal_title', 'job_title', 'gender_id', 'prefix_id', @@ -1204,6 +1205,7 @@ WHERE id={$id}; "; 'first_name', 'middle_name', 'last_name', + 'formal_title', 'job_title', 'gender_id', 'prefix_id', @@ -1444,6 +1446,7 @@ WHERE id={$id}; "; 'first_name', 'middle_name', 'last_name', + 'formal_title', 'job_title', 'gender_id', 'prefix_id', @@ -1467,6 +1470,7 @@ WHERE id={$id}; "; 'first_name', 'middle_name', 'last_name', + 'formal_title', 'job_title', 'gender_id', 'prefix_id', diff --git a/CRM/Contact/BAO/Individual.php b/CRM/Contact/BAO/Individual.php index f51d957f58..1887ba445f 100644 --- a/CRM/Contact/BAO/Individual.php +++ b/CRM/Contact/BAO/Individual.php @@ -61,7 +61,7 @@ class CRM_Contact_BAO_Individual extends CRM_Contact_DAO_Contact { // "null" value for example is passed by dedupe merge in order to empty. // Display name computation shouldn't consider such values. foreach (array( - 'first_name', 'middle_name', 'last_name', 'nick_name') as $displayField) { + 'first_name', 'middle_name', 'last_name', 'nick_name', 'formal_title') as $displayField) { if (CRM_Utils_Array::value($displayField, $params) == "null") { $params[$displayField] = ''; } @@ -74,6 +74,7 @@ class CRM_Contact_BAO_Individual extends CRM_Contact_DAO_Contact { $nickName = CRM_Utils_Array::value('nick_name', $params, ''); $prefix_id = CRM_Utils_Array::value('prefix_id', $params, ''); $suffix_id = CRM_Utils_Array::value('suffix_id', $params, ''); + $formalTitle = CRM_Utils_Array::value('formal_title', $params, ''); // get prefix and suffix names $prefixes = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'prefix_id'); @@ -121,6 +122,10 @@ class CRM_Contact_BAO_Individual extends CRM_Contact_DAO_Contact { } } + if ($individual->formal_title && CRM_Utils_Array::value('preserveDBName', $params)) { + $useDBNames[] = 'formal_title'; + } + // CRM-4430 //1. preserve db name if want //2. lets get value from param if exists. @@ -174,6 +179,18 @@ class CRM_Contact_BAO_Individual extends CRM_Contact_DAO_Contact { $$phpName = $temp[$value]; } } + + if (in_array('formal_title', $useDBNames)) { + $params['formal_title'] = $individual->formal_title; + $contact->formal_title = $individual->formal_title; + $formalTitle = $individual->formal_title; + } + elseif (array_key_exists('formal_title', $params)) { + $formalTitle = $params['formal_title']; + } + elseif ($individual->formal_title) { + $formalTitle = $individual->formal_title; + } } } @@ -195,6 +212,7 @@ class CRM_Contact_BAO_Individual extends CRM_Contact_DAO_Contact { 'individual_prefix' => $prefix, 'prefix_id' => $prefix_id, 'suffix_id' => $suffix_id, + 'formal_title' => $formalTitle, ); // make sure we have all the name fields. foreach ($nameParams as $name => $value) { diff --git a/CRM/Contact/BAO/Query.php b/CRM/Contact/BAO/Query.php index d4c2dad662..064308d657 100644 --- a/CRM/Contact/BAO/Query.php +++ b/CRM/Contact/BAO/Query.php @@ -3987,6 +3987,7 @@ civicrm_relationship.start_date > {$today} 'last_name' => 1, 'prefix_id' => 1, 'suffix_id' => 1, + 'formal_title' => 1, 'birth_date' => 1, 'gender_id' => 1, 'street_address' => 1, @@ -4538,6 +4539,7 @@ SELECT COUNT( civicrm_contribution.total_amount ) as cancel_count, 'last_name' => 1, 'prefix_id' => 1, 'suffix_id' => 1, + 'formal_title' => 1, 'email_greeting' => 1, 'postal_greeting' => 1, 'addressee' => 1, diff --git a/CRM/Contact/Form/Edit/Individual.php b/CRM/Contact/Form/Edit/Individual.php index f87e842f84..d87f7dddc4 100644 --- a/CRM/Contact/Form/Edit/Individual.php +++ b/CRM/Contact/Form/Edit/Individual.php @@ -63,6 +63,8 @@ class CRM_Contact_Form_Edit_Individual { $attributes = CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact'); + $form->addElement('text', 'formal_title', ts('Title'), $attributes['formal_title']); + // first_name $form->addElement('text', 'first_name', ts('First Name'), $attributes['first_name']); diff --git a/CRM/Upgrade/Incremental/sql/4.5.alpha1.mysql.tpl b/CRM/Upgrade/Incremental/sql/4.5.alpha1.mysql.tpl index 3fd798cb0f..dc95209664 100644 --- a/CRM/Upgrade/Incremental/sql/4.5.alpha1.mysql.tpl +++ b/CRM/Upgrade/Incremental/sql/4.5.alpha1.mysql.tpl @@ -1 +1,4 @@ {* file to handle db changes in 4.5.alpha1 during upgrade *} + +ALTER TABLE `civicrm_contact` + ADD COLUMN `formal_title` varchar(64) COMMENT 'Formal (academic or similar) title in front of name. (Prof., Dr. etc.)' AFTER `suffix_id`; diff --git a/CRM/Utils/Address.php b/CRM/Utils/Address.php index 83ccea7cd2..352927daba 100644 --- a/CRM/Utils/Address.php +++ b/CRM/Utils/Address.php @@ -107,6 +107,7 @@ class CRM_Utils_Address { $replacements = array( 'contact.display_name' => CRM_Utils_Array::value('display_name', $fields), 'contact.individual_prefix' => CRM_Utils_Array::value('individual_prefix', $fields), + 'contact.formal_title' => CRM_Utils_Array::value('formal_title', $fields), 'contact.first_name' => CRM_Utils_Array::value('first_name', $fields), 'contact.middle_name' => CRM_Utils_Array::value('middle_name', $fields), 'contact.last_name' => CRM_Utils_Array::value('last_name', $fields), diff --git a/templates/CRM/Contact/Form/Edit/Individual.tpl b/templates/CRM/Contact/Form/Edit/Individual.tpl index 11268d5883..4fa5077911 100644 --- a/templates/CRM/Contact/Form/Edit/Individual.tpl +++ b/templates/CRM/Contact/Form/Edit/Individual.tpl @@ -86,6 +86,12 @@ cj(function($) { {$form.prefix_id.html} {/if} + {if $form.formal_title} + + {$form.formal_title.label}
+ {$form.formal_title.html} + + {/if} {$form.first_name.label}
{$form.first_name.html} diff --git a/templates/CRM/Contact/Form/Inline/ContactName.tpl b/templates/CRM/Contact/Form/Inline/ContactName.tpl index 40a0b4679e..9397bf9802 100644 --- a/templates/CRM/Contact/Form/Inline/ContactName.tpl +++ b/templates/CRM/Contact/Form/Inline/ContactName.tpl @@ -36,6 +36,12 @@ {$form.prefix_id.html} {/if} + {if $form.formal_title} +
+ {$form.formal_title.label}
+ {$form.formal_title.html} +
+ {/if}
{$form.first_name.label}
{$form.first_name.html} diff --git a/xml/schema/Contact/Contact.xml b/xml/schema/Contact/Contact.xml index 6c90dc3b98..292a3691a7 100644 --- a/xml/schema/Contact/Contact.xml +++ b/xml/schema/Contact/Contact.xml @@ -381,6 +381,15 @@ suffix_id 1.6 + + formal_title + varchar + 64 + true + /^title/i + Formal (academic or similar) title in front of name. (Prof., Dr. etc.) + 4.5 + greeting_type varchar -- 2.25.1