/** * singleton function used to manage this object * * @return object * @static * */ static function &singleton() { if (self::$_singleton === null) { $config = CRM_Core_Config::singleton(); $classPath = str_replace('_', '/', $config->smsClass) . '.php'; require_once $classPath; self::$_singleton = eval('return ' . $config->smsClass . '::singleton( $mode );'); } return self::$_singleton; }
/** * send the message to a specific contact * * @param string $from the name and sms of the sender * @param int $toID the contact id of the recipient * @param string $message the message contents * @param string $smsNumber use this 'number' instead of the default primary sms number * @param int $activityID the activity ID that tracks the message * * @return array (total, added, notAdded) count of emails sent * @access public * @static */ function sendMessage($from, $toID, &$message, $smsNumber, $activityID) { list($toDisplayName, $toSMS) = CRM_Contact_BAO_Contact::getPhoneDetails($toID, 'Mobile'); if ($toSMS) { $to = trim($toSMS); } // make sure sms number is non-empty if (empty($to)) { return false; } $params = array(); $params['From'] = $from; $params['To'] = $to; $params['Body'] = $message; $params['id'] = substr(md5(uniqid(rand(), true)), 0, 31); $params['Type'] = "SMS_TEXT"; $aggregator =& CRM_SMS_Protocol::singleton(); if (!$aggregator->sendMessage($params)) { return false; } // we need to insert an activity history record here $params = array('entity_table' => 'civicrm_contact', 'entity_id' => $toID, 'activity_type' => ts('SMS Sent'), 'module' => 'CiviCRM', 'callback' => 'CRM_SMS_BAO_History::details', 'activity_id' => $activityID, 'activity_summary' => ts('To: %1; Message: %2', array(1 => "{$toDisplayName} <{$toSMS}>", 2 => $message)), 'activity_date' => date('YmdHis')); if (is_a(crm_create_activity_history($params), CRM_Core_Error)) { return false; } return true; }