HasNames.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. namespace Dcat\Admin\Grid\Concerns;
  3. use Dcat\Admin\Grid;
  4. /**
  5. * @method Grid\Model model()
  6. */
  7. trait HasNames
  8. {
  9. /**
  10. * Grid name.
  11. *
  12. * @var string
  13. */
  14. protected $_name;
  15. /**
  16. * Set name to grid.
  17. *
  18. * @param string $name
  19. * @return $this
  20. */
  21. public function setName($name)
  22. {
  23. $this->_name = $name;
  24. $this->tableId = $this->makeName($this->tableId);
  25. return $this;
  26. }
  27. /**
  28. * Get name of grid.
  29. *
  30. * @return string
  31. */
  32. public function getName()
  33. {
  34. return $this->_name;
  35. }
  36. /**
  37. * Retrieve an input item from the request.
  38. *
  39. * @param string $key
  40. * @return mixed
  41. */
  42. public function getRequestInput($key)
  43. {
  44. return $this->request->get($this->makeName($key));
  45. }
  46. /**
  47. * @param string $key
  48. * @return string
  49. */
  50. public function makeName($key)
  51. {
  52. return $this->getNamePrefix().$key;
  53. }
  54. /**
  55. * @return string
  56. */
  57. public function getNamePrefix()
  58. {
  59. if (! $name = $this->getName()) {
  60. return;
  61. }
  62. return $name.'_';
  63. }
  64. /**
  65. * @return string
  66. */
  67. public function getRowName()
  68. {
  69. return $this->makeName('grid-row');
  70. }
  71. /**
  72. * @return string
  73. */
  74. public function getSelectAllName()
  75. {
  76. return $this->makeName('grid-select-all');
  77. }
  78. /**
  79. * @return string
  80. */
  81. public function getPerPageName()
  82. {
  83. return $this->makeName('grid-per-page');
  84. }
  85. /**
  86. * @return string
  87. */
  88. public function getExportSelectedName()
  89. {
  90. return $this->makeName('export-selected');
  91. }
  92. }