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