当前位置: 首页>>代码示例>>PHP>>正文


PHP CRM_Utils_Token::flattenTokens方法代码示例

本文整理汇总了PHP中CRM_Utils_Token::flattenTokens方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Utils_Token::flattenTokens方法的具体用法?PHP CRM_Utils_Token::flattenTokens怎么用?PHP CRM_Utils_Token::flattenTokens使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CRM_Utils_Token的用法示例。


在下文中一共展示了CRM_Utils_Token::flattenTokens方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: sendTemplate

 /**
  * Send an email from the specified template based on an array of params.
  *
  * @param array $params
  *   A string-keyed array of function params, see function body for details.
  *
  * @return array
  *   Array of four parameters: a boolean whether the email was sent, and the subject, text and HTML templates
  */
 public static function sendTemplate($params)
 {
     $defaults = array('groupName' => NULL, 'valueName' => NULL, 'messageTemplateID' => NULL, 'contactId' => NULL, 'tplParams' => array(), 'from' => NULL, 'toName' => NULL, 'toEmail' => NULL, 'cc' => NULL, 'bcc' => NULL, 'replyTo' => NULL, 'attachments' => NULL, 'isTest' => FALSE, 'PDFFilename' => NULL);
     $params = array_merge($defaults, $params);
     CRM_Utils_Hook::alterMailParams($params, 'messageTemplate');
     if ((!$params['groupName'] || !$params['valueName']) && !$params['messageTemplateID']) {
         CRM_Core_Error::fatal(ts("Message template's option group and/or option value or ID missing."));
     }
     if ($params['messageTemplateID']) {
         // fetch the three elements from the db based on id
         $query = 'SELECT msg_subject subject, msg_text text, msg_html html, pdf_format_id format
                   FROM civicrm_msg_template mt
                   WHERE mt.id = %1 AND mt.is_default = 1';
         $sqlParams = array(1 => array($params['messageTemplateID'], 'String'));
     } else {
         // fetch the three elements from the db based on option_group and option_value names
         $query = 'SELECT msg_subject subject, msg_text text, msg_html html, pdf_format_id format
                   FROM civicrm_msg_template mt
                   JOIN civicrm_option_value ov ON workflow_id = ov.id
                   JOIN civicrm_option_group og ON ov.option_group_id = og.id
                   WHERE og.name = %1 AND ov.name = %2 AND mt.is_default = 1';
         $sqlParams = array(1 => array($params['groupName'], 'String'), 2 => array($params['valueName'], 'String'));
     }
     $dao = CRM_Core_DAO::executeQuery($query, $sqlParams);
     $dao->fetch();
     if (!$dao->N) {
         if ($params['messageTemplateID']) {
             CRM_Core_Error::fatal(ts('No such message template: id=%1.', array(1 => $params['messageTemplateID'])));
         } else {
             CRM_Core_Error::fatal(ts('No such message template: option group %1, option value %2.', array(1 => $params['groupName'], 2 => $params['valueName'])));
         }
     }
     $mailContent = array('subject' => $dao->subject, 'text' => $dao->text, 'html' => $dao->html, 'format' => $dao->format);
     $dao->free();
     CRM_Utils_Hook::alterMailContent($mailContent);
     // add the test banner (if requested)
     if ($params['isTest']) {
         $query = "SELECT msg_subject subject, msg_text text, msg_html html\n                      FROM civicrm_msg_template mt\n                      JOIN civicrm_option_value ov ON workflow_id = ov.id\n                      JOIN civicrm_option_group og ON ov.option_group_id = og.id\n                      WHERE og.name = 'msg_tpl_workflow_meta' AND ov.name = 'test_preview' AND mt.is_default = 1";
         $testDao = CRM_Core_DAO::executeQuery($query);
         $testDao->fetch();
         $mailContent['subject'] = $testDao->subject . $mailContent['subject'];
         $mailContent['text'] = $testDao->text . $mailContent['text'];
         $mailContent['html'] = preg_replace('/<body(.*)$/im', "<body\\1\n{$testDao->html}", $mailContent['html']);
         $testDao->free();
     }
     // replace tokens in the three elements (in subject as if it was the text body)
     $domain = CRM_Core_BAO_Domain::getDomain();
     $hookTokens = array();
     $mailing = new CRM_Mailing_BAO_Mailing();
     $mailing->subject = $mailContent['subject'];
     $mailing->body_text = $mailContent['text'];
     $mailing->body_html = $mailContent['html'];
     $tokens = $mailing->getTokens();
     CRM_Utils_Hook::tokens($hookTokens);
     $categories = array_keys($hookTokens);
     $contactID = CRM_Utils_Array::value('contactId', $params);
     if ($contactID) {
         $contactParams = array('contact_id' => $contactID);
         $returnProperties = array();
         if (isset($tokens['subject']['contact'])) {
             foreach ($tokens['subject']['contact'] as $name) {
                 $returnProperties[$name] = 1;
             }
         }
         if (isset($tokens['text']['contact'])) {
             foreach ($tokens['text']['contact'] as $name) {
                 $returnProperties[$name] = 1;
             }
         }
         if (isset($tokens['html']['contact'])) {
             foreach ($tokens['html']['contact'] as $name) {
                 $returnProperties[$name] = 1;
             }
         }
         // @todo CRM-17253 don't resolve contact details if there are no tokens
         // effectively comment out this next (performance-expensive) line
         // but unfortunately testing is a bit think on the ground to that needs to
         // be added.
         list($contact) = CRM_Utils_Token::getTokenDetails($contactParams, $returnProperties, FALSE, FALSE, NULL, CRM_Utils_Token::flattenTokens($tokens), 'CRM_Core_BAO_MessageTemplate');
         $contact = $contact[$contactID];
     }
     $mailContent['subject'] = CRM_Utils_Token::replaceDomainTokens($mailContent['subject'], $domain, FALSE, $tokens['text'], TRUE);
     $mailContent['text'] = CRM_Utils_Token::replaceDomainTokens($mailContent['text'], $domain, FALSE, $tokens['text'], TRUE);
     $mailContent['html'] = CRM_Utils_Token::replaceDomainTokens($mailContent['html'], $domain, TRUE, $tokens['html'], TRUE);
     if ($contactID) {
         $mailContent['subject'] = CRM_Utils_Token::replaceContactTokens($mailContent['subject'], $contact, FALSE, $tokens['text'], FALSE, TRUE);
         $mailContent['text'] = CRM_Utils_Token::replaceContactTokens($mailContent['text'], $contact, FALSE, $tokens['text'], FALSE, TRUE);
         $mailContent['html'] = CRM_Utils_Token::replaceContactTokens($mailContent['html'], $contact, FALSE, $tokens['html'], FALSE, TRUE);
         $contactArray = array($contactID => $contact);
         CRM_Utils_Hook::tokenValues($contactArray, array($contactID), NULL, CRM_Utils_Token::flattenTokens($tokens), 'CRM_Core_BAO_MessageTemplate');
         $contact = $contactArray[$contactID];
//.........这里部分代码省略.........
开发者ID:kcristiano,项目名称:civicrm-core,代码行数:101,代码来源:MessageTemplate.php

示例2:

 /**
  * Returns the token set for all 3 parts as one set. This allows it to be sent to the
  * hook in one call and standardizes it across other token workflows
  *
  * @return array
  *   reference to an assoc array
  */
 public function &getFlattenedTokens()
 {
     if (!$this->flattenedTokens) {
         $tokens = $this->getTokens();
         $this->flattenedTokens = CRM_Utils_Token::flattenTokens($tokens);
     }
     return $this->flattenedTokens;
 }
开发者ID:scardinius,项目名称:civicrm-core-api-mailing,代码行数:15,代码来源:Mailing.php

示例3: sendTemplate

 /**
  * Send an email from the specified template based on an array of params
  *
  * @param array $params  a string-keyed array of function params, see function body for details
  *
  * @return array  of four parameters: a boolean whether the email was sent, and the subject, text and HTML templates
  */
 static function sendTemplate($params)
 {
     $defaults = array('groupName' => NULL, 'valueName' => NULL, 'messageTemplateID' => NULL, 'contactId' => NULL, 'tplParams' => array(), 'from' => NULL, 'toName' => NULL, 'toEmail' => NULL, 'cc' => NULL, 'bcc' => NULL, 'replyTo' => NULL, 'attachments' => NULL, 'isTest' => FALSE, 'PDFFilename' => NULL);
     $params = array_merge($defaults, $params);
     if ((!$params['groupName'] || !$params['valueName']) && !$params['messageTemplateID']) {
         CRM_Core_Error::fatal(ts("Message template's option group and/or option value or ID missing."));
     }
     if ($params['messageTemplateID']) {
         // fetch the three elements from the db based on id
         $query = 'SELECT msg_subject subject, msg_text text, msg_html html, pdf_format_id format
                   FROM civicrm_msg_template mt
                   WHERE mt.id = %1 AND mt.is_default = 1';
         $sqlParams = array(1 => array($params['messageTemplateID'], 'String'));
     } else {
         // fetch the three elements from the db based on option_group and option_value names
         $query = 'SELECT msg_subject subject, msg_text text, msg_html html, pdf_format_id format
                   FROM civicrm_msg_template mt
                   JOIN civicrm_option_value ov ON workflow_id = ov.id
                   JOIN civicrm_option_group og ON ov.option_group_id = og.id
                   WHERE og.name = %1 AND ov.name = %2 AND mt.is_default = 1';
         $sqlParams = array(1 => array($params['groupName'], 'String'), 2 => array($params['valueName'], 'String'));
     }
     $dao = CRM_Core_DAO::executeQuery($query, $sqlParams);
     $dao->fetch();
     if (!$dao->N) {
         if ($params['messageTemplateID']) {
             CRM_Core_Error::fatal(ts('No such message template: id=%1.', array(1 => $params['messageTemplateID'])));
         } else {
             CRM_Core_Error::fatal(ts('No such message template: option group %1, option value %2.', array(1 => $params['groupName'], 2 => $params['valueName'])));
         }
     }
     $subject = $dao->subject;
     $text = $dao->text;
     $html = $dao->html;
     $format = $dao->format;
     $dao->free();
     // add the test banner (if requested)
     if ($params['isTest']) {
         $query = "SELECT msg_subject subject, msg_text text, msg_html html\n                      FROM civicrm_msg_template mt\n                      JOIN civicrm_option_value ov ON workflow_id = ov.id\n                      JOIN civicrm_option_group og ON ov.option_group_id = og.id\n                      WHERE og.name = 'msg_tpl_workflow_meta' AND ov.name = 'test_preview' AND mt.is_default = 1";
         $testDao = CRM_Core_DAO::executeQuery($query);
         $testDao->fetch();
         $subject = $testDao->subject . $subject;
         $text = $testDao->text . $text;
         $html = preg_replace('/<body(.*)$/im', "<body\\1\n{$testDao->html}", $html);
         $testDao->free();
     }
     // replace tokens in the three elements (in subject as if it was the text body)
     $domain = CRM_Core_BAO_Domain::getDomain();
     $hookTokens = array();
     $mailing = new CRM_Mailing_BAO_Mailing();
     $mailing->body_text = $text;
     $mailing->body_html = $html;
     $tokens = $mailing->getTokens();
     CRM_Utils_Hook::tokens($hookTokens);
     $categories = array_keys($hookTokens);
     $contactID = CRM_Utils_Array::value('contactId', $params);
     if ($contactID) {
         $contactParams = array('contact_id' => $contactID);
         $returnProperties = array();
         if (isset($tokens['text']['contact'])) {
             foreach ($tokens['text']['contact'] as $name) {
                 $returnProperties[$name] = 1;
             }
         }
         if (isset($tokens['html']['contact'])) {
             foreach ($tokens['html']['contact'] as $name) {
                 $returnProperties[$name] = 1;
             }
         }
         list($contact) = CRM_Utils_Token::getTokenDetails($contactParams, $returnProperties, FALSE, FALSE, NULL, CRM_Utils_Token::flattenTokens($tokens), 'CRM_Core_BAO_MessageTemplate');
         $contact = $contact[$contactID];
     }
     $subject = CRM_Utils_Token::replaceDomainTokens($subject, $domain, TRUE, $tokens['text'], TRUE);
     $text = CRM_Utils_Token::replaceDomainTokens($text, $domain, TRUE, $tokens['text'], TRUE);
     $html = CRM_Utils_Token::replaceDomainTokens($html, $domain, TRUE, $tokens['html'], TRUE);
     if ($contactID) {
         $subject = CRM_Utils_Token::replaceContactTokens($subject, $contact, FALSE, $tokens['text'], FALSE, TRUE);
         $text = CRM_Utils_Token::replaceContactTokens($text, $contact, FALSE, $tokens['text'], FALSE, TRUE);
         $html = CRM_Utils_Token::replaceContactTokens($html, $contact, FALSE, $tokens['html'], FALSE, TRUE);
         $contactArray = array($contactID => $contact);
         CRM_Utils_Hook::tokenValues($contactArray, array($contactID), NULL, CRM_Utils_Token::flattenTokens($tokens), 'CRM_Core_BAO_MessageTemplate');
         $contact = $contactArray[$contactID];
         $subject = CRM_Utils_Token::replaceHookTokens($subject, $contact, $categories, TRUE);
         $text = CRM_Utils_Token::replaceHookTokens($text, $contact, $categories, TRUE);
         $html = CRM_Utils_Token::replaceHookTokens($html, $contact, $categories, TRUE);
     }
     // strip whitespace from ends and turn into a single line
     $subject = "{strip}{$subject}{/strip}";
     // parse the three elements with Smarty
     $smarty = CRM_Core_Smarty::singleton();
     foreach ($params['tplParams'] as $name => $value) {
         $smarty->assign($name, $value);
     }
//.........这里部分代码省略.........
开发者ID:hguru,项目名称:224Civi,代码行数:101,代码来源:MessageTemplate.php


注:本文中的CRM_Utils_Token::flattenTokens方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。