Completed
Push — master ( 9c34f1...bd7a69 )
by Song
02:46
created

RowAction::display()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Encore\Admin\Actions;
4
5
use Encore\Admin\Grid\Column;
6
use Illuminate\Http\Request;
7
8
abstract class RowAction extends GridAction
9
{
10
    /**
11
     * @var \Illuminate\Database\Eloquent\Model
12
     */
13
    protected $row;
14
15
    /**
16
     * @var Column
17
     */
18
    protected $column;
19
20
    /**
21
     * @var string
22
     */
23
    public $selectorPrefix = '.grid-row-action-';
24
25
    /**
26
     * @var bool
27
     */
28
    protected $asColumn = false;
29
30
    /**
31
     * Get primary key value of current row.
32
     *
33
     * @return mixed
34
     */
35
    protected function getKey()
36
    {
37
        return $this->row->getKey();
38
    }
39
40
    /**
41
     * Set row model.
42
     *
43
     * @param mixed $key
44
     *
45
     * @return \Illuminate\Database\Eloquent\Model|mixed
46
     */
47
    public function row($key = null)
48
    {
49
        if (func_num_args() == 0) {
50
            return $this->row;
51
        }
52
53
        return $this->row->getAttribute($key);
54
    }
55
56
    /**
57
     * Set row model.
58
     *
59
     * @param \Illuminate\Database\Eloquent\Model $row
60
     *
61
     * @return $this
62
     */
63
    public function setRow($row)
64
    {
65
        $this->row = $row;
66
67
        return $this;
68
    }
69
70
    public function getRow()
71
    {
72
        return $this->row;
73
    }
74
75
    /**
76
     * @param Column $column
77
     *
78
     * @return $this
79
     */
80
    public function setColumn(Column $column)
81
    {
82
        $this->column = $column;
83
84
        return $this;
85
    }
86
87
    /**
88
     * Show this action as a column.
89
     *
90
     * @return $this
91
     */
92
    public function asColumn()
93
    {
94
        $this->asColumn = true;
95
96
        return $this;
97
    }
98
99
    /**
100
     * @return string
101
     */
102
    public function href()
103
    {
104
    }
105
106
    /**
107
     * @param Request $request
108
     *
109
     * @return mixed
110
     */
111
    public function retrieveModel(Request $request)
112
    {
113
        if (!$key = $request->get('_key')) {
114
            return false;
115
        }
116
117
        $modelClass = str_replace('_', '\\', $request->get('_model'));
118
119
        return $modelClass::findOrFail($key);
120
    }
121
122
    public function display($value)
0 ignored issues
show
Unused Code introduced by
The parameter $value is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
123
    {
124
125
    }
126
127
    /**
128
     * Render row action.
129
     *
130
     * @return string
131
     */
132
    public function render()
133
    {
134
        if ($href = $this->href()) {
135
            return "<a href='{$href}'>{$this->name()}</a>";
136
        }
137
138
        $this->addScript();
139
140
        $attributes = $this->formatAttributes();
141
142
        return sprintf(
143
            "<a data-_key='%s' href='javascript:void(0);' class='%s' {$attributes}>%s</a>",
144
            $this->getKey(),
145
            $this->getElementClass(),
146
            $this->asColumn ? $this->display($this->row($this->column->getName())) : $this->name()
147
        );
148
    }
149
}
150