3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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-2014
37 * BAO object for crm_log table
39 class CRM_Core_BAO_Log
extends CRM_Core_DAO_Log
{
40 static $_processed = NULL;
44 * @param string $table
48 public static function &lastModified($id, $table = 'civicrm_contact') {
50 $log = new CRM_Core_DAO_Log();
52 $log->entity_table
= $table;
53 $log->entity_id
= $id;
54 $log->orderBy('modified_date desc');
56 $result = CRM_Core_DAO
::$_nullObject;
57 if ($log->find(TRUE)) {
58 list($displayName, $contactImage) = CRM_Contact_BAO_Contact
::getDisplayAndImage($log->modified_id
);
60 'id' => $log->modified_id
,
61 'name' => $displayName,
62 'image' => $contactImage,
63 'date' => $log->modified_date
,
70 * Add log to civicrm_log table
72 * @param array $params
73 * Array of name-value pairs of log table.
77 public static function add(&$params) {
79 $log = new CRM_Core_DAO_Log();
80 $log->copyValues($params);
85 * @param int $contactID
86 * @param string $tableName
90 static function register(
96 if (!self
::$_processed) {
97 self
::$_processed = array();
101 $session = CRM_Core_Session
::singleton();
102 $userID = $session->get('userID');
106 $api_key = CRM_Utils_Request
::retrieve('api_key', 'String', $store, FALSE, NULL, 'REQUEST');
108 if ($api_key && strtolower($api_key) != 'null') {
109 $userID = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $api_key, 'id', 'api_key');
114 $userID = $contactID;
121 $log = new CRM_Core_DAO_Log();
124 if (isset(self
::$_processed[$contactID])) {
125 if (isset(self
::$_processed[$contactID][$userID])) {
126 $log->id
= self
::$_processed[$contactID][$userID];
128 self
::$_processed[$contactID][$userID] = 1;
131 self
::$_processed[$contactID] = array($userID => 1);
134 $logData = "$tableName,$tableID";
136 $log->entity_table
= 'civicrm_contact';
137 $log->entity_id
= $contactID;
138 $log->modified_id
= $userID;
139 $log->modified_date
= date("YmdHis");
140 $log->data
= $logData;
146 SET data = concat( data, ':$logData' )
147 WHERE id = {$log->id}
149 CRM_Core_DAO
::executeQuery($query);
152 self
::$_processed[$contactID][$userID] = $log->id
;
156 * Get log record count for a Contact
158 * @param int $contactID
160 * @return int count of log records
163 public static function getContactLogCount($contactID) {
164 $query = "SELECT count(*) FROM civicrm_log
165 WHERE civicrm_log.entity_table = 'civicrm_contact' AND civicrm_log.entity_id = {$contactID}";
166 return CRM_Core_DAO
::singleValueQuery($query);
170 * Function for find out whether to use logging schema entries for contact
171 * summary, instead of normal log entries.
173 * @return int report id of Contact Logging Report (Summary) / false
176 public static function useLoggingReport() {
177 // first check if logging is enabled
178 $config = CRM_Core_Config
::singleton();
179 if (!$config->logging
) {
183 $loggingSchema = new CRM_Logging_Schema();
185 if ($loggingSchema->isEnabled()) {
186 $params = array('report_id' => 'logging/contact/summary');
188 CRM_Report_BAO_ReportInstance
::retrieve($params, $instance);
190 if (!empty($instance) &&
191 (empty($instance['permission']) ||
192 (!empty($instance['permission']) && CRM_Core_Permission
::check($instance['permission']))
195 return $instance['id'];