Merge remote-tracking branch 'upstream/4.3' into 4.3-master-2013-06-05-06-52-23
[civicrm-core.git] / api / v3 / utils.php
index af6a11e9e950ad5d0c65fd04a6bf5efc2995232d..75ec408df92a4e321efe268885694eda13a5760f 100644 (file)
  * Initialize CiviCRM - should be run at the start of each API function
  */
 function _civicrm_api3_initialize() {
-  require_once 'CRM/Core/Config.php';
-  $config = CRM_Core_Config::singleton();
-  }
+  require_once 'CRM/Core/ClassLoader.php';
+  CRM_Core_ClassLoader::singleton()->register();
+  CRM_Core_Config::singleton();
+}
 
 /**
  * Wrapper Function for civicrm_verify_mandatory to make it simple to pass either / or fields for checking
@@ -189,14 +190,6 @@ function civicrm_api3_create_success($values = 1, $params = array(
   }
   //if ( array_key_exists ('debug',$params) && is_object ($dao)) {
   if (is_array($params) && array_key_exists('debug', $params)) {
-    if (!is_object($dao)) {
-      $d = _civicrm_api3_get_DAO(CRM_Utils_Array::value('entity', $params));
-      if (!empty($d)) {
-        $file = str_replace('_', '/', $d) . ".php";
-        require_once ($file);
-        $dao = new $d();
-      }
-    }
     if (is_string($action) && $action != 'getfields') {
       $apiFields = civicrm_api($entity, 'getfields', array('version' => 3, 'action' => $action) + $params);
     }
@@ -259,8 +252,6 @@ function _civicrm_api3_load_DAO($entity) {
   if (empty($dao)) {
     return FALSE;
   }
-  $file = str_replace('_', '/', $dao) . ".php";
-  require_once ($file);
   $d = new $dao();
   return $d;
 }
@@ -302,17 +293,6 @@ function _civicrm_api3_get_DAO($name) {
   if(strtolower($name) == 'im'){
     return 'CRM_Core_BAO_IM';
   }
-  if(strtolower($name) == 'group'){
-    //    CRM-12628
-    //@todo we have to do this because the naming convention of MailingGroup is
-    // wrong & it clobbers group
-    return 'CRM_Contact_BAO_Group';
-  }
-
-  if(strtolower($name) == 'mailing_group' || $name == 'MailingGroup'){
-    //    CRM-12628
-    return 'CRM_Mailing_BAO_Group';
-  }
   return CRM_Core_DAO_AllCoreTables::getFullName(_civicrm_api_get_camel_name($name, 3));
 }
 
@@ -915,8 +895,6 @@ function _civicrm_api3_api_check_permission($entity, $action, &$params, $throw =
     return TRUE;
   }
 
-  require_once 'CRM/Core/Permission.php';
-
   require_once 'CRM/Core/DAO/permissions.php';
   $permissions = _civicrm_api3_permissions($entity, $action, $params);
 
@@ -1033,8 +1011,6 @@ function _civicrm_api3_basic_delete($bao_name, &$params) {
  *
  */
 function _civicrm_api3_custom_data_get(&$returnArray, $entity, $entity_id, $groupID = NULL, $subType = NULL, $subName = NULL) {
-  require_once 'CRM/Core/BAO/CustomGroup.php';
-  require_once 'CRM/Core/BAO/CustomField.php';
   $groupTree = &CRM_Core_BAO_CustomGroup::getTree($entity,
     CRM_Core_DAO::$_nullObject,
     $entity_id,
@@ -1094,11 +1070,12 @@ function _civicrm_api3_validate_fields($entity, $action, &$params, $errorMode =
         //field is of type date or datetime
         _civicrm_api3_validate_date($params, $fieldname, $fieldInfo);
         break;
-    case 32://blob
+
+      case 32://blob
         _civicrm_api3_validate_html($params, $fieldname, $fieldInfo);
         break;
-      case CRM_Utils_Type::T_STRING:
 
+      case CRM_Utils_Type::T_STRING:
         _civicrm_api3_validate_string($params, $fieldname, $fieldInfo);
         break;
 
@@ -1166,8 +1143,6 @@ function _civicrm_api3_validate_date(&$params, &$fieldname, &$fieldInfo) {
  * @param array $fieldinfo array of fields from getfields function
  */
 function _civicrm_api3_validate_constraint(&$params, &$fieldname, &$fieldInfo) {
-  $file = str_replace('_', '/', $fieldInfo['FKClassName']) . ".php";
-  require_once ($file);
   $dao = new $fieldInfo['FKClassName'];
   $dao->id = $params[$fieldname];
   $dao->selectAdd();
@@ -1212,7 +1187,6 @@ function _civicrm_api3_validate_uniquekey(&$params, &$fieldname, &$fieldInfo) {
  */
 function _civicrm_api3_generic_replace($entity, $params) {
 
-  require_once 'CRM/Core/Transaction.php';
   $transaction = new CRM_Core_Transaction();
   try {
     if (!is_array($params['values'])) {
@@ -1287,8 +1261,6 @@ function _civicrm_api_get_fields($entity, $unique = FALSE, &$params = array(
   if (empty($dao)) {
     return array();
   }
-  $file = str_replace('_', '/', $dao) . ".php";
-  require_once ($file);
   $d = new $dao();
   $fields = $d->fields();
   // replace uniqueNames by the normal names as the key
@@ -1322,7 +1294,6 @@ function _civicrm_api_get_fields($entity, $unique = FALSE, &$params = array(
  * fields are prefixed with 'custom_' to represent api params
  */
 function _civicrm_api_get_custom_fields($entity, &$params) {
-  require_once 'CRM/Core/BAO/CustomField.php';
   $customfields = array();
   $entity = _civicrm_api_get_camel_name($entity);
   if (strtolower($entity) == 'contact') {
@@ -1475,7 +1446,7 @@ function _civicrm_api3_validate_integer(&$params, &$fieldname, &$fieldInfo, $ent
       $session = &CRM_Core_Session::singleton();
       $params[$fieldname] = $session->get('userID');
     }
-    if (CRM_Utils_Array::value('pseudoconstant', $fieldInfo) ) {
+    if (!empty($fieldInfo['options'])) {
       $constant = CRM_Utils_Array::value('options', $fieldInfo);
       if (is_numeric($params[$fieldname]) && !CRM_Utils_Array::value('FKClassName',$fieldInfo) && !array_key_exists($params[$fieldname], $fieldInfo['options'])) {
         throw new API_Exception("$fieldname is not valid", 2001, array('error_field' => $fieldname,"type"=>"integer"));