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


PHP Formatter::replaceVariables方法代码示例

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


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

示例1: replaceVariables

 /**
  * Replace tokens with model attribute values.
  *
  * @param type $str Input text
  * @param X2Model $model Model to use for replacement
  * @param array $vars List of extra variables to replace
  * @param bool $encode Encode replacement values if true; use renderAttribute otherwise.
  * @return string
  */
 public static function replaceVariables($str, $model, $vars = array(), $encode = false, $renderFlag = true)
 {
     if ($encode) {
         foreach (array_keys($vars) as $key) {
             $vars[$key] = CHtml::encode($vars[$key]);
         }
     }
     $str = strtr($str, $vars);
     // replace any manually set variables
     if ($model instanceof X2Model) {
         if (get_class($model) !== 'Quote') {
             $str = Formatter::replaceVariables($str, $model, '', $renderFlag, false);
         } else {
             // Specialized, separate method for quotes that can use details from
             // either accounts or quotes.
             // There may still be some stray quotes with 2+ contacts on it, so
             // explode and pick the first to be on the safe side. The most
             // common use case by far is to have only one contact on the quote.
             $accountId = $model->accountName;
             $staticModels = array('Contact' => Contacts::model(), 'Account' => Accounts::model(), 'Quote' => Quote::model());
             $models = array('Contact' => $model->contact, 'Account' => empty($accountId) ? null : $staticModels['Account']->findByAttributes(array('nameId' => $accountId)), 'Quote' => $model);
             $attributes = array();
             foreach ($models as $name => $modelObj) {
                 $moduleRef = Modules::displayName(false, $name . "s");
                 if (empty($modelObj)) {
                     // Model will be blank
                     foreach ($staticModels[$name]->fields as $field) {
                         $attributes['{' . $moduleRef . '.' . $field->fieldName . '}'] = '';
                     }
                 } else {
                     // Insert attributes
                     foreach ($modelObj->attributes as $fieldName => $value) {
                         if ($renderFlag) {
                             $attributes['{' . $moduleRef . '.' . $fieldName . '}'] = $modelObj->renderAttribute($fieldName, false, true, $encode);
                         } else {
                             $attributes['{' . $moduleRef . '.' . $fieldName . '}'] = $modelObj->getAttribute($fieldName);
                         }
                     }
                 }
             }
             $quoteTitle = Modules::displayName(false, "Quotes");
             $quoteParams = array('{' . $quoteTitle . '.lineItems}' => $model->productTable(true), '{' . $quoteTitle . '.dateNow}' => date("F d, Y", time()), '{' . $quoteTitle . '.quoteOrInvoice}' => Yii::t('quotes', $model->type == 'invoice' ? 'Invoice' : $quoteTitle));
             // Run the replacement:
             $str = strtr($str, array_merge($attributes, $quoteParams));
             return $str;
         }
     }
     return $str;
 }
开发者ID:keyeMyria,项目名称:CRM,代码行数:58,代码来源:Docs.php

示例2: renderCustom

 protected function renderCustom($field, $makeLinks, $textOnly, $encode)
 {
     $fieldName = $field->fieldName;
     if ($field->linkType == 'display') {
         // Interpret as HTML. Restore curly braces in href
         // attributes that HTMLPurifier has replaced:
         $fieldText = preg_replace('/%7B([\\w\\.]+)%7D/', '{$1}', $field->data);
         return Formatter::replaceVariables($fieldText, $this->owner, '', false);
     } elseif ($field->linkType == 'formula') {
         $evald = Formatter::parseFormula($field->data, array('model' => $this->owner));
         if ($evald[0]) {
             return $this->render($evald[1], $encode);
         } else {
             return Yii::t('app', 'Error parsing formula.') . ' ' . $evald[1];
         }
     } else {
         return $this->render($this->owner->{$fieldName}, $encode);
     }
 }
开发者ID:tymiles003,项目名称:X2CRM,代码行数:19,代码来源:FieldFormatter.php

示例3: replaceVariables

 /**
  * Replace tokens with model attribute values.
  *
  * @param type $str Input text
  * @param X2Model $model Model to use for replacement
  * @param array $vars List of extra variables to replace
  * @param bool $encode Encode replacement values if true; use renderAttribute otherwise.
  * @return string
  */
 public static function replaceVariables($str, $model, $vars = array(), $encode = false, $renderFlag = true)
 {
     if ($encode) {
         foreach (array_keys($vars) as $key) {
             $vars[$key] = CHtml::encode($vars[$key]);
         }
     }
     $str = strtr($str, $vars);
     // replace any manually set variables
     if ($model instanceof X2Model) {
         if (get_class($model) === 'Quote') {
             $quoteTitle = Modules::displayName(false, "Quotes");
             $quoteParams = array('{lineItems}' => $model->productTable(true), '{dateNow}' => date("F d, Y", time()), '{quoteOrInvoice}' => Yii::t('quotes', $model->type == 'invoice' ? 'Invoice' : $quoteTitle));
             $str = strtr($str, $quoteParams);
         }
         $str = Formatter::replaceVariables($str, $model, '', $renderFlag, false);
     }
     return $str;
 }
开发者ID:dsyman2,项目名称:X2CRM,代码行数:28,代码来源:Docs.php


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