3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2017 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2016
35 * BAO object for crm_log table
37 class CRM_Core_BAO_Log
extends CRM_Core_DAO_Log
{
38 static $_processed = NULL;
42 * @param string $table
46 public static function &lastModified($id, $table = 'civicrm_contact') {
48 $log = new CRM_Core_DAO_Log();
50 $log->entity_table
= $table;
51 $log->entity_id
= $id;
52 $log->orderBy('modified_date desc');
55 if ($log->find(TRUE)) {
56 list($displayName, $contactImage) = CRM_Contact_BAO_Contact
::getDisplayAndImage($log->modified_id
);
58 'id' => $log->modified_id
,
59 'name' => $displayName,
60 'image' => $contactImage,
61 'date' => $log->modified_date
,
68 * Add log to civicrm_log table.
70 * @param array $params
71 * Array of name-value pairs of log table.
74 public static function add(&$params) {
76 $log = new CRM_Core_DAO_Log();
77 $log->copyValues($params);
82 * @param int $contactID
83 * @param string $tableName
87 public static function register(
93 if (!self
::$_processed) {
94 self
::$_processed = array();
98 $session = CRM_Core_Session
::singleton();
99 $userID = $session->get('userID');
103 $api_key = CRM_Utils_Request
::retrieve('api_key', 'String', $store, FALSE, NULL, 'REQUEST');
105 if ($api_key && strtolower($api_key) != 'null') {
106 $userID = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $api_key, 'id', 'api_key');
111 $userID = $contactID;
118 $log = new CRM_Core_DAO_Log();
121 if (isset(self
::$_processed[$contactID])) {
122 if (isset(self
::$_processed[$contactID][$userID])) {
123 $log->id
= self
::$_processed[$contactID][$userID];
125 self
::$_processed[$contactID][$userID] = 1;
128 self
::$_processed[$contactID] = array($userID => 1);
131 $logData = "$tableName,$tableID";
133 $log->entity_table
= 'civicrm_contact';
134 $log->entity_id
= $contactID;
135 $log->modified_id
= $userID;
136 $log->modified_date
= date("YmdHis");
137 $log->data
= $logData;
143 SET data = concat( data, ':$logData' )
144 WHERE id = {$log->id}
146 CRM_Core_DAO
::executeQuery($query);
149 self
::$_processed[$contactID][$userID] = $log->id
;
153 * Get log record count for a Contact.
155 * @param int $contactID
158 * count of log records
160 public static function getContactLogCount($contactID) {
161 $query = "SELECT count(*) FROM civicrm_log
162 WHERE civicrm_log.entity_table = 'civicrm_contact' AND civicrm_log.entity_id = {$contactID}";
163 return CRM_Core_DAO
::singleValueQuery($query);
167 * Get the id of the report to use to display the change log.
169 * If logging is not enabled a return value of FALSE means to use the
170 * basic change log view.
173 * report id of Contact Logging Report (Summary)
175 public static function useLoggingReport() {
176 if (!\Civi
::settings()->get('logging')) {
180 $loggingSchema = new CRM_Logging_Schema();
182 if ($loggingSchema->isEnabled()) {
183 $params = array('report_id' => 'logging/contact/summary');
185 CRM_Report_BAO_ReportInstance
::retrieve($params, $instance);
187 if (!empty($instance) &&
188 (empty($instance['permission']) ||
189 (!empty($instance['permission']) && CRM_Core_Permission
::check($instance['permission']))
192 return $instance['id'];