/** * 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 */ function send(&$contactIds, &$message, $smsNumber) { $session =& CRM_Core_Session::singleton(); $userID = $session->get('userID'); list($fromDisplayName, $fromSMSNumber) = CRM_Contact_BAO_Contact::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 (CRM_SMS_BAO_History::sendMessage($fromSMSNumber, $contactId, $message, $smsNumber, $history->id)) { $sent++; } else { $notSent++; } } return array(count($contactIds), $sent, $notSent); }
/** * process the form after the input has been submitted and validated * * @access public * @return None */ public function postProcess() { $smsNumber = null; if ($this->_single) { $smsNumber = $this->controller->exportValue('SMS', 'to'); } $message = $this->controller->exportValue('SMS', 'message'); require_once 'CRM/SMS/BAO/History.php'; list($total, $sent, $notSent) = CRM_SMS_BAO_History::send($this->_contactIds, $message, $smsNumber); $status = array('', ts('Total Selected Contact(s): %1', array(1 => $total))); if ($sent) { $status[] = ts('SMS sent to contact(s): %1', array(1 => $sent)); } if ($notSent) { $status[] = ts('SMS not sent to contact(s): %1', array(1 => $notSent)); } CRM_Core_Session::setStatus($status); }