本文整理汇总了PHP中PluginEvent::get方法的典型用法代码示例。如果您正苦于以下问题:PHP PluginEvent::get方法的具体用法?PHP PluginEvent::get怎么用?PHP PluginEvent::get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PluginEvent
的用法示例。
在下文中一共展示了PluginEvent::get方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: sendRegistrationEmail
/**
* Send the register email with $_POST value
* @param $iSurveyId Survey Id to register
* @return boolean : if email is set to sent (before SMTP problem)
*/
public function sendRegistrationEmail($iSurveyId, $iTokenId)
{
$sLanguage = App()->language;
$aSurveyInfo = getSurveyInfo($iSurveyId, $sLanguage);
$aMail['subject'] = $aSurveyInfo['email_register_subj'];
$aMail['message'] = $aSurveyInfo['email_register'];
$aReplacementFields = array();
$aReplacementFields["{ADMINNAME}"] = $aSurveyInfo['adminname'];
$aReplacementFields["{ADMINEMAIL}"] = $aSurveyInfo['adminemail'];
$aReplacementFields["{SURVEYNAME}"] = $aSurveyInfo['name'];
$aReplacementFields["{SURVEYDESCRIPTION}"] = $aSurveyInfo['description'];
$aReplacementFields["{EXPIRY}"] = $aSurveyInfo["expiry"];
$oToken = Token::model($iSurveyId)->findByPk($iTokenId);
// Reload the token (needed if just created)
foreach ($oToken->attributes as $attribute => $value) {
$aReplacementFields["{" . strtoupper($attribute) . "}"] = $value;
}
$sToken = $oToken->token;
$useHtmlEmail = getEmailFormat($iSurveyId) == 'html';
$aMail['subject'] = preg_replace("/{TOKEN:([A-Z0-9_]+)}/", "{" . "\$1" . "}", $aMail['subject']);
$aMail['message'] = preg_replace("/{TOKEN:([A-Z0-9_]+)}/", "{" . "\$1" . "}", $aMail['message']);
$aReplacementFields["{SURVEYURL}"] = App()->createAbsoluteUrl("/survey/index/sid/{$iSurveyId}", array('lang' => $sLanguage, 'token' => $sToken));
$aReplacementFields["{OPTOUTURL}"] = App()->createAbsoluteUrl("/optout/tokens/surveyid/{$iSurveyId}", array('langcode' => $sLanguage, 'token' => $sToken));
$aReplacementFields["{OPTINURL}"] = App()->createAbsoluteUrl("/optin/tokens/surveyid/{$iSurveyId}", array('langcode' => $sLanguage, 'token' => $sToken));
foreach (array('OPTOUT', 'OPTIN', 'SURVEY') as $key) {
$url = $aReplacementFields["{{$key}URL}"];
if ($useHtmlEmail) {
$aReplacementFields["{{$key}URL}"] = "<a href='{$url}'>" . htmlspecialchars($url) . '</a>';
}
$aMail['subject'] = str_replace("@@{$key}URL@@", $url, $aMail['subject']);
$aMail['message'] = str_replace("@@{$key}URL@@", $url, $aMail['message']);
}
// Replace the fields
$aMail['subject'] = ReplaceFields($aMail['subject'], $aReplacementFields);
$aMail['message'] = ReplaceFields($aMail['message'], $aReplacementFields);
$sFrom = "{$aSurveyInfo['adminname']} <{$aSurveyInfo['adminemail']}>";
$sBounce = getBounceEmail($iSurveyId);
$sTo = $oToken->email;
$sitename = Yii::app()->getConfig('sitename');
// Plugin event for email handling (Same than admin token but with register type)
$event = new PluginEvent('beforeTokenEmail');
$event->set('type', 'register');
$event->set('subject', $aMail['subject']);
$event->set('to', $sTo);
$event->set('body', $aMail['message']);
$event->set('from', $sFrom);
$event->set('bounce', $sBounce);
$event->set('token', $oToken->attributes);
$aMail['subject'] = $event->get('subject');
$aMail['message'] = $event->get('body');
$sTo = $event->get('to');
$sFrom = $event->get('from');
if ($event->get('send', true) == false) {
$this->sMessage = $event->get('message', '');
if ($event->get('error') == null) {
// mimic token system, set send to today
$today = dateShift(date("Y-m-d H:i:s"), "Y-m-d H:i", Yii::app()->getConfig('timeadjust'));
$oToken->sent = $today;
$oToken->save();
}
} elseif (SendEmailMessage($aMail['message'], $aMail['subject'], $sTo, $sFrom, $sitename, $useHtmlEmail, $sBounce)) {
// TLR change to put date into sent
$today = dateShift(date("Y-m-d H:i:s"), "Y-m-d H:i", Yii::app()->getConfig('timeadjust'));
$oToken->sent = $today;
$oToken->save();
$this->sMessage = "<div id='wrapper' class='message tokenmessage'>" . "<p>" . gT("Thank you for registering to participate in this survey.") . "</p>\n" . "<p>{$this->sMailMessage}</p>\n" . "<p>" . sprintf(gT("Survey administrator %s (%s)"), $aSurveyInfo['adminname'], $aSurveyInfo['adminemail']) . "</p>" . "</div>\n";
} else {
$this->sMessage = "<div id='wrapper' class='message tokenmessage'>" . "<p>" . gT("Thank you for registering to participate in this survey.") . "</p>\n" . "<p>" . gT("You are registered but an error happened when trying to send the email - please contact the survey administrator.") . "</p>\n" . "<p>" . sprintf(gT("Survey administrator %s (%s)"), $aSurveyInfo['adminname'], $aSurveyInfo['adminemail']) . "</p>" . "</div>\n";
}
// Allways return true : if we come here, we allways trye to send an email
return true;
}
示例2: checkCompletedQuota
/**
* checkCompletedQuota() returns matched quotas information for the current response
* @param integer $surveyid - Survey identification number
* @param bool $return - set to true to return information, false do the quota
* @return array - nested array, Quotas->Members->Fields, includes quota information matched in session.
*/
function checkCompletedQuota($surveyid, $return = false)
{
if (!isset($_SESSION['survey_' . $surveyid]['srid'])) {
return;
}
static $aMatchedQuotas;
// EM call 2 times quotas with 3 lines of php code, then use static.
if (!$aMatchedQuotas) {
$aMatchedQuotas = array();
$quota_info = $aQuotasInfo = getQuotaInformation($surveyid, $_SESSION['survey_' . $surveyid]['s_lang']);
// $aQuotasInfo have an 'active' key, we don't use it ?
if (!$aQuotasInfo || empty($aQuotasInfo)) {
return $aMatchedQuotas;
}
// Test only completed quota, other is not needed
$aQuotasCompleted = array();
foreach ($aQuotasInfo as $aQuotaInfo) {
$iCompleted = getQuotaCompletedCount($surveyid, $aQuotaInfo['id']);
// Return a string
if (ctype_digit($iCompleted) && (int) $iCompleted >= (int) $aQuotaInfo['qlimit']) {
// This remove invalid quota and not completed
$aQuotasCompleted[] = $aQuotaInfo;
}
}
if (empty($aQuotasCompleted)) {
return $aMatchedQuotas;
}
// OK, we have some quota, then find if this $_SESSION have some set
$aPostedFields = explode("|", Yii::app()->request->getPost('fieldnames', ''));
// Needed for quota allowing update
foreach ($aQuotasCompleted as $aQuotaCompleted) {
$iMatchedAnswers = 0;
$bPostedField = false;
// Array of field with quota array value
$aQuotaFields = array();
// Array of fieldnames with relevance value : EM fill $_SESSION with default value even is unrelevant (em_manager_helper line 6548)
$aQuotaRelevantFieldnames = array();
foreach ($aQuotaCompleted['members'] as $aQuotaMember) {
$aQuotaFields[$aQuotaMember['fieldname']][] = $aQuotaMember['value'];
$aQuotaRelevantFieldnames[$aQuotaMember['fieldname']] = isset($_SESSION['survey_' . $surveyid]['relevanceStatus'][$aQuotaMember['qid']]) && $_SESSION['survey_' . $surveyid]['relevanceStatus'][$aQuotaMember['qid']];
}
// For each field : test if actual responses is in quota (and is relevant)
foreach ($aQuotaFields as $sFieldName => $aValues) {
$bInQuota = isset($_SESSION['survey_' . $surveyid][$sFieldName]) && in_array($_SESSION['survey_' . $surveyid][$sFieldName], $aValues);
if ($bInQuota && $aQuotaRelevantFieldnames[$sFieldName]) {
$iMatchedAnswers++;
}
if (in_array($sFieldName, $aPostedFields)) {
$bPostedField = true;
}
}
if ($iMatchedAnswers == count($aQuotaFields)) {
switch ($aQuotaCompleted['action']) {
case '1':
default:
$aMatchedQuotas[] = $aQuotaCompleted;
break;
case '2':
if ($bPostedField) {
// Action 2 allow to correct last answers, then need to be posted
$aMatchedQuotas[] = $aQuotaCompleted;
}
break;
}
}
}
}
if ($return) {
return $aMatchedQuotas;
}
if (empty($aMatchedQuotas)) {
return;
}
// Now we have all the information we need about the quotas and their status.
// We need to construct the page and do all needed action
$thissurvey = getSurveyInfo($surveyid, $_SESSION['survey_' . $surveyid]['s_lang']);
$sTemplatePath = getTemplatePath($thissurvey['templatedir']);
$sClientToken = isset($_SESSION['survey_' . $surveyid]['token']) ? $_SESSION['survey_' . $surveyid]['token'] : "";
$redata = compact(array_keys(get_defined_vars()));
// We take only the first matched quota, no need for each
$aMatchedQuota = $aMatchedQuotas[0];
// If a token is used then mark the token as completed, do it before event : this allow plugin to update token information
$event = new PluginEvent('afterSurveyQuota');
$event->set('surveyId', $surveyid);
$event->set('responseId', $_SESSION['survey_' . $surveyid]['srid']);
// We allways have a responseId
$event->set('aMatchedQuotas', $aMatchedQuotas);
// Give all the matched quota : the first is the active
$blocks = array();
foreach ($event->getAllContent() as $blockData) {
/* @var $blockData PluginEventContent */
$blocks[] = CHtml::tag('div', array('id' => $blockData->getCssId(), 'class' => $blockData->getCssClass()), $blockData->getContent());
}
// Allow plugin to update message, url, url description and action
//.........这里部分代码省略.........