@@ -7,59 +7,59 @@ |
||
| 7 | 7 | |
| 8 | 8 | class AttributeColumn extends BaseColumn |
| 9 | 9 | { |
| 10 | - /** |
|
| 11 | - * @var string - allowed: url, email, text, image |
|
| 12 | - */ |
|
| 13 | - public $contentFormat = 'text'; |
|
| 10 | + /** |
|
| 11 | + * @var string - allowed: url, email, text, image |
|
| 12 | + */ |
|
| 13 | + public $contentFormat = 'text'; |
|
| 14 | 14 | |
| 15 | - public function __construct($config) |
|
| 16 | - { |
|
| 17 | - if (is_string($config)) { |
|
| 18 | - $config = [ |
|
| 19 | - 'value' => $config, |
|
| 20 | - ]; |
|
| 21 | - } |
|
| 15 | + public function __construct($config) |
|
| 16 | + { |
|
| 17 | + if (is_string($config)) { |
|
| 18 | + $config = [ |
|
| 19 | + 'value' => $config, |
|
| 20 | + ]; |
|
| 21 | + } |
|
| 22 | 22 | |
| 23 | - parent::__construct($config); |
|
| 23 | + parent::__construct($config); |
|
| 24 | 24 | |
| 25 | - if (empty($this->title)) { |
|
| 26 | - $this->title = ucfirst(str_replace('_', ' ', $this->value)); |
|
| 27 | - } |
|
| 28 | - } |
|
| 25 | + if (empty($this->title)) { |
|
| 26 | + $this->title = ucfirst(str_replace('_', ' ', $this->value)); |
|
| 27 | + } |
|
| 28 | + } |
|
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * @inheritdoc |
|
| 32 | - * @throws ColumnRenderException |
|
| 33 | - * @throws GridViewConfigException |
|
| 34 | - */ |
|
| 35 | - public function renderValue($row) |
|
| 36 | - { |
|
| 37 | - $value = ''; |
|
| 30 | + /** |
|
| 31 | + * @inheritdoc |
|
| 32 | + * @throws ColumnRenderException |
|
| 33 | + * @throws GridViewConfigException |
|
| 34 | + */ |
|
| 35 | + public function renderValue($row) |
|
| 36 | + { |
|
| 37 | + $value = ''; |
|
| 38 | 38 | |
| 39 | - if (is_array($row)) { |
|
| 39 | + if (is_array($row)) { |
|
| 40 | 40 | |
| 41 | - if (isset($row[$this->value])) { |
|
| 42 | - $value = $row[$this->value]; |
|
| 43 | - } |
|
| 44 | - } elseif (isset($row->{$this->value})) { |
|
| 45 | - $value = $row->{$this->value}; |
|
| 46 | - } |
|
| 41 | + if (isset($row[$this->value])) { |
|
| 42 | + $value = $row[$this->value]; |
|
| 43 | + } |
|
| 44 | + } elseif (isset($row->{$this->value})) { |
|
| 45 | + $value = $row->{$this->value}; |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - switch ($this->contentFormat) { |
|
| 49 | - case 'text': |
|
| 50 | - return htmlentities($value); |
|
| 48 | + switch ($this->contentFormat) { |
|
| 49 | + case 'text': |
|
| 50 | + return htmlentities($value); |
|
| 51 | 51 | |
| 52 | - case 'url': |
|
| 53 | - return '<a href="' . htmlspecialchars($value, ENT_QUOTES) . '">' . htmlentities($value) . '</a>'; |
|
| 52 | + case 'url': |
|
| 53 | + return '<a href="' . htmlspecialchars($value, ENT_QUOTES) . '">' . htmlentities($value) . '</a>'; |
|
| 54 | 54 | |
| 55 | - case 'email': |
|
| 56 | - return '<a href="mailto:' . htmlspecialchars($value, ENT_QUOTES) . '">' . htmlentities($value) . '</a>'; |
|
| 55 | + case 'email': |
|
| 56 | + return '<a href="mailto:' . htmlspecialchars($value, ENT_QUOTES) . '">' . htmlentities($value) . '</a>'; |
|
| 57 | 57 | |
| 58 | - case 'image': |
|
| 59 | - return '<img src="' . htmlspecialchars($value, ENT_QUOTES) . '">'; |
|
| 58 | + case 'image': |
|
| 59 | + return '<img src="' . htmlspecialchars($value, ENT_QUOTES) . '">'; |
|
| 60 | 60 | |
| 61 | - default: |
|
| 62 | - throw new GridViewConfigException('Invalid content format for attribute collumn: ' . $this->value); |
|
| 63 | - } |
|
| 64 | - } |
|
| 61 | + default: |
|
| 62 | + throw new GridViewConfigException('Invalid content format for attribute collumn: ' . $this->value); |
|
| 63 | + } |
|
| 64 | + } |
|
| 65 | 65 | } |
| 66 | 66 | \ No newline at end of file |
@@ -6,69 +6,69 @@ |
||
| 6 | 6 | |
| 7 | 7 | class ActionsColumn extends BaseColumn |
| 8 | 8 | { |
| 9 | - /** |
|
| 10 | - * By default is empty for this column |
|
| 11 | - * @var string |
|
| 12 | - */ |
|
| 13 | - public $title = ''; |
|
| 9 | + /** |
|
| 10 | + * By default is empty for this column |
|
| 11 | + * @var string |
|
| 12 | + */ |
|
| 13 | + public $title = ''; |
|
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * Value contains short codes for actions |
|
| 17 | - * @var string |
|
| 18 | - */ |
|
| 19 | - public $value = '{show} {edit} {delete}'; |
|
| 15 | + /** |
|
| 16 | + * Value contains short codes for actions |
|
| 17 | + * @var string |
|
| 18 | + */ |
|
| 19 | + public $value = '{show} {edit} {delete}'; |
|
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * Additional actions could be added, key is short-code and value is callback |
|
| 23 | - * @var array |
|
| 24 | - */ |
|
| 25 | - public $additionalActions = []; |
|
| 21 | + /** |
|
| 22 | + * Additional actions could be added, key is short-code and value is callback |
|
| 23 | + * @var array |
|
| 24 | + */ |
|
| 25 | + public $additionalActions = []; |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * @var \Closure|null |
|
| 29 | - */ |
|
| 30 | - public $actionsUrls; |
|
| 27 | + /** |
|
| 28 | + * @var \Closure|null |
|
| 29 | + */ |
|
| 30 | + public $actionsUrls; |
|
| 31 | 31 | |
| 32 | - public function __construct(array $config) |
|
| 33 | - { |
|
| 34 | - parent::__construct($config); |
|
| 32 | + public function __construct(array $config) |
|
| 33 | + { |
|
| 34 | + parent::__construct($config); |
|
| 35 | 35 | |
| 36 | - GridViewHelper::testConfig($this, [ |
|
| 37 | - 'value' => 'string', |
|
| 38 | - 'additionalActions' => 'array', |
|
| 39 | - 'actionsUrls' => 'any', |
|
| 40 | - ]); |
|
| 41 | - } |
|
| 36 | + GridViewHelper::testConfig($this, [ |
|
| 37 | + 'value' => 'string', |
|
| 38 | + 'additionalActions' => 'array', |
|
| 39 | + 'actionsUrls' => 'any', |
|
| 40 | + ]); |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - public function basicActions() |
|
| 44 | - { |
|
| 45 | - return [ |
|
| 46 | - 'show' => function($model) { |
|
| 47 | - return '<a href="' . call_user_func($this->actionsUrls, $model)['show'] . '">View</a>'; |
|
| 48 | - }, |
|
| 49 | - 'edit' => function($model) { |
|
| 50 | - return '<a href="' . call_user_func($this->actionsUrls, $model)['edit'] . '">Edit</a>'; |
|
| 51 | - }, |
|
| 52 | - 'delete' => function($model) { |
|
| 53 | - return '<a href="' . call_user_func($this->actionsUrls, $model)['delete'] . '">Delete</a>'; |
|
| 54 | - }, |
|
| 55 | - ]; |
|
| 56 | - } |
|
| 43 | + public function basicActions() |
|
| 44 | + { |
|
| 45 | + return [ |
|
| 46 | + 'show' => function($model) { |
|
| 47 | + return '<a href="' . call_user_func($this->actionsUrls, $model)['show'] . '">View</a>'; |
|
| 48 | + }, |
|
| 49 | + 'edit' => function($model) { |
|
| 50 | + return '<a href="' . call_user_func($this->actionsUrls, $model)['edit'] . '">Edit</a>'; |
|
| 51 | + }, |
|
| 52 | + 'delete' => function($model) { |
|
| 53 | + return '<a href="' . call_user_func($this->actionsUrls, $model)['delete'] . '">Delete</a>'; |
|
| 54 | + }, |
|
| 55 | + ]; |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - public function renderValue($row) |
|
| 59 | - { |
|
| 60 | - $result = $this->value; |
|
| 58 | + public function renderValue($row) |
|
| 59 | + { |
|
| 60 | + $result = $this->value; |
|
| 61 | 61 | |
| 62 | - $actions = array_merge($this->basicActions(), $this->additionalActions); |
|
| 62 | + $actions = array_merge($this->basicActions(), $this->additionalActions); |
|
| 63 | 63 | |
| 64 | - foreach ($actions as $key => $action) { |
|
| 65 | - if (strpos($result, '{' . $key . '}') === false) { |
|
| 66 | - continue; |
|
| 67 | - } |
|
| 64 | + foreach ($actions as $key => $action) { |
|
| 65 | + if (strpos($result, '{' . $key . '}') === false) { |
|
| 66 | + continue; |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - $result = str_replace('{' . $key . '}', $action($row), $result); |
|
| 70 | - } |
|
| 69 | + $result = str_replace('{' . $key . '}', $action($row), $result); |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - return $result; |
|
| 73 | - } |
|
| 72 | + return $result; |
|
| 73 | + } |
|
| 74 | 74 | } |
| 75 | 75 | \ No newline at end of file |