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 | /** | |
3819f101 | 19 | * This class generates form components for Activity Links. |
6a488035 TO |
20 | */ |
21 | class CRM_Activity_Form_ActivityLinks extends CRM_Core_Form { | |
62d3ee27 | 22 | |
6a488035 | 23 | public function buildQuickForm() { |
cfcb7676 DL |
24 | self::commonBuildQuickForm($this); |
25 | } | |
26 | ||
ffd93213 EM |
27 | /** |
28 | * @param $self | |
29 | */ | |
00be9182 | 30 | public static function commonBuildQuickForm($self) { |
cfcb7676 | 31 | $contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $self); |
6a488035 | 32 | if (!$contactId) { |
1be22cfb | 33 | $contactId = CRM_Utils_Request::retrieve('cid', 'Positive'); |
6a488035 TO |
34 | } |
35 | $urlParams = "action=add&reset=1&cid={$contactId}&selectedChild=activity&atype="; | |
36 | ||
be2fb01f | 37 | $allTypes = CRM_Utils_Array::value('values', civicrm_api3('OptionValue', 'get', [ |
00c2ff9e CW |
38 | 'option_group_id' => 'activity_type', |
39 | 'is_active' => 1, | |
be2fb01f CW |
40 | 'options' => ['limit' => 0, 'sort' => 'weight'], |
41 | ])); | |
6a488035 | 42 | |
be2fb01f | 43 | $activityTypes = []; |
6a488035 | 44 | |
194b8168 | 45 | foreach ($allTypes as $act) { |
00c2ff9e CW |
46 | $url = 'civicrm/activity/add'; |
47 | if ($act['name'] == 'Email') { | |
48 | if (!CRM_Utils_Mail::validOutBoundMail() || !$contactId) { | |
49 | continue; | |
50 | } | |
83a8a606 MW |
51 | list($name, $email, $doNotEmail, $onHold, $isDeceased) = CRM_Contact_BAO_Contact::getContactDetails($contactId); |
52 | if (!$doNotEmail && $email && !$isDeceased) { | |
00c2ff9e CW |
53 | $url = 'civicrm/activity/email/add'; |
54 | $act['label'] = ts('Send an Email'); | |
55 | } | |
56 | else { | |
57 | continue; | |
58 | } | |
6a488035 | 59 | } |
00c2ff9e | 60 | elseif ($act['name'] == 'SMS') { |
63483feb | 61 | if (!$contactId || !CRM_SMS_BAO_Provider::activeProviderCount() || !CRM_Core_Permission::check('send SMS')) { |
00c2ff9e CW |
62 | continue; |
63 | } | |
64 | // Check for existence of a mobile phone and ! do not SMS privacy setting | |
c9184ed3 | 65 | try { |
be2fb01f | 66 | $phone = civicrm_api3('Phone', 'getsingle', [ |
c9184ed3 MW |
67 | 'contact_id' => $contactId, |
68 | 'phone_type_id' => CRM_Core_PseudoConstant::getKey('CRM_Core_BAO_Phone', 'phone_type_id', 'Mobile'), | |
be2fb01f CW |
69 | 'return' => ['phone', 'contact_id'], |
70 | 'options' => ['limit' => 1, 'sort' => "is_primary DESC"], | |
71 | 'api.Contact.getsingle' => [ | |
c9184ed3 MW |
72 | 'id' => '$value.contact_id', |
73 | 'return' => 'do_not_sms', | |
be2fb01f CW |
74 | ], |
75 | ]); | |
c9184ed3 MW |
76 | } |
77 | catch (CiviCRM_API3_Exception $e) { | |
78 | continue; | |
79 | } | |
80 | if (!$phone['api.Contact.getsingle']['do_not_sms'] && $phone['phone']) { | |
00c2ff9e CW |
81 | $url = 'civicrm/activity/sms/add'; |
82 | } | |
83 | else { | |
84 | continue; | |
85 | } | |
32864ccf | 86 | } |
00c2ff9e CW |
87 | elseif ($act['name'] == 'Print PDF Letter') { |
88 | $url = 'civicrm/activity/pdf/add'; | |
6a488035 | 89 | } |
00c2ff9e CW |
90 | elseif (!empty($act['filter']) || (!empty($act['component_id']) && $act['component_id'] != '1')) { |
91 | continue; | |
6a488035 | 92 | } |
00c2ff9e | 93 | $act['url'] = CRM_Utils_System::url($url, |
194b8168 | 94 | "{$urlParams}{$act['value']}", FALSE, NULL, FALSE |
00c2ff9e | 95 | ); |
be2fb01f | 96 | $act += ['icon' => 'fa-plus-square-o']; |
00c2ff9e | 97 | $activityTypes[$act['value']] = $act; |
6a488035 TO |
98 | } |
99 | ||
cfcb7676 | 100 | $self->assign('activityTypes', $activityTypes); |
6a488035 | 101 | |
cfcb7676 | 102 | $self->assign('suppressForm', TRUE); |
6a488035 | 103 | } |
96025800 | 104 | |
6a488035 | 105 | } |