3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
19 * BAO object for crm_log table
21 class CRM_Core_BAO_Log
extends CRM_Core_DAO_Log
{
22 public static $_processed = NULL;
26 * @param string $table
31 public static function &lastModified($id, $table = 'civicrm_contact') {
33 $log = new CRM_Core_DAO_Log();
35 $log->entity_table
= $table;
36 $log->entity_id
= $id;
37 $log->orderBy('modified_date desc');
39 $displayName = $result = $contactImage = NULL;
40 if ($log->find(TRUE)) {
41 if ($log->modified_id
) {
42 list($displayName, $contactImage) = CRM_Contact_BAO_Contact
::getDisplayAndImage($log->modified_id
);
45 'id' => $log->modified_id
,
46 'name' => $displayName,
47 'image' => $contactImage,
48 'date' => $log->modified_date
,
55 * Add log to civicrm_log table.
57 * @param array $params
58 * Array of name-value pairs of log table.
61 public static function add(&$params) {
63 $log = new CRM_Core_DAO_Log();
64 $log->copyValues($params);
69 * @param int $contactID
70 * @param string $tableName
74 public static function register(
80 if (!self
::$_processed) {
81 self
::$_processed = [];
85 $session = CRM_Core_Session
::singleton();
86 $userID = $session->get('userID');
90 $api_key = CRM_Utils_Request
::retrieve('api_key', 'String', $store, FALSE, NULL, 'REQUEST');
92 if ($api_key && strtolower($api_key) != 'null') {
93 $userID = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $api_key, 'id', 'api_key');
105 $log = new CRM_Core_DAO_Log();
108 if (isset(self
::$_processed[$contactID])) {
109 if (isset(self
::$_processed[$contactID][$userID])) {
110 $log->id
= self
::$_processed[$contactID][$userID];
112 self
::$_processed[$contactID][$userID] = 1;
115 self
::$_processed[$contactID] = [$userID => 1];
118 $logData = "$tableName,$tableID";
120 $log->entity_table
= 'civicrm_contact';
121 $log->entity_id
= $contactID;
122 $log->modified_id
= $userID;
123 $log->modified_date
= date("YmdHis");
124 $log->data
= $logData;
130 SET data = concat( data, ':$logData' )
131 WHERE id = {$log->id}
133 CRM_Core_DAO
::executeQuery($query);
136 self
::$_processed[$contactID][$userID] = $log->id
;
140 * Get log record count for a Contact.
142 * @param int $contactID
145 * count of log records
147 public static function getContactLogCount($contactID) {
148 $query = "SELECT count(*) FROM civicrm_log
149 WHERE civicrm_log.entity_table = 'civicrm_contact' AND civicrm_log.entity_id = {$contactID}";
150 return CRM_Core_DAO
::singleValueQuery($query);
154 * Get the id of the report to use to display the change log.
156 * If logging is not enabled a return value of FALSE means to use the
157 * basic change log view.
160 * report id of Contact Logging Report (Summary)
162 public static function useLoggingReport() {
163 if (!\Civi
::settings()->get('logging')) {
167 $loggingSchema = new CRM_Logging_Schema();
169 if ($loggingSchema->isEnabled()) {
170 $params = ['report_id' => 'logging/contact/summary'];
172 CRM_Report_BAO_ReportInstance
::retrieve($params, $instance);
174 if (!empty($instance) &&
175 (empty($instance['permission']) ||
176 (!empty($instance['permission']) && CRM_Core_Permission
::check($instance['permission']))
179 return $instance['id'];