本文整理汇总了PHP中Currency::getById方法的典型用法代码示例。如果您正苦于以下问题:PHP Currency::getById方法的具体用法?PHP Currency::getById怎么用?PHP Currency::getById使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Currency
的用法示例。
在下文中一共展示了Currency::getById方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: resolveValueForImport
/**
* There is a special way you can import rateToBase and currencyCode for an amount attribute.
* if the column data is formatted like: $54.67__1.2__USD then it will split the column and properly
* handle rate and currency code. Eventually this will be exposed in the user interface
*
* @param mixed $value
* @param string $columnName
* @param array $columnMappingData
* @param ImportSanitizeResultsUtil $importSanitizeResultsUtil
* @return array
*/
public function resolveValueForImport($value, $columnName, $columnMappingData, ImportSanitizeResultsUtil $importSanitizeResultsUtil)
{
assert('is_string($columnName)');
$attributeNames = $this->getRealModelAttributeNames();
$modelClassName = $this->getModelClassName();
$parts = explode(FormModelUtil::DELIMITER, $value);
if (count($parts) == 3) {
$value = $parts[0];
$rateToBase = $parts[1];
try {
$currency = Currency::getByCode($parts[2]);
} catch (NotFoundException $e) {
$currency = null;
$importSanitizeResultsUtil->addMessage('Currency Code: ' . $parts[2] . ' is invalid.');
$importSanitizeResultsUtil->setModelShouldNotBeSaved();
}
} else {
$rateToBase = $columnMappingData['mappingRulesData']['CurrencyRateToBaseModelAttributeMappingRuleForm']['rateToBase'];
$currency = Currency::getById((int) $columnMappingData['mappingRulesData']['CurrencyIdModelAttributeMappingRuleForm']['id']);
}
$sanitizedValue = ImportSanitizerUtil::sanitizeValueBySanitizerTypes(static::getSanitizerUtilTypesInProcessingOrder(), $modelClassName, $this->getModelAttributeName(), $value, $columnName, $columnMappingData, $importSanitizeResultsUtil);
if ($sanitizedValue == null) {
$sanitizedValue = 0;
}
$currencyValue = new CurrencyValue();
$currencyValue->setScenario('importModel');
$currencyValue->value = $sanitizedValue;
$currencyValue->rateToBase = $rateToBase;
$currencyValue->currency = $currency;
return array($this->getModelAttributeName() => $currencyValue);
}
示例2: sanitizeValue
public function sanitizeValue($value)
{
$resolvedAcceptableValues = ArrayUtil::resolveArrayToLowerCase(static::getAcceptableValues());
if ($value != null) {
if (!in_array(strtolower($value), $resolvedAcceptableValues)) {
return null;
}
$currency = Currency::getByCode($value);
if ($currency != null) {
return $currency;
}
}
if (isset($this->mappingRuleData['defaultValue']) && $this->mappingRuleData['defaultValue'] != null) {
$currency = Currency::getById(intval($this->mappingRuleData['defaultValue']));
if ($currency != null) {
return $currency;
}
}
}
示例3: resolveValueAndSetToModel
/**
* Utilized to create or update model attribute values after a workflow's triggers are fired as true.
* @param WorkflowActionProcessingModelAdapter $adapter
* @param $attribute
* @throws NotSupportedException
*/
public function resolveValueAndSetToModel(WorkflowActionProcessingModelAdapter $adapter, $attribute)
{
assert('is_string($attribute)');
if ($this->type == static::TYPE_STATIC) {
$adapter->getModel()->{$attribute}->value = $this->value;
$adapter->getModel()->{$attribute}->currency = Currency::getById((int) $this->currencyId);
} else {
throw new NotSupportedException();
}
}
示例4: setCurrency__Id
/**
* @param $currency__id
* @throws \Exception
*/
public function setCurrency__Id($currency__id)
{
$currency = null;
if (is_int($currency__id)) {
$currency = Currency::getById($currency__id);
if (!$currency instanceof Currency) {
throw new \Exception("Currency with ID '{$currency__id}' not found");
}
}
$this->currency__id = $currency__id;
$this->currency = $currency;
}