Column.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. /**
  3. * Copyright (c) 2019. Mallto.Co.Ltd.<mall-to.com> All rights reserved.
  4. */
  5. namespace Encore\Admin\Form\Layout;
  6. use Encore\Admin\Form\Field;
  7. use Illuminate\Support\Collection;
  8. class Column
  9. {
  10. /**
  11. * @var Collection
  12. */
  13. protected $fields;
  14. /**
  15. * @var int
  16. */
  17. protected $width;
  18. /**
  19. * Column constructor.
  20. *
  21. * @param int $width
  22. */
  23. public function __construct($width = 12)
  24. {
  25. $this->width = $width;
  26. $this->fields = new Collection();
  27. }
  28. /**
  29. * Add a filter to this column.
  30. *
  31. * @param Field $field
  32. */
  33. public function add(Field $field)
  34. {
  35. $this->fields->push($field);
  36. }
  37. /**
  38. * Remove fields from column.
  39. *
  40. * @param $fields
  41. */
  42. public function removeFields($fields)
  43. {
  44. $this->fields = $this->fields->reject(function (Field $field) use ($fields) {
  45. return in_array($field->column(), $fields);
  46. });
  47. }
  48. /**
  49. * Get all filters in this column.
  50. *
  51. * @return Collection
  52. */
  53. public function fields()
  54. {
  55. return $this->fields;
  56. }
  57. /**
  58. * Set column width.
  59. *
  60. * @param int $width
  61. */
  62. public function setWidth($width)
  63. {
  64. $this->width = $width;
  65. }
  66. /**
  67. * Get column width.
  68. *
  69. * @return int
  70. */
  71. public function width()
  72. {
  73. return $this->width;
  74. }
  75. }