1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Finance module for HiPanel |
4
|
|
|
* |
5
|
|
|
* @link https://github.com/hiqdev/hipanel-module-finance |
6
|
|
|
* @package hipanel-module-finance |
7
|
|
|
* @license BSD-3-Clause |
8
|
|
|
* @copyright Copyright (c) 2015-2019, HiQDev (http://hiqdev.com/) |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace hipanel\modules\finance\grid\presenters\price; |
12
|
|
|
|
13
|
|
|
use hipanel\helpers\StringHelper; |
14
|
|
|
use hipanel\modules\finance\models\Price; |
15
|
|
|
use Yii; |
16
|
|
|
use yii\base\InvalidConfigException; |
17
|
|
|
use yii\helpers\Html; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Class TemplatePricePresenter. |
21
|
|
|
* |
22
|
|
|
* @author Dmytro Naumenko <[email protected]> |
23
|
|
|
*/ |
24
|
|
|
class TemplatePricePresenter extends PricePresenter |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* @param \hipanel\modules\finance\models\TemplatePrice $price |
28
|
|
|
* @return string |
29
|
|
|
*/ |
30
|
|
|
public function renderPrice(Price $price): string |
31
|
|
|
{ |
32
|
|
|
$formatter = Yii::$app->formatter; |
33
|
|
|
|
34
|
|
|
$unit = ''; |
35
|
|
|
if ($price->getUnitLabel()) { |
36
|
|
|
$unit = ' ' . Yii::t('hipanel:finance', 'per {unit}', ['unit' => $price->getUnitLabel()]); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
if (StringHelper::startsWith($price->type, 'referral')) { |
40
|
|
|
$result = [ |
41
|
|
|
Html::tag('strong', $price->rate . '%'), |
|
|
|
|
42
|
|
|
]; |
43
|
|
|
} else { |
44
|
|
|
$result = [ |
45
|
|
|
Html::tag('strong', $formatter->asCurrency($price->price, $price->currency) . $unit), |
46
|
|
|
]; |
47
|
|
|
} |
48
|
|
|
if ($price->subprices) { |
|
|
|
|
49
|
|
|
foreach ($price->subprices as $currencyCode => $amount) { |
|
|
|
|
50
|
|
|
try { |
51
|
|
|
$result[] = $formatter->asCurrency($amount, $currencyCode); |
52
|
|
|
} catch (InvalidConfigException $e) { |
53
|
|
|
$result[] = $amount . ' ' . $currencyCode; |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
return implode(' — ', $result); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|
Since your code implements the magic getter
_get
, this function will be called for any read access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.