本文整理汇总了PHP中Docs::replaceVariables方法的典型用法代码示例。如果您正苦于以下问题:PHP Docs::replaceVariables方法的具体用法?PHP Docs::replaceVariables怎么用?PHP Docs::replaceVariables使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Docs
的用法示例。
在下文中一共展示了Docs::replaceVariables方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testReplaceVariables
public function testReplaceVariables()
{
$quote = $this->quotes('docsTest');
$contact = $this->contacts('testAnyone');
$account = $this->accounts('testQuote');
$attrs = $quote->getAttributes();
$contactAttrs = $contact->getAttributes();
$accountAttrs = $account->getAttributes();
// ensure that tokens with references to customized class names get properly replaced
$quoteTemplate = array();
foreach ($attrs as $name => $val) {
$quoteTemplate[$name] = "{" . $name . "}";
}
foreach ($contactAttrs as $name => $val) {
$quoteTemplate[$name] = "{" . self::$contactsField . ".{$name}}";
}
foreach ($accountAttrs as $name => $val) {
$quoteTemplate[$name] = "{" . self::$accountsField . ".{$name}}";
}
foreach (array_intersect(array_keys($contactAttrs), array_keys($attrs), array_keys($accountAttrs)) as $name) {
unset($quoteTemplate[$name]);
unset($attrs[$name]);
unset($contactAttrs[$name]);
unset($accountAttrs[$name]);
}
// add quotes template-specific token
$quoteTemplate['dateNow'] = '{dateNow}';
$quoteTemplate['lineItems'] = '{lineItems}';
$quoteTemplate['quoteOrInvoice'] = '{quoteOrInvoice}';
$quoteTemplate = CJSON::encode($quoteTemplate);
$str = Docs::replaceVariables($quoteTemplate, $quote, array(), false, false);
$this->assertEquals(array_merge(array_map(function ($elem) {
return (string) $elem;
}, $attrs), array_map(function ($elem) {
return (string) $elem;
}, $contactAttrs), array_map(function ($elem) {
return (string) $elem;
}, $accountAttrs), array('lineItems' => preg_replace("/\r|\n/", "", $quote->productTable(true)), 'dateNow' => date("F d, Y", time()), 'quoteOrInvoice' => Yii::t('quotes', $quote->type == 'invoice' ? 'Invoice' : Modules::displayName(false, "Quotes")))), CJSON::decode($str));
}
示例2: recordEmailSent
public static function recordEmailSent(Campaign $campaign, Contacts $contact)
{
$action = new Actions();
// Disable the unsightly notifications for loads of emails:
$action->scenario = 'noNotif';
$now = time();
$action->associationType = 'contacts';
$action->associationId = $contact->id;
$action->associationName = $contact->firstName . ' ' . $contact->lastName;
$action->visibility = $contact->visibility;
$action->type = 'email';
$action->assignedTo = $contact->assignedTo;
$action->createDate = $now;
$action->completeDate = $now;
$action->complete = 'Yes';
$action->actionDescription = '<b>' . Yii::t('marketing', 'Campaign') . ': ' . $campaign->name . "</b>\n\n" . Yii::t('marketing', 'Subject') . ": " . Docs::replaceVariables($campaign->subject, $contact) . "\n\n" . Docs::replaceVariables($campaign->content, $contact);
if (!$action->save()) {
throw new CException('Campaing email action history record failed to save with validation errors: ' . CJSON::encode($action->errors));
}
}
示例3: testReplaceVariables
public function testReplaceVariables()
{
$quote = $this->quotes('docsTest');
$contact = $this->contacts('testAnyone');
$attrs = $quote->getAttributes();
$contactAttrs = $contact->getAttributes();
// $quoteTemplate = array ();
// foreach ($attrs as $name => &$val) {
// $quoteTemplate[$name] = "{Quote.$name}";
// }
// foreach ($contactAttrs as $name => &$val) {
// $quoteTemplate[$name] = "{Contact.$name}";
// }
// foreach (array_intersect (array_keys ($contactAttrs), array_keys ($attrs)) as $name) {
// unset ($quoteTemplate[$name]);
// unset ($attrs[$name]);
// unset ($contactAttrs[$name]);
// }
// $quoteTemplate = CJSON::encode ($quoteTemplate);
// $str = Docs::replaceVariables ($quoteTemplate, $quote, array (), false , false);
// $this->assertEquals (
// array_merge (
// array_map (function ($elem) { return (string) $elem; }, $attrs),
// array_map (function ($elem) { return (string) $elem; }, $contactAttrs)
// ),
// CJSON::decode ($str)
// );
// ensure that tokens with references to customized class names get properly replaced
$quoteTemplate = array();
foreach ($attrs as $name => $val) {
$quoteTemplate[$name] = "{" . self::$customQuotesTitle . ".{$name}}";
}
foreach ($contactAttrs as $name => $val) {
$quoteTemplate[$name] = "{" . self::$customContactsTitle . ".{$name}}";
}
foreach (array_intersect(array_keys($contactAttrs), array_keys($attrs)) as $name) {
unset($quoteTemplate[$name]);
unset($attrs[$name]);
unset($contactAttrs[$name]);
}
// add quotes template-specific token
$quoteTemplate['dateNow'] = '{' . self::$customQuotesTitle . '.quoteOrInvoice}';
$quoteTemplate = CJSON::encode($quoteTemplate);
$str = Docs::replaceVariables($quoteTemplate, $quote, array(), false, false);
$this->assertEquals(array_merge(array_map(function ($elem) {
return (string) $elem;
}, $attrs), array_map(function ($elem) {
return (string) $elem;
}, $contactAttrs), array('dateNow' => Yii::t('quotes', $quote->type == 'invoice' ? 'Invoice' : self::$customQuotesTitle))), CJSON::decode($str));
// old test
// $this->markTestSkipped('This test has been very badly broken by '
// . 'changes made to X2Model.getAttribute and '
// . 'Formatter.replaceVariables which apparently make it so that '
// . 'no combination of arguments sent to Docs.replaceVariables '
// . 'versus to X2Model.getAttribute produce an equivalent list '
// . 'of values. Thus, for now, abandon hope of fixing it.');
//
// // Test replacement in emails:
// $contact = $this->contacts('testAnyone');
// $textIn = array();
// $textOutExpected = array();
// $delimiter = "\n@@|@@\n";
// foreach($contact->attributes as $name=>$value) {
// $textIn[] = '{'.$name.'}';
// $textOutExpected[] = $contact->renderAttribute($name, false);
// }
// $textIn = implode($delimiter,$textIn);
// $textOutExpected = implode($delimiter,$textOutExpected);
// $textOut = Docs::replaceVariables($textIn,$contact);
// $this->assertEquals($textOutExpected,$textOut,'Failed asserting that email template replacement succeeded.');
//
// // Test replacement in Quote bodies:
// $quote = $this->quotes('docsTest');
// $classes = array(
// 'Accounts',
// 'Contacts',
// 'Quote'
// ); // In that order
// $models = array(
// 'Accounts' => $this->accounts('testQuote'),
// 'Contacts' => $this->contacts('testAnyone'),
// 'Quote' => $this->quotes('docsTest'),
// );
// $textIn = array();
// $textOutExpected = array();
// $delimiter = "\n*|*\n";
//
// foreach($classes as $class) {
// $classNick = rtrim($class,'s');
// $attrs = array_keys($class::model()->attributeLabels());
// foreach($attrs as $attribute) {
// $textIn[] = '{'.$classNick.'.'.$attribute.'}';
// $textOutExpected[] = empty($models[$class])?'':$models[$class]->renderAttribute($attribute, false);
// }
// }
// $textIn = implode($delimiter,$textIn);
// $textOutExpected = implode($delimiter,$textOutExpected);
// $textOut = Docs::replaceVariables($textIn,$quote);
// $this->assertEquals($textOutExpected,$textOut, 'Failed asserting that Quote template replacement succeeded.');
//
//.........这里部分代码省略.........
示例4: getPrintQuote
/**
* Generate presentation markup for the quote.
*
* @param integer $id ID of the quote for which to create a presentation
* @param bool $email Parameter passed to the item table markup generator
* @param string $header Optional header to pass to the print view
* @return type
*/
public function getPrintQuote($id = null, $email = false)
{
$this->throwOnNullModel = false;
$model = $this->getModel($id);
if ($model == null) {
return Yii::t('quotes', 'Quote {id} does not exist. It may have been deleted.', array('{id}' => $id));
}
if (!$model->templateModel instanceof Docs) {
// Legacy view (very, very plain!)
return $this->renderPartial('print', array('model' => $model, 'email' => $email), true);
} else {
// User-defined template
$template = $model->templateModel;
if (!$template instanceof Docs) {
// Template not found (it was probably deleted).
// Use the default quotes view.
$model->template = null;
$model->update(array('template'));
return $this->getPrintQuote($model->id);
}
return Docs::replaceVariables($template->text, $model);
}
}
示例5: prepareBody
/**
* Prepare the email body for sending or customization by the user.
*/
public function prepareBody($postReplace = 0)
{
if (!$this->validate()) {
return false;
}
// Replace the existing body, if any, with a template, i.e. for initial
// set-up or an automated email.
if ($this->scenario === 'template') {
// Get the template and associated model
if (!empty($this->templateModel)) {
if ($this->templateModel->emailTo !== null) {
$this->to = Docs::replaceVariables($this->templateModel->emailTo, $this->targetModel, array(), false, false);
}
// Replace variables in the subject and body of the email
$this->subject = Docs::replaceVariables($this->templateModel->subject, $this->targetModel);
// if(!empty($this->targetModel)) {
$this->message = Docs::replaceVariables($this->templateModel->text, $this->targetModel, array('{signature}' => self::insertedPattern('signature', $this->signature)));
// } else {
// $this->insertInBody('<span style="color:red">'.Yii::t('app','Error: attempted using a template, but the referenced model was not found.').'</span>');
// }
} else {
// No template?
$this->message = self::emptyBody();
$this->insertSignature();
}
} else {
if ($postReplace) {
$this->subject = Docs::replaceVariables($this->subject, $this->targetModel);
$this->message = Docs::replaceVariables($this->message, $this->targetModel);
}
}
return true;
}