1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* HiPanel core package |
5
|
|
|
* |
6
|
|
|
* @link https://hipanel.com/ |
7
|
|
|
* @package hipanel-core |
8
|
|
|
* @license BSD-3-Clause |
9
|
|
|
* @copyright Copyright (c) 2014-2016, HiQDev (http://hiqdev.com/) |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace hipanel\widgets; |
13
|
|
|
|
14
|
|
|
use hipanel\base\Model; |
15
|
|
|
use Yii; |
16
|
|
|
use yii\helpers\Html; |
17
|
|
|
|
18
|
|
|
class ClientSellerLink extends \yii\base\Widget |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @var Model |
22
|
|
|
*/ |
23
|
|
|
public $model; |
24
|
|
|
|
25
|
|
|
public $clientAttribute = 'client'; |
26
|
|
|
public $clientIdAttribute = 'client_id'; |
27
|
|
|
public $sellerAttribute = 'seller'; |
28
|
|
|
public $sellerIdAttribute = 'seller_id'; |
29
|
|
|
|
30
|
|
|
public function run() |
31
|
|
|
{ |
32
|
|
|
if ($this->getClient() === 'anonym') { |
33
|
|
|
$result = Html::tag('b', 'anonym'); |
34
|
|
|
} elseif ($this->getClientId() === Yii::$app->user->id || Yii::$app->user->can('support')) { |
35
|
|
|
$result = Html::a($this->getClient(), ['@client/view', 'id' => $this->getClientId()]); |
36
|
|
|
} else { |
37
|
|
|
$result = $this->getClient(); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
if (Yii::$app->user->can('support') && $this->getSeller() !== false) { |
41
|
|
|
$result .= ' / ' . Html::a($this->getSeller(), ['@client/view', 'id' => $this->getSellerId()]); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
return $result; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function getClient() |
48
|
|
|
{ |
49
|
|
|
return $this->getValue($this->clientAttribute); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function getClientId() |
53
|
|
|
{ |
54
|
|
|
return $this->getValue($this->clientIdAttribute); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function getSeller() |
58
|
|
|
{ |
59
|
|
|
return $this->getValue($this->sellerAttribute); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function getSellerId() |
63
|
|
|
{ |
64
|
|
|
return $this->getValue($this->sellerIdAttribute); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function getValue($attribute) |
68
|
|
|
{ |
69
|
|
|
return $attribute === false ? false : $this->model->{$attribute}; |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|