本文整理汇总了PHP中CRM_Activity_BAO_Activity::sendSMS方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Activity_BAO_Activity::sendSMS方法的具体用法?PHP CRM_Activity_BAO_Activity::sendSMS怎么用?PHP CRM_Activity_BAO_Activity::sendSMS使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Activity_BAO_Activity
的用法示例。
在下文中一共展示了CRM_Activity_BAO_Activity::sendSMS方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: postProcess
/**
* Process the form after the input has been submitted and validated.
*
*
* @param CRM_Core_Form $form
*
* @return void
*/
public static function postProcess(&$form)
{
// check and ensure that
$thisValues = $form->controller->exportValues($form->getName());
$fromSmsProviderId = $thisValues['sms_provider_id'];
// process message template
if (!empty($thisValues['saveTemplate']) || !empty($thisValues['updateTemplate'])) {
$messageTemplate = array('msg_text' => $thisValues['sms_text_message'], 'is_active' => TRUE);
if (!empty($thisValues['saveTemplate'])) {
$messageTemplate['msg_title'] = $thisValues['saveTemplateName'];
CRM_Core_BAO_MessageTemplate::add($messageTemplate);
}
if (!empty($thisValues['template']) && !empty($thisValues['updateTemplate'])) {
$messageTemplate['id'] = $thisValues['template'];
unset($messageTemplate['msg_title']);
CRM_Core_BAO_MessageTemplate::add($messageTemplate);
}
}
// format contact details array to handle multiple sms from same contact
$formattedContactDetails = array();
$tempPhones = array();
foreach ($form->_contactIds as $key => $contactId) {
$phone = $form->_toContactPhone[$key];
if ($phone) {
$phoneKey = "{$contactId}::{$phone}";
if (!in_array($phoneKey, $tempPhones)) {
$tempPhones[] = $phoneKey;
if (!empty($form->_contactDetails[$contactId])) {
$formattedContactDetails[] = $form->_contactDetails[$contactId];
}
}
}
}
// $smsParams carries all the arguments provided on form (or via hooks), to the provider->send() method
// this gives flexibity to the users / implementors to add their own args via hooks specific to their sms providers
$smsParams = $thisValues;
unset($smsParams['sms_text_message']);
$smsParams['provider_id'] = $fromSmsProviderId;
$contactIds = array_keys($form->_contactDetails);
$allContactIds = array_keys($form->_allContactDetails);
list($sent, $activityId, $countSuccess) = CRM_Activity_BAO_Activity::sendSMS($formattedContactDetails, $thisValues, $smsParams, $contactIds);
if ($countSuccess > 0) {
CRM_Core_Session::setStatus(ts('One message was sent successfully.', array('plural' => '%count messages were sent successfully.', 'count' => $countSuccess)), ts('Message Sent', array('plural' => 'Messages Sent', 'count' => $countSuccess)), 'success');
}
if (is_array($sent)) {
// At least one PEAR_Error object was generated.
// Display the error messages to the user.
$status = '<ul>';
foreach ($sent as $errMsg) {
$status .= '<li>' . $errMsg . '</li>';
}
$status .= '</ul>';
CRM_Core_Session::setStatus($status, ts('One Message Not Sent', array('count' => count($sent), 'plural' => '%count Messages Not Sent')), 'info');
} else {
//Display the name and number of contacts for those sms is not sent.
$smsNotSent = array_diff_assoc($allContactIds, $contactIds);
if (!empty($smsNotSent)) {
$not_sent = array();
foreach ($smsNotSent as $index => $contactId) {
$displayName = $form->_allContactDetails[$contactId]['display_name'];
$phone = $form->_allContactDetails[$contactId]['phone'];
$contactViewUrl = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$contactId}");
$not_sent[] = "<a href='{$contactViewUrl}' title='{$phone}'>{$displayName}</a>";
}
$status = '(' . ts('because no phone number on file or communication preferences specify DO NOT SMS or Contact is deceased');
if (CRM_Utils_System::getClassName($form) == 'CRM_Activity_Form_Task_SMS') {
$status .= ' ' . ts("or the contact is not part of the activity '%1'", array(1 => self::RECIEVED_SMS_ACTIVITY_SUBJECT));
}
$status .= ')<ul><li>' . implode('</li><li>', $not_sent) . '</li></ul>';
CRM_Core_Session::setStatus($status, ts('One Message Not Sent', array('count' => count($smsNotSent), 'plural' => '%count Messages Not Sent')), 'info');
}
}
}
示例2: postProcess
/**
* process the form after the input has been submitted and validated
*
* @access public
*
* @return None
*/
static function postProcess(&$form)
{
// check and ensure that
$thisValues = $form->controller->exportValues($form->getName());
$fromSmsProviderId = $thisValues['sms_provider_id'];
// process message template
if (CRM_Utils_Array::value('saveTemplate', $thisValues) || CRM_Utils_Array::value('updateTemplate', $thisValues)) {
$messageTemplate = array('msg_text' => $thisValues['text_message'], 'is_active' => TRUE);
if (CRM_Utils_Array::value('saveTemplate', $thisValues)) {
$messageTemplate['msg_title'] = $thisValues['saveTemplateName'];
CRM_Core_BAO_MessageTemplates::add($messageTemplate);
}
if (CRM_Utils_Array::value('template', $thisValues) && CRM_Utils_Array::value('updateTemplate', $thisValues)) {
$messageTemplate['id'] = $thisValues['template'];
unset($messageTemplate['msg_title']);
CRM_Core_BAO_MessageTemplates::add($messageTemplate);
}
}
// format contact details array to handle multiple sms from same contact
$formattedContactDetails = array();
$tempPhones = array();
foreach ($form->_contactIds as $key => $contactId) {
$phone = $form->_toContactPhone[$key];
if ($phone) {
$phoneKey = "{$contactId}::{$phone}";
if (!in_array($phoneKey, $tempPhones)) {
$tempPhones[] = $phoneKey;
if (CRM_Utils_Array::value($contactId, $form->_contactDetails)) {
$formattedContactDetails[] = $form->_contactDetails[$contactId];
}
}
}
}
// $smsParams carries all the arguments provided on form (or via hooks), to the provider->send() method
// this gives flexibity to the users / implementors to add their own args via hooks specific to their sms providers
$smsParams = $thisValues;
unset($smsParams['text_message']);
$smsParams['provider_id'] = $fromSmsProviderId;
list($sent, $activityId) = CRM_Activity_BAO_Activity::sendSMS($formattedContactDetails, $thisValues, $smsParams, array_keys($form->_contactDetails));
if ($sent) {
$status = array('', ts('Your message has been sent.'));
}
//Display the name and number of contacts for those sms is not sent.
$smsNotSent = array_diff_assoc($form->_allContactDetails, $form->_contactDetails);
if (!empty($smsNotSent)) {
$extraMess = CRM_Utils_System::getClassName($form) == 'CRM_Activity_Form_Task_SMS' ? " or the contact is not a target contact to activity of '" . self::RECIEVED_SMS_ACTIVITY_SUBJECT . "' as subject " : "";
$statusDisplay = ts("SMS not sent to contact(s) (No phone no. on file or communication preferences specify DO NOT SMS or Contact is deceased {$extraMess}): %1", array(1 => count($smsNotSent))) . '<br />' . ts('Details') . ': ';
foreach ($smsNotSent as $contactId => $values) {
$displayName = $values['display_name'];
$phone = $values['phone'];
$contactViewUrl = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$contactId}");
$statusDisplay .= "<a href='{$contactViewUrl}'>{$displayName}</a>, ";
}
$status[] = $statusDisplay;
}
if (!empty($status)) {
CRM_Core_Session::setStatus($status);
}
}