|
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 array will be passed to the ```pluginOptions``` of [[XEditable]] plugin |
|
32
|
|
|
*/ |
|
33
|
|
|
public $noteOptions = []; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @var Closure callback to render cell |
|
37
|
|
|
*/ |
|
38
|
|
|
public $renderer; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Builds url. |
|
42
|
|
|
* @param string $url |
|
43
|
|
|
* @return string |
|
44
|
|
|
*/ |
|
45
|
|
|
public function buildUrl($url) |
|
46
|
|
|
{ |
|
47
|
|
|
if (strncmp($url, '/', 0) === 0) { |
|
48
|
|
|
return $url; |
|
49
|
|
|
} |
|
50
|
|
|
$baseUrl = isset($this->grid->controllerUrl) ? $this->grid->controllerUrl : ''; |
|
51
|
|
|
return $baseUrl ? Url::to($baseUrl . '/' . $url) : Url::to($url); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public function init() |
|
55
|
|
|
{ |
|
56
|
|
|
parent::init(); |
|
57
|
|
|
$this->noteOptions = ArrayHelper::merge([ |
|
58
|
|
|
'url' => $this->buildUrl('set-note'), |
|
59
|
|
|
], $this->noteOptions); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** {@inheritdoc} */ |
|
63
|
|
|
protected function renderDataCellContent($model, $key, $index) |
|
64
|
|
|
{ |
|
65
|
|
|
if ($this->renderer instanceof Closure) { |
|
66
|
|
|
return call_user_func($this->renderer, $this, $model, $key, $index); |
|
67
|
|
|
} else { |
|
68
|
|
|
$link = $this->renderViewLink($model, $key, $index); |
|
69
|
|
|
$note = $this->renderNoteLink($model, $key, $index); |
|
70
|
|
|
|
|
71
|
|
|
return $link . ($note ? '<br>' . $note : ''); |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
public function renderViewLink($model, $key, $index) |
|
76
|
|
|
{ |
|
77
|
|
|
$value = parent::renderDataCellContent($model, $key, $index); |
|
|
|
|
|
|
78
|
|
|
return Html::a($value, [$this->buildUrl('view'), 'id' => $model->id], ['class' => 'bold']); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* Renders link to edit note. |
|
83
|
|
|
* @param $model |
|
84
|
|
|
* @param $key |
|
85
|
|
|
* @param $index |
|
86
|
|
|
* @return string|null |
|
87
|
|
|
*/ |
|
88
|
|
|
public function renderNoteLink($model, $key, $index) |
|
|
|
|
|
|
89
|
|
|
{ |
|
90
|
|
|
return $this->note ? Html::tag('span', Yii::t('app', 'Note') . ': ', ['class' => 'bold']) . XEditable::widget([ |
|
91
|
|
|
'model' => $model, |
|
92
|
|
|
'attribute' => $this->note === true ? 'note' : $this->note, |
|
93
|
|
|
'pluginOptions' => $this->noteOptions, |
|
94
|
|
|
]) : null; |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
|
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 theSoncalls the wrong method in the parent class.