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');
99 $log = new CRM_Core_DAO_Log();
102 if (isset(self
::$_processed[$contactID])) {
103 if (isset(self
::$_processed[$contactID][$userID])) {
104 $log->id
= self
::$_processed[$contactID][$userID];
106 self
::$_processed[$contactID][$userID] = 1;
109 self
::$_processed[$contactID] = array($userID => 1);
112 $logData = "$tableName,$tableID";
114 $log->entity_table
= 'civicrm_contact';
115 $log->entity_id
= $contactID;
116 $log->modified_id
= $userID;
117 $log->modified_date
= date("YmdHis");
118 $log->data
= $logData;
124 SET data = concat( data, ':$logData' )
125 WHERE id = {$log->id}
127 CRM_Core_DAO
::executeQuery($query);
130 self
::$_processed[$contactID][$userID] = $log->id
;
134 * Function to get log record count for a Contact
136 * @param int $contactId Contact ID
138 * @return int count of log records
142 static function getContactLogCount($contactID) {
143 $query = "SELECT count(*) FROM civicrm_log
144 WHERE civicrm_log.entity_table = 'civicrm_contact' AND civicrm_log.entity_id = {$contactID}";
145 return CRM_Core_DAO
::singleValueQuery($query);
149 * Function for find out whether to use logging schema entries for contact
150 * summary, instead of normal log entries.
152 * @return int report id of Contact Logging Report (Summary) / false
156 static function useLoggingReport() {
157 // first check if logging is enabled
158 $config = CRM_Core_Config
::singleton();
159 if (!$config->logging
) {
163 $loggingSchema = new CRM_Logging_Schema();
165 if ($loggingSchema->isEnabled()) {
166 $params = array('report_id' => 'logging/contact/summary');
168 CRM_Report_BAO_ReportInstance
::retrieve($params, $instance);
170 if (!empty($instance) &&
171 (!CRM_Utils_Array
::value('permission', $instance) ||
172 (CRM_Utils_Array
::value('permission', $instance) && CRM_Core_Permission
::check($instance['permission']))
175 return $instance['id'];