SectionAdvController.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Section;
  4. use App\SectionAdv;
  5. use Illuminate\Http\Request;
  6. use File;
  7. class SectionAdvController extends Controller
  8. {
  9. protected $rules = [
  10. // 'name' => ['required']
  11. ];
  12. public function index(Section $section)
  13. {
  14. if ($section->layout == 'layout_1')
  15. {
  16. $aDatas['300x75'] = array();
  17. $aDatas['300x75 Sotto'] = array();
  18. $aDatas['300x600'] = array();
  19. }
  20. if ($section->layout == 'layout_2')
  21. {
  22. $aDatas['300x600'] = array();
  23. $aDatas['300x75'] = array();
  24. $aDatas['300x75 Sotto'] = array();
  25. }
  26. if ($section->layout == 'layout_3')
  27. {
  28. $aDatas['300x600'] = array();
  29. $aDatas['300x250'] = array();
  30. }
  31. if ($section->layout == 'layout_4')
  32. {
  33. $aDatas['300x250 Sopra'] = array();
  34. $aDatas['300x250 Centro'] = array();
  35. $aDatas['300x250 Sotto'] = array();
  36. $aDatas['300x250 Quarto'] = array();
  37. // $aDatas['300x75'] = array();
  38. }
  39. if ($section->layout == 'layout_5')
  40. {
  41. $aDatas['300x75'] = array();
  42. $aDatas['300x250 Sopra'] = array();
  43. $aDatas['300x250 Centro'] = array();
  44. $aDatas['300x250 Sotto'] = array();
  45. }
  46. if ($section->layout == 'layout_6')
  47. {
  48. $aDatas['300x250'] = array();
  49. $aDatas['300x250 Sotto'] = array();
  50. // $aDatas['300x75'] = array();
  51. }
  52. if ($section->layout == 'layout_7')
  53. {
  54. $aDatas['300x250 Sopra'] = array();
  55. $aDatas['300x75 Sopra'] = array();
  56. $aDatas['300x75 Centro'] = array();
  57. $aDatas['300x75 Sotto'] = array();
  58. $aDatas['300x75 Quarto'] = array();
  59. $aDatas['300x250 Sotto'] = array();
  60. }
  61. $sections_advs = SectionAdv::where('section_id', '=', $section->id)->orderBy('position')->get();
  62. foreach($sections_advs as $a)
  63. {
  64. if (array_key_exists($a->position, $aDatas))
  65. $aDatas[$a->position][] = $a;
  66. }
  67. return view('sections_advs.index',compact('aDatas', 'section'));
  68. // ->with('i', (request()->input('page', 1) - 1) * 5);
  69. }
  70. /**
  71. * Show the form for creating a new resource.
  72. *
  73. * @return \Illuminate\Http\Response
  74. */
  75. public function create(Section $section)
  76. {
  77. return view('sections_advs.create', compact('section'));
  78. }
  79. /**
  80. * Store a newly created resource in storage.
  81. *
  82. * @param \Illuminate\Http\Request $request
  83. * @return \Illuminate\Http\Response
  84. */
  85. public function store(Request $request, Section $section, SectionAdv $section_adv)
  86. {
  87. $request->validate($this->rules);
  88. $input = $request->all();
  89. $input["name"] = $input["name"] == null ? '' : $input["name"];
  90. $input["online"] = isset($input["online"]) ? ($input["online"] == 'on' ? true : false) : false;
  91. $input["section_id"] = $section->id;
  92. if(request()->image)
  93. {
  94. $file = request()->image;
  95. $filename = time() . '_' . $file->getClientOriginalName();
  96. if (! File::exists(public_path()."/files/adv"))
  97. File::makeDirectory(public_path()."/files/adv");
  98. $path = public_path('files/adv');
  99. request()->image->move($path, $filename);
  100. $input["image"] = $filename;
  101. }
  102. if(request()->jingle)
  103. {
  104. $file = request()->jingle;
  105. $filename = time() . '_' . $file->getClientOriginalName();
  106. if (! File::exists(public_path()."/files/adv"))
  107. File::makeDirectory(public_path()."/files/adv");
  108. $path = public_path('files/news');
  109. request()->jingle->move($path, $filename);
  110. $input["jingle"] = $filename;
  111. }
  112. SectionAdv::create($input);
  113. return redirect()->route('sections.advs.index', compact('section'))
  114. ->with('success','Section created successfully.');
  115. }
  116. /**
  117. * Display the specified resource.
  118. *
  119. * @param \App\Section $section
  120. * @return \Illuminate\Http\Response
  121. */
  122. public function show(SectionAdv $section_adv, Section $section)
  123. {
  124. return view('sections_advs.show',compact('section'));
  125. }
  126. /**
  127. * Show the form for editing the specified resource.
  128. *
  129. * @param \App\Section $section
  130. * @return \Illuminate\Http\Response
  131. */
  132. public function edit(Section $section, SectionAdv $adv)
  133. {
  134. return view('sections_advs.edit',compact('section', 'adv'));
  135. }
  136. /**
  137. * Update the specified resource in storage.
  138. *
  139. * @param \Illuminate\Http\Request $request
  140. * @param \App\Section $section
  141. * @return \Illuminate\Http\Response
  142. */
  143. public function update(Request $request, Section $section, SectionAdv $adv)
  144. {
  145. $request->validate($this->rules);
  146. $input = $request->all();
  147. $input["name"] = $input["name"] == null ? '' : $input["name"];
  148. $input["online"] = isset($input["online"]) ? ($input["online"] == 'on' ? true : false) : false;
  149. if(request()->image)
  150. {
  151. $file = request()->image;
  152. $filename = time() . '_' . $file->getClientOriginalName();
  153. if (! File::exists(public_path()."/files/adv"))
  154. File::makeDirectory(public_path()."/files/adv");
  155. $path = public_path('files/adv');
  156. request()->image->move($path, $filename);
  157. $input["image"] = $filename;
  158. }
  159. if(request()->jingle)
  160. {
  161. $file = request()->jingle;
  162. $filename = time() . '_' . $file->getClientOriginalName();
  163. if (! File::exists(public_path()."/files/adv"))
  164. File::makeDirectory(public_path()."/files/adv");
  165. $path = public_path('files/news');
  166. request()->jingle->move($path, $filename);
  167. $input["jingle"] = $filename;
  168. }
  169. $adv->update($input);
  170. return redirect()->route('sections.advs.index', compact('section'))
  171. ->with('success','Section adv updated successfully');
  172. }
  173. /**
  174. * Remove the specified resource from storage.
  175. *
  176. * @param \App\Section $section
  177. * @return \Illuminate\Http\Response
  178. */
  179. public function destroy(Section $section, SectionAdv $adv)
  180. {
  181. $adv->delete();
  182. return redirect()->route('sections.advs.index', compact('section'))
  183. ->with('success','Section adv deleted successfully');
  184. }
  185. }