itstructure /
laravel-grid-view
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Itstructure\GridView\Actions; |
||
| 4 | |||
| 5 | use Closure; |
||
| 6 | use Itstructure\GridView\Traits\{Configurable, Attributable}; |
||
| 7 | |||
| 8 | /** |
||
| 9 | * Class BaseAction. |
||
| 10 | * @package Itstructure\GridView\Actions |
||
| 11 | * |
||
| 12 | * @property string $url |
||
| 13 | */ |
||
| 14 | abstract class BaseAction |
||
| 15 | { |
||
| 16 | use Configurable, Attributable; |
||
| 17 | |||
| 18 | const BOOTSTRAP_COL_WIDTH = 4; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * @var string|Closure|null |
||
| 22 | */ |
||
| 23 | protected $url; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * BaseButton constructor. |
||
| 27 | * @param array $config |
||
| 28 | */ |
||
| 29 | public function __construct(array $config = []) |
||
| 30 | { |
||
| 31 | $this->loadConfig($config); |
||
| 32 | } |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @param $row |
||
| 36 | * @param int $bootstrapColWidth |
||
| 37 | * @return mixed |
||
| 38 | */ |
||
| 39 | abstract public function render($row, int $bootstrapColWidth = self::BOOTSTRAP_COL_WIDTH); |
||
| 40 | |||
| 41 | /** |
||
| 42 | * Build url for some actions. |
||
| 43 | * @param $row |
||
| 44 | */ |
||
| 45 | abstract protected function buildUrl($row); |
||
| 46 | |||
| 47 | /** |
||
| 48 | * @param $row |
||
| 49 | * @return mixed|string |
||
| 50 | */ |
||
| 51 | protected function getUrl($row) |
||
| 52 | { |
||
| 53 | if ($this->url instanceof Closure) { |
||
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
| 54 | return call_user_func($this->url, $row); |
||
| 55 | |||
| 56 | } else if (!is_null($this->url) && is_string($this->url)) { |
||
|
0 ignored issues
–
show
|
|||
| 57 | return $this->url; |
||
| 58 | } |
||
| 59 | |||
| 60 | return $this->buildUrl($row); |
||
| 61 | } |
||
| 62 | |||
| 63 | /** |
||
| 64 | * @return string |
||
| 65 | */ |
||
| 66 | protected function getCurrentUrl() |
||
| 67 | { |
||
| 68 | return url()->current(); |
||
| 69 | } |
||
| 70 | } |
||
| 71 |