ScaleController.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. namespace App\Admin\Controllers;
  3. use App\Models\Scale;
  4. use Encore\Admin\Controllers\AdminController;
  5. use Encore\Admin\Form;
  6. use Encore\Admin\Grid;
  7. use Encore\Admin\Show;
  8. use App\Models\ScaleCategory;
  9. use App\Models\ThirdScale;
  10. class ScaleController extends AdminController
  11. {
  12. /**
  13. * Title for current resource.
  14. *
  15. * @var string
  16. */
  17. // protected $title = '量表内容';
  18. protected $title = '心理评估内容';
  19. /**
  20. * Make a grid builder.
  21. *
  22. * @return Grid
  23. */
  24. protected function grid()
  25. {
  26. $grid = new Grid(new Scale());
  27. $grid->column('id', __('Id'));
  28. $grid->column('category_id', __('分类'))->display(function ($pid) {
  29. if ($pid>0){
  30. $scaleCategoryData = ScaleCategory::find($pid);
  31. if ($scaleCategoryData){
  32. return $scaleCategoryData->name;
  33. }
  34. }
  35. return '';
  36. });
  37. $grid->column('title', __('标题'));
  38. $grid->column('time', __('测试时间'));
  39. $grid->column('suitable_for_the_crowd', __('适合人群'));
  40. $grid->column('number_of_questions', __('问题数'));
  41. $grid->column('number_of_replay', __('报告数'));
  42. $grid->column('number_of_test', __('测试次数'));
  43. $grid->column('rank', __('排序 越大越前'));
  44. $grid->column('created_at', __('创建时间'));
  45. $grid->column('updated_at', __('更新时间'));
  46. return $grid;
  47. }
  48. /**
  49. * Make a show builder.
  50. *
  51. * @param mixed $id
  52. * @return Show
  53. */
  54. protected function detail($id)
  55. {
  56. $show = new Show(Scale::findOrFail($id));
  57. $show->field('id', __('Id'));
  58. $show->field('category_id', __('Category id'));
  59. $show->field('third_id', __('Third id'));
  60. $show->field('title', __('Title'));
  61. $show->field('subtitle', __('Subtitle'));
  62. $show->field('pic', __('Pic'));
  63. $show->field('content', __('Content'));
  64. $show->field('time', __('Time'));
  65. $show->field('suitable_for_the_crowd', __('Suitable for the crowd'));
  66. $show->field('number_of_questions', __('Number of questions'));
  67. $show->field('number_of_replay', __('Number of replay'));
  68. $show->field('number_of_test', __('Number of test'));
  69. $show->field('notice', __('Notice'));
  70. $show->field('rank', __('Rank'));
  71. $show->field('created_at', __('Created at'));
  72. $show->field('updated_at', __('Updated at'));
  73. $show->field('deleted_at', __('Deleted at'));
  74. return $show;
  75. }
  76. /**
  77. * Make a form builder.
  78. *
  79. * @return Form
  80. */
  81. protected function form()
  82. {
  83. $form = new Form(new Scale());
  84. $thirdScale = ThirdScale::get(['id', 'title as name'])->pluck('name','id');
  85. $form->select('third_id', __('远程量表'))->options($thirdScale)->required();
  86. $cloumns = ScaleCategory::get(['id','name'])->pluck('name','id');
  87. $form->select('category_id', __('分类'))->options($cloumns)->required();
  88. $form->text('title', __('标题'))->required();
  89. $form->text('subtitle', __('副标题'))->required();
  90. $form->image('pic', __('图片'))->required();
  91. $form->editor('content', __('内容'))->required();
  92. $form->number('time', __('测试时间(分钟)'))->required();
  93. $form->text('suitable_for_the_crowd', __('适合人群'))->required();
  94. $form->number('number_of_questions', __('问题数'))->default(0);
  95. $form->number('number_of_replay', __('报告数'))->default(0);
  96. $form->number('number_of_test', __('测试次数'))->default(0);
  97. $form->textarea('notice', __('测试须知'))->required();
  98. $form->number('rank', __('排序 越大越前'))->default(0);
  99. $form->list('comment_tag', __('推荐标签'));
  100. return $form;
  101. }
  102. }