Merge pull request #15815 from artfulrobot/issue-1108-fix-unsubscribe
[civicrm-core.git] / CRM / Contact / Page / View / Log.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
bc77d7c0 4 | Copyright CiviCRM LLC. All rights reserved. |
6a488035 5 | |
bc77d7c0
TO
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 |
6a488035 9 +--------------------------------------------------------------------+
d25dd0ee 10 */
6a488035
TO
11
12/**
13 *
14 * @package CRM
ca5cec67 15 * @copyright CiviCRM LLC https://civicrm.org/licensing
6a488035
TO
16 */
17class CRM_Contact_Page_View_Log extends CRM_Core_Page {
18
19 /**
95cdcc0f 20 * Called when action is browse.
6a488035 21 *
76e7a76c 22 * @return null
6a488035 23 */
00be9182 24 public function browse() {
6a488035
TO
25 $loggingReport = CRM_Core_BAO_Log::useLoggingReport();
26 $this->assign('useLogging', $loggingReport);
27
28 if ($loggingReport) {
8ef12e64 29 $this->assign('instanceUrl',
353ffa53
TO
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));
a1a2a83d 32 return NULL;
6a488035
TO
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
be2fb01f 42 $logEntries = [];
6a488035
TO
43 while ($log->fetch()) {
44 list($displayName, $contactImage) = CRM_Contact_BAO_Contact::getDisplayAndImage($log->modified_id);
be2fb01f 45 $logEntries[] = [
6a488035
TO
46 'id' => $log->modified_id,
47 'name' => $displayName,
48 'image' => $contactImage,
49 'date' => $log->modified_date,
be2fb01f 50 ];
6a488035
TO
51 }
52
53 $this->assign('logCount', count($logEntries));
b4efde7a
CW
54 $this->ajaxResponse['tabCount'] = count($logEntries);
55 $this->ajaxResponse += CRM_Contact_Form_Inline::renderFooter($this->_contactId, FALSE);
6a488035
TO
56 $this->assign_by_ref('log', $logEntries);
57 }
58
00be9182 59 public function preProcess() {
6a488035
TO
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 /**
dc195289 74 * the main function that is called when the page loads, it decides the which action has to be taken for the page.
6a488035 75 *
76e7a76c 76 * @return null
6a488035 77 */
00be9182 78 public function run() {
6a488035
TO
79 $this->preProcess();
80
81 $this->browse();
82
83 return parent::run();
84 }
96025800 85
6a488035 86}