diff --git a/CRM/Core/SelectValues.php b/CRM/Core/SelectValues.php index 3a27216e18bb79c1806e099141c69bf4bcfa1dc9..74d1e74ac10b223bcd9877ed9a37c589ca13473b 100644 --- a/CRM/Core/SelectValues.php +++ b/CRM/Core/SelectValues.php @@ -97,8 +97,7 @@ class CRM_Core_SelectValues { static function &contactType() { static $contactType = NULL; if (!$contactType) { - $contactType = array('' => ts('- any contact type -')); - $contactType = $contactType + CRM_Contact_BAO_ContactType::basicTypePairs(); + $contactType = CRM_Contact_BAO_ContactType::basicTypePairs(); } return $contactType; } @@ -248,7 +247,6 @@ class CRM_Core_SelectValues { 'Campaign' => ts('Campaigns'), ); $contactTypes = self::contactType(); - unset($contactTypes['']); $contactTypes = !empty($contactTypes) ? array('Contact' => 'Contacts') + $contactTypes : array(); $extendObjs = CRM_Core_OptionGroup::values('cg_extend_objects'); $customGroupExtends = array_merge($contactTypes, $customGroupExtends, $extendObjs); diff --git a/CRM/Logging/Differ.php b/CRM/Logging/Differ.php index dcbebb089513a3db2c7f41bf2f22b874da8feef4..9c27255dc212b4313901bb73ddcf9fac2295c9d0 100644 --- a/CRM/Logging/Differ.php +++ b/CRM/Logging/Differ.php @@ -65,6 +65,9 @@ class CRM_Logging_Differ { 2 => array($this->log_date, 'String'), ); + $logging = new CRM_Logging_Schema; + $addressCustomTables = $logging->entityCustomDataLogTables('Address'); + $contactIdClause = $join = ''; if ( $contactID ) { $params[3] = array($contactID, 'Integer'); @@ -97,6 +100,12 @@ LEFT JOIN civicrm_activity_contact source ON source.activity_id = lt.id AND sour $contactIdClause = "AND id = (select case_id FROM civicrm_case_contact WHERE contact_id = %3 LIMIT 1)"; break; default: + if (array_key_exists($table, $addressCustomTables)) { + $join = "INNER JOIN `{$this->db}`.`log_civicrm_address` et ON et.id = lt.entity_id"; + $contactIdClause = "AND contact_id = %3"; + break; + } + // allow tables to be extended by report hook query objects list($contactIdClause, $join) = CRM_Report_BAO_Hook::singleton()->logDiffClause($this, $table); @@ -113,8 +122,8 @@ LEFT JOIN civicrm_activity_contact source ON source.activity_id = lt.id AND sour $sql = " SELECT DISTINCT lt.id FROM `{$this->db}`.`log_$table` lt {$join} -WHERE log_conn_id = %1 AND - log_date BETWEEN DATE_SUB(%2, INTERVAL {$this->interval}) AND DATE_ADD(%2, INTERVAL {$this->interval}) +WHERE lt.log_conn_id = %1 AND + lt.log_date BETWEEN DATE_SUB(%2, INTERVAL {$this->interval}) AND DATE_ADD(%2, INTERVAL {$this->interval}) {$contactIdClause}"; $dao = CRM_Core_DAO::executeQuery($sql, $params); diff --git a/CRM/Logging/ReportSummary.php b/CRM/Logging/ReportSummary.php index f4638b1228a0b28ace95c4b7e1b46ff96ceeffa8..fcd11ce94521ae7abe996981e0d221960e5a954e 100644 --- a/CRM/Logging/ReportSummary.php +++ b/CRM/Logging/ReportSummary.php @@ -40,6 +40,15 @@ class CRM_Logging_ReportSummary extends CRM_Report_Form { protected $loggingDB; function __construct() { + // don’t display the ‘Add these Contacts to Group’ button + $this->_add2groupSupported = FALSE; + + $dsn = defined('CIVICRM_LOGGING_DSN') ? DB::parseDSN(CIVICRM_LOGGING_DSN) : DB::parseDSN(CIVICRM_DSN); + $this->loggingDB = $dsn['database']; + + // used for redirect back to contact summary + $this->cid = CRM_Utils_Request::retrieve('cid', 'Integer', CRM_Core_DAO::$_nullObject); + $activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name'); $sourceID = CRM_Utils_Array::key('Activity Source', $activityContacts); $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts); @@ -161,21 +170,28 @@ class CRM_Logging_ReportSummary extends CRM_Report_Form { ), ); - // don’t display the ‘Add these Contacts to Group’ button - $this->_add2groupSupported = FALSE; - - $dsn = defined('CIVICRM_LOGGING_DSN') ? DB::parseDSN(CIVICRM_LOGGING_DSN) : DB::parseDSN(CIVICRM_DSN); - $this->loggingDB = $dsn['database']; - - // used for redirect back to contact summary - $this->cid = CRM_Utils_Request::retrieve('cid', 'Integer', CRM_Core_DAO::$_nullObject); - $logging = new CRM_Logging_Schema; - $customTables = $logging->customDataLogTables(); + + // build _logTables for contact custom tables + $customTables = $logging->entityCustomDataLogTables('Contact'); foreach ($customTables as $table) { $this->_logTables[$table] = array('fk' => 'entity_id', 'log_type' => 'Contact'); } + // build _logTables for address custom tables + $customTables = $logging->entityCustomDataLogTables('Address'); + foreach ($customTables as $table) { + $this->_logTables[$table] = + array( + 'fk' => 'contact_id',// for join of fk_table with contact table + 'joins' => array( + 'table' => 'log_civicrm_address', // fk_table + 'join' => 'entity_log_civireport.entity_id = fk_table.id' + ), + 'log_type' => 'Contact' + ); + } + // allow log tables to be extended via report hooks CRM_Report_BAO_Hook::singleton()->alterLogTables($this, $this->_logTables); diff --git a/CRM/Logging/Schema.php b/CRM/Logging/Schema.php index 0e779ba793622e48540127a601d6e634b05c7e78..49acc02794846b4586afe97ba668a7a2640a8f44 100644 --- a/CRM/Logging/Schema.php +++ b/CRM/Logging/Schema.php @@ -111,6 +111,19 @@ AND TABLE_NAME LIKE 'log_civicrm_%' return preg_grep('/^log_civicrm_value_/', $this->logs); } + /** + * Return custom data tables for specified entity / extends. + */ + function entityCustomDataLogTables($extends) { + $customGroupTables = array(); + $customGroupDAO = CRM_Core_BAO_CustomGroup::getAllCustomGroupsByBaseEntity($extends); + $customGroupDAO->find(); + while ($customGroupDAO->fetch()) { + $customGroupTables[$customGroupDAO->table_name] = $this->logs[$customGroupDAO->table_name]; + } + return $customGroupTables; + } + /** * Disable logging by dropping the triggers (but keep the log tables intact). */