Allow "Outbound SMS" when Mobile is not primary phone number
authorMatthew Wire <devel@mrwire.co.uk>
Wed, 8 Nov 2017 11:24:16 +0000 (11:24 +0000)
committerMatthew Wire <devel@mrwire.co.uk>
Fri, 16 Feb 2018 09:05:43 +0000 (09:05 +0000)
CRM/Activity/Form/ActivityLinks.php
CRM/Contact/BAO/Contact/Location.php

index d06ba2db63738f947bc2d3d50597ce772324a103..c8591959994fcb7eb9a0867775631888db4da460 100644 (file)
@@ -77,9 +77,22 @@ class CRM_Activity_Form_ActivityLinks extends CRM_Core_Form {
           continue;
         }
         // Check for existence of a mobile phone and ! do not SMS privacy setting
-        $mobileTypeID = CRM_Core_PseudoConstant::getKey('CRM_Core_BAO_Phone', 'phone_type_id', 'Mobile');
-        list($name, $phone, $doNotSMS) = CRM_Contact_BAO_Contact_Location::getPhoneDetails($contactId, $mobileTypeID);
-        if (!$doNotSMS && $phone) {
+        try {
+          $phone = civicrm_api3('Phone', 'getsingle', array(
+            'contact_id' => $contactId,
+            'phone_type_id' => CRM_Core_PseudoConstant::getKey('CRM_Core_BAO_Phone', 'phone_type_id', 'Mobile'),
+            'return' => array('phone', 'contact_id'),
+            'options' => array('limit' => 1, 'sort' => "is_primary DESC"),
+            'api.Contact.getsingle' => array(
+              'id' => '$value.contact_id',
+              'return' => 'do_not_sms',
+            ),
+          ));
+        }
+        catch (CiviCRM_API3_Exception $e) {
+          continue;
+        }
+        if (!$phone['api.Contact.getsingle']['do_not_sms'] && $phone['phone']) {
           $url = 'civicrm/activity/sms/add';
         }
         else {
index 7405537b44459794a477bfa0c2fd16c0638c927a..d9539c54b1b748d2f5b4915a1dd6b406dec01d41 100644 (file)
@@ -73,6 +73,7 @@ WHERE     civicrm_contact.id = %1";
   }
 
   /**
+   * @deprecated Not used anywhere, use the Phone API instead
    * Get the sms number and display name of a contact.
    *
    * @param int $id
@@ -84,6 +85,7 @@ WHERE     civicrm_contact.id = %1";
    *   tuple of display_name and sms if found, or (null,null)
    */
   public static function getPhoneDetails($id, $type = NULL) {
+    Civi::log()->warning('Deprecated function CRM_Contact_BAO_Contact_Location::getPhoneDetails, use Phone.get API instead', array('civi.tag' => 'deprecated'));
     if (!$id) {
       return array(NULL, NULL);
     }