| @@ 11-85 (lines=75) @@ | ||
| 8 | use Encore\Admin\Form\Field; |
|
| 9 | use Illuminate\Support\Collection; |
|
| 10 | ||
| 11 | class Column |
|
| 12 | { |
|
| 13 | /** |
|
| 14 | * @var Collection |
|
| 15 | */ |
|
| 16 | protected $fields; |
|
| 17 | ||
| 18 | /** |
|
| 19 | * @var int |
|
| 20 | */ |
|
| 21 | protected $width; |
|
| 22 | ||
| 23 | /** |
|
| 24 | * Column constructor. |
|
| 25 | * |
|
| 26 | * @param int $width |
|
| 27 | */ |
|
| 28 | public function __construct($width = 12) |
|
| 29 | { |
|
| 30 | $this->width = $width; |
|
| 31 | $this->fields = new Collection(); |
|
| 32 | } |
|
| 33 | ||
| 34 | /** |
|
| 35 | * Add a filter to this column. |
|
| 36 | * |
|
| 37 | * @param Field $field |
|
| 38 | */ |
|
| 39 | public function add(Field $field) |
|
| 40 | { |
|
| 41 | $this->fields->push($field); |
|
| 42 | } |
|
| 43 | ||
| 44 | /** |
|
| 45 | * Remove fields from column. |
|
| 46 | * |
|
| 47 | * @param $fields |
|
| 48 | */ |
|
| 49 | public function removeFields($fields) |
|
| 50 | { |
|
| 51 | $this->fields = $this->fields->reject(function (Field $field) use ($fields) { |
|
| 52 | return in_array($field->column(), $fields); |
|
| 53 | }); |
|
| 54 | } |
|
| 55 | ||
| 56 | /** |
|
| 57 | * Get all filters in this column. |
|
| 58 | * |
|
| 59 | * @return Collection |
|
| 60 | */ |
|
| 61 | public function fields() |
|
| 62 | { |
|
| 63 | return $this->fields; |
|
| 64 | } |
|
| 65 | ||
| 66 | /** |
|
| 67 | * Set column width. |
|
| 68 | * |
|
| 69 | * @param int $width |
|
| 70 | */ |
|
| 71 | public function setWidth($width) |
|
| 72 | { |
|
| 73 | $this->width = $width; |
|
| 74 | } |
|
| 75 | ||
| 76 | /** |
|
| 77 | * Get column width. |
|
| 78 | * |
|
| 79 | * @return int |
|
| 80 | */ |
|
| 81 | public function width() |
|
| 82 | { |
|
| 83 | return $this->width; |
|
| 84 | } |
|
| 85 | } |
|
| 86 | ||
| @@ 8-80 (lines=73) @@ | ||
| 5 | use Encore\Admin\Grid\Filter\AbstractFilter; |
|
| 6 | use Illuminate\Support\Collection; |
|
| 7 | ||
| 8 | class Column |
|
| 9 | { |
|
| 10 | /** |
|
| 11 | * @var Collection |
|
| 12 | */ |
|
| 13 | protected $filters; |
|
| 14 | ||
| 15 | /** |
|
| 16 | * @var int |
|
| 17 | */ |
|
| 18 | protected $width; |
|
| 19 | ||
| 20 | /** |
|
| 21 | * Column constructor. |
|
| 22 | * |
|
| 23 | * @param int $width |
|
| 24 | */ |
|
| 25 | public function __construct($width = 12) |
|
| 26 | { |
|
| 27 | $this->width = $width; |
|
| 28 | $this->filters = new Collection(); |
|
| 29 | } |
|
| 30 | ||
| 31 | /** |
|
| 32 | * Add a filter to this column. |
|
| 33 | * |
|
| 34 | * @param AbstractFilter $filter |
|
| 35 | */ |
|
| 36 | public function addFilter(AbstractFilter $filter) |
|
| 37 | { |
|
| 38 | $this->filters->push($filter); |
|
| 39 | } |
|
| 40 | ||
| 41 | /** |
|
| 42 | * Get all filters in this column. |
|
| 43 | * |
|
| 44 | * @return Collection |
|
| 45 | */ |
|
| 46 | public function filters() |
|
| 47 | { |
|
| 48 | return $this->filters; |
|
| 49 | } |
|
| 50 | ||
| 51 | /** |
|
| 52 | * Set column width. |
|
| 53 | * |
|
| 54 | * @param int $width |
|
| 55 | */ |
|
| 56 | public function setWidth($width) |
|
| 57 | { |
|
| 58 | $this->width = $width; |
|
| 59 | } |
|
| 60 | ||
| 61 | /** |
|
| 62 | * Get column width. |
|
| 63 | * |
|
| 64 | * @return int |
|
| 65 | */ |
|
| 66 | public function width() |
|
| 67 | { |
|
| 68 | return $this->width; |
|
| 69 | } |
|
| 70 | ||
| 71 | /** |
|
| 72 | * Remove filter from column by id. |
|
| 73 | */ |
|
| 74 | public function removeFilterByID($id) |
|
| 75 | { |
|
| 76 | $this->filters = $this->filters->reject(function (AbstractFilter $filter) use ($id) { |
|
| 77 | return $filter->getId() == $id; |
|
| 78 | }); |
|
| 79 | } |
|
| 80 | } |
|
| 81 | ||