本文整理匯總了PHP中CRM_Utils_Token::getTokenDetails方法的典型用法代碼示例。如果您正苦於以下問題:PHP CRM_Utils_Token::getTokenDetails方法的具體用法?PHP CRM_Utils_Token::getTokenDetails怎麽用?PHP CRM_Utils_Token::getTokenDetails使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類CRM_Utils_Token
的用法示例。
在下文中一共展示了CRM_Utils_Token::getTokenDetails方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: _testDocumentContent
/**
* Assert the content of document
*
* @param array $formValues
* @param array $type
*/
public function _testDocumentContent($formValues, $type)
{
$html = array();
$form = new CRM_Contact_Form_Task_PDFLetterCommon();
list($formValues, $categories, $html_message, $messageToken, $returnProperties) = $form->processMessageTemplate($formValues);
list($html_message, $zip) = CRM_Utils_PDF_Document::unzipDoc($formValues['document_file_path'], $formValues['document_type']);
foreach ($this->_contactIds as $item => $contactId) {
$params = array('contact_id' => $contactId);
list($contact) = CRM_Utils_Token::getTokenDetails($params, $returnProperties, FALSE, FALSE, NULL, $messageToken, 'CRM_Contact_Form_Task_PDFLetterCommon');
$html[] = CRM_Utils_Token::replaceContactTokens($html_message, $contact[$contactId], TRUE, $messageToken);
}
$returnContent = CRM_Utils_PDF_Document::printDocuments($formValues['document_file_path'], $html, $type, $zip, TRUE);
$returnContent = strip_tags($returnContent);
$this->assertTrue(strpos($returnContent, 'Hello Antonia D`souza') !== 0);
$this->assertTrue(strpos($returnContent, 'Hello Anthony Collins') !== 0);
}
示例2: generateHTML
/**
* generate htmlfor pdf letters
*
* @param array $membershipIDs
* @param array $returnProperties
* @param bool $skipOnHold
* @param bool $skipDeceased
* @param unknown_type $messageToken
* @param $html_message
* @param $categories
*
* @return unknown
*/
static function generateHTML($membershipIDs, $returnProperties, $skipOnHold, $skipDeceased, $messageToken, $html_message, $categories)
{
$memberships = CRM_Utils_Token::getMembershipTokenDetails($membershipIDs);
foreach ($membershipIDs as $membershipID) {
$membership = $memberships[$membershipID];
// get contact information
$contactId = $membership['contact_id'];
$params = array('contact_id' => $contactId);
//getTokenDetails is much like calling the api contact.get function - but - with some minor
// special handlings. It preceeds the existence of the api
list($contacts) = CRM_Utils_Token::getTokenDetails($params, $returnProperties, $skipOnHold, $skipDeceased, NULL, $messageToken, 'CRM_Contribution_Form_Task_PDFLetterCommon');
$tokenHtml = CRM_Utils_Token::replaceContactTokens($html_message, $contacts[$contactId], TRUE, $messageToken);
$tokenHtml = CRM_Utils_Token::replaceEntityTokens('membership', $membership, $tokenHtml, $messageToken);
$tokenHtml = CRM_Utils_Token::replaceHookTokens($tokenHtml, $contacts[$contactId], $categories, TRUE);
$tokenHtml = CRM_Utils_Token::parseThroughSmarty($tokenHtml, $contacts[$contactId]);
$html[] = $tokenHtml;
}
return $html;
}
示例3: run
/**
* Run this page (figure out the action needed and perform it).
*
* @return void
*/
public function run()
{
$session = CRM_Core_Session::singleton();
$qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', CRM_Core_DAO::$_nullObject, FALSE, 'text');
$type = CRM_Utils_Request::retrieve('type', 'String', CRM_Core_DAO::$_nullObject, FALSE, 'text');
$options = array();
$session->getVars($options, "CRM_Mailing_Controller_Send_{$qfKey}");
//get the options if control come from search context, CRM-3711
if (empty($options)) {
$session->getVars($options, "CRM_Contact_Controller_Search_{$qfKey}");
}
// FIXME: the below and CRM_Mailing_Form_Test::testMail()
// should be refactored
$fromEmail = NULL;
$mailing = new CRM_Mailing_BAO_Mailing();
if (!empty($options)) {
$mailing->id = $options['mailing_id'];
$fromEmail = CRM_Utils_Array::value('from_email', $options);
}
$mailing->find(TRUE);
CRM_Mailing_BAO_Mailing::tokenReplace($mailing);
// get and format attachments
$attachments = CRM_Core_BAO_File::getEntityFile('civicrm_mailing', $mailing->id);
//get details of contact with token value including Custom Field Token Values.CRM-3734
$returnProperties = $mailing->getReturnProperties();
$params = array('contact_id' => $session->get('userID'));
$details = CRM_Utils_Token::getTokenDetails($params, $returnProperties, TRUE, TRUE, NULL, $mailing->getFlattenedTokens(), get_class($this));
$mime =& $mailing->compose(NULL, NULL, NULL, $session->get('userID'), $fromEmail, $fromEmail, TRUE, $details[0][$session->get('userID')], $attachments);
if ($type == 'html') {
CRM_Utils_System::setHttpHeader('Content-Type', 'text/html; charset=utf-8');
print $mime->getHTMLBody();
} else {
CRM_Utils_System::setHttpHeader('Content-Type', 'text/plain; charset=utf-8');
print $mime->getTXTBody();
}
CRM_Utils_System::civiExit();
}
示例4: buildContributionArray
/**
* Generate the contribution array from the form, we fill in the contact details and determine any aggregation
* around contact_id of contribution_recur_id
*
* @param string $groupBy
* @param array $contributionIDs
* @param array $returnProperties
* @param bool $skipOnHold
* @param bool $skipDeceased
* @param array $messageToken
* @param string $task
* @param string $separator
* @param bool $isIncludeSoftCredits
*
* @return array
*/
public static function buildContributionArray($groupBy, $contributionIDs, $returnProperties, $skipOnHold, $skipDeceased, $messageToken, $task, $separator, $isIncludeSoftCredits)
{
$contributions = $contacts = $notSent = array();
foreach ($contributionIDs as $item => $contributionId) {
// get contribution information
$contribution = CRM_Utils_Token::getContributionTokenDetails(array('contribution_id' => $contributionId), $returnProperties, NULL, $messageToken, $task);
$contribution = $contributions[$contributionId] = $contribution[$contributionId];
if ($isIncludeSoftCredits) {
//@todo find out why this happens & add comments
list($contactID) = explode('-', $item);
$contactID = (int) $contactID;
} else {
$contactID = $contribution['contact_id'];
}
if (!isset($contacts[$contactID])) {
$contacts[$contactID] = array();
$contacts[$contactID]['contact_aggregate'] = 0;
$contacts[$contactID]['combined'] = $contacts[$contactID]['contribution_ids'] = array();
}
$contacts[$contactID]['contact_aggregate'] += $contribution['total_amount'];
$groupByID = empty($contribution[$groupBy]) ? 0 : $contribution[$groupBy];
$contacts[$contactID]['contribution_ids'][$groupBy][$groupByID][$contributionId] = TRUE;
if (!isset($contacts[$contactID]['combined'][$groupBy]) || !isset($contacts[$contactID]['combined'][$groupBy][$groupByID])) {
$contacts[$contactID]['combined'][$groupBy][$groupByID] = $contribution;
$contacts[$contactID]['aggregates'][$groupBy][$groupByID] = $contribution['total_amount'];
} else {
$contacts[$contactID]['combined'][$groupBy][$groupByID] = self::combineContributions($contacts[$contactID]['combined'][$groupBy][$groupByID], $contribution, $separator);
$contacts[$contactID]['aggregates'][$groupBy][$groupByID] += $contribution['total_amount'];
}
}
// Assign the available contributions before calling tokens so hooks parsing smarty can access it.
// Note that in core code you can only use smarty here if enable if for the whole site, incl
// CiviMail, with a big performance impact.
// Hooks allow more nuanced smarty usage here.
CRM_Core_Smarty::singleton()->assign('contributions', $contributions);
foreach ($contacts as $contactID => $contact) {
$tokenResolvedContacts = CRM_Utils_Token::getTokenDetails(array('contact_id' => $contactID), $returnProperties, $skipOnHold, $skipDeceased, NULL, $messageToken, $task);
$contacts[$contactID] = array_merge($tokenResolvedContacts[0][$contactID], $contact);
}
return array($contributions, $contacts);
}
示例5: replaceTokens
protected function replaceTokens($input, $contact_id)
{
//get contact
$params = array(array('contact_id', '=', $contact_id, 0, 0));
list($contact, $_) = CRM_Contact_BAO_Query::apiQuery($params);
$contact = reset($contact);
if (!$contact || is_a($contact, 'CRM_Core_Error')) {
throw new API_Exception('Could not find contact with ID: ' . $params['contact_id']);
}
$tokens = CRM_Utils_Token::getTokens($input);
// get replacement text for these tokens
$returnProperties = array('sort_name' => 1, 'email' => 1, 'do_not_email' => 1, 'is_deceased' => 1, 'on_hold' => 1, 'display_name' => 1, 'preferred_mail_format' => 1);
if (isset($tokens['contact'])) {
foreach ($tokens['contact'] as $key => $value) {
$returnProperties[$value] = 1;
}
}
list($details) = CRM_Utils_Token::getTokenDetails(array($contact_id), $returnProperties, false, false, null, $tokens);
$contact = reset($details);
// call token hook
$hookTokens = array();
CRM_Utils_Hook::tokens($hookTokens);
$categories = array_keys($hookTokens);
CRM_Utils_Token::replaceGreetingTokens($input, NULL, $contact['contact_id']);
$input = CRM_Utils_Token::replaceDomainTokens($input, $domain, true, $tokens, true);
$input = CRM_Utils_Token::replaceContactTokens($input, $contact, false, $tokens, false, true);
$input = CRM_Utils_Token::replaceComponentTokens($input, $contact, $tokens, true);
$input = CRM_Utils_Token::replaceHookTokens($input, $contact, $categories, true);
return $input;
}
示例6: buildQuickForm
/**
* Build the form object.
*
*
* @param CRM_Core_Form $form
*
* @return void
*/
public static function buildQuickForm(&$form)
{
$toArray = array();
$providers = CRM_SMS_BAO_Provider::getProviders(NULL, NULL, TRUE, 'is_default desc');
$providerSelect = array();
foreach ($providers as $provider) {
$providerSelect[$provider['id']] = $provider['title'];
}
$suppressedSms = 0;
//here we are getting logged in user id as array but we need target contact id. CRM-5988
$cid = $form->get('cid');
if ($cid) {
$form->_contactIds = array($cid);
}
$to = $form->add('text', 'to', ts('To'), array('class' => 'huge'), TRUE);
$form->add('text', 'activity_subject', ts('Name The SMS'), array('class' => 'huge'), TRUE);
$toSetDefault = TRUE;
if (property_exists($form, '_context') && $form->_context == 'standalone') {
$toSetDefault = FALSE;
}
// when form is submitted recompute contactIds
$allToSMS = array();
if ($to->getValue()) {
$allToPhone = explode(',', $to->getValue());
$form->_contactIds = array();
foreach ($allToPhone as $value) {
list($contactId, $phone) = explode('::', $value);
if ($contactId) {
$form->_contactIds[] = $contactId;
$form->_toContactPhone[] = $phone;
}
}
$toSetDefault = TRUE;
}
//get the group of contacts as per selected by user in case of Find Activities
if (!empty($form->_activityHolderIds)) {
$extendTargetContacts = 0;
$invalidActivity = 0;
$validActivities = 0;
foreach ($form->_activityHolderIds as $key => $id) {
//valid activity check
if (CRM_Core_DAO::getFieldValue('CRM_Activity_DAO_Activity', $id, 'subject', 'id') != self::RECIEVED_SMS_ACTIVITY_SUBJECT) {
$invalidActivity++;
continue;
}
$activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name');
$targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts);
//target contacts limit check
$ids = array_keys(CRM_Activity_BAO_ActivityContact::getNames($id, $targetID));
if (count($ids) > 1) {
$extendTargetContacts++;
continue;
}
$validActivities++;
$form->_contactIds = empty($form->_contactIds) ? $ids : array_unique(array_merge($form->_contactIds, $ids));
}
if (!$validActivities) {
$errorMess = "";
if ($extendTargetContacts) {
$errorMess = ts('One selected activity consists of more than one target contact.', array('count' => $extendTargetContacts, 'plural' => '%count selected activities consist of more than one target contact.'));
}
if ($invalidActivity) {
$errorMess = $errorMess ? ' ' : '';
$errorMess .= ts('The selected activity is invalid.', array('count' => $invalidActivity, 'plural' => '%count selected activities are invalid.'));
}
CRM_Core_Error::statusBounce(ts("%1: SMS Reply will not be sent.", array(1 => $errorMess)));
}
}
if (is_array($form->_contactIds) && !empty($form->_contactIds) && $toSetDefault) {
$returnProperties = array('sort_name' => 1, 'phone' => 1, 'do_not_sms' => 1, 'is_deceased' => 1, 'display_name' => 1);
list($form->_contactDetails) = CRM_Utils_Token::getTokenDetails($form->_contactIds, $returnProperties, FALSE, FALSE);
// make a copy of all contact details
$form->_allContactDetails = $form->_contactDetails;
foreach ($form->_contactIds as $key => $contactId) {
$value = $form->_contactDetails[$contactId];
//to check if the phone type is "Mobile"
$phoneTypes = CRM_Core_OptionGroup::values('phone_type', TRUE, FALSE, FALSE, NULL, 'name');
if (CRM_Utils_System::getClassName($form) == 'CRM_Activity_Form_Task_SMS') {
//to check for "if the contact id belongs to a specified activity type"
$actDetails = CRM_Activity_BAO_Activity::getContactActivity($contactId);
if (self::RECIEVED_SMS_ACTIVITY_SUBJECT != CRM_Utils_Array::retrieveValueRecursive($actDetails, 'subject')) {
$suppressedSms++;
unset($form->_contactDetails[$contactId]);
continue;
}
}
if (isset($value['phone_type_id']) && $value['phone_type_id'] != CRM_Utils_Array::value('Mobile', $phoneTypes) || $value['do_not_sms'] || empty($value['phone']) || !empty($value['is_deceased'])) {
//if phone is not primary check if non-primary phone is "Mobile"
if (!empty($value['phone']) && $value['phone_type_id'] != CRM_Utils_Array::value('Mobile', $phoneTypes) && empty($value['is_deceased'])) {
$filter = array('do_not_sms' => 0);
$contactPhones = CRM_Core_BAO_Phone::allPhones($contactId, FALSE, 'Mobile', $filter);
if (count($contactPhones) > 0) {
//.........這裏部分代碼省略.........
示例7: sendSMS
static function sendSMS(&$contactDetails, &$activityParams, &$smsParams = array(), &$contactIds, $userID = NULL)
{
if ($userID == NULL) {
$session = CRM_Core_Session::singleton();
$userID = $session->get('userID');
}
$text =& $activityParams['text_message'];
$html =& $activityParams['html_message'];
// CRM-4575
// token replacement of addressee/email/postal greetings
// get the tokens added in subject and message
$messageToken = CRM_Utils_Token::getTokens($text);
$messageToken = array_merge($messageToken, CRM_Utils_Token::getTokens($html));
//create the meta level record first ( sms activity )
$activityTypeID = CRM_Core_OptionGroup::getValue('activity_type', 'SMS', 'name');
// CRM-6265: save both text and HTML parts in details (if present)
if ($html and $text) {
$details = "-ALTERNATIVE ITEM 0-\n{$html}\n-ALTERNATIVE ITEM 1-\n{$text}\n-ALTERNATIVE END-\n";
} else {
$details = $html ? $html : $text;
}
$activitySubject = $activityParams['activity_subject'];
$activityParams = array('source_contact_id' => $userID, 'activity_type_id' => $activityTypeID, 'activity_date_time' => date('YmdHis'), 'subject' => $activitySubject, 'details' => $details, 'status_id' => 2);
$activity = self::create($activityParams);
$activityID = $activity->id;
$returnProperties = array();
if (isset($messageToken['contact'])) {
foreach ($messageToken['contact'] as $key => $value) {
$returnProperties[$value] = 1;
}
}
// get token details for contacts, call only if tokens are used
$details = array();
if (!empty($returnProperties)) {
list($details) = CRM_Utils_Token::getTokenDetails($contactIds, $returnProperties, NULL, NULL, FALSE, $messageToken, 'CRM_Activity_BAO_Activity');
}
// call token hook
$tokens = array();
CRM_Utils_Hook::tokens($tokens);
$categories = array_keys($tokens);
$escapeSmarty = $sent = FALSE;
foreach ($contactDetails as $values) {
$contactId = $values['contact_id'];
if (!empty($details) && is_array($details["{$contactId}"])) {
// unset email from details since it always returns primary email address
unset($details["{$contactId}"]['email']);
unset($details["{$contactId}"]['email_id']);
$values = array_merge($values, $details["{$contactId}"]);
}
$tokenText = CRM_Utils_Token::replaceContactTokens($text, $values, FALSE, $messageToken, FALSE, $escapeSmarty);
$tokenText = CRM_Utils_Token::replaceHookTokens($tokenText, $values, $categories, FALSE, $escapeSmarty);
$tokenHtml = CRM_Utils_Token::replaceContactTokens($html, $values, TRUE, $messageToken, FALSE, $escapeSmarty);
$tokenHtml = CRM_Utils_Token::replaceHookTokens($tokenHtml, $values, $categories, TRUE, $escapeSmarty);
$smsParams['To'] = $values['phone'];
if (self::sendSMSMessage($contactId, $tokenText, $tokenHtml, $smsParams, $activityID)) {
// even a single successful delivery should set this falg to true
$sent = TRUE;
}
}
return array($sent, $activity->id);
}
示例8: cancelParticipant
/**
* Cancel this participant and finish, send cancellation email. At this point no
* auto-cancellation of payment is handled, so payment needs to be manually cancelled
*
* return @void
*/
public function cancelParticipant($params)
{
//set participant record status to Cancelled, refund payment if possible
// send email to participant and admin, and log Activity
$value = array();
$value['id'] = $this->_participant_id;
$cancelledId = array_search('Cancelled', CRM_Event_PseudoConstant::participantStatus(NULL, "class = 'Negative'"));
$value['status_id'] = $cancelledId;
CRM_Event_BAO_Participant::create($value);
$domainValues = array();
$domain = CRM_Core_BAO_Domain::getDomain();
$tokens = array('domain' => array('name', 'phone', 'address', 'email'), 'contact' => CRM_Core_SelectValues::contactTokens());
foreach ($tokens['domain'] as $token) {
$domainValues[$token] = CRM_Utils_Token::getDomainTokenReplacement($token, $domain);
}
$participantRoles = array();
$participantRoles = CRM_Event_PseudoConstant::participantRole();
$participantDetails = array();
$query = "SELECT * FROM civicrm_participant WHERE id = {$this->_participant_id}";
$dao = CRM_Core_DAO::executeQuery($query);
while ($dao->fetch()) {
$participantDetails[$dao->id] = array('id' => $dao->id, 'role' => $participantRoles[$dao->role_id], 'is_test' => $dao->is_test, 'event_id' => $dao->event_id, 'status_id' => $dao->status_id, 'fee_amount' => $dao->fee_amount, 'contact_id' => $dao->contact_id, 'register_date' => $dao->register_date, 'registered_by_id' => $dao->registered_by_id);
}
$eventDetails = array();
$eventParams = array('id' => $this->_event_id);
CRM_Event_BAO_Event::retrieve($eventParams, $eventDetails[$this->_event_id]);
//get default participant role.
$eventDetails[$this->_event_id]['participant_role'] = CRM_Utils_Array::value($eventDetails[$this->_event_id]['default_role_id'], $participantRoles);
//get the location info
$locParams = array('entity_id' => $this->_event_id, 'entity_table' => 'civicrm_event');
$eventDetails[$this->_event_id]['location'] = CRM_Core_BAO_Location::getValues($locParams, TRUE);
//get contact details
$contactIds[$this->_contact_id] = $this->_contact_id;
list($currentContactDetails) = CRM_Utils_Token::getTokenDetails($contactIds, NULL, FALSE, FALSE, NULL, array(), 'CRM_Event_BAO_Participant');
foreach ($currentContactDetails as $contactId => $contactValues) {
$contactDetails[$this->_contact_id] = $contactValues;
}
//send a 'cancelled' email to user, and cc the event's cc_confirm email
$mail = CRM_Event_BAO_Participant::sendTransitionParticipantMail($this->_participant_id, $participantDetails[$this->_participant_id], $eventDetails[$this->_event_id], $contactDetails[$this->_contact_id], $domainValues, "Cancelled", "");
$statusMsg = ts('Event registration information for %1 has been updated.', array(1 => $this->_contact_name));
$statusMsg .= ' ' . ts('A cancellation email has been sent to %1.', array(1 => $this->_contact_email));
CRM_Core_Session::setStatus($statusMsg, ts('Saved'), 'success');
$url = CRM_Utils_System::url('civicrm/event/info', "reset=1&id={$this->_event_id}&noFullMsg=true");
CRM_Utils_System::redirect($url);
}
示例9: sendSMS
/**
* Send SMS.
*
* @param array $contactDetails
* @param array $activityParams
* @param array $smsParams
* @param $contactIds
* @param int $userID
*
* @return array
* @throws CRM_Core_Exception
*/
public static function sendSMS(&$contactDetails, &$activityParams, &$smsParams = array(), &$contactIds, $userID = NULL)
{
if ($userID == NULL) {
$session = CRM_Core_Session::singleton();
$userID = $session->get('userID');
}
$text =& $activityParams['sms_text_message'];
// CRM-4575
// token replacement of addressee/email/postal greetings
// get the tokens added in subject and message
$messageToken = CRM_Utils_Token::getTokens($text);
// Create the meta level record first ( sms activity )
$activityTypeID = CRM_Core_OptionGroup::getValue('activity_type', 'SMS', 'name');
$details = $text;
$activitySubject = $activityParams['activity_subject'];
$activityParams = array('source_contact_id' => $userID, 'activity_type_id' => $activityTypeID, 'activity_date_time' => date('YmdHis'), 'subject' => $activitySubject, 'details' => $details, 'status_id' => 2);
$activity = self::create($activityParams);
$activityID = $activity->id;
$returnProperties = array();
if (isset($messageToken['contact'])) {
foreach ($messageToken['contact'] as $key => $value) {
$returnProperties[$value] = 1;
}
}
// call token hook
$tokens = array();
CRM_Utils_Hook::tokens($tokens);
$categories = array_keys($tokens);
// get token details for contacts, call only if tokens are used
$details = array();
if (!empty($returnProperties) || !empty($tokens)) {
list($details) = CRM_Utils_Token::getTokenDetails($contactIds, $returnProperties, NULL, NULL, FALSE, $messageToken, 'CRM_Activity_BAO_Activity');
}
$success = 0;
$escapeSmarty = FALSE;
$errMsgs = array();
foreach ($contactDetails as $values) {
$contactId = $values['contact_id'];
if (!empty($details) && is_array($details["{$contactId}"])) {
// unset email from details since it always returns primary email address
unset($details["{$contactId}"]['email']);
unset($details["{$contactId}"]['email_id']);
$values = array_merge($values, $details["{$contactId}"]);
}
$tokenText = CRM_Utils_Token::replaceContactTokens($text, $values, FALSE, $messageToken, FALSE, $escapeSmarty);
$tokenText = CRM_Utils_Token::replaceHookTokens($tokenText, $values, $categories, FALSE, $escapeSmarty);
// Only send if the phone is of type mobile
$phoneTypes = CRM_Core_OptionGroup::values('phone_type', TRUE, FALSE, FALSE, NULL, 'name');
if ($values['phone_type_id'] == CRM_Utils_Array::value('Mobile', $phoneTypes)) {
$smsParams['To'] = $values['phone'];
} else {
$smsParams['To'] = '';
}
$sendResult = self::sendSMSMessage($contactId, $tokenText, $smsParams, $activityID, $userID);
if (PEAR::isError($sendResult)) {
// Collect all of the PEAR_Error objects
$errMsgs[] = $sendResult;
} else {
$success++;
}
}
// If at least one message was sent and no errors
// were generated then return a boolean value of TRUE.
// Otherwise, return FALSE (no messages sent) or
// and array of 1 or more PEAR_Error objects.
$sent = FALSE;
if ($success > 0 && count($errMsgs) == 0) {
$sent = TRUE;
} elseif (count($errMsgs) > 0) {
$sent = $errMsgs;
}
return array($sent, $activity->id, $success);
}
示例10: postProcess
/**
* process the form after the input has been submitted and validated
*
* @access public
*
* @return void
*/
public function postProcess()
{
// get all the details needed to generate a receipt
$contribIDs = implode(',', $this->_contributionIds);
$details = CRM_Contribute_Form_Task_Status::getDetails($contribIDs);
$baseIPN = new CRM_Core_Payment_BaseIPN();
$message = array();
$template = CRM_Core_Smarty::singleton();
$params = $this->controller->exportValues($this->_name);
$createPdf = FALSE;
if ($params['output'] == "pdf_receipt") {
$createPdf = TRUE;
}
$excludeContactIds = array();
if (!$createPdf) {
$returnProperties = array('email' => 1, 'do_not_email' => 1, 'is_deceased' => 1, 'on_hold' => 1);
list($contactDetails) = CRM_Utils_Token::getTokenDetails($this->_contactIds, $returnProperties, FALSE, FALSE);
$suppressedEmails = 0;
foreach ($contactDetails as $id => $values) {
if (empty($values['email']) || !empty($values['do_not_email']) || CRM_Utils_Array::value('is_deceased', $values) || !empty($values['on_hold'])) {
$suppressedEmails++;
$excludeContactIds[] = $values['contact_id'];
}
}
}
foreach ($details as $contribID => $detail) {
$input = $ids = $objects = array();
if (in_array($detail['contact'], $excludeContactIds)) {
continue;
}
$input['component'] = $detail['component'];
$ids['contact'] = $detail['contact'];
$ids['contribution'] = $contribID;
$ids['contributionRecur'] = NULL;
$ids['contributionPage'] = NULL;
$ids['membership'] = CRM_Utils_Array::value('membership', $detail);
$ids['participant'] = CRM_Utils_Array::value('participant', $detail);
$ids['event'] = CRM_Utils_Array::value('event', $detail);
if (!$baseIPN->validateData($input, $ids, $objects, FALSE)) {
CRM_Core_Error::fatal();
}
$contribution =& $objects['contribution'];
// CRM_Core_Error::debug('o',$objects);
// set some fake input values so we can reuse IPN code
$input['amount'] = $contribution->total_amount;
$input['is_test'] = $contribution->is_test;
$input['fee_amount'] = $contribution->fee_amount;
$input['net_amount'] = $contribution->net_amount;
$input['trxn_id'] = $contribution->trxn_id;
$input['trxn_date'] = isset($contribution->trxn_date) ? $contribution->trxn_date : NULL;
// CRM_Contribute_BAO_Contribution::composeMessageArray expects mysql formatted date
$objects['contribution']->receive_date = CRM_Utils_Date::isoToMysql($objects['contribution']->receive_date);
// CRM_Core_Error::debug('input',$input);
$values = array();
$mail = $baseIPN->sendMail($input, $ids, $objects, $values, FALSE, $createPdf);
if ($mail['html']) {
$message[] = $mail['html'];
} else {
$message[] = nl2br($mail['body']);
}
// reset template values before processing next transactions
$template->clearTemplateVars();
}
if ($createPdf) {
CRM_Utils_PDF_Utils::html2pdf($message, 'civicrmContributionReceipt.pdf', FALSE, $params['pdf_format_id']);
CRM_Utils_System::civiExit();
} else {
if ($suppressedEmails) {
$status = ts('Email was NOT sent to %1 contacts (no email address on file, or communication preferences specify DO NOT EMAIL, or contact is deceased).', array(1 => $suppressedEmails));
$msgTitle = ts('Email Error');
$msgType = 'error';
} else {
$status = ts('Your mail has been sent.');
$msgTitle = ts('Sent');
$msgType = 'success';
}
CRM_Core_Session::setStatus($status, $msgTitle, $msgType);
}
}
示例11: buildQuickForm
/**
* Build the form
*
* @access public
*
* @return void
*/
static function buildQuickForm(&$form)
{
$toArray = $ccArray = $bccArray = array();
$suppressedEmails = 0;
//here we are getting logged in user id as array but we need target contact id. CRM-5988
$cid = $form->get('cid');
if ($cid) {
$form->_contactIds = array($cid);
}
$to = $form->add('text', 'to', ts('To'), '', TRUE);
$cc = $form->add('text', 'cc_id', ts('CC'));
$bcc = $form->add('text', 'bcc_id', ts('BCC'));
$elements = array('cc', 'bcc');
foreach ($elements as $element) {
if (${$element}->getValue()) {
preg_match_all('!"(.*?)"\\s+<\\s*(.*?)\\s*>!', ${$element}->getValue(), $matches);
$elementValues = array();
for ($i = 0; $i < count($matches[0]); $i++) {
$name = '"' . $matches[1][$i] . '" <' . $matches[2][$i] . '>';
$elementValues[] = array('name' => $name, 'id' => $matches[0][$i]);
}
$var = "{$element}Contact";
$form->assign($var, json_encode($elementValues));
}
}
$toSetDefault = TRUE;
if (property_exists($form, '_context') && $form->_context == 'standalone') {
$toSetDefault = FALSE;
}
// when form is submitted recompute contactIds
$allToEmails = array();
if ($to->getValue()) {
$allToEmails = explode(',', $to->getValue());
$form->_contactIds = array();
foreach ($allToEmails as $value) {
list($contactId, $email) = explode('::', $value);
if ($contactId) {
$form->_contactIds[] = $contactId;
$form->_toContactEmails[] = $email;
}
}
$toSetDefault = TRUE;
}
//get the group of contacts as per selected by user in case of Find Activities
if (!empty($form->_activityHolderIds)) {
$contact = $form->get('contacts');
$form->_contactIds = $contact;
}
if (is_array($form->_contactIds) && $toSetDefault) {
$returnProperties = array('sort_name' => 1, 'email' => 1, 'do_not_email' => 1, 'is_deceased' => 1, 'on_hold' => 1, 'display_name' => 1, 'preferred_mail_format' => 1);
list($form->_contactDetails) = CRM_Utils_Token::getTokenDetails($form->_contactIds, $returnProperties, FALSE, FALSE);
// make a copy of all contact details
$form->_allContactDetails = $form->_contactDetails;
foreach ($form->_contactIds as $key => $contactId) {
$value = $form->_contactDetails[$contactId];
if ($value['do_not_email'] || empty($value['email']) || CRM_Utils_Array::value('is_deceased', $value) || $value['on_hold']) {
$suppressedEmails++;
// unset contact details for contacts that we won't be sending email. This is prevent extra computation
// during token evaluation etc.
unset($form->_contactDetails[$contactId]);
} else {
if (empty($form->_toContactEmails)) {
$email = $value['email'];
} else {
$email = $form->_toContactEmails[$key];
}
$toArray[] = array('name' => '"' . $value['sort_name'] . '" <' . $email . '>', 'id' => "{$contactId}::{$email}");
}
}
if (empty($toArray)) {
CRM_Core_Error::statusBounce(ts('Selected contact(s) do not have a valid email address, or communication preferences specify DO NOT EMAIL, or they are deceased or Primary email address is On Hold.'));
}
}
$form->assign('toContact', json_encode($toArray));
$form->assign('suppressedEmails', $suppressedEmails);
$form->assign('totalSelectedContacts', count($form->_contactIds));
$form->add('text', 'subject', ts('Subject'), 'size=50 maxlength=254', TRUE);
$form->add('select', 'fromEmailAddress', ts('From'), $form->_fromEmails, TRUE);
CRM_Mailing_BAO_Mailing::commonCompose($form);
// add attachments
CRM_Core_BAO_File::buildAttachment($form, NULL);
if ($form->_single) {
// also fix the user context stack
if ($form->_caseId) {
$ccid = CRM_Core_DAO::getFieldValue('CRM_Case_DAO_CaseContact', $form->_caseId, 'contact_id', 'case_id');
$url = CRM_Utils_System::url('civicrm/contact/view/case', "&reset=1&action=view&cid={$ccid}&id={$form->_caseId}");
} elseif ($form->_context) {
$url = CRM_Utils_System::url('civicrm/dashboard', 'reset=1');
} else {
$url = CRM_Utils_System::url('civicrm/contact/view', "&show=1&action=browse&cid={$form->_contactIds[0]}&selectedChild=activity");
}
$session = CRM_Core_Session::singleton();
$session->replaceUserContext($url);
//.........這裏部分代碼省略.........
示例12: run
/**
* Run this page (figure out the action needed and perform it).
*
* @param int $id
* @param int $contactID
* @param bool $print
* @param bool $allowID
*/
public function run($id = NULL, $contactID = NULL, $print = TRUE, $allowID = FALSE)
{
if (is_numeric($id)) {
$this->_mailingID = $id;
} else {
$print = TRUE;
$this->_mailingID = CRM_Utils_Request::retrieve('id', 'String', CRM_Core_DAO::$_nullObject, TRUE);
}
// # CRM-7651
// override contactID from the function level if passed in
if (isset($contactID) && is_numeric($contactID)) {
$this->_contactID = $contactID;
} else {
$session = CRM_Core_Session::singleton();
$this->_contactID = $session->get('userID');
}
// mailing key check
if (Civi::settings()->get('hash_mailing_url')) {
$this->_mailing = new CRM_Mailing_BAO_Mailing();
if (!is_numeric($this->_mailingID)) {
$this->_mailing->hash = $this->_mailingID;
} elseif (is_numeric($this->_mailingID)) {
$this->_mailing->id = $this->_mailingID;
// if mailing is present and associated hash is present
// while 'hash' is not been used for mailing view : throw 'permissionDenied'
if ($this->_mailing->find() && CRM_Core_DAO::getFieldValue('CRM_Mailing_BAO_Mailing', $this->_mailingID, 'hash', 'id') && !$allowID) {
CRM_Utils_System::permissionDenied();
return;
}
}
} else {
$this->_mailing = new CRM_Mailing_BAO_Mailing();
$this->_mailing->id = $this->_mailingID;
}
if (!$this->_mailing->find(TRUE) || !$this->checkPermission()) {
CRM_Utils_System::permissionDenied();
return;
}
CRM_Mailing_BAO_Mailing::tokenReplace($this->_mailing);
// get and format attachments
$attachments = CRM_Core_BAO_File::getEntityFile('civicrm_mailing', $this->_mailing->id);
// get contact detail and compose if contact id exists
$returnProperties = $this->_mailing->getReturnProperties();
if (isset($this->_contactID)) {
// get details of contact with token value including Custom Field Token Values.CRM-3734
$params = array('contact_id' => $this->_contactID);
$details = CRM_Utils_Token::getTokenDetails($params, $returnProperties, FALSE, TRUE, NULL, $this->_mailing->getFlattenedTokens(), get_class($this));
$details = $details[0][$this->_contactID];
$contactId = $this->_contactID;
} else {
// get tokens that are not contact specific resolved
$params = array('contact_id' => 0);
$details = CRM_Utils_Token::getAnonymousTokenDetails($params, $returnProperties, TRUE, TRUE, NULL, $this->_mailing->getFlattenedTokens(), get_class($this));
$details = CRM_Utils_Array::value(0, $details[0]);
$contactId = 0;
}
$mime =& $this->_mailing->compose(NULL, NULL, NULL, $contactId, $this->_mailing->from_email, $this->_mailing->from_email, TRUE, $details, $attachments);
$title = NULL;
if (isset($this->_mailing->body_html) && empty($_GET['text'])) {
$header = 'text/html; charset=utf-8';
$content = $mime->getHTMLBody();
if (strpos($content, '<head>') === FALSE && strpos($content, '<title>') === FALSE) {
$title = '<head><title>' . $this->_mailing->subject . '</title></head>';
}
} else {
$header = 'text/plain; charset=utf-8';
$content = $mime->getTXTBody();
}
CRM_Utils_System::setTitle($this->_mailing->subject);
if (CRM_Utils_Array::value('snippet', $_GET) === 'json') {
CRM_Core_Page_AJAX::returnJsonResponse($content);
}
if ($print) {
CRM_Utils_System::setHttpHeader('Content-Type', $header);
print $title;
print $content;
CRM_Utils_System::civiExit();
} else {
return $content;
}
}
示例13: postProcess
/**
* process the form after the input has been submitted and validated
*
* @access public
*
* @return None
*/
static function postProcess(&$form)
{
list($formValues, $categories, $html_message, $messageToken, $returnProperties) = self::processMessageTemplate($form);
$skipOnHold = isset($form->skipOnHold) ? $form->skipOnHold : FALSE;
$skipDeceased = isset($form->skipDeceased) ? $form->skipDeceased : TRUE;
foreach ($form->_contactIds as $item => $contactId) {
$params = array('contact_id' => $contactId);
list($contact) = CRM_Utils_Token::getTokenDetails($params, $returnProperties, $skipOnHold, $skipDeceased, NULL, $messageToken, 'CRM_Contact_Form_Task_PDFLetterCommon');
if (civicrm_error($contact)) {
$notSent[] = $contactId;
continue;
}
$tokenHtml = CRM_Utils_Token::replaceContactTokens($html_message, $contact[$contactId], TRUE, $messageToken);
$tokenHtml = CRM_Utils_Token::replaceHookTokens($tokenHtml, $contact[$contactId], $categories, TRUE);
if (defined('CIVICRM_MAIL_SMARTY') && CIVICRM_MAIL_SMARTY) {
$smarty = CRM_Core_Smarty::singleton();
// also add the contact tokens to the template
$smarty->assign_by_ref('contact', $contact);
$tokenHtml = $smarty->fetch("string:{$tokenHtml}");
}
$html[] = $tokenHtml;
}
self::createActivities($form, $html_message, $form->_contactIds);
CRM_Utils_PDF_Utils::html2pdf($html, "CiviLetter.pdf", FALSE, $formValues);
$form->postProcessHook();
CRM_Utils_System::civiExit(1);
}
示例14: sendCancellation
/**
* Send confirmation of cancellation to source participant
*
* return @ void
*/
public function sendCancellation()
{
$domainValues = array();
$domain = CRM_Core_BAO_Domain::getDomain();
$tokens = array('domain' => array('name', 'phone', 'address', 'email'), 'contact' => CRM_Core_SelectValues::contactTokens());
foreach ($tokens['domain'] as $token) {
$domainValues[$token] = CRM_Utils_Token::getDomainTokenReplacement($token, $domain);
}
$participantRoles = array();
$participantRoles = CRM_Event_PseudoConstant::participantRole();
$participantDetails = array();
$query = "SELECT * FROM civicrm_participant WHERE id = {$this->_from_participant_id}";
$dao = CRM_Core_DAO::executeQuery($query);
while ($dao->fetch()) {
$participantDetails[$dao->id] = array('id' => $dao->id, 'role' => $participantRoles[$dao->role_id], 'is_test' => $dao->is_test, 'event_id' => $dao->event_id, 'status_id' => $dao->status_id, 'fee_amount' => $dao->fee_amount, 'contact_id' => $dao->contact_id, 'register_date' => $dao->register_date, 'registered_by_id' => $dao->registered_by_id);
}
$eventDetails = array();
$eventParams = array('id' => $this->_event_id);
CRM_Event_BAO_Event::retrieve($eventParams, $eventDetails[$this->_event_id]);
//get default participant role.
$eventDetails[$this->_event_id]['participant_role'] = CRM_Utils_Array::value($eventDetails[$this->_event_id]['default_role_id'], $participantRoles);
//get the location info
$locParams = array('entity_id' => $this->_event_id, 'entity_table' => 'civicrm_event');
$eventDetails[$this->_event_id]['location'] = CRM_Core_BAO_Location::getValues($locParams, TRUE);
//get contact details
$contactIds[$this->_from_contact_id] = $this->_from_contact_id;
list($currentContactDetails) = CRM_Utils_Token::getTokenDetails($contactIds, NULL, FALSE, FALSE, NULL, array(), 'CRM_Event_BAO_Participant');
foreach ($currentContactDetails as $contactId => $contactValues) {
$contactDetails[$this->_from_contact_id] = $contactValues;
}
//send a 'cancelled' email to user, and cc the event's cc_confirm email
$mail = CRM_Event_BAO_Participant::sendTransitionParticipantMail($this->_from_participant_id, $participantDetails[$this->_from_participant_id], $eventDetails[$this->_event_id], $contactDetails[$this->_from_contact_id], $domainValues, "Transferred", "");
$statusMsg = ts('Event registration information for %1 has been updated.', array(1 => $this->_contact_name));
$statusMsg .= ' ' . ts('A cancellation email has been sent to %1.', array(1 => $this->_contact_email));
CRM_Core_Session::setStatus($statusMsg, ts('Thanks'), 'success');
}
示例15: postProcess
/**
* process the form after the input has been submitted and validated
*
* @access public
*
* @return void
*/
static function postProcess(&$form)
{
list($formValues, $categories, $html_message, $messageToken, $returnProperties) = self::processMessageTemplate($form);
// update dates ?
$receipt_update = isset($formValues['receipt_update']) ? $formValues['receipt_update'] : FALSE;
$thankyou_update = isset($formValues['thankyou_update']) ? $formValues['thankyou_update'] : FALSE;
$nowDate = date('YmdHis');
$receipts = 0;
$thanks = 0;
$updateStatus = '';
// skip some contacts ?
$skipOnHold = isset($form->skipOnHold) ? $form->skipOnHold : FALSE;
$skipDeceased = isset($form->skipDeceased) ? $form->skipDeceased : TRUE;
foreach ($form->getVar('_contributionIds') as $item => $contributionId) {
// get contact information
$contactId = civicrm_api("Contribution", "getvalue", array('version' => '3', 'id' => $contributionId, 'return' => 'contact_id'));
$params = array('contact_id' => $contactId);
list($contact) = CRM_Utils_Token::getTokenDetails($params, $returnProperties, $skipOnHold, $skipDeceased, NULL, $messageToken, 'CRM_Contribution_Form_Task_PDFLetterCommon');
if (civicrm_error($contact)) {
$notSent[] = $contributionId;
continue;
}
// get contribution information
$params = array('contribution_id' => $contributionId);
$contribution = CRM_Utils_Token::getContributionTokenDetails($params, $returnProperties, NULL, $messageToken, 'CRM_Contribution_Form_Task_PDFLetterCommon');
if (civicrm_error($contribution)) {
$notSent[] = $contributionId;
continue;
}
$tokenHtml = CRM_Utils_Token::replaceContactTokens($html_message, $contact[$contactId], TRUE, $messageToken);
$tokenHtml = CRM_Utils_Token::replaceContributionTokens($tokenHtml, $contribution[$contributionId], TRUE, $messageToken);
$tokenHtml = CRM_Utils_Token::replaceHookTokens($tokenHtml, $contact[$contactId], $categories, TRUE);
if (defined('CIVICRM_MAIL_SMARTY') && CIVICRM_MAIL_SMARTY) {
$smarty = CRM_Core_Smarty::singleton();
// also add the tokens to the template
$smarty->assign_by_ref('contact', $contact);
$tokenHtml = $smarty->fetch("string:{$tokenHtml}");
}
$html[] = $tokenHtml;
// update dates (do it for each contribution including grouped recurring contribution)
if ($receipt_update) {
$result = CRM_Core_DAO::setFieldValue('CRM_Contribute_DAO_Contribution', $contributionId, 'receipt_date', $nowDate);
// We can't use CRM_Core_Error::fatal here because the api error elevates the exception level. FIXME. dgg
if ($result) {
$receipts++;
}
}
if ($thankyou_update) {
$result = CRM_Core_DAO::setFieldValue('CRM_Contribute_DAO_Contribution', $contributionId, 'thankyou_date', $nowDate);
// We can't use CRM_Core_Error::fatal here because the api error elevates the exception level. FIXME. dgg
if ($result) {
$thanks++;
}
}
}
self::createActivities($form, $html_message, $form->_contactIds);
CRM_Utils_PDF_Utils::html2pdf($html, "CiviLetter.pdf", FALSE, $formValues);
$form->postProcessHook();
if ($receipts) {
$updateStatus = ts('Receipt date has been updated for %1 contributions.', array(1 => $receipts));
}
if ($thanks) {
$updateStatus .= ' ' . ts('Thank-you date has been updated for %1 contributions.', array(1 => $thanks));
}
if ($updateStatus) {
CRM_Core_Session::setStatus($updateStatus);
}
CRM_Utils_System::civiExit(1);
}