From e597fc33c6fd2afbeb978492bb54e04493544255 Mon Sep 17 00:00:00 2001 From: Dave Greenberg Date: Wed, 11 Nov 2015 11:52:28 -0800 Subject: [PATCH] CRM-17357 - Conditional label for Name / Email search fields based on search setting. ---------------------------------------- * CRM-17357: PHP fatal error during creation of receipt PDF https://issues.civicrm.org/jira/browse/CRM-17357 --- CRM/Activity/Form/Search.php | 2 +- CRM/Case/Form/Search.php | 28 ++++++++++++++++++---- CRM/Contact/Form/Search/Basic.php | 5 +--- CRM/Contribute/Form/Search.php | 31 +++++++++++++++++------- CRM/Core/Form/Search.php | 40 +++++++++++++++++++++++++++++++ CRM/Event/Form/Search.php | 24 ++++++++++++++++++- CRM/Grant/Form/Search.php | 2 +- CRM/Member/Form/Search.php | 24 ++++++++++++++++++- CRM/Pledge/Form/Search.php | 24 ++++++++++++++++++- 9 files changed, 158 insertions(+), 22 deletions(-) diff --git a/CRM/Activity/Form/Search.php b/CRM/Activity/Form/Search.php index fa0a9db5d8..ba25b59755 100644 --- a/CRM/Activity/Form/Search.php +++ b/CRM/Activity/Form/Search.php @@ -166,7 +166,7 @@ class CRM_Activity_Form_Search extends CRM_Core_Form_Search { */ public function buildQuickForm() { parent::buildQuickForm(); - $this->addElement('text', 'sort_name', ts('Name or Email'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name')); + $this->addSortNameField(); CRM_Activity_BAO_Query::buildSearchForm($this); diff --git a/CRM/Case/Form/Search.php b/CRM/Case/Form/Search.php index a43f10585f..d1c08247db 100644 --- a/CRM/Case/Form/Search.php +++ b/CRM/Case/Form/Search.php @@ -171,11 +171,7 @@ class CRM_Case_Form_Search extends CRM_Core_Form_Search { */ public function buildQuickForm() { parent::buildQuickForm(); - $this->addElement('text', - 'sort_name', - ts('Client Name or Email'), - CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name') - ); + $this->addSortNameField(); CRM_Case_BAO_Query::buildSearchForm($this); @@ -201,6 +197,28 @@ class CRM_Case_Form_Search extends CRM_Core_Form_Search { } + /** + * Get the label for the sortName field if email searching is on. + * + * (email searching is a setting under search preferences). + * + * @return string + */ + protected function getSortNameLabelWithEmail() { + return ts('Client Name or Email'); + } + + /** + * Get the label for the sortName field if email searching is off. + * + * (email searching is a setting under search preferences). + * + * @return string + */ + protected function getSortNameLabelWithOutEmail() { + return ts('Client Name'); + } + /** * The post processing of the form gets done here. * diff --git a/CRM/Contact/Form/Search/Basic.php b/CRM/Contact/Form/Search/Basic.php index c49b90a638..e6c2bb7f22 100644 --- a/CRM/Contact/Form/Search/Basic.php +++ b/CRM/Contact/Form/Search/Basic.php @@ -57,10 +57,7 @@ class CRM_Contact_Form_Search_Basic extends CRM_Contact_Form_Search { * @return void */ public function buildQuickForm() { - // text for sort_name or email criteria - $config = CRM_Core_Config::singleton(); - $label = empty($config->includeEmailInName) ? ts('Name') : ts('Name or Email'); - $this->add('text', 'sort_name', $label); + $this->addSortNameField(); $searchOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'advanced_search_options' diff --git a/CRM/Contribute/Form/Search.php b/CRM/Contribute/Form/Search.php index e6635b93ba..3158716bc4 100644 --- a/CRM/Contribute/Form/Search.php +++ b/CRM/Contribute/Form/Search.php @@ -168,14 +168,7 @@ class CRM_Contribute_Form_Search extends CRM_Core_Form_Search { */ public function buildQuickForm() { parent::buildQuickForm(); - // text for sort_name - $this->addElement('text', - 'sort_name', - ts('Contributor Name or Email'), - CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', - 'sort_name' - ) - ); + $this->addSortNameField(); $this->_group = CRM_Core_PseudoConstant::nestedGroup(); @@ -216,6 +209,28 @@ class CRM_Contribute_Form_Search extends CRM_Core_Form_Search { } + /** + * Get the label for the sortName field if email searching is on. + * + * (email searching is a setting under search preferences). + * + * @return string + */ + protected function getSortNameLabelWithEmail() { + return ts('Contributor Name or Email'); + } + + /** + * Get the label for the sortName field if email searching is off. + * + * (email searching is a setting under search preferences). + * + * @return string + */ + protected function getSortNameLabelWithOutEmail() { + return ts('Contributor Name'); + } + /** * The post processing of the form gets done here. * diff --git a/CRM/Core/Form/Search.php b/CRM/Core/Form/Search.php index 5a610b57fa..99c66f3da7 100644 --- a/CRM/Core/Form/Search.php +++ b/CRM/Core/Form/Search.php @@ -150,4 +150,44 @@ class CRM_Core_Form_Search extends CRM_Core_Form { } } + /** + * Add the sort-name field to the form. + * + * There is a setting to determine whether email is included in the search & we look this up to determine + * which text to choose. + * + * Note that for translation purposes the full string works better than using 'prefix' hence we use override-able functions + * to define the string. + */ + protected function addSortNameField() { + $this->addElement( + 'text', + 'sort_name', + civicrm_api3('setting', 'getvalue', array('name' => 'includeEmailInName', 'group' => 'Search Preferences')) ? $this->getSortNameLabelWithEmail() : $this->getSortNameLabelWithOutEmail(), + CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name') + ); + } + + /** + * Get the label for the sortName field if email searching is on. + * + * (email searching is a setting under search preferences). + * + * @return string + */ + protected function getSortNameLabelWithEmail() { + return ts('Name or Email'); + } + + /** + * Get the label for the sortName field if email searching is off. + * + * (email searching is a setting under search preferences). + * + * @return string + */ + protected function getSortNameLabelWithOutEmail() { + return ts('Name'); + } + } diff --git a/CRM/Event/Form/Search.php b/CRM/Event/Form/Search.php index 5d77cbfd57..f71addcb2f 100644 --- a/CRM/Event/Form/Search.php +++ b/CRM/Event/Form/Search.php @@ -170,7 +170,7 @@ class CRM_Event_Form_Search extends CRM_Core_Form_Search { */ public function buildQuickForm() { parent::buildQuickForm(); - $this->addElement('text', 'sort_name', ts('Participant Name or Email'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name')); + $this->addSortNameField(); CRM_Event_BAO_Query::buildSearchForm($this); @@ -241,6 +241,28 @@ class CRM_Event_Form_Search extends CRM_Core_Form_Search { } + /** + * Get the label for the sortName field if email searching is on. + * + * (email searching is a setting under search preferences). + * + * @return string + */ + protected function getSortNameLabelWithEmail() { + return ts('Participant Name or Email'); + } + + /** + * Get the label for the sortName field if email searching is off. + * + * (email searching is a setting under search preferences). + * + * @return string + */ + protected function getSortNameLabelWithOutEmail() { + return ts('Participant Name'); + } + /** * The post processing of the form gets done here. * diff --git a/CRM/Grant/Form/Search.php b/CRM/Grant/Form/Search.php index 4b4c307e70..7f09be2bc2 100644 --- a/CRM/Grant/Form/Search.php +++ b/CRM/Grant/Form/Search.php @@ -162,7 +162,7 @@ class CRM_Grant_Form_Search extends CRM_Core_Form_Search { */ public function buildQuickForm() { parent::buildQuickForm(); - $this->addElement('text', 'sort_name', ts('Name or Email'), array('class' => 'twenty') + CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name')); + $this->addSortNameField(); CRM_Grant_BAO_Query::buildSearchForm($this); diff --git a/CRM/Member/Form/Search.php b/CRM/Member/Form/Search.php index 796b54b04f..09f14305ae 100644 --- a/CRM/Member/Form/Search.php +++ b/CRM/Member/Form/Search.php @@ -160,7 +160,7 @@ class CRM_Member_Form_Search extends CRM_Core_Form_Search { */ public function buildQuickForm() { parent::buildQuickForm(); - $this->addElement('text', 'sort_name', ts('Member Name or Email'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name')); + $this->addSortNameField(); CRM_Member_BAO_Query::buildSearchForm($this); @@ -177,6 +177,28 @@ class CRM_Member_Form_Search extends CRM_Core_Form_Search { } + /** + * Get the label for the sortName field if email searching is on. + * + * (email searching is a setting under search preferences). + * + * @return string + */ + protected function getSortNameLabelWithEmail() { + return ts('Member Name or Email'); + } + + /** + * Get the label for the sortName field if email searching is off. + * + * (email searching is a setting under search preferences). + * + * @return string + */ + protected function getSortNameLabelWithOutEmail() { + return ts('Member Name'); + } + /** * The post processing of the form gets done here. * diff --git a/CRM/Pledge/Form/Search.php b/CRM/Pledge/Form/Search.php index 74914ced03..8670624f8d 100644 --- a/CRM/Pledge/Form/Search.php +++ b/CRM/Pledge/Form/Search.php @@ -158,7 +158,7 @@ class CRM_Pledge_Form_Search extends CRM_Core_Form_Search { */ public function buildQuickForm() { parent::buildQuickForm(); - $this->addElement('text', 'sort_name', ts('Pledger Name or Email'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name')); + $this->addSortNameField(); CRM_Pledge_BAO_Query::buildSearchForm($this); @@ -175,6 +175,28 @@ class CRM_Pledge_Form_Search extends CRM_Core_Form_Search { } + /** + * Get the label for the sortName field if email searching is on. + * + * (email searching is a setting under search preferences). + * + * @return string + */ + protected function getSortNameLabelWithEmail() { + return ts('Pledger Name or Email'); + } + + /** + * Get the label for the sortName field if email searching is off. + * + * (email searching is a setting under search preferences). + * + * @return string + */ + protected function getSortNameLabelWithOutEmail() { + return ts('Pledger Name'); + } + /** * The post processing of the form gets done here. * -- 2.25.1