本文整理汇总了PHP中CRM_Utils_Token类的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Utils_Token类的具体用法?PHP CRM_Utils_Token怎么用?PHP CRM_Utils_Token使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CRM_Utils_Token类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getAngularModules
/**
* Get AngularJS modules and their dependencies
*
* @return array
* list of modules; same format as CRM_Utils_Hook::angularModules(&$angularModules)
* @see CRM_Utils_Hook::angularModules
*/
public function getAngularModules()
{
// load angular files only if valid permissions are granted to the user
if (!CRM_Core_Permission::check('access CiviMail') && !CRM_Core_Permission::check('create mailings') && !CRM_Core_Permission::check('schedule mailings') && !CRM_Core_Permission::check('approve mailings')) {
return array();
}
$result = array();
$result['crmMailing'] = array('ext' => 'civicrm', 'js' => array('ang/crmMailing.js', 'ang/crmMailing/*.js'), 'css' => array('ang/crmMailing.css'), 'partials' => array('ang/crmMailing'));
$result['crmMailingAB'] = array('ext' => 'civicrm', 'js' => array('ang/crmMailingAB.js', 'ang/crmMailingAB/*.js', 'ang/crmMailingAB/*/*.js'), 'css' => array('ang/crmMailingAB.css'), 'partials' => array('ang/crmMailingAB'));
$result['crmD3'] = array('ext' => 'civicrm', 'js' => array('ang/crmD3.js', 'bower_components/d3/d3.min.js'));
$config = CRM_Core_Config::singleton();
$session = CRM_Core_Session::singleton();
$contactID = $session->get('userID');
// Get past mailings
// CRM-16155 - Limit to a reasonable number
$civiMails = civicrm_api3('Mailing', 'get', array('is_completed' => 1, 'mailing_type' => array('IN' => array('standalone', 'winner')), 'return' => array('id', 'name', 'scheduled_date'), 'sequential' => 1, 'options' => array('limit' => 500, 'sort' => 'is_archived asc, scheduled_date desc')));
// Generic params
$params = array('options' => array('limit' => 0), 'sequential' => 1);
$groupNames = civicrm_api3('Group', 'get', $params + array('is_active' => 1, 'check_permissions' => TRUE, 'return' => array('title', 'visibility', 'group_type', 'is_hidden')));
$headerfooterList = civicrm_api3('MailingComponent', 'get', $params + array('is_active' => 1, 'return' => array('name', 'component_type', 'is_default', 'body_html', 'body_text')));
$emailAdd = civicrm_api3('Email', 'get', array('sequential' => 1, 'return' => "email", 'contact_id' => $contactID));
$mesTemplate = civicrm_api3('MessageTemplate', 'get', $params + array('sequential' => 1, 'is_active' => 1, 'return' => array("id", "msg_title"), 'workflow_id' => array('IS NULL' => "")));
$mailTokens = civicrm_api3('Mailing', 'gettokens', array('entity' => array('contact', 'mailing'), 'sequential' => 1));
$fromAddress = civicrm_api3('OptionValue', 'get', $params + array('option_group_id' => "from_email_address", 'domain_id' => CRM_Core_Config::domainID()));
CRM_Core_Resources::singleton()->addSetting(array('crmMailing' => array('civiMails' => $civiMails['values'], 'campaignEnabled' => in_array('CiviCampaign', $config->enableComponents), 'groupNames' => $groupNames['values'], 'headerfooterList' => $headerfooterList['values'], 'mesTemplate' => $mesTemplate['values'], 'emailAdd' => $emailAdd['values'], 'mailTokens' => $mailTokens['values'], 'contactid' => $contactID, 'requiredTokens' => CRM_Utils_Token::getRequiredTokens(), 'enableReplyTo' => (int) CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, 'replyTo'), 'disableMandatoryTokensCheck' => (int) CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, 'disable_mandatory_tokens_check'), 'fromAddress' => $fromAddress['values'], 'defaultTestEmail' => civicrm_api3('Contact', 'getvalue', array('id' => 'user_contact_id', 'return' => 'email')), 'visibility' => CRM_Utils_Array::makeNonAssociative(CRM_Core_SelectValues::groupVisibility()), 'workflowEnabled' => CRM_Mailing_Info::workflowEnabled())))->addPermissions(array('view all contacts', 'access CiviMail', 'create mailings', 'schedule mailings', 'approve mailings', 'delete in CiviMail', 'edit message templates'));
return $result;
}
示例2: buildQuickForm
/**
* Build the form object.
*/
public function buildQuickForm()
{
$this->applyFilter('__ALL__', 'trim');
$this->addFormRule(array('CRM_Admin_Form_Preferences_Address', 'formRule'));
//get the tokens for Mailing Label field
$tokens = CRM_Core_SelectValues::contactTokens();
$this->assign('tokens', CRM_Utils_Token::formatTokensForDisplay($tokens));
parent::buildQuickForm();
}
示例3: _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);
}
示例4: onRender
/**
* Apply the various CRM_Utils_Token helpers.
*
* @param TokenRenderEvent $e
*/
public function onRender(TokenRenderEvent $e)
{
$isHtml = $e->message['format'] == 'text/html';
$useSmarty = !empty($e->context['smarty']);
$e->string = \CRM_Utils_Token::replaceDomainTokens($e->string, \CRM_Core_BAO_Domain::getDomain(), $isHtml, $e->message['tokens'], $useSmarty);
if (!empty($e->context['contact'])) {
$e->string = \CRM_Utils_Token::replaceContactTokens($e->string, $e->context['contact'], $isHtml, $e->message['tokens'], FALSE, $useSmarty);
// FIXME: This may depend on $contact being merged with hook values.
$e->string = \CRM_Utils_Token::replaceHookTokens($e->string, $e->context['contact'], $e->context['hookTokenCategories'], $isHtml, $useSmarty);
\CRM_Utils_Token::replaceGreetingTokens($e->string, NULL, $e->context['contact']['contact_id'], NULL, $useSmarty);
}
if ($useSmarty) {
$smarty = \CRM_Core_Smarty::singleton();
$e->string = $smarty->fetch("string:" . $e->string);
}
}
示例5: 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;
}
示例6: 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();
}
示例7: _replaceMergeTokens
/**
* @param int $contactId
* @param array $exportParams
*
* @return array
*/
public static function _replaceMergeTokens($contactId, $exportParams)
{
$greetings = array();
$contact = NULL;
$greetingFields = array('postal_greeting', 'addressee');
foreach ($greetingFields as $greeting) {
if (!empty($exportParams[$greeting])) {
$greetingLabel = $exportParams[$greeting];
if (empty($contact)) {
$values = array('id' => $contactId, 'version' => 3);
$contact = civicrm_api('contact', 'get', $values);
if (!empty($contact['is_error'])) {
return $greetings;
}
$contact = $contact['values'][$contact['id']];
}
$tokens = array('contact' => $greetingLabel);
$greetings[$greeting] = CRM_Utils_Token::replaceContactTokens($greetingLabel, $contact, NULL, $tokens);
}
}
return $greetings;
}
示例8: transitionParticipants
/**
* Function takes participant ids and statuses
* update status from $fromStatusId to $toStatusId
* and send mail + create activities.
*
* @param array $participantIds
* Participant ids.
* @param int $toStatusId
* Update status id.
* @param int $fromStatusId
* From status id.
* @param bool $returnResult
* @param bool $skipCascadeRule
*
* @return array|NULL
*/
public static function transitionParticipants($participantIds, $toStatusId, $fromStatusId = NULL, $returnResult = FALSE, $skipCascadeRule = FALSE)
{
if (!is_array($participantIds) || empty($participantIds) || !$toStatusId) {
return NULL;
}
//thumb rule is if we triggering primary participant need to triggered additional
$allParticipantIds = $primaryANDAdditonalIds = array();
foreach ($participantIds as $id) {
$allParticipantIds[] = $id;
if (self::isPrimaryParticipant($id)) {
//filter additional as per status transition rules, CRM-5403
if ($skipCascadeRule) {
$additionalIds = self::getAdditionalParticipantIds($id);
} else {
$additionalIds = self::getValidAdditionalIds($id, $fromStatusId, $toStatusId);
}
if (!empty($additionalIds)) {
$allParticipantIds = array_merge($allParticipantIds, $additionalIds);
$primaryANDAdditonalIds[$id] = $additionalIds;
}
}
}
//get the unique participant ids,
$allParticipantIds = array_unique($allParticipantIds);
//pull required participants, contacts, events data, if not in hand
static $eventDetails = array();
static $domainValues = array();
static $contactDetails = array();
$contactIds = $eventIds = $participantDetails = array();
$statusTypes = CRM_Event_PseudoConstant::participantStatus();
$participantRoles = CRM_Event_PseudoConstant::participantRole();
$pendingStatuses = CRM_Event_PseudoConstant::participantStatus(NULL, "class = 'Pending'");
//first thing is pull all necessory data from db.
$participantIdClause = '(' . implode(',', $allParticipantIds) . ')';
//get all participants data.
$query = "SELECT * FROM civicrm_participant WHERE id IN {$participantIdClause}";
$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);
if (!array_key_exists($dao->contact_id, $contactDetails)) {
$contactIds[$dao->contact_id] = $dao->contact_id;
}
if (!array_key_exists($dao->event_id, $eventDetails)) {
$eventIds[$dao->event_id] = $dao->event_id;
}
}
//get the domain values.
if (empty($domainValues)) {
// making all tokens available to templates.
$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);
}
}
//get all required contacts detail.
if (!empty($contactIds)) {
// get the contact details.
list($currentContactDetails) = CRM_Utils_Token::getTokenDetails($contactIds, NULL, FALSE, FALSE, NULL, array(), 'CRM_Event_BAO_Participant');
foreach ($currentContactDetails as $contactId => $contactValues) {
$contactDetails[$contactId] = $contactValues;
}
}
//get all required events detail.
if (!empty($eventIds)) {
foreach ($eventIds as $eventId) {
//retrieve event information
$eventParams = array('id' => $eventId);
CRM_Event_BAO_Event::retrieve($eventParams, $eventDetails[$eventId]);
//get default participant role.
$eventDetails[$eventId]['participant_role'] = CRM_Utils_Array::value($eventDetails[$eventId]['default_role_id'], $participantRoles);
//get the location info
$locParams = array('entity_id' => $eventId, 'entity_table' => 'civicrm_event');
$eventDetails[$eventId]['location'] = CRM_Core_BAO_Location::getValues($locParams, TRUE);
}
}
//now we are ready w/ all required data.
//take a decision as per statuses.
$emailType = NULL;
$toStatus = $statusTypes[$toStatusId];
$fromStatus = CRM_Utils_Array::value($fromStatusId, $statusTypes);
switch ($toStatus) {
case 'Pending from waitlist':
case 'Pending from approval':
//.........这里部分代码省略.........
示例9: replaceContributionTokens
/**
* Replace Contribution tokens in html.
*
* @param string $str
* @param array $contribution
* @param bool|string $html
* @param string $knownTokens
* @param bool|string $escapeSmarty
*
* @return mixed
*/
public static function replaceContributionTokens($str, &$contribution, $html = FALSE, $knownTokens = NULL, $escapeSmarty = FALSE)
{
$key = 'contribution';
if (!$knownTokens || !CRM_Utils_Array::value($key, $knownTokens)) {
return $str;
//early return
}
self::_buildContributionTokens();
// here we intersect with the list of pre-configured valid tokens
// so that we remove anything we do not recognize
// I hope to move this step out of here soon and
// then we will just iterate on a list of tokens that are passed to us
$str = preg_replace_callback(self::tokenRegex($key), function ($matches) use(&$contribution, $html, $escapeSmarty) {
return CRM_Utils_Token::getContributionTokenReplacement($matches[1], $contribution, $html, $escapeSmarty);
}, $str);
$str = preg_replace('/\\\\|\\{(\\s*)?\\}/', ' ', $str);
return $str;
}
示例10: 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);
}
示例11: updatePledgeStatus
public static function updatePledgeStatus($params)
{
$returnMessages = array();
$sendReminders = CRM_Utils_Array::value('send_reminders', $params, FALSE);
$allStatus = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
//unset statues that we never use for pledges
foreach (array('Completed', 'Cancelled', 'Failed') as $statusKey) {
if ($key = CRM_Utils_Array::key($statusKey, $allStatus)) {
unset($allStatus[$key]);
}
}
$statusIds = implode(',', array_keys($allStatus));
$updateCnt = 0;
$query = "\nSELECT pledge.contact_id as contact_id,\n pledge.id as pledge_id,\n pledge.amount as amount,\n payment.scheduled_date as scheduled_date,\n pledge.create_date as create_date,\n payment.id as payment_id,\n pledge.currency as currency,\n pledge.contribution_page_id as contribution_page_id,\n payment.reminder_count as reminder_count,\n pledge.max_reminders as max_reminders,\n payment.reminder_date as reminder_date,\n pledge.initial_reminder_day as initial_reminder_day,\n pledge.additional_reminder_day as additional_reminder_day,\n pledge.status_id as pledge_status,\n payment.status_id as payment_status,\n pledge.is_test as is_test,\n pledge.campaign_id as campaign_id,\n SUM(payment.scheduled_amount) as amount_due,\n ( SELECT sum(civicrm_pledge_payment.actual_amount)\n FROM civicrm_pledge_payment\n WHERE civicrm_pledge_payment.status_id = 1\n AND civicrm_pledge_payment.pledge_id = pledge.id\n ) as amount_paid\n FROM civicrm_pledge pledge, civicrm_pledge_payment payment\n WHERE pledge.id = payment.pledge_id\n AND payment.status_id IN ( {$statusIds} ) AND pledge.status_id IN ( {$statusIds} )\n GROUP By payment.id\n ";
$dao = CRM_Core_DAO::executeQuery($query);
$now = date('Ymd');
$pledgeDetails = $contactIds = $pledgePayments = $pledgeStatus = array();
while ($dao->fetch()) {
$checksumValue = CRM_Contact_BAO_Contact_Utils::generateChecksum($dao->contact_id);
$pledgeDetails[$dao->payment_id] = array('scheduled_date' => $dao->scheduled_date, 'amount_due' => $dao->amount_due, 'amount' => $dao->amount, 'amount_paid' => $dao->amount_paid, 'create_date' => $dao->create_date, 'contact_id' => $dao->contact_id, 'pledge_id' => $dao->pledge_id, 'checksumValue' => $checksumValue, 'contribution_page_id' => $dao->contribution_page_id, 'reminder_count' => $dao->reminder_count, 'max_reminders' => $dao->max_reminders, 'reminder_date' => $dao->reminder_date, 'initial_reminder_day' => $dao->initial_reminder_day, 'additional_reminder_day' => $dao->additional_reminder_day, 'pledge_status' => $dao->pledge_status, 'payment_status' => $dao->payment_status, 'is_test' => $dao->is_test, 'currency' => $dao->currency, 'campaign_id' => $dao->campaign_id);
$contactIds[$dao->contact_id] = $dao->contact_id;
$pledgeStatus[$dao->pledge_id] = $dao->pledge_status;
if (CRM_Utils_Date::overdue(CRM_Utils_Date::customFormat($dao->scheduled_date, '%Y%m%d'), $now) && $dao->payment_status != array_search('Overdue', $allStatus)) {
$pledgePayments[$dao->pledge_id][$dao->payment_id] = $dao->payment_id;
}
}
// process the updating script...
foreach ($pledgePayments as $pledgeId => $paymentIds) {
// 1. update the pledge /pledge payment status. returns new status when an update happens
$returnMessages[] = "Checking if status update is needed for Pledge Id: {$pledgeId} (current status is {$allStatus[$pledgeStatus[$pledgeId]]})";
$newStatus = CRM_Pledge_BAO_PledgePayment::updatePledgePaymentStatus($pledgeId, $paymentIds, array_search('Overdue', $allStatus), NULL, 0, FALSE, TRUE);
if ($newStatus != $pledgeStatus[$pledgeId]) {
$returnMessages[] = "- status updated to: {$allStatus[$newStatus]}";
$updateCnt += 1;
}
}
if ($sendReminders) {
// retrieve domain tokens
$domain = CRM_Core_BAO_Domain::getDomain();
$tokens = array('domain' => array('name', 'phone', 'address', 'email'), 'contact' => CRM_Core_SelectValues::contactTokens());
$domainValues = array();
foreach ($tokens['domain'] as $token) {
$domainValues[$token] = CRM_Utils_Token::getDomainTokenReplacement($token, $domain);
}
//get the domain email address, since we don't carry w/ object.
$domainValue = CRM_Core_BAO_Domain::getNameAndEmail();
$domainValues['email'] = $domainValue[1];
// retrieve contact tokens
// this function does NOT return Deceased contacts since we don't want to send them email
list($contactDetails) = CRM_Utils_Token::getTokenDetails($contactIds, NULL, FALSE, FALSE, NULL, $tokens, 'CRM_UpdatePledgeRecord');
// assign domain values to template
$template = CRM_Core_Smarty::singleton();
$template->assign('domain', $domainValues);
//set receipt from
$receiptFrom = '"' . $domainValues['name'] . '" <' . $domainValues['email'] . '>';
foreach ($pledgeDetails as $paymentId => $details) {
if (array_key_exists($details['contact_id'], $contactDetails)) {
$contactId = $details['contact_id'];
$pledgerName = $contactDetails[$contactId]['display_name'];
} else {
continue;
}
if (empty($details['reminder_date'])) {
$nextReminderDate = new DateTime($details['scheduled_date']);
$nextReminderDate->modify("-" . $details['initial_reminder_day'] . "day");
$nextReminderDate = $nextReminderDate->format("Ymd");
} else {
$nextReminderDate = new DateTime($details['reminder_date']);
$nextReminderDate->modify("+" . $details['additional_reminder_day'] . "day");
$nextReminderDate = $nextReminderDate->format("Ymd");
}
if ($details['reminder_count'] < $details['max_reminders'] && $nextReminderDate <= $now) {
$toEmail = $doNotEmail = $onHold = NULL;
if (!empty($contactDetails[$contactId]['email'])) {
$toEmail = $contactDetails[$contactId]['email'];
}
if (!empty($contactDetails[$contactId]['do_not_email'])) {
$doNotEmail = $contactDetails[$contactId]['do_not_email'];
}
if (!empty($contactDetails[$contactId]['on_hold'])) {
$onHold = $contactDetails[$contactId]['on_hold'];
}
// 2. send acknowledgement mail
if ($toEmail && !($doNotEmail || $onHold)) {
//assign value to template
$template->assign('amount_paid', $details['amount_paid'] ? $details['amount_paid'] : 0);
$template->assign('contact', $contactDetails[$contactId]);
$template->assign('next_payment', $details['scheduled_date']);
$template->assign('amount_due', $details['amount_due']);
$template->assign('checksumValue', $details['checksumValue']);
$template->assign('contribution_page_id', $details['contribution_page_id']);
$template->assign('pledge_id', $details['pledge_id']);
$template->assign('scheduled_payment_date', $details['scheduled_date']);
$template->assign('amount', $details['amount']);
$template->assign('create_date', $details['create_date']);
$template->assign('currency', $details['currency']);
list($mailSent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate::sendTemplate(array('groupName' => 'msg_tpl_workflow_pledge', 'valueName' => 'pledge_reminder', 'contactId' => $contactId, 'from' => $receiptFrom, 'toName' => $pledgerName, 'toEmail' => $toEmail));
// 3. update pledge payment details
if ($mailSent) {
CRM_Pledge_BAO_PledgePayment::updateReminderDetails($paymentId);
//.........这里部分代码省略.........
示例12: 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);
}
示例13: formRule
/**
* Function for validation
*
* @param array $params (ref.) an assoc array of name/value pairs
*
* @param $files
* @param $self
*
* @return mixed true or array of errors
* @access public
* @static
*/
static function formRule($params, $files, $self)
{
if (!empty($_POST['_qf_Import_refresh'])) {
return TRUE;
}
$errors = array();
$template = CRM_Core_Smarty::singleton();
$domain = CRM_Core_BAO_Domain::getDomain();
$mailing = new CRM_Mailing_BAO_Mailing();
$mailing->id = $self->_mailingID;
$mailing->find(TRUE);
$session = CRM_Core_Session::singleton();
$values = array('contact_id' => $session->get('userID'), 'version' => 3);
require_once 'api/api.php';
$contact = civicrm_api('contact', 'get', $values);
//CRM-4524
$contact = reset($contact['values']);
$verp = array_flip(array('optOut', 'reply', 'unsubscribe', 'resubscribe', 'owner'));
foreach ($verp as $key => $value) {
$verp[$key]++;
}
$urls = array_flip(array('forward', 'optOutUrl', 'unsubscribeUrl', 'resubscribeUrl'));
foreach ($urls as $key => $value) {
$urls[$key]++;
}
$skipTextFile = $self->get('skipTextFile');
if (!$params['upload_type']) {
if (!isset($files['textFile']) || !file_exists($files['textFile']['tmp_name'])) {
if (!$skipTextFile) {
$errors['textFile'] = ts('Please provide a Text');
}
}
} else {
if (empty($params['text_message'])) {
$errors['text_message'] = ts('Please provide a Text');
} else {
if (!empty($params['text_message'])) {
$messageCheck = CRM_Utils_Array::value('text_message', $params);
if ($messageCheck && strlen($messageCheck) > CRM_SMS_Provider::MAX_SMS_CHAR) {
$errors['text_message'] = ts("You can configure the SMS message body up to %1 characters", array(1 => CRM_SMS_Provider::MAX_SMS_CHAR));
}
}
}
if (!empty($params['saveTemplate']) && empty($params['saveTemplateName'])) {
$errors['saveTemplateName'] = ts('Please provide a Template Name.');
}
}
if ($params['upload_type'] || file_exists(CRM_Utils_Array::value('tmp_name', $files['textFile'])) || !$params['upload_type'] && $params['text_message']) {
if (!$params['upload_type']) {
$str = file_get_contents($files['textFile']['tmp_name']);
$name = $files['textFile']['name'];
} else {
$str = $params['text_message'];
$name = 'text message';
}
$dataErrors = array();
/* Do a full token replacement on a dummy verp, the current
* contact and domain, and the first organization. */
// here we make a dummy mailing object so that we
// can retrieve the tokens that we need to replace
// so that we do get an invalid token error
// this is qute hacky and I hope that there might
// be a suggestion from someone on how to
// make it a bit more elegant
$dummy_mail = new CRM_Mailing_BAO_Mailing();
$mess = "body_text";
$dummy_mail->{$mess} = $str;
$tokens = $dummy_mail->getTokens();
$str = CRM_Utils_Token::replaceSubscribeInviteTokens($str);
$str = CRM_Utils_Token::replaceDomainTokens($str, $domain, NULL, $tokens['text']);
$str = CRM_Utils_Token::replaceMailingTokens($str, $mailing, NULL, $tokens['text']);
$str = CRM_Utils_Token::replaceOrgTokens($str, $org);
$str = CRM_Utils_Token::replaceActionTokens($str, $verp, $urls, NULL, $tokens['text']);
$str = CRM_Utils_Token::replaceContactTokens($str, $contact, NULL, $tokens['text']);
$unmatched = CRM_Utils_Token::unmatchedTokens($str);
$contentCheck = CRM_Utils_String::htmlToText($str);
if (!empty($unmatched) && 0) {
foreach ($unmatched as $token) {
$dataErrors[] = '<li>' . ts('Invalid token code') . ' {' . $token . '}</li>';
}
}
if (strlen($contentCheck) > CRM_SMS_Provider::MAX_SMS_CHAR) {
$dataErrors[] = '<li>' . ts('The body of the SMS cannot exceed %1 characters.', array(1 => CRM_SMS_Provider::MAX_SMS_CHAR)) . '</li>';
}
if (!empty($dataErrors)) {
$errors['textFile'] = ts('The following errors were detected in %1:', array(1 => $name)) . ' <ul>' . implode('', $dataErrors) . '</ul>';
}
}
//.........这里部分代码省略.........
示例14: send_confirm_request
/**
* Ask a contact for subscription confirmation (opt-in)
*
* @param string $email
* The email address.
*
* @return void
*/
public function send_confirm_request($email)
{
$config = CRM_Core_Config::singleton();
$domain = CRM_Core_BAO_Domain::getDomain();
//get the default domain email address.
list($domainEmailName, $domainEmailAddress) = CRM_Core_BAO_Domain::getNameAndEmail();
$localpart = CRM_Core_BAO_MailSettings::defaultLocalpart();
$emailDomain = CRM_Core_BAO_MailSettings::defaultDomain();
$confirm = implode($config->verpSeparator, array($localpart . 'c', $this->contact_id, $this->id, $this->hash)) . "@{$emailDomain}";
$group = new CRM_Contact_BAO_Group();
$group->id = $this->group_id;
$group->find(TRUE);
$component = new CRM_Mailing_BAO_Component();
$component->is_default = 1;
$component->is_active = 1;
$component->component_type = 'Subscribe';
$component->find(TRUE);
$headers = array('Subject' => $component->subject, 'From' => "\"{$domainEmailName}\" <{$domainEmailAddress}>", 'To' => $email, 'Reply-To' => $confirm, 'Return-Path' => "do-not-reply@{$emailDomain}");
$url = CRM_Utils_System::url('civicrm/mailing/confirm', "reset=1&cid={$this->contact_id}&sid={$this->id}&h={$this->hash}", TRUE);
$html = $component->body_html;
if ($component->body_text) {
$text = $component->body_text;
} else {
$text = CRM_Utils_String::htmlToText($component->body_html);
}
$bao = new CRM_Mailing_BAO_Mailing();
$bao->body_text = $text;
$bao->body_html = $html;
$tokens = $bao->getTokens();
$html = CRM_Utils_Token::replaceDomainTokens($html, $domain, TRUE, $tokens['html']);
$html = CRM_Utils_Token::replaceSubscribeTokens($html, $group->title, $url, TRUE);
$text = CRM_Utils_Token::replaceDomainTokens($text, $domain, FALSE, $tokens['text']);
$text = CRM_Utils_Token::replaceSubscribeTokens($text, $group->title, $url, FALSE);
// render the & entities in text mode, so that the links work
$text = str_replace('&', '&', $text);
$message = new Mail_mime("\n");
$message->setHTMLBody($html);
$message->setTxtBody($text);
$b = CRM_Utils_Mail::setMimeParams($message);
$h = $message->headers($headers);
CRM_Mailing_BAO_Mailing::addMessageIdHeader($h, 's', $this->contact_id, $this->id, $this->hash);
$mailer = \Civi::service('pear_mail');
if (is_object($mailer)) {
$errorScope = CRM_Core_TemporaryErrorScope::ignoreException();
$mailer->send($email, $h, $b);
unset($errorScope);
}
}
示例15: processGreetingTemplate
/**
* Process a greeting template string to produce the individualised greeting text.
*
* This works just like message templates for mailings:
* the template is processed with the token substitution mechanism,
* to supply the individual contact data;
* and it is also processed with Smarty,
* to allow for conditionals etc. based on the contact data.
*
* Note: We don't pass any variables to Smarty --
* all variable data is inserted into the input string
* by the token substitution mechanism,
* before Smarty is invoked.
*
* @param string $templateString
* The greeting template string with contact tokens + Smarty syntax.
*
* @param array $contactDetails
* @param int $contactID
* @param string $className
*/
public static function processGreetingTemplate(&$templateString, $contactDetails, $contactID, $className)
{
CRM_Utils_Token::replaceGreetingTokens($templateString, $contactDetails, $contactID, $className, TRUE);
$smarty = CRM_Core_Smarty::singleton();
$templateString = $smarty->fetch("string:{$templateString}");
}