CRM-14057 - contact logging detail report may have missing/wrong altered and altered...
authorDeepak Srivastava <deepak.srivastava.0303@gmail.com>
Tue, 14 Jan 2014 11:00:50 +0000 (16:30 +0530)
committerDeepak Srivastava <deepak.srivastava.0303@gmail.com>
Tue, 14 Jan 2014 11:00:50 +0000 (16:30 +0530)
----------------------------------------
* CRM-14057: contact logging detail report may have missing/wrong altered and altered by name
  http://issues.civicrm.org/jira/browse/CRM-14057

CRM/Logging/ReportDetail.php
CRM/Report/Form/Contact/LoggingDetail.php
CRM/Report/Form/Contact/LoggingSummary.php
CRM/Report/Form/Contribute/LoggingDetail.php

index 0ee0fad7094d135932eea8eae6717d1efa3385dd..bfaeaf44306e4b1736554abc79d9783c8d4f2777 100644 (file)
@@ -41,6 +41,10 @@ class CRM_Logging_ReportDetail extends CRM_Report_Form {
   protected $tables = array();
   protected $interval = '10 SECOND';
 
+  protected $altered_name;
+  protected $altered_by;
+  protected $altered_by_id;
+
   // detail/summary report ids
   protected $detail;
   protected $summary;
@@ -57,6 +61,10 @@ class CRM_Logging_ReportDetail extends CRM_Report_Form {
     $this->cid         = CRM_Utils_Request::retrieve('cid', 'Integer', CRM_Core_DAO::$_nullObject);
     $this->raw         = CRM_Utils_Request::retrieve('raw', 'Boolean', CRM_Core_DAO::$_nullObject);
 
+    $this->altered_name  = CRM_Utils_Request::retrieve('alteredName', 'String',  CRM_Core_DAO::$_nullObject);
+    $this->altered_by    = CRM_Utils_Request::retrieve('alteredBy',   'String',  CRM_Core_DAO::$_nullObject);
+    $this->altered_by_id = CRM_Utils_Request::retrieve('alteredById', 'Integer', CRM_Core_DAO::$_nullObject);
     parent::__construct();
 
     CRM_Utils_System::resetBreadCrumb();
@@ -199,22 +207,16 @@ class CRM_Logging_ReportDetail extends CRM_Report_Form {
       2 => array($this->log_date, 'String'),
     );
 
-    // let the template know who updated whom when
-    $dao = CRM_Core_DAO::executeQuery($this->whoWhomWhenSql(), $params);
-    if ($dao->fetch()) {
-      $this->assign('who_url', CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$dao->who_id}"));
-      $this->assign('whom_url', CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$dao->whom_id}"));
-      $this->assign('who_name', $dao->who_name);
-      $this->assign('whom_name', $dao->whom_name);
-    }
+    $this->assign('whom_url', CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$this->cid}"));
+    $this->assign('who_url',  CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$this->altered_by_id}"));
+    $this->assign('whom_name', $this->altered_name);
+    $this->assign('who_name',  $this->altered_by);
+
     $this->assign('log_date', CRM_Utils_Date::mysqlToIso($this->log_date));
 
     $q = "reset=1&log_conn_id={$this->log_conn_id}&log_date={$this->log_date}";
     $this->assign('revertURL', CRM_Report_Utils_Report::getNextUrl($this->detail, "$q&revert=1", FALSE, TRUE));
     $this->assign('revertConfirm', ts('Are you sure you want to revert all these changes?'));
   }
-
-  // redefine this accordingly in ancestors for buildQuickForm()’s sake
-  protected function whoWhomWhenSql() {}
 }
 
index 9a0b40fac8c0239b5411e9e427e509a116438b72..37b7b3aaacdca9bf8e2bbcc0c8c0799612063dd3 100644 (file)
@@ -74,15 +74,5 @@ class CRM_Report_Form_Contact_LoggingDetail extends CRM_Logging_ReportDetail {
       $this->assign('backURL', CRM_Report_Utils_Report::getNextUrl('logging/contact/summary', 'reset=1', FALSE, TRUE));
     }
   }
-
-  protected function whoWhomWhenSql() {
-    return "
-            SELECT who.id who_id, who.display_name who_name, whom.id whom_id, whom.display_name whom_name, l.is_deleted
-            FROM `{$this->db}`.log_civicrm_contact l
-            JOIN civicrm_contact who ON (l.log_user_id = who.id)
-            JOIN civicrm_contact whom ON (l.id = whom.id)
-            WHERE log_action = 'Update' AND log_conn_id = %1 AND log_date = %2 ORDER BY log_date DESC LIMIT 1
-        ";
-  }
 }
 
index 2daa35d4be55457c213f1164fb5efe7602775f21..fef8530c266c700755cbfdb9df4ec67573e2be29 100644 (file)
@@ -201,6 +201,12 @@ class CRM_Report_Form_Contact_LoggingSummary extends CRM_Logging_ReportSummary {
         if ($this->cid) {
           $q .= '&cid=' . $this->cid;
         }
+        $q .= (!empty($row['log_civicrm_entity_altered_contact'])) ?
+          '&alteredName='.$row['log_civicrm_entity_altered_contact'] : '';
+        $q .= (!empty($row['altered_by_contact_display_name'])) ?
+          '&alteredBy='.$row['altered_by_contact_display_name'] : '';
+        $q .= (!empty($row['log_civicrm_entity_log_user_id'])) ?
+          '&alteredById='.$row['log_civicrm_entity_log_user_id'] : '';
 
         $url1 = CRM_Report_Utils_Report::getNextUrl('logging/contact/detail', "{$q}&snippet=4&section=2&layout=overlay", FALSE, TRUE);
         $url2 = CRM_Report_Utils_Report::getNextUrl('logging/contact/detail', "{$q}&section=2", FALSE, TRUE);
index 276689a514aa7c423cc733988ed595215e99a0c4..223cc6f29a828eb3e070f424a98b5a0e370d0b81 100644 (file)
@@ -51,15 +51,5 @@ class CRM_Report_Form_Contribute_LoggingDetail extends CRM_Logging_ReportDetail
     // link back to summary report
     $this->assign('backURL', CRM_Report_Utils_Report::getNextUrl('logging/contribute/summary', 'reset=1', FALSE, TRUE));
   }
-
-  protected function whoWhomWhenSql() {
-    return "
-            SELECT who.id who_id, who.display_name who_name, whom.id whom_id, whom.display_name whom_name
-            FROM `{$this->db}`.log_civicrm_contribution l
-            LEFT JOIN civicrm_contact who ON (l.log_user_id = who.id)
-            LEFT JOIN civicrm_contact whom ON (l.contact_id = whom.id)
-            WHERE log_action = 'Update' AND log_conn_id = %1 AND log_date = %2 ORDER BY log_date DESC LIMIT 1
-        ";
-  }
 }