| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154 |
- <?php
-
- namespace App\Http\Controllers;
-
- use App\News;
- use App\Section;
- use App\Event;
- use App\Page;
- use App\Home;
- use Illuminate\Http\Request;
- use File;
- use Auth;
- use App\Notifications\FacebookPost;
- use App\Notifications\TwitterPost;
- class NewsController extends Controller
- {
-
- protected $rules = [
- //'section_id' => ['required']
- 'title' => ['required'],
- //'page_id' => ['required'],
- ];
- public function index(Request $request)
- {
- // Se stavo modificando una news metto a null il campo
- if ($request->session()->has('current_news')) {
- $news_id = session('current_news', 0);
- if ($news_id > 0)
- {
- $n = News::where('id', '=', $news_id)->take(1000)->get();
- if ($n->count() > 0)
- {
- $n = $n->first();
- if ($n->user_id == Auth::user()->id)
- {
- $n->user_id = null;
- $n->save();
- }
- }
- $request->session()->forget('current_news');
- }
- }
- $news = News::orderBy('date', 'DESC')->take(1000)->get();//->paginate(50);
-
- return view('news.index',compact('news'))
- ->with('i', (request()->input('page', 1) - 1) * 5);
- }
-
- public function load_json()
- {
- $start = $_GET["start"];
- $end = 50;//$_GET["length"];
- $total = News::count();
- $filtered = $total;
- $sort_by = '';
- $sort = $_GET["order"][0]["column"];
- switch ($sort) {
- case '0':
- $sort_by = 'date';
- break;
- case '2':
- $sort_by = 'title';
- break;
- case '3':
- $sort_by = 'name';
- break;
- case '4':
- $sort_by = 'name';
- break;
- case '5':
- $sort_by = 'name';
- break;
- case '6':
- $sort_by = 'title';
- break;
- case '7':
- $sort_by = 'online';
- break;
- case '8':
- $sort_by = 'clicks';
- break;
- default:
- $sort_by = 'date';
- break;
- }
- $sort_by_dir = $_GET["order"][0]["dir"];
- $search = $_GET["search"]["value"];
-
- if ($sort == '3')
- {
- $news = News::with(['section' => function ($query) use ($sort_by, $sort_by_dir) {
- $query->orderBy($sort_by, $sort_by_dir);
- }]);
- }
- else if ($sort == '4')
- {
- $news = News::with(['region_1' => function ($query) use ($sort_by, $sort_by_dir) {
- $query->orderBy($sort_by, $sort_by_dir);
- }]);
- }
- else if ($sort == '5')
- {
- $news = News::with(['region_2' => function ($query) use ($sort_by, $sort_by_dir) {
- $query->orderBy($sort_by, $sort_by_dir);
- }]);
- }
- else if ($sort == '6')
- {
- $news = News::with(['event' => function ($query) use ($sort_by, $sort_by_dir) {
- $query->orderBy($sort_by, $sort_by_dir);
- }]);
- }
- else
- $news = News::orderBy($sort_by, $sort_by_dir);
- if ($search != '')
- {
- $news = $news->where('title', 'LIKE', '%' . $search . '%');
- $filtered = $news->count();
- }
- $news = $news->limit($end)->offset($start)->get();//->paginate(50);
- $aData = array();
- foreach($news as $n)
- {
- $x = array();
- $x[] = $n->date;
- if ($n->image != '')
- $x[] = '<img src="/files/news/' . $n->image . '" style="max-width:100px" />';
- else
- $x[] = '';
- $x[] = $n->title;
- $section = @$n->section->name;
- if($n->section)
- $section .= '<br>' . isset($n->section) ? $n->section->position($n->id) : '';
- $x[] = $section;
- $region_1 = @$n->region_1->name;
- if($n->region_1)
- $region_1 .= '<br>' . isset($n->region_1) ? $n->region_1->position($n->id) : '';
- $x[] = $region_1;
- $region_2 = @$n->region_2->name;
- if($n->region_2)
- $region_2 .= '<br>' . isset($n->region_2) ? $n->region_2->position($n->id) : '';
- $x[] = $region_2;
- //$x[] = @$n->event->title;
- $x[] = @$n->online ? '<a si class="btn btn-w-m btn-default" href="/admin/news/status/' . $n->id . '/offline"> Si </a>' : '<a no class="btn btn-w-m btn-default" href="/admin/news/status/' . $n->id . '/online">No</a>';
- $x[] = @$n->clicks;
- $x[] = '<a href="/admin/news/duplicate/' . $n->id . '" type="button" class="btn btn-w-m btn-primary"><i class="fa fa-clone" aria-hidden="true"></i></a>';
- $x[] = '<a href="/admin/news/' . $n->id . '/edit" type="button" class="btn btn-w-m btn-primary"><i class="fa fa-pencil" aria-hidden="true"></i></a>';
- $form = '<form method="POST" action="/admin/news/' . $n->id . '" accept-charset="UTF-8" class="form-inline">
- <input name="_method" type="hidden" value="DELETE">
- <input name="_token" type="hidden" value="' . csrf_token() . '">
- <button type="submit" class="btn btn-w-m btn-danger" onclick="return confirm(\'Sei sicuro?\')"><i class="fa fa-trash-o" aria-hidden="true"></i></button>
- </form>';
- $x[] = $form;
- $aData[] = $x;
- }
- $aRet = array('recordsTotal' => $total, 'recordsFiltered' => $filtered, 'data' => $aData);
- return json_encode($aRet);
- }
- /**
- * Show the form for creating a new resource.
- *
- * @return \Illuminate\Http\Response
- */
- public function create()
- {
- $sections = Section::where('type', '=', 'section')->orderBy('position')->pluck('name', 'id')->toArray();;
- $regions = Section::where('type', '=', 'region')->orderBy('name')->pluck('name', 'id')->toArray();;
- $layouts = Section::pluck('layout', 'id')->toArray();
- $events = Event::orderBy('title')->pluck('title', 'id')->toArray();;
- $pages = Page::where('online', '=', true)->orderBy('title')->pluck('title', 'id')->toArray();;
- $section_position = '';
- $region_1_position = '';
- $region_2_position = '';
- $first = '';
- $aFirst = array();
- $home = Home::first();
- if ($home != null)
- {
- $pos = '';
- $home->loadData();
- if (isset($home->slide1) && $home->slide1 != '')
- $aFirst[] = $home->slide1->title . " (immagine grande)";
- for($a=1;$a<=5;$a++)
- {
- if (isset($home["left" . $a]) && $home["left" . $a] != '')
- $aFirst[] = $home["left" . $a]["title"] . " (slide sinistra)";
- }
- for($a=1;$a<=5;$a++)
- {
- if (isset($home["right" . $a]) && $home["right" . $a] != '')
- $aFirst[] = $home["right" . $a]["title"] . " (slide destra)";
- }
- $first = '<li>' . implode("</li><li>", $aFirst) . '</li>';
- }
- return view('news.create', compact('sections', 'regions', 'events', 'pages', 'layouts', 'section_position', 'region_1_position', 'region_2_position', 'first'));
- }
-
- /**
- * Store a newly created resource in storage.
- *
- * @param \Illuminate\Http\Request $request
- * @return \Illuminate\Http\Response
- */
- public function store(Request $request)
- {
- $request->validate($this->rules);
- $input = $request->all();
- if(request()->image)
- {
- $file = request()->image;
- $filename = time() . '_' . $file->getClientOriginalName();
- if (! File::exists(public_path()."/files/news"))
- File::makeDirectory(public_path()."/files/news");
-
- $path = public_path('files/news');
- request()->image->move($path, $filename);
- $input["image"] = $filename;
- }
- else
- {
- if (isset($_POST["filename"]))
- $input["image"] = $_POST["filename"];
- }
- for($i=1;$i<=5;$i++)
- {
- if(isset($input["image" . $i]))
- {
- $file = $input["image" . $i];
- $filename = time() . '_' . $file->getClientOriginalName();
- if (! File::exists(public_path()."/files/news"))
- File::makeDirectory(public_path()."/files/news");
-
- $path = public_path('files/news');
- $input["image" . $i]->move($path, $filename);
- $input["image" . $i] = $filename;
- }
- }
- if(request()->pdf)
- {
- $file = request()->pdf;
- $filename = time() . '_' . $file->getClientOriginalName();
- if (! File::exists(public_path()."/files/news"))
- File::makeDirectory(public_path()."/files/news");
-
- $path = public_path('files/news');
- request()->pdf->move($path, $filename);
- $input["pdf"] = $filename;
- }
- $final_date = null;
- if ($input["date"] != '')
- {
- list($dt, $time) = explode(" ", $input["date"]);
- list($day, $month, $year) = explode("/", $dt);
- $final_date = $year . "-" . $month . "-" . $day . " " . $time;
- }
- $input["date"] = $final_date;
- // $input["online"] = isset($input["online"]) ? ($input["online"] == 'on' ? true : false) : false;
- $input["online"] = false;
- $input["homepage"] = isset($input["homepage"]) ? ($input["homepage"] == 'on' ? true : false) : false;
- $input["live"] = isset($input["live"]) ? ($input["live"] == 'on' ? true : false) : false;
- $input["breaking_news"] = isset($input["breaking_news"]) ? ($input["breaking_news"] == 'on' ? true : false) : false;
-
- $news = News::create($input);
- if (isset($input['publish']))
- {
- $news->online = true;
- $news->save();
-
- // Posiziono la notizia se la data non è
- if ($final_date <= date("Y-m-d H:i:s"))
- {
- if ($_POST["section_position"] != '')
- {
- $s = Section::findOrFail($input["section_id"]);
- $s[$_POST["section_position"]] = $news->id;
- $s->save();
- $news->section_position = '';
-
- }
- if ($_POST["region_1_position"] != '')
- {
- $s = Section::findOrFail($input["region_1_id"]);
- $s[$_POST["region_1_position"]] = $news->id;
- $s->save();
- $news->region_1_position = '';
- }
- if ($_POST["region_2_position"] != '')
- {
- $s = Section::findOrFail($input["region_2_id"]);
- $s[$_POST["region_2_position"]] = $news->id;
- $s->save();
- $news->region_2_position = '';
- }
- }
- if (isset($input['no_social']))
- {
- }
- else
- {
- @$news->notify(new FacebookPost());
- $news->notify(new TwitterPost());
- $news->published = true;
- $news->save();
- }
- }
- if (isset($input['unpublish']))
- {
- $news->online = false;
- $news->save();
- }
- if ($_POST["homepage_position"] != '' && $news->online)
- {
- $home = Home::first();
- if ($home != null)
- {
- $home->fill([
- $_POST["homepage_position"] => $news->id
- ]);
- $home->save();
- }
- }
- /*
- // Posizione
- if ($_POST["section_position"] != '')
- {
- $field = $input["section_position"];
- $s = Section::findOrFail($input["section_id"]);
- $s->big = ($field != 'big' && $s->big == $news->id) ? '' : $s->big;
- $s->small1 = ($field != 'small1' && $s->small1 == $news->id) ? '' : $s->small1;
- $s->small2 = ($field != 'small2' && $s->small2 == $news->id) ? '' : $s->small2;
- $s->small3 = ($field != 'small3' && $s->small3 == $news->id) ? '' : $s->small3;
- $s->small4 = ($field != 'small4' && $s->small4 == $news->id) ? '' : $s->small4;
- $s->small5 = ($field != 'small5' && $s->small5 == $news->id) ? '' : $s->small5;
- $s->small6 = ($field != 'small6' && $s->small6 == $news->id) ? '' : $s->small6;
- $s->$field = $news->id;
- $s->save();
- // CLEARLAYOUT
- $s->clearLayout();
- }
- if ($_POST["region_1_position"] != '')
- {
- $field = $input["region_1_position"];
- $r = Section::findOrFail($input["region_1_id"]);
- $r->big = ($field != 'big' && $r->big == $news->id) ? '' : $r->big;
- $r->small1 = ($field != 'small1' && $r->small1 == $news->id) ? '' : $r->small1;
- $r->small2 = ($field != 'small2' && $r->small2 == $news->id) ? '' : $r->small2;
- $r->small3 = ($field != 'small3' && $r->small3 == $news->id) ? '' : $r->small3;
- $r->small4 = ($field != 'small4' && $r->small4 == $news->id) ? '' : $r->small4;
- $r->small5 = ($field != 'small5' && $r->small5 == $news->id) ? '' : $r->small5;
- $r->small6 = ($field != 'small6' && $r->small6 == $news->id) ? '' : $r->small6;
- $r->$field = $news->id;
- $r->save();
-
- // CLEARLAYOUT
- $r->clearLayout();
- }
- if ($_POST["region_2_position"] != '')
- {
- $field = $input["region_2_position"];
- $r = Section::findOrFail($input["region_2_id"]);
- $r->big = ($field != 'big' && $r->big == $news->id) ? '' : $r->big;
- $r->small1 = ($field != 'small1' && $r->small1 == $news->id) ? '' : $r->small1;
- $r->small2 = ($field != 'small2' && $r->small2 == $news->id) ? '' : $r->small2;
- $r->small3 = ($field != 'small3' && $r->small3 == $news->id) ? '' : $r->small3;
- $r->small4 = ($field != 'small4' && $r->small4 == $news->id) ? '' : $r->small4;
- $r->small5 = ($field != 'small5' && $r->small5 == $news->id) ? '' : $r->small5;
- $r->small6 = ($field != 'small6' && $r->small6 == $news->id) ? '' : $r->small6;
- $r->$field = $news->id;
- $r->save();
- // CLEARLAYOUT
- $r->clearLayout();
- }
- */
- if (isset($input['publish']))
- return redirect()->route('news.index')->with('success','News updated successfully');
- if (isset($input['unpublish']))
- return redirect()->route('news.index')->with('success','News updated successfully');
- if (isset($input['save']))
- {
- return redirect()->route('news.edit', $news->id)->with('success','News updated successfully');
- }
- if (isset($input['save_exit']))
- {
- return redirect()->route('news.index')->with('success','News updated successfully');
- }
-
- }
-
- /**
- * Display the specified resource.
- *
- * @param \App\News $news
- * @return \Illuminate\Http\Response
- */
- public function show(News $news)
- {
- return view('news.show',compact('news'));
- }
-
- /**
- * Show the form for editing the specified resource.
- *
- * @param \App\News $news
- * @return \Illuminate\Http\Response
- */
- public function edit(News $news)
- {
- // Aggiorno l'utente che sta guardando la news
- if ($news->user_id == null)
- {
- session(['current_news' => $news->id]);
- $news->user_id = Auth::user()->id;
- $news->save();
- }
- $sections = Section::where('type', '=', 'section')->orderBy('position')->pluck('name', 'id')->toArray();;
- $regions = Section::where('type', '=', 'region')->orderBy('name')->pluck('name', 'id')->toArray();;
- $layouts = Section::pluck('layout', 'id')->toArray();
- $events = Event::orderBy('title')->pluck('title', 'id')->toArray();;
- $pages = Page::where('online', '=', true)->orderBy('title')->pluck('title', 'id')->toArray();;
- $final_date = null;
- if ($news->date != null)
- {
- list($dt, $time) = explode(" ", $news->date);
- list($year, $month, $day) = explode("-", $dt);
- $final_date = $day . "/" . $month . "/" . $year . " " . $time;
- }
- /*
- $section_position = '';
- if ($news->section_id > 0)
- {
- if ($news->section->big == $news->id)
- $section_position = 'big';
- if ($news->section->small1 == $news->id)
- $section_position = 'small1';
- if ($news->section->small2 == $news->id)
- $section_position = 'small2';
- if ($news->section->small3 == $news->id)
- $section_position = 'small3';
- if ($news->section->small4 == $news->id)
- $section_position = 'small4';
- if ($news->section->small5 == $news->id)
- $section_position = 'small5';
- if ($news->section->small6 == $news->id)
- $section_position = 'small6';
-
- if ($section_position == null)
- $section_position = $news->section_position;
- }
- $region_1_position = '';
- if ($news->region_1_id > 0)
- {
- if ($news->region_1->big == $news->id)
- $region_1_position = 'big';
- if ($news->region_1->small1 == $news->id)
- $region_1_position = 'small1';
- if ($news->region_1->small2 == $news->id)
- $region_1_position = 'small2';
- if ($news->region_1->small3 == $news->id)
- $region_1_position = 'small3';
- if ($news->region_1->small4 == $news->id)
- $region_1_position = 'small4';
- if ($news->region_1->small5 == $news->id)
- $region_1_position = 'small5';
- if ($news->region_1->small6 == $news->id)
- $region_1_position = 'small6';
- if ($region_1_position == '')
- $region_1_position = $news->region_1_position;
- }
- $region_2_position = '';
- if ($news->region_2_id > 0)
- {
- if ($news->region_2->big == $news->id)
- $region_2_position = 'big';
- if ($news->region_2->small1 == $news->id)
- $region_2_position = 'small1';
- if ($news->region_2->small2 == $news->id)
- $region_2_position = 'small2';
- if ($news->region_2->small3 == $news->id)
- $region_2_position = 'small3';
- if ($news->region_2->small4 == $news->id)
- $region_2_position = 'small4';
- if ($news->region_2->small5 == $news->id)
- $region_2_position = 'small5';
- if ($news->region_2->small6 == $news->id)
- $region_2_position = 'small6';
- if ($region_2_position == '')
- $region_2_position = $news->region_2_position;
- }
- */
- $section_position = $news->section_position;
- $region_1_position = $news->region_1_position;
- $region_2_position = $news->region_2_position;
- $first = '';
- $aFirst = array();
- $home = Home::first();
- if ($home != null)
- {
- $pos = '';
- if ($home->slide1 == $news->id)
- $news->homepage_position = "slide1";
- if ($home->left1 == $news->id)
- $news->homepage_position = "left1";
- if ($home->left2 == $news->id)
- $news->homepage_position = "left2";
- if ($home->left3 == $news->id)
- $news->homepage_position = "left3";
- if ($home->right1 == $news->id)
- $news->homepage_position = "right1";
- if ($home->right2 == $news->id)
- $news->homepage_position = "right2";
- if ($home->right3 == $news->id)
- $news->homepage_position = "right3";
- $home->loadData();
- if (isset($home->slide1) && $home->slide1 != '')
- $aFirst[] = $home->slide1->title . " (immagine grande)";
- for($a=1;$a<=5;$a++)
- {
- if (isset($home["left" . $a]) && $home["left" . $a] != '')
- $aFirst[] = $home["left" . $a]["title"] . " (slide sinistra)";
-
- }
- for($a=1;$a<=5;$a++)
- {
- if (isset($home["right" . $a]) && $home["right" . $a] != '')
- $aFirst[] = $home["right" . $a]["title"] . " (slide destra)";
- }
- $first = '<li>' . implode("</li><li>", $aFirst) . '</li>';
- }
-
- $news->date = $final_date;
- return view('news.edit',compact('news', 'sections', 'regions', 'pages', 'events', 'layouts', 'section_position', 'region_1_position', 'region_2_position', 'first'));
- }
-
- /**
- * Update the specified resource in storage.
- *
- * @param \Illuminate\Http\Request $request
- * @param \App\News $news
- * @return \Illuminate\Http\Response
- */
- public function update(Request $request, News $news)
- {
- $request->validate($this->rules);
- $input = $request->all();
- $old_section_id = $news->section_id;
- $old_region_1_id = $news->region_1_id;
- $old_region_2_id = $news->region_2_id;
- $old_event_id = $news->event_id;
- $section_position = '';
- if ($news->section_id > 0)
- {
- if ($news->section->big == $news->id)
- $section_position = 'big';
- /*if ($news->section->medium1 == $news->id)
- $section_position = 'medium1';
- if ($news->section->medium2 == $news->id)
- $section_position = 'medium2';
- if ($news->section->medium3 == $news->id)
- $section_position = 'medium3';*/
- if ($news->section->small1 == $news->id)
- $section_position = 'small1';
- if ($news->section->small2 == $news->id)
- $section_position = 'small2';
- if ($news->section->small3 == $news->id)
- $section_position = 'small3';
- if ($news->section->small4 == $news->id)
- $section_position = 'small4';
- if ($news->section->small5 == $news->id)
- $section_position = 'small5';
- if ($news->section->small6 == $news->id)
- $section_position = 'small6';
-
- if ($section_position == null)
- $section_position = $news->section_position;
- }
- $region_1_position = '';
- if ($news->region_1_id > 0)
- {
- if ($news->region_1->big == $news->id)
- $region_1_position = 'big';
- /*if ($news->region_1->medium1 == $news->id)
- $region_1_position = 'medium1';
- if ($news->region_1->medium2 == $news->id)
- $region_1_position = 'medium2';
- if ($news->region_1->medium3 == $news->id)
- $region_1_position = 'medium3';*/
- if ($news->region_1->small1 == $news->id)
- $region_1_position = 'small1';
- if ($news->region_1->small2 == $news->id)
- $region_1_position = 'small2';
- if ($news->region_1->small3 == $news->id)
- $region_1_position = 'small3';
- if ($news->region_1->small4 == $news->id)
- $region_1_position = 'small4';
- if ($news->region_1->small5 == $news->id)
- $region_1_position = 'small5';
- if ($news->region_1->small6 == $news->id)
- $region_1_position = 'small6';
- if ($region_1_position == '')
- $region_1_position = $news->region_1_position;
- }
- $region_2_position = '';
- if ($news->region_2_id > 0)
- {
- if ($news->region_2->big == $news->id)
- $region_2_position = 'big';
- /*if ($news->region_2->medium1 == $news->id)
- $region_2_position = 'medium1';
- if ($news->region_2->medium2 == $news->id)
- $region_2_position = 'medium2';
- if ($news->region_2->medium3 == $news->id)
- $region_2_position = 'medium3';*/
- if ($news->region_2->small1 == $news->id)
- $region_2_position = 'small1';
- if ($news->region_2->small2 == $news->id)
- $region_2_position = 'small2';
- if ($news->region_2->small3 == $news->id)
- $region_2_position = 'small3';
- if ($news->region_2->small4 == $news->id)
- $region_2_position = 'small4';
- if ($news->region_2->small5 == $news->id)
- $region_2_position = 'small5';
- if ($news->region_2->small6 == $news->id)
- $region_2_position = 'small6';
- if ($region_2_position == '')
- $region_2_position = $news->region_2_position;
- }
- if ($old_section_id == $input["section_id"] && $section_position == $input["section_position"])
- unset($input["section_position"]);
-
- if ($old_region_1_id == $input["region_1_id"] && $region_1_position == $input["region_1_position"])
- unset($input["region_1_position"]);
- if ($old_region_2_id == $input["region_2_id"] && $region_2_position == $input["region_2_position"])
- unset($input["region_2_position"]);
- if(request()->image)
- {
- $file = request()->image;
- $filename = time() . '_' . $file->getClientOriginalName();
- if (! File::exists(public_path()."/files/news"))
- File::makeDirectory(public_path()."/files/news");
-
- $path = public_path('files/news');
- request()->image->move($path, $filename);
- $input["image"] = $filename;
- }
- for($i=1;$i<=5;$i++)
- {
- if(isset($input["image" . $i]))
- {
- $file = $input["image" . $i];
- $filename = time() . '_' . $file->getClientOriginalName();
- if (! File::exists(public_path()."/files/news"))
- File::makeDirectory(public_path()."/files/news");
-
- $path = public_path('files/news');
- $input["image" . $i]->move($path, $filename);
- $input["image" . $i] = $filename;
- }
- }
- if (isset($input["remove_pdf"]))
- {
- $input["pdf"] = '';
- }
- if(request()->pdf)
- {
- $file = request()->pdf;
- $filename = time() . '_' . $file->getClientOriginalName();
- if (! File::exists(public_path()."/files/news"))
- File::makeDirectory(public_path()."/files/news");
-
- $path = public_path('files/news');
- request()->pdf->move($path, $filename);
- $input["pdf"] = $filename;
- }
- $final_date = null;
- if ($input["date"] != '')
- {
- list($dt, $time) = explode(" ", $input["date"]);
- list($day, $month, $year) = explode("/", $dt);
- $final_date = $year . "-" . $month . "-" . $day . " " . $time;
- }
- $input["date"] = $final_date;
- // $input["online"] = isset($input["online"]) ? ($input["online"] == 'on' ? true : false) : false;
- $input["homepage"] = isset($input["homepage"]) ? ($input["homepage"] == 'on' ? true : false) : false;
- $input["live"] = isset($input["live"]) ? ($input["live"] == 'on' ? true : false) : false;
- $input["breaking_news"] = isset($input["breaking_news"]) ? ($input["breaking_news"] == 'on' ? true : false) : false;
-
- $news->update($input);
- $news->user_id = null;
- $news->save();
- $request->session()->forget('current_news');
- if (isset($input['publish']))
- {
-
- $news->online = true;
- $news->save();
- if (isset($input['no_social']))
- {
- // Non pubblico sui social
- }
- else
- {
- @$news->notify(new FacebookPost());
- $news->notify(new TwitterPost());
- $news->published = true;
- $news->save();
- }
-
- }
- if (isset($input['unpublish']))
- {
- $news->online = false;
- $news->save();
- }
- if ($_POST["homepage_position"] != '' && $news->online)
- {
- $home = Home::first();
- if ($home != null)
- {
- $home->fill([
- $_POST["homepage_position"] => $news->id
- ]);
- $home->save();
- }
- }
-
- if ($news->event_id != $old_event_id)
- {
- $e = Event::where('id', '=', $old_event_id)->first();
- if ($e)
- {
- if ($e->big == $news->id)
- $e->big = '';
- if ($e->small1 == $news->id)
- $e->small1 = '';
- if ($e->small2 == $news->id)
- $e->small2 = '';
- if ($e->small3 == $news->id)
- $e->small3 = '';
- if ($e->small4 == $news->id)
- $e->small4 = '';
- $e->save();
- }
- }
- /*
- // Posizione
- if ($_POST["section_position"] != '')
- {
- if ($input["section_id"] == '')
- {
- if ($old_section_id > 0)
- {
- $s_old = Section::findOrFail($old_section_id);
- $s_old->big = ($s_old->big == $news->id) ? '' : $s_old->big;
- $s_old->small1 = ($s_old->small1 == $news->id) ? '' : $s_old->small1;
- $s_old->small2 = ($s_old->small2 == $news->id) ? '' : $s_old->small2;
- $s_old->small3 = ($s_old->small3 == $news->id) ? '' : $s_old->small3;
- $s_old->small4 = ($s_old->small4 == $news->id) ? '' : $s_old->small4;
- $s_old->small5 = ($s_old->small5 == $news->id) ? '' : $s_old->small5;
- $s_old->small6 = ($s_old->small6 == $news->id) ? '' : $s_old->small6;
- $s_old->save();
- // CLEARLAYOUT
- $s_old->clearLayout();
- }
- }
- else
- {
- // Se online e data > adesso
- if ($news->online && $news->data < date("Y-m-d H:i:s"))
- {
- $field = $input["section_position"];
- $s = Section::findOrFail($input["section_id"]);
- // Se ho cambiato sezione, tolgo dalla vecchia me metto nella nuova
- if ($input["section_id"] != $old_section_id)
- {
- if ($old_section_id > 0)
- {
- $s_old = Section::findOrFail($old_section_id);
- $s_old->big = ($s_old->big == $news->id) ? '' : $s_old->big;
- $s_old->small1 = ($s_old->small1 == $news->id) ? '' : $s_old->small1;
- $s_old->small2 = ($s_old->small2 == $news->id) ? '' : $s_old->small2;
- $s_old->small3 = ($s_old->small3 == $news->id) ? '' : $s_old->small3;
- $s_old->small4 = ($s_old->small4 == $news->id) ? '' : $s_old->small4;
- $s_old->small5 = ($s_old->small5 == $news->id) ? '' : $s_old->small5;
- $s_old->small6 = ($s_old->small6 == $news->id) ? '' : $s_old->small6;
- $s_old->save();
- // CLEARLAYOUT
- $s_old->clearLayout();
- }
- }
- else
- {
- $s->big = ($field != 'big' && $s->big == $news->id) ? '' : $s->big;
- $s->small1 = ($field != 'small1' && $s->small1 == $news->id) ? '' : $s->small1;
- $s->small2 = ($field != 'small2' && $s->small2 == $news->id) ? '' : $s->small2;
- $s->small3 = ($field != 'small3' && $s->small3 == $news->id) ? '' : $s->small3;
- $s->small4 = ($field != 'small4' && $s->small4 == $news->id) ? '' : $s->small4;
- $s->small5 = ($field != 'small5' && $s->small5 == $news->id) ? '' : $s->small5;
- $s->small6 = ($field != 'small6' && $s->small6 == $news->id) ? '' : $s->small6;
- }
- $s->$field = $news->id;
- $s->save();
-
- // CLEARLAYOUT
- $s->clearLayout();
-
- }
- }
- }
- else
- {
-
- if ($input["section_id"] == '')
- {
- if ($old_section_id > 0)
- {
- $s_old = Section::findOrFail($old_section_id);
- $s_old->big = ($s_old->big == $news->id) ? '' : $s_old->big;
- $s_old->small1 = ($s_old->small1 == $news->id) ? '' : $s_old->small1;
- $s_old->small2 = ($s_old->small2 == $news->id) ? '' : $s_old->small2;
- $s_old->small3 = ($s_old->small3 == $news->id) ? '' : $s_old->small3;
- $s_old->small4 = ($s_old->small4 == $news->id) ? '' : $s_old->small4;
- $s_old->small5 = ($s_old->small5 == $news->id) ? '' : $s_old->small5;
- $s_old->small6 = ($s_old->small6 == $news->id) ? '' : $s_old->small6;
- $s_old->save();
- // CLEARLAYOUT
- $s_old->clearLayout();
- }
- }
- else
- {
- if ($input["section_id"] != $old_section_id)
- {
- $s_old = Section::findOrFail($old_section_id);
- $s_old->big = ($s_old->big == $news->id) ? '' : $s_old->big;
- $s_old->small1 = ($s_old->small1 == $news->id) ? '' : $s_old->small1;
- $s_old->small2 = ($s_old->small2 == $news->id) ? '' : $s_old->small2;
- $s_old->small3 = ($s_old->small3 == $news->id) ? '' : $s_old->small3;
- $s_old->small4 = ($s_old->small4 == $news->id) ? '' : $s_old->small4;
- $s_old->small5 = ($s_old->small5 == $news->id) ? '' : $s_old->small5;
- $s_old->small6 = ($s_old->small6 == $news->id) ? '' : $s_old->small6;
- $s_old->save();
- // CLEARLAYOUT
- $s_old->clearLayout();
- }
- else
- {
-
- $s_old = Section::findOrFail($input["section_id"]);
- $s_old->big = ($s_old->big == $news->id) ? '' : $s_old->big;
- $s_old->small1 = ($s_old->small1 == $news->id) ? '' : $s_old->small1;
- $s_old->small2 = ($s_old->small2 == $news->id) ? '' : $s_old->small2;
- $s_old->small3 = ($s_old->small3 == $news->id) ? '' : $s_old->small3;
- $s_old->small4 = ($s_old->small4 == $news->id) ? '' : $s_old->small4;
- $s_old->small5 = ($s_old->small5 == $news->id) ? '' : $s_old->small5;
- $s_old->small6 = ($s_old->small6 == $news->id) ? '' : $s_old->small6;
- print $s_old->small3;
- $s_old->save();
- // CLEARLAYOUT
- $s_old->clearLayout();
- }
- }
- }
- if ($_POST["region_1_position"] != '')
- {
- if ($input["region_1_id"] == '')
- {
- if ($old_region_1_id > 0)
- {
- $s_old = Section::findOrFail($old_region_1_id);
- $s_old->big = ($s_old->big == $news->id) ? '' : $s_old->big;
- $s_old->small1 = ($s_old->small1 == $news->id) ? '' : $s_old->small1;
- $s_old->small2 = ($s_old->small2 == $news->id) ? '' : $s_old->small2;
- $s_old->small3 = ($s_old->small3 == $news->id) ? '' : $s_old->small3;
- $s_old->small4 = ($s_old->small4 == $news->id) ? '' : $s_old->small4;
- $s_old->small5 = ($s_old->small5 == $news->id) ? '' : $s_old->small5;
- $s_old->small6 = ($s_old->small6 == $news->id) ? '' : $s_old->small6;
- $s_old->save();
- // CLEARLAYOUT
- $s_old->clearLayout();
- }
- }
- else
- {
- $field = $input["region_1_position"];
- $r = Section::findOrFail($input["region_1_id"]);
- // Se ho cambiato sezione, tolgo dalla vecchia me metto nella nuova
- if ($input["region_1_id"] != $old_region_1_id)
- {
- if ($old_region_1_id > 0)
- {
- $s_old = Section::findOrFail($old_region_1_id);
- $s_old->big = ($s_old->big == $news->id) ? '' : $s_old->big;
- $s_old->small1 = ($s_old->small1 == $news->id) ? '' : $s_old->small1;
- $s_old->small2 = ($s_old->small2 == $news->id) ? '' : $s_old->small2;
- $s_old->small3 = ($s_old->small3 == $news->id) ? '' : $s_old->small3;
- $s_old->small4 = ($s_old->small4 == $news->id) ? '' : $s_old->small4;
- $s_old->small5 = ($s_old->small5 == $news->id) ? '' : $s_old->small5;
- $s_old->small6 = ($s_old->small6 == $news->id) ? '' : $s_old->small6;
- $s_old->save();
- // CLEARLAYOUT
- $s_old->clearLayout();
- }
- }
- else
- {
- $r->big = ($field != 'big' && $r->big == $news->id) ? '' : $r->big;
- $r->small1 = ($field != 'small1' && $r->small1 == $news->id) ? '' : $r->small1;
- $r->small2 = ($field != 'small2' && $r->small2 == $news->id) ? '' : $r->small2;
- $r->small3 = ($field != 'small3' && $r->small3 == $news->id) ? '' : $r->small3;
- $r->small4 = ($field != 'small4' && $r->small4 == $news->id) ? '' : $r->small4;
- $r->small5 = ($field != 'small5' && $r->small5 == $news->id) ? '' : $r->small5;
- $r->small6 = ($field != 'small6' && $r->small6 == $news->id) ? '' : $r->small6;
- }
- $r->$field = $news->id;
- $r->save();
- // CLEARLAYOUT
- $r->clearLayout();
- }
- }
- if ($_POST["region_2_position"] != '')
- {
- if ($input["region_2_id"] == '')
- {
- if ($old_region_2_id > 0)
- {
- $s_old = Section::findOrFail($old_region_2_id);
- $s_old->big = ($s_old->big == $news->id) ? '' : $s_old->big;
- $s_old->small1 = ($s_old->small1 == $news->id) ? '' : $s_old->small1;
- $s_old->small2 = ($s_old->small2 == $news->id) ? '' : $s_old->small2;
- $s_old->small3 = ($s_old->small3 == $news->id) ? '' : $s_old->small3;
- $s_old->small4 = ($s_old->small4 == $news->id) ? '' : $s_old->small4;
- $s_old->small5 = ($s_old->small5 == $news->id) ? '' : $s_old->small5;
- $s_old->small6 = ($s_old->small6 == $news->id) ? '' : $s_old->small6;
- $s_old->save();
- // CLEARLAYOUT
- $s_old->clearLayout();
- }
- }
- else
- {
- $field = $input["region_2_position"];
- $r = Section::findOrFail($input["region_2_id"]);
- // Se ho cambiato sezione, tolgo dalla vecchia me metto nella nuova
- if ($input["region_2_id"] != $old_region_2_id)
- {
- if ($old_region_2_id > 0)
- {
- $s_old = Section::findOrFail($old_region_2_id);
- $s_old->big = ($s_old->big == $news->id) ? '' : $s_old->big;
- $s_old->small1 = ($s_old->small1 == $news->id) ? '' : $s_old->small1;
- $s_old->small2 = ($s_old->small2 == $news->id) ? '' : $s_old->small2;
- $s_old->small3 = ($s_old->small3 == $news->id) ? '' : $s_old->small3;
- $s_old->small4 = ($s_old->small4 == $news->id) ? '' : $s_old->small4;
- $s_old->small5 = ($s_old->small5 == $news->id) ? '' : $s_old->small5;
- $s_old->small6 = ($s_old->small6 == $news->id) ? '' : $s_old->small6;
- $s_old->save();
- // CLEARLAYOUT
- $s_old->clearLayout();
- }
- }
- else
- {
- $r->big = ($field != 'big' && $r->big == $news->id) ? '' : $r->big;
- $r->small1 = ($field != 'small1' && $r->small1 == $news->id) ? '' : $r->small1;
- $r->small2 = ($field != 'small2' && $r->small2 == $news->id) ? '' : $r->small2;
- $r->small3 = ($field != 'small3' && $r->small3 == $news->id) ? '' : $r->small3;
- $r->small4 = ($field != 'small4' && $r->small4 == $news->id) ? '' : $r->small4;
- $r->small5 = ($field != 'small5' && $r->small5 == $news->id) ? '' : $r->small5;
- $r->small6 = ($field != 'small6' && $r->small6 == $news->id) ? '' : $r->small6;
- }
- $r->$field = $news->id;
- $r->save();
- // CLEARLAYOUT
- $r->clearLayout();
- }
- }
- */
- if (isset($input['publish']))
- {
-
- return redirect()->route('news.index')->with('success','News updated successfully');
- }
- if (isset($input['crop']))
- {
- return redirect('/admin/news/crop?news_id=' . $news->id);
- // return redirect()->route('news.crop')->with('success','News updated successfully');
- }
- if (isset($input['unpublish']))
- {
- return redirect()->route('news.index')->with('success','News updated successfully');
- }
- if (isset($input['save']))
- {
- return redirect()->route('news.edit', $news->id)->with('success','News updated successfully');
- }
- if (isset($input['save_exit']))
- {
- return redirect()->route('news.index')->with('success','News updated successfully');
- }
- }
-
- /**
- * Remove the specified resource from storage.
- *
- * @param \App\News $news
- * @return \Illuminate\Http\Response
- */
- public function destroy(News $news)
- {
- $section = null;
- if (isset($news->section))
- {
- $section = $news->section;
- }
- $region_1 = null;
- if (isset($news->region_1))
- {
- $region_1 = $news->region_1;
- }
- $region_2 = null;
- if (isset($news->region_2))
- {
- $region_2 = $news->region_2;
- }
- $news->delete();
- /*if ($section != null)
- {
- // CLEARLAYOUT
- $section->clearLayout();
- }
- if ($region_1 != null)
- {
- // CLEARLAYOUT
- $region_1->clearLayout();
- }
- if ($region_2 != null)
- {
- // CLEARLAYOUT
- $region_2->clearLayout();
- }*/
-
- return redirect()->route('news.index')
- ->with('success','News deleted successfully');
- }
- }
|