Merge pull request #3571 from totten/master-casetype-maxinst
[civicrm-core.git] / CRM / Utils / Api.php
index 4d700e5e1da6b81c0695e443448784ce08e8d96e..3c1b145684465b8c648748f10606b78640977a60 100644 (file)
@@ -1,9 +1,9 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.4                                                |
+ | CiviCRM version 4.5                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013                                |
+ | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
  +--------------------------------------------------------------------+
 */
 
+/**
+ * Class CRM_Utils_Api
+ */
 class CRM_Utils_Api {
   /**
-   * Attempt to retrieve the api entity name from any calling class
-   * @param $classNameOrObject
+   * Attempts to retrieve the API entity name from any calling class.
+   *
+   * @param string|object $classNameOrObject
+   *
+   * @return string
    * @throws CRM_Core_Exception
    */
   static function getEntityName($classNameOrObject) {
@@ -41,15 +47,20 @@ class CRM_Utils_Api {
 
     // If that didn't work, try a different pattern
     if (!$shortName) {
-      list(, $entity) = explode('_', $className);
-      $daoName = "CRM_{$entity}_DAO_$entity";
+      list(, $parent, , $child) = explode('_', $className);
+      $daoName = "CRM_{$parent}_DAO_$child";
       $shortName = CRM_Core_DAO_AllCoreTables::getBriefName($daoName);
     }
 
     // If that didn't work, try a different pattern
     if (!$shortName) {
-      list(, , , $entity) = explode('_', $className);
-      $daoName = "CRM_Core_DAO_$entity";
+      $daoName = "CRM_{$parent}_DAO_$parent";
+      $shortName = CRM_Core_DAO_AllCoreTables::getBriefName($daoName);
+    }
+
+    // If that didn't work, try a different pattern
+    if (!$shortName) {
+      $daoName = "CRM_Core_DAO_$child";
       $shortName = CRM_Core_DAO_AllCoreTables::getBriefName($daoName);
     }
     if (!$shortName) {