5f69c54193318e45874c4755386d4bf2722dd9c1
[civicrm-core.git] / CRM / Activity / Form / ActivityView.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
18 /**
19 * This class handle activity view mode.
20 */
21 class CRM_Activity_Form_ActivityView extends CRM_Core_Form {
22
23 /**
24 * @var bool
25 */
26 public $submitOnce = TRUE;
27
28 /**
29 * Set variables up before form is built.
30 */
31 public function preProcess() {
32 // Get the activity values.
33 $activityId = CRM_Utils_Request::retrieve('id', 'Positive', $this);
34 $context = CRM_Utils_Request::retrieve('context', 'Alphanumeric', $this);
35 $cid = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
36
37 // Check for required permissions, CRM-6264.
38 if ($activityId &&
39 !CRM_Activity_BAO_Activity::checkPermission($activityId, CRM_Core_Action::VIEW)
40 ) {
41 CRM_Core_Error::statusBounce(ts('You do not have permission to access this page.'));
42 }
43
44 $session = CRM_Core_Session::singleton();
45 if (!in_array($context, [
46 'home',
47 'dashlet',
48 'dashletFullscreen',
49 ])
50 ) {
51 $url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$cid}&selectedChild=activity");
52 }
53 else {
54 $url = CRM_Utils_System::url('civicrm/dashboard', 'reset=1');
55 }
56
57 $session->pushUserContext($url);
58 $defaults = [];
59 $params = ['id' => $activityId];
60 CRM_Activity_BAO_Activity::retrieve($params, $defaults);
61
62 // Send activity type description to template.
63 list(, $activityTypeDescription) = CRM_Core_BAO_OptionValue::getActivityTypeDetails($defaults['activity_type_id']);
64 $this->assign('activityTypeDescription', $activityTypeDescription);
65
66 if (!empty($defaults['mailingId'])) {
67 $this->_mailing_id = $defaults['source_record_id'] ?? NULL;
68 $mailingReport = CRM_Mailing_BAO_Mailing::report($this->_mailing_id, TRUE);
69 CRM_Mailing_BAO_Mailing::getMailingContent($mailingReport, $this);
70 $this->assign('mailingReport', $mailingReport);
71
72 $full_open_report = CRM_Mailing_Event_BAO_Opened::getRows(
73 $this->_mailing_id, NULL, FALSE, NULL, NULL, NULL, $cid);
74 $this->assign('openreport', $full_open_report);
75
76 $click_thru_report = CRM_Mailing_Event_BAO_TrackableURLOpen::getRows($this->_mailing_id, NULL, FALSE, NULL, NULL, NULL, NULL, $cid);
77 $this->assign('clickreport', $click_thru_report);
78 }
79
80 foreach ($defaults as $key => $value) {
81 if (substr($key, -3) != '_id') {
82 $values[$key] = $value;
83 }
84 }
85
86 // Get the campaign.
87 if ($campaignId = CRM_Utils_Array::value('campaign_id', $defaults)) {
88 $campaigns = CRM_Campaign_BAO_Campaign::getCampaigns($campaignId);
89 $values['campaign'] = $campaigns[$campaignId];
90 }
91 if ($engagementLevel = CRM_Utils_Array::value('engagement_level', $defaults)) {
92 $engagementLevels = CRM_Campaign_PseudoConstant::engagementLevel();
93 $values['engagement_level'] = CRM_Utils_Array::value($engagementLevel, $engagementLevels, $engagementLevel);
94 }
95
96 $values['attachment'] = CRM_Core_BAO_File::attachmentInfo('civicrm_activity', $activityId);
97 $this->assign('values', $values);
98
99 $url = CRM_Utils_System::url(implode("/", $this->urlPath), "reset=1&id={$activityId}&action=view&cid={$defaults['source_contact_id']}");
100 CRM_Utils_Recent::add($defaults['subject'],
101 $url,
102 $activityId,
103 'Activity',
104 $defaults['source_contact_id'],
105 $defaults['source_contact']
106 );
107 }
108
109 /**
110 * Build the form object.
111 */
112 public function buildQuickForm() {
113 $this->addButtons([
114 [
115 'type' => 'cancel',
116 'name' => ts('Done'),
117 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',
118 'isDefault' => TRUE,
119 ],
120 ]
121 );
122 }
123
124 }