3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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-2013
37 * BAO object for crm_log table
39 class CRM_Core_BAO_Log
extends CRM_Core_DAO_Log
{
40 static $_processed = NULL;
42 static function &lastModified($id, $table = 'civicrm_contact') {
44 $log = new CRM_Core_DAO_Log();
46 $log->entity_table
= $table;
47 $log->entity_id
= $id;
48 $log->orderBy('modified_date desc');
50 $result = CRM_Core_DAO
::$_nullObject;
51 if ($log->find(TRUE)) {
52 list($displayName, $contactImage) = CRM_Contact_BAO_Contact
::getDisplayAndImage($log->modified_id
);
54 'id' => $log->modified_id
,
55 'name' => $displayName,
56 'image' => $contactImage,
57 'date' => $log->modified_date
,
64 * add log to civicrm_log table
66 * @param array $params array of name-value pairs of log table.
70 static function add(&$params) {
72 $log = new CRM_Core_DAO_Log();
73 $log->copyValues($params);
77 static function register($contactID,
82 if (!self
::$_processed) {
83 self
::$_processed = array();
87 $session = CRM_Core_Session
::singleton();
88 $userID = $session->get('userID');
92 $api_key = CRM_Utils_Request
::retrieve('api_key', 'String', $store, FALSE, NULL, 'REQUEST');
94 if ($api_key && strtolower($api_key) != 'null') {
95 $userID = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $api_key, 'id', 'api_key');
100 $userID = $contactID;
107 $log = new CRM_Core_DAO_Log();
110 if (isset(self
::$_processed[$contactID])) {
111 if (isset(self
::$_processed[$contactID][$userID])) {
112 $log->id
= self
::$_processed[$contactID][$userID];
114 self
::$_processed[$contactID][$userID] = 1;
117 self
::$_processed[$contactID] = array($userID => 1);
120 $logData = "$tableName,$tableID";
122 $log->entity_table
= 'civicrm_contact';
123 $log->entity_id
= $contactID;
124 $log->modified_id
= $userID;
125 $log->modified_date
= date("YmdHis");
126 $log->data
= $logData;
132 SET data = concat( data, ':$logData' )
133 WHERE id = {$log->id}
135 CRM_Core_DAO
::executeQuery($query);
138 self
::$_processed[$contactID][$userID] = $log->id
;
142 * Function to get log record count for a Contact
144 * @param int $contactId Contact ID
146 * @return int count of log records
150 static function getContactLogCount($contactID) {
151 $query = "SELECT count(*) FROM civicrm_log
152 WHERE civicrm_log.entity_table = 'civicrm_contact' AND civicrm_log.entity_id = {$contactID}";
153 return CRM_Core_DAO
::singleValueQuery($query);
157 * Function for find out whether to use logging schema entries for contact
158 * summary, instead of normal log entries.
160 * @return int report id of Contact Logging Report (Summary) / false
164 static function useLoggingReport() {
165 // first check if logging is enabled
166 $config = CRM_Core_Config
::singleton();
167 if (!$config->logging
) {
171 $loggingSchema = new CRM_Logging_Schema();
173 if ($loggingSchema->isEnabled()) {
174 $params = array('report_id' => 'logging/contact/summary');
176 CRM_Report_BAO_ReportInstance
::retrieve($params, $instance);
178 if (!empty($instance) &&
179 (!CRM_Utils_Array
::value('permission', $instance) ||
180 (CRM_Utils_Array
::value('permission', $instance) && CRM_Core_Permission
::check($instance['permission']))
183 return $instance['id'];