<?php
/*
+--------------------------------------------------------------------+
- | CiviCRM version 4.3 |
+ | CiviCRM version 4.4 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2013 |
+--------------------------------------------------------------------+
*/
static function getBlockIds($blockName, $contactId = NULL, $entityElements = NULL, $updateBlankLocInfo = FALSE) {
$allBlocks = array();
+
$name = ucfirst($blockName);
if ($blockName == 'im') {
$name = 'IM';
$name = 'OpenID';
}
+ $baoString = 'CRM_Core_BAO_' . $name;
if ($contactId) {
- eval('$allBlocks = CRM_Core_BAO_' . $name . '::all' . $name . 's( $contactId, $updateBlankLocInfo );');
+ //@todo a cleverer way to do this would be to use the same fn name on each
+ // BAO rather than constructing the fn
+ // it would also be easier to grep for
+ // e.g $bao = new $baoString;
+ // $bao->getAllBlocks()
+ $baoFunction = 'all' . $name . 's';
+ $allBlocks = $baoString::$baoFunction( $contactId, $updateBlankLocInfo );
}
elseif (!empty($entityElements) && $blockName != 'openid') {
- eval('$allBlocks = CRM_Core_BAO_' . $name . '::allEntity' . $name . 's( $entityElements );');
+ $baoFunction = 'allEntity' . $name . 's';
+ $allBlocks = $baoString::$baoFunction( $entityElements );
}
return $allBlocks;
}
}
if ($resetPrimaryId) {
- eval('$block = new CRM_Core_BAO_' . $blockName . '( );');
+ $baoString = 'CRM_Core_BAO_' . $blockName;
+ $block = new $baoString( );
$block->selectAdd();
$block->selectAdd("id, is_primary");
$block->id = $resetPrimaryId;
if ($blockName == 'phone') {
$phoneTypeBlockValue = CRM_Utils_Array::value('phoneTypeId', $blockValue);
- if ($phoneTypeBlockValue == $value['phone_type_id']) {
+ if ($phoneTypeBlockValue == CRM_Utils_Array::value('phone_type_id', $value)) {
$valueId = TRUE;
}
}
$name = 'OpenID';
}
- require_once "CRM/Core/DAO/{$name}.php";
- eval('$block = new CRM_Core_DAO_' . $name . '( );');
+ $baoString = 'CRM_Core_DAO_' . $name;
+ $block = new $baoString( );
$block->copyValues($params);
/*
* @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);
+ if (!$table) {
+ throw new API_Exception("Failed to locate table for class [$class]");
}
- // if id is set & we don't have contact_id we need to retrieve it
- $contactId = null;
- if (!empty($params['id']) && empty($params['contact_id'])) {
+
+ // 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
+ if (!empty($params['id']) && !isset($params['contact_id'])) {
$entity = new $class();
$entity->id = $params['id'];
$entity->find(TRUE);
$contactId = $entity->contact_id;
}
- elseif (CRM_Utils_Array::value('contact_id', $params)) {
- $contactId = $params['contact_id'];
- }
- if ( !$contactId ) {
- // entity not associated with contact so concept of is_primary not relevant
+ // If entity is not associated with contact, concept of is_primary not relevant
+ if (!$contactId) {
return;
}