<?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) {
// 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) {