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\grid; |
13
|
|
|
|
14
|
|
|
use hipanel\helpers\ArrayHelper; |
15
|
|
|
use hipanel\widgets\XEditable; |
16
|
|
|
use Closure; |
17
|
|
|
use Yii; |
18
|
|
|
use yii\helpers\Html; |
19
|
|
|
use yii\helpers\Url; |
20
|
|
|
|
21
|
|
|
class MainColumn extends DataColumn |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @var true|string |
25
|
|
|
* true - note editing is enabled in this column, target attribute name is `note` |
26
|
|
|
* string - target atttribute name |
27
|
|
|
*/ |
28
|
|
|
public $note; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var string name of attribute with extra data showed under main data |
32
|
|
|
*/ |
33
|
|
|
public $extraAttribute; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var array will be passed to the ```pluginOptions``` of [[XEditable]] plugin |
37
|
|
|
*/ |
38
|
|
|
public $noteOptions = []; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var string|Closure badges string or callback to render badges |
42
|
|
|
*/ |
43
|
|
|
public $badges; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Builds url. |
47
|
|
|
* @param string $url |
48
|
|
|
* @return string |
49
|
|
|
*/ |
50
|
|
|
public function buildUrl($url) |
51
|
|
|
{ |
52
|
|
|
if (strncmp($url, '/', 0) === 0) { |
53
|
|
|
return $url; |
54
|
|
|
} |
55
|
|
|
$baseUrl = isset($this->grid->controllerUrl) ? $this->grid->controllerUrl : ''; |
56
|
|
|
return $baseUrl ? Url::to($baseUrl . '/' . $url) : Url::to($url); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function init() |
60
|
|
|
{ |
61
|
|
|
parent::init(); |
62
|
|
|
$this->noteOptions = ArrayHelper::merge([ |
63
|
|
|
'url' => $this->buildUrl('set-note'), |
64
|
|
|
], $this->noteOptions); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** {@inheritdoc} */ |
68
|
|
|
protected function renderDataCellContent($model, $key, $index) |
69
|
|
|
{ |
70
|
|
|
if ($this->value !== null) { |
71
|
|
|
if (is_string($this->value)) { |
72
|
|
|
$value = ArrayHelper::getValue($model, $this->value); |
73
|
|
|
} else { |
74
|
|
|
$value = call_user_func($this->value, $model, $key, $index, $this); |
75
|
|
|
} |
76
|
|
|
} else { |
77
|
|
|
$value = $this->renderViewLink($model, $key, $index); |
78
|
|
|
} |
79
|
|
|
$note = $this->renderNoteLink($model, $key, $index); |
80
|
|
|
$extra = $this->renderExtra($model); |
81
|
|
|
$badges = $this->badges instanceof Closure ? call_user_func($this->badges, $model, $key, $index) : $this->badges; |
82
|
|
|
|
83
|
|
|
return $value . $extra . ($badges ? ' ' . $badges : '') . ($note ? '<br>' . $note : ''); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
public function renderExtra($model) |
87
|
|
|
{ |
88
|
|
|
$value = $this->extraAttribute ? $model->{$this->extraAttribute} : null; |
89
|
|
|
|
90
|
|
|
return $value ? "<br>$value" : ''; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
public function renderViewLink($model, $key, $index) |
94
|
|
|
{ |
95
|
|
|
$value = parent::renderDataCellContent($model, $key, $index); |
|
|
|
|
96
|
|
|
return Html::a($value, [$this->buildUrl('view'), 'id' => $model->id], ['class' => 'bold']); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Renders link to edit note. |
101
|
|
|
* @param $model |
102
|
|
|
* @param $key |
103
|
|
|
* @param $index |
104
|
|
|
* @return string|null |
105
|
|
|
*/ |
106
|
|
|
public function renderNoteLink($model, $key, $index) |
|
|
|
|
107
|
|
|
{ |
108
|
|
|
return $this->note ? Html::tag('span', Yii::t('hipanel', 'Note') . ': ', ['class' => 'bold']) . XEditable::widget([ |
109
|
|
|
'model' => $model, |
110
|
|
|
'attribute' => $this->note === true ? 'note' : $this->note, |
111
|
|
|
'pluginOptions' => $this->noteOptions, |
112
|
|
|
]) : null; |
113
|
|
|
} |
114
|
|
|
} |
115
|
|
|
|
This check looks for a call to a parent method whose name is different than the method from which it is called.
Consider the following code:
The
getFirstName()
method in theSon
calls the wrong method in the parent class.