From a6c6fe56b993e449fde1faeeb31e180d73b1dd01 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Wed, 31 Jul 2013 13:32:54 -0700 Subject: [PATCH] CRM-13075 - CRM_Core_BAO_Block - Allow handlePrimary() with entities from extensions ---------------------------------------- * CRM-13075: Mark is_primary for HRJob records http://issues.civicrm.org/jira/browse/CRM-13075 --- CRM/Core/BAO/Block.php | 14 +------------- tests/phpunit/CRM/Core/DAO/AllCoreTablesTest.php | 9 +++++++++ xml/templates/listAll.tpl | 13 +++++++++++++ 3 files changed, 23 insertions(+), 13 deletions(-) create mode 100644 tests/phpunit/CRM/Core/DAO/AllCoreTablesTest.php diff --git a/CRM/Core/BAO/Block.php b/CRM/Core/BAO/Block.php index 46f796b282..2866138b74 100644 --- a/CRM/Core/BAO/Block.php +++ b/CRM/Core/BAO/Block.php @@ -434,19 +434,7 @@ class CRM_Core_BAO_Block { * @static */ public static function handlePrimary(&$params, $class) { - switch ($class) { - case 'CRM_Core_BAO_Phone': - $table = 'civicrm_phone'; - break; - - case 'CRM_Core_BAO_Email': - $table = 'civicrm_email'; - break; - - case 'CRM_Core_BAO_Address': - $table = 'civicrm_address'; - break; - } + $table = CRM_Core_DAO_AllCoreTables::getTableForClass($class); // contact_id in params might be empty or the string 'null' so cast to integer $contactId = (int) CRM_Utils_Array::value('contact_id', $params); // If id is set & we haven't been passed a contact_id, retrieve it diff --git a/tests/phpunit/CRM/Core/DAO/AllCoreTablesTest.php b/tests/phpunit/CRM/Core/DAO/AllCoreTablesTest.php new file mode 100644 index 0000000000..ecff916268 --- /dev/null +++ b/tests/phpunit/CRM/Core/DAO/AllCoreTablesTest.php @@ -0,0 +1,9 @@ +assertEquals('civicrm_email', CRM_Core_DAO_AllCoreTables::getTableForClass('CRM_Core_DAO_Email')); + $this->assertEquals('civicrm_email', CRM_Core_DAO_AllCoreTables::getTableForClass('CRM_Core_BAO_Email')); + } +} \ No newline at end of file diff --git a/xml/templates/listAll.tpl b/xml/templates/listAll.tpl index f64a058325..35d1cddb5c 100644 --- a/xml/templates/listAll.tpl +++ b/xml/templates/listAll.tpl @@ -87,6 +87,10 @@ class CRM_Core_DAO_AllCoreTables {ldelim} return FALSE !== array_search($tableName, self::tables()); {rdelim} + static public function getCanonicalClassName($className) {ldelim} + return str_replace('_BAO_', '_DAO_', $className); + {rdelim} + static public function getClasses() {ldelim} return array_values(self::daoToClass()); {rdelim} @@ -103,4 +107,13 @@ class CRM_Core_DAO_AllCoreTables {ldelim} return CRM_Utils_Array::value($className, array_flip(self::daoToClass())); {rdelim} + /** + * @param string $className DAO or BAO name + * @return string|FALSE SQL table name + */ + static public function getTableForClass($className) {ldelim} + return array_search(self::getCanonicalClassName($className), self::tables()); + {rdelim} + + {rdelim} -- 2.25.1