Merge in 5.48
[civicrm-core.git] / CRM / Contact / Page / View / Log.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
10 */
11
12 /**
13 *
14 * @package CRM
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
16 */
17 class CRM_Contact_Page_View_Log extends CRM_Core_Page {
18
19 /**
20 * Called when action is browse.
21 *
22 * @return null
23 */
24 public function browse() {
25 $loggingReport = CRM_Core_BAO_Log::useLoggingReport();
26 $this->assign('useLogging', $loggingReport);
27
28 if ($loggingReport) {
29 $this->assign('instanceUrl',
30 CRM_Utils_System::url("civicrm/report/instance/{$loggingReport}",
31 "reset=1&force=1&snippet=4&section=2&altered_contact_id_op=eq&altered_contact_id_value={$this->_contactId}&cid={$this->_contactId}", FALSE, NULL, FALSE));
32 return NULL;
33 }
34
35 $log = new CRM_Core_DAO_Log();
36
37 $log->entity_table = 'civicrm_contact';
38 $log->entity_id = $this->_contactId;
39 $log->orderBy('modified_date desc');
40 $log->find();
41
42 $logEntries = [];
43 while ($log->fetch()) {
44 list($displayName, $contactImage) = CRM_Contact_BAO_Contact::getDisplayAndImage($log->modified_id);
45 $logEntries[] = [
46 'id' => $log->modified_id,
47 'name' => $displayName,
48 'image' => $contactImage,
49 'date' => $log->modified_date,
50 ];
51 }
52
53 $this->assign('logCount', count($logEntries));
54 $this->ajaxResponse['tabCount'] = count($logEntries);
55 $this->ajaxResponse += CRM_Contact_Form_Inline::renderFooter($this->_contactId, FALSE);
56 $this->assign_by_ref('log', $logEntries);
57 }
58
59 public function preProcess() {
60 $this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE);
61 $this->assign('contactId', $this->_contactId);
62
63 $displayName = CRM_Contact_BAO_Contact::displayName($this->_contactId);
64 $this->assign('displayName', $displayName);
65
66 // check logged in url permission
67 CRM_Contact_Page_View::checkUserPermission($this);
68
69 $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'browse');
70 $this->assign('action', $this->_action);
71 }
72
73 /**
74 * the main function that is called when the page loads, it decides the which action has to be taken for the page.
75 *
76 * @return null
77 */
78 public function run() {
79 $this->preProcess();
80
81 $this->browse();
82
83 return parent::run();
84 }
85
86 }