Beispiel #1
0
 /**
  * Attempts to retrieve the API entity name from any calling class.
  * FIXME: This is a bit hackish but the naming convention for forms is not very strict
  *
  * @param string|object $classNameOrObject
  *
  * @return string
  * @throws CRM_Core_Exception
  */
 public static function getEntityName($classNameOrObject)
 {
     require_once 'api/api.php';
     $className = is_string($classNameOrObject) ? $classNameOrObject : get_class($classNameOrObject);
     // First try the obvious replacements
     $daoName = str_replace(array('_BAO_', '_Form_', '_Page_'), '_DAO_', $className);
     $entityName = CRM_Core_DAO_AllCoreTables::getBriefName($daoName);
     // If that didn't work, try a different pattern
     if (!$entityName) {
         list(, $parent, , $child) = explode('_', $className);
         $daoName = "CRM_{$parent}_DAO_{$child}";
         $entityName = CRM_Core_DAO_AllCoreTables::getBriefName($daoName);
     }
     // If that didn't work, try a different pattern
     if (!$entityName) {
         $daoName = "CRM_{$parent}_DAO_{$parent}";
         $entityName = CRM_Core_DAO_AllCoreTables::getBriefName($daoName);
     }
     // If that didn't work, try a different pattern
     if (!$entityName) {
         $daoName = "CRM_Core_DAO_{$child}";
         $entityName = CRM_Core_DAO_AllCoreTables::getBriefName($daoName);
     }
     // If that didn't work, try using just the trailing name
     if (!$entityName) {
         $entityName = CRM_Core_DAO_AllCoreTables::getFullName($child) ? $child : NULL;
     }
     // If that didn't work, try using just the leading name
     if (!$entityName) {
         $entityName = CRM_Core_DAO_AllCoreTables::getFullName($parent) ? $parent : NULL;
     }
     if (!$entityName) {
         throw new CRM_Core_Exception('Could not find api name for supplied class');
     }
     return $entityName;
 }
Beispiel #2
0
/**
 * Return the DAO of the function or Entity.
 *
 * @param string $name
 *   Either a function of the api (civicrm_{entity}_create or the entity name.
 *   return the DAO name to manipulate this function
 *   eg. "civicrm_api3_contact_create" or "Contact" will return "CRM_Contact_BAO_Contact"
 *
 * @return mixed|string
 */
function _civicrm_api3_get_DAO($name)
{
    if (strpos($name, 'civicrm_api3') !== FALSE) {
        $last = strrpos($name, '_');
        // len ('civicrm_api3_') == 13
        $name = substr($name, 13, $last - 13);
    }
    $name = _civicrm_api_get_camel_name($name);
    if ($name == 'Individual' || $name == 'Household' || $name == 'Organization') {
        $name = 'Contact';
    }
    // hack to deal with incorrectly named BAO/DAO - see CRM-10859
    // FIXME: DAO should be renamed CRM_Mailing_DAO_MailingEventQueue
    if ($name == 'MailingEventQueue') {
        return 'CRM_Mailing_Event_DAO_Queue';
    }
    // FIXME: DAO should be renamed CRM_Mailing_DAO_MailingRecipients
    // but am not confident mailing_recipients is tested so have not tackled.
    if ($name == 'MailingRecipients') {
        return 'CRM_Mailing_DAO_Recipients';
    }
    // FIXME: DAO should be renamed CRM_Mailing_DAO_MailingComponent
    if ($name == 'MailingComponent') {
        return 'CRM_Mailing_DAO_Component';
    }
    // FIXME: DAO should be renamed CRM_ACL_DAO_AclRole
    if ($name == 'AclRole') {
        return 'CRM_ACL_DAO_EntityRole';
    }
    // FIXME: DAO should be renamed CRM_SMS_DAO_SmsProvider
    // But this would impact SMS extensions so need to coordinate
    // Probably best approach is to migrate them to use the api and decouple them from core BAOs
    if ($name == 'SmsProvider') {
        return 'CRM_SMS_DAO_Provider';
    }
    // FIXME: DAO names should follow CamelCase convention
    if ($name == 'Im' || $name == 'Acl') {
        $name = strtoupper($name);
    }
    $dao = CRM_Core_DAO_AllCoreTables::getFullName($name);
    if ($dao || !$name) {
        return $dao;
    }
    // Really weird apis can declare their own DAO name. Not sure if this is a good idea...
    if (file_exists("api/v3/{$name}.php")) {
        include_once "api/v3/{$name}.php";
    }
    $daoFn = "_civicrm_api3_" . _civicrm_api_get_entity_name_from_camel($name) . "_DAO";
    if (function_exists($daoFn)) {
        return $daoFn();
    }
    return NULL;
}
 /**
  * Return the name of the DAO Class. If a dao class does not exist return an empty value
  *
  * @return string
  */
 protected function getDaoClassName()
 {
     $daoClassName = CRM_Core_DAO_AllCoreTables::getFullName($this->objectName);
     return $daoClassName;
 }
