Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
fee14197 | 4 | | CiviCRM version 5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
f299f7db | 6 | | Copyright CiviCRM LLC (c) 2004-2020 | |
6a488035 TO |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
10 | | CiviCRM is free software; you can copy, modify, and distribute it | | |
11 | | under the terms of the GNU Affero General Public License | | |
12 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | |
13 | | | | |
14 | | CiviCRM is distributed in the hope that it will be useful, but | | |
15 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
17 | | See the GNU Affero General Public License for more details. | | |
18 | | | | |
19 | | You should have received a copy of the GNU Affero General Public | | |
20 | | License and the CiviCRM Licensing Exception along | | |
21 | | with this program; if not, contact CiviCRM LLC | | |
22 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
23 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
24 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
25 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
29 | * | |
30 | * @package CRM | |
f299f7db | 31 | * @copyright CiviCRM LLC (c) 2004-2020 |
6a488035 TO |
32 | */ |
33 | ||
34 | /** | |
3819f101 | 35 | * This class generates form components for Activity Links. |
6a488035 TO |
36 | */ |
37 | class CRM_Activity_Form_ActivityLinks extends CRM_Core_Form { | |
62d3ee27 | 38 | |
6a488035 | 39 | public function buildQuickForm() { |
cfcb7676 DL |
40 | self::commonBuildQuickForm($this); |
41 | } | |
42 | ||
ffd93213 EM |
43 | /** |
44 | * @param $self | |
45 | */ | |
00be9182 | 46 | public static function commonBuildQuickForm($self) { |
cfcb7676 | 47 | $contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $self); |
6a488035 TO |
48 | if (!$contactId) { |
49 | $contactId = CRM_Utils_Request::retrieve('cid', 'Positive', CRM_Core_DAO::$_nullObject, FALSE, NULL, $_REQUEST); | |
50 | } | |
51 | $urlParams = "action=add&reset=1&cid={$contactId}&selectedChild=activity&atype="; | |
52 | ||
be2fb01f | 53 | $allTypes = CRM_Utils_Array::value('values', civicrm_api3('OptionValue', 'get', [ |
00c2ff9e CW |
54 | 'option_group_id' => 'activity_type', |
55 | 'is_active' => 1, | |
be2fb01f CW |
56 | 'options' => ['limit' => 0, 'sort' => 'weight'], |
57 | ])); | |
6a488035 | 58 | |
be2fb01f | 59 | $activityTypes = []; |
6a488035 | 60 | |
194b8168 | 61 | foreach ($allTypes as $act) { |
00c2ff9e CW |
62 | $url = 'civicrm/activity/add'; |
63 | if ($act['name'] == 'Email') { | |
64 | if (!CRM_Utils_Mail::validOutBoundMail() || !$contactId) { | |
65 | continue; | |
66 | } | |
83a8a606 MW |
67 | list($name, $email, $doNotEmail, $onHold, $isDeceased) = CRM_Contact_BAO_Contact::getContactDetails($contactId); |
68 | if (!$doNotEmail && $email && !$isDeceased) { | |
00c2ff9e CW |
69 | $url = 'civicrm/activity/email/add'; |
70 | $act['label'] = ts('Send an Email'); | |
71 | } | |
72 | else { | |
73 | continue; | |
74 | } | |
6a488035 | 75 | } |
00c2ff9e | 76 | elseif ($act['name'] == 'SMS') { |
63483feb | 77 | if (!$contactId || !CRM_SMS_BAO_Provider::activeProviderCount() || !CRM_Core_Permission::check('send SMS')) { |
00c2ff9e CW |
78 | continue; |
79 | } | |
80 | // Check for existence of a mobile phone and ! do not SMS privacy setting | |
c9184ed3 | 81 | try { |
be2fb01f | 82 | $phone = civicrm_api3('Phone', 'getsingle', [ |
c9184ed3 MW |
83 | 'contact_id' => $contactId, |
84 | 'phone_type_id' => CRM_Core_PseudoConstant::getKey('CRM_Core_BAO_Phone', 'phone_type_id', 'Mobile'), | |
be2fb01f CW |
85 | 'return' => ['phone', 'contact_id'], |
86 | 'options' => ['limit' => 1, 'sort' => "is_primary DESC"], | |
87 | 'api.Contact.getsingle' => [ | |
c9184ed3 MW |
88 | 'id' => '$value.contact_id', |
89 | 'return' => 'do_not_sms', | |
be2fb01f CW |
90 | ], |
91 | ]); | |
c9184ed3 MW |
92 | } |
93 | catch (CiviCRM_API3_Exception $e) { | |
94 | continue; | |
95 | } | |
96 | if (!$phone['api.Contact.getsingle']['do_not_sms'] && $phone['phone']) { | |
00c2ff9e CW |
97 | $url = 'civicrm/activity/sms/add'; |
98 | } | |
99 | else { | |
100 | continue; | |
101 | } | |
32864ccf | 102 | } |
00c2ff9e CW |
103 | elseif ($act['name'] == 'Print PDF Letter') { |
104 | $url = 'civicrm/activity/pdf/add'; | |
6a488035 | 105 | } |
00c2ff9e CW |
106 | elseif (!empty($act['filter']) || (!empty($act['component_id']) && $act['component_id'] != '1')) { |
107 | continue; | |
6a488035 | 108 | } |
00c2ff9e | 109 | $act['url'] = CRM_Utils_System::url($url, |
194b8168 | 110 | "{$urlParams}{$act['value']}", FALSE, NULL, FALSE |
00c2ff9e | 111 | ); |
be2fb01f | 112 | $act += ['icon' => 'fa-plus-square-o']; |
00c2ff9e | 113 | $activityTypes[$act['value']] = $act; |
6a488035 TO |
114 | } |
115 | ||
cfcb7676 | 116 | $self->assign('activityTypes', $activityTypes); |
6a488035 | 117 | |
cfcb7676 | 118 | $self->assign('suppressForm', TRUE); |
6a488035 | 119 | } |
96025800 | 120 | |
6a488035 | 121 | } |