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