Beispiel #4
0
/**
 * Function to return the DAO of the function or Entity
 * @param String $name  either a function of the api (civicrm_{entity}_create or the entity name
 * return the DAO name to manipulate this function
 * eg. "civicrm_api3_contact_create" or "Contact" will return "CRM_Contact_BAO_Contact"
 * @return mixed|string
 */
function _civicrm_api3_get_DAO($name)
{
    if (strpos($name, 'civicrm_api3') !== FALSE) {
        $last = strrpos($name, '_');
        // len ('civicrm_api3_') == 13
        $name = substr($name, 13, $last - 13);
    }
    $name = _civicrm_api_get_camel_name($name, 3);
    if ($name == 'Individual' || $name == 'Household' || $name == 'Organization') {
        $name = 'Contact';
    }
    // hack to deal with incorrectly named BAO/DAO - see CRM-10859
    // FIXME: DAO should be renamed CRM_Mailing_DAO_MailingRecipients
    // but am not confident mailing_recipients is tested so have not tackled.
    if ($name == 'MailingRecipients') {
        return 'CRM_Mailing_DAO_Recipients';
    }
    // FIXME: DAO should be renamed CRM_Mailing_DAO_MailingComponent
    if ($name == 'MailingComponent') {
        return 'CRM_Mailing_DAO_Component';
    }
    // FIXME: DAO should be renamed CRM_ACL_DAO_AclRole
    if ($name == 'AclRole') {
        return 'CRM_ACL_DAO_EntityRole';
    }
    // FIXME: DAO should be renamed CRM_SMS_DAO_SmsProvider
    // But this would impact SMS extensions so need to coordinate
    // Probably best approach is to migrate them to use the api and decouple them from core BAOs
    if ($name == 'SmsProvider') {
        return 'CRM_SMS_DAO_Provider';
    }
    // FIXME: DAO names should follow CamelCase convention
    if ($name == 'Im' || $name == 'Acl') {
        $name = strtoupper($name);
    }
    return CRM_Core_DAO_AllCoreTables::getFullName($name);
}
Beispiel #5
0
/**
 * Function to return the DAO of the function or Entity
 * @param String $name  either a function of the api (civicrm_{entity}_create or the entity name
 * return the DAO name to manipulate this function
 * eg. "civicrm_api3_contact_create" or "Contact" will return "CRM_Contact_BAO_Contact"
 * @return mixed|string
 */
function _civicrm_api3_get_DAO($name)
{
    if (strpos($name, 'civicrm_api3') !== FALSE) {
        $last = strrpos($name, '_');
        // len ('civicrm_api3_') == 13
        $name = substr($name, 13, $last - 13);
    }
    $name = _civicrm_api_get_camel_name($name, 3);
    if ($name == 'Individual' || $name == 'Household' || $name == 'Organization') {
        $name = 'Contact';
    }
    //hack to deal with incorrectly named BAO/DAO - see CRM-10859 -
    // several of these have been removed but am not confident mailing_recipients is
    // tests so have not tackled.
    // correct approach for im is unclear
    if ($name == 'mailing_recipients' || $name == 'MailingRecipients') {
        return 'CRM_Mailing_BAO_Recipients';
    }
    if (strtolower($name) == 'im') {
        return 'CRM_Core_BAO_IM';
    }
    $dao = CRM_Core_DAO_AllCoreTables::getFullName($name);
    if ($dao || !$name) {
        return $dao;
    }
    // Really weird apis can declare their own DAO name. Not sure if this is a good idea...
    if (file_exists("api/v3/{$name}.php")) {
        include_once "api/v3/{$name}.php";
    }
    $daoFn = "_civicrm_api3_" . _civicrm_api_get_entity_name_from_camel($name) . "_DAO";
    if (function_exists($daoFn)) {
        return $daoFn();
    }
    return NULL;
}