3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
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 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
19 * This class generates form components for Activity Links.
21 class CRM_Activity_Form_ActivityLinks
extends CRM_Core_Form
{
23 public function buildQuickForm() {
24 self
::commonBuildQuickForm($this);
30 public static function commonBuildQuickForm($self) {
31 $contactId = CRM_Utils_Request
::retrieve('cid', 'Positive', $self);
33 $contactId = CRM_Utils_Request
::retrieve('cid', 'Positive');
35 $urlParams = "action=add&reset=1&cid={$contactId}&selectedChild=activity&atype=";
37 $allTypes = CRM_Utils_Array
::value('values', civicrm_api3('OptionValue', 'get', [
38 'option_group_id' => 'activity_type',
40 'options' => ['limit' => 0, 'sort' => 'weight'],
45 foreach ($allTypes as $act) {
46 $url = 'civicrm/activity/add';
47 if ($act['name'] == 'Email') {
48 if (!CRM_Utils_Mail
::validOutBoundMail() ||
!$contactId) {
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');
60 elseif ($act['name'] == 'SMS') {
61 if (!$contactId ||
!CRM_SMS_BAO_Provider
::activeProviderCount() ||
!CRM_Core_Permission
::check('send SMS')) {
64 // Check for existence of a mobile phone and ! do not SMS privacy setting
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',
77 catch (CiviCRM_API3_Exception
$e) {
80 if (!$phone['api.Contact.getsingle']['do_not_sms'] && $phone['phone']) {
81 $url = 'civicrm/activity/sms/add';
87 elseif ($act['name'] == 'Print PDF Letter') {
88 $url = 'civicrm/activity/pdf/add';
90 elseif (!empty($act['filter']) ||
(!empty($act['component_id']) && $act['component_id'] != '1')) {
93 $act['url'] = CRM_Utils_System
::url($url,
94 "{$urlParams}{$act['value']}", FALSE, NULL, FALSE
96 $act +
= ['icon' => 'fa-plus-square-o'];
97 $activityTypes[$act['value']] = $act;
100 $self->assign('activityTypes', $activityTypes);
102 $self->assign('suppressForm', TRUE);