/** * send the message to all the contacts and also insert a * contact activity in each contacts record * * @param array $contactIds the array of contact ids to send the email * @param string $message the message contents * @param string $smsNumber use this 'number' instead of the default primary sms number * * @return array (total, added, notAdded) count of emails sent * @access public * @static */ static function send(&$contactIds, &$message, $smsNumber) { $session = CRM_Core_Session::singleton(); $userID = $session->get('userID'); list($fromDisplayName, $fromSMSNumber) = CRM_Contact_BAO_Contact_Location::getPhoneDetails($userID, 'Mobile'); if (!$fromSMSNumber) { return array(count($contactIds), 0, count($contactIds)); } $message = trim($message); // create the meta level record first $history = new CRM_SMS_DAO_History(); $history->message = $message; $history->contact_id = $userID; $history->sent_date = date('Ymd'); $history->save(); $sent = $notSent = 0; require_once 'CRM/SMS/Protocol.php'; foreach ($contactIds as $contactId) { if (self::sendMessage($fromSMSNumber, $contactId, $message, $smsNumber, $history->id)) { $sent++; } else { $notSent++; } } return array(count($contactIds), $sent, $notSent); }