1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace hipanel\modules\finance\models\decorators\server; |
4
|
|
|
|
5
|
|
|
use hipanel\inputs\TextInput; |
6
|
|
|
use hipanel\modules\finance\models\decorators\AbstractResourceDecorator; |
7
|
|
|
use hipanel\modules\finance\models\decorators\ResourceDecoratorInterface; |
8
|
|
|
use hipanel\modules\finance\models\ServerResource; |
9
|
|
|
use Yii; |
10
|
|
|
use yii\helpers\Inflector; |
11
|
|
|
|
12
|
|
|
abstract class AbstractServerResourceDecorator extends AbstractResourceDecorator implements ResourceDecoratorInterface |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @var ServerResource |
16
|
|
|
*/ |
17
|
|
|
public $resource; |
18
|
|
|
|
19
|
|
|
public function __construct(ServerResource $resource) |
20
|
|
|
{ |
21
|
|
|
parent::__construct($resource); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
public function displayTitle() |
25
|
|
|
{ |
26
|
|
|
return $this->resource->getTypes()[$this->resource->type]; |
|
|
|
|
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function getPrepaidQuantity() |
30
|
|
|
{ |
31
|
|
|
return $this->resource->quantity; |
|
|
|
|
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function getOverusePrice() |
35
|
|
|
{ |
36
|
|
|
return $this->resource->price; |
|
|
|
|
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function displayUnit() |
40
|
|
|
{ |
41
|
|
|
return $this->resource->unit; |
|
|
|
|
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function displayOverusePrice() |
45
|
|
|
{ |
46
|
|
|
return Yii::$app->formatter->asCurrency($this->getOverusePrice(), $this->resource->currency); |
|
|
|
|
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function displayPrepaidAmount() |
50
|
|
|
{ |
51
|
|
|
return \Yii::t('hipanel/finance/tariff', '{amount} {unit}', [ |
52
|
|
|
'amount' => $this->getPrepaidQuantity(), |
53
|
|
|
'unit' => $this->displayUnit() |
54
|
|
|
]); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function prepaidAmountType() |
58
|
|
|
{ |
59
|
|
|
return new TextInput(); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function realObjectId() |
63
|
|
|
{ |
64
|
|
|
$resource = $this->resource; |
65
|
|
|
|
66
|
|
|
if (!$resource->isPeriodic()) { |
67
|
|
|
return $resource->object_id; |
|
|
|
|
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
if (!$resource->tariff->is_personal && isset($resource->r_object_id)) { |
|
|
|
|
71
|
|
|
return $resource->r_object_id; |
|
|
|
|
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
return $resource->object_id; |
|
|
|
|
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
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.