|
|
@@ -12,6 +12,8 @@ use Illuminate\Support\Facades\File;
|
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
use App\Notifications\FacebookPost;
|
|
|
use App\Notifications\TwitterPost;
|
|
|
+use Illuminate\Support\Facades\Log;
|
|
|
+
|
|
|
class NewsController extends Controller
|
|
|
{
|
|
|
|
|
|
@@ -27,14 +29,11 @@ class NewsController extends Controller
|
|
|
// 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)
|
|
|
- {
|
|
|
+ if ($news_id > 0) {
|
|
|
$n = News::where('id', '=', $news_id)->take(1000)->get();
|
|
|
- if ($n->count() > 0)
|
|
|
- {
|
|
|
+ if ($n->count() > 0) {
|
|
|
$n = $n->first();
|
|
|
- if ($n->user_id == Auth::user()->id)
|
|
|
- {
|
|
|
+ if ($n->user_id == Auth::user()->id) {
|
|
|
$n->user_id = null;
|
|
|
$n->save();
|
|
|
}
|
|
|
@@ -43,16 +42,16 @@ class NewsController extends Controller
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- $news = News::orderBy('date', 'DESC')->take(1000)->get();//->paginate(50);
|
|
|
+ $news = News::orderBy('date', 'DESC')->take(1000)->get(); //->paginate(50);
|
|
|
|
|
|
- return view('news.index',compact('news'))
|
|
|
+ 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"];
|
|
|
+ $end = 50; //$_GET["length"];
|
|
|
$total = News::count();
|
|
|
$filtered = $total;
|
|
|
|
|
|
@@ -92,44 +91,34 @@ class NewsController extends Controller
|
|
|
|
|
|
$search = $_GET["search"]["value"];
|
|
|
|
|
|
- if ($sort == '3')
|
|
|
- {
|
|
|
+ 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')
|
|
|
- {
|
|
|
+ } 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')
|
|
|
- {
|
|
|
+ } 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')
|
|
|
- {
|
|
|
+ } else if ($sort == '6') {
|
|
|
$news = News::with(['event' => function ($query) use ($sort_by, $sort_by_dir) {
|
|
|
$query->orderBy($sort_by, $sort_by_dir);
|
|
|
}]);
|
|
|
- }
|
|
|
- else
|
|
|
+ } else
|
|
|
$news = News::orderBy($sort_by, $sort_by_dir);
|
|
|
|
|
|
- if ($search != '')
|
|
|
- {
|
|
|
+ if ($search != '') {
|
|
|
$news = $news->where('title', 'LIKE', '%' . $search . '%');
|
|
|
$filtered = $news->count();
|
|
|
}
|
|
|
|
|
|
- $news = $news->limit($end)->offset($start)->get();//->paginate(50);
|
|
|
+ $news = $news->limit($end)->offset($start)->get(); //->paginate(50);
|
|
|
|
|
|
$aData = array();
|
|
|
- foreach($news as $n)
|
|
|
- {
|
|
|
+ foreach ($news as $n) {
|
|
|
$x = array();
|
|
|
$x[] = $n->date;
|
|
|
if ($n->image != '')
|
|
|
@@ -138,15 +127,15 @@ class NewsController extends Controller
|
|
|
$x[] = '';
|
|
|
$x[] = $n->title;
|
|
|
$section = @$n->section->name;
|
|
|
- if($n->section)
|
|
|
+ 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)
|
|
|
+ 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)
|
|
|
+ if ($n->region_2)
|
|
|
$region_2 .= '<br>' . isset($n->region_2) ? $n->region_2->position($n->id) : '';
|
|
|
$x[] = $region_2;
|
|
|
//$x[] = @$n->event->title;
|
|
|
@@ -187,19 +176,16 @@ class NewsController extends Controller
|
|
|
$first = '';
|
|
|
$aFirst = array();
|
|
|
$home = Home::first();
|
|
|
- if ($home != null)
|
|
|
- {
|
|
|
+ if ($home != null) {
|
|
|
$pos = '';
|
|
|
$home->loadData();
|
|
|
if (isset($home->slide1) && $home->slide1 != '')
|
|
|
$aFirst[] = $home->slide1->title . " (immagine grande)";
|
|
|
- for($a=1;$a<=5;$a++)
|
|
|
- {
|
|
|
+ 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++)
|
|
|
- {
|
|
|
+ for ($a = 1; $a <= 5; $a++) {
|
|
|
if (isset($home["right" . $a]) && $home["right" . $a] != '')
|
|
|
$aFirst[] = $home["right" . $a]["title"] . " (slide destra)";
|
|
|
}
|
|
|
@@ -215,165 +201,220 @@ class NewsController extends Controller
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
* @return \Illuminate\Http\Response
|
|
|
*/
|
|
|
+
|
|
|
public function store(Request $request)
|
|
|
{
|
|
|
- $request->validate($this->rules);
|
|
|
+ Log::info('=== NEWS STORE METHOD START ===');
|
|
|
+ Log::info('Request data:', $request->all());
|
|
|
+ Log::info('Request method:', [$request->method()]);
|
|
|
|
|
|
- $input = $request->all();
|
|
|
-
|
|
|
- if(request()->image)
|
|
|
- {
|
|
|
+ try {
|
|
|
+ $request->validate($this->rules);
|
|
|
+ Log::info('Validation passed');
|
|
|
|
|
|
- $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');
|
|
|
+ $input = $request->all();
|
|
|
+ Log::info('Input data:', $input);
|
|
|
|
|
|
- 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]))
|
|
|
- {
|
|
|
+ // Check which button was clicked
|
|
|
+ if (isset($input['save'])) {
|
|
|
+ Log::info('SAVE button clicked');
|
|
|
+ }
|
|
|
+ if (isset($input['save_exit'])) {
|
|
|
+ Log::info('SAVE_EXIT button clicked');
|
|
|
+ }
|
|
|
+ if (isset($input['publish'])) {
|
|
|
+ Log::info('PUBLISH button clicked');
|
|
|
+ }
|
|
|
+ if (isset($input['unpublish'])) {
|
|
|
+ Log::info('UNPUBLISH button clicked');
|
|
|
+ }
|
|
|
|
|
|
- $file = $input["image" . $i];
|
|
|
+ // Image handling
|
|
|
+ if (request()->image) {
|
|
|
+ Log::info('Processing main image upload');
|
|
|
+ $file = request()->image;
|
|
|
$filename = time() . '_' . $file->getClientOriginalName();
|
|
|
|
|
|
- if (! File::exists(public_path()."/files/news"))
|
|
|
- File::makeDirectory(public_path()."/files/news");
|
|
|
+ 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;
|
|
|
-
|
|
|
+ request()->image->move($path, $filename);
|
|
|
+ $input["image"] = $filename;
|
|
|
+ Log::info('Main image uploaded:', [$filename]);
|
|
|
+ } else {
|
|
|
+ if (isset($input["filename"])) {
|
|
|
+ $input["image"] = $input["filename"];
|
|
|
+ Log::info('Using existing filename:', [$input["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);
|
|
|
+ // Handle additional images
|
|
|
+ for ($i = 1; $i <= 5; $i++) {
|
|
|
+ if (isset($input["image" . $i])) {
|
|
|
+ Log::info("Processing image{$i} upload");
|
|
|
+ $file = $input["image" . $i];
|
|
|
+ $filename = time() . '_' . $file->getClientOriginalName();
|
|
|
|
|
|
- $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"] = 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;
|
|
|
+ if (! File::exists(public_path() . "/files/news"))
|
|
|
+ File::makeDirectory(public_path() . "/files/news");
|
|
|
|
|
|
- $news = News::create($input);
|
|
|
+ $path = public_path('files/news');
|
|
|
+ $input["image" . $i]->move($path, $filename);
|
|
|
+ $input["image" . $i] = $filename;
|
|
|
+ Log::info("Image{$i} uploaded:", [$filename]);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- if (isset($input['publish']))
|
|
|
- {
|
|
|
- $news->online = true;
|
|
|
- $news->save();
|
|
|
+ // Handle PDF
|
|
|
+ if (request()->pdf) {
|
|
|
+ Log::info('Processing PDF upload');
|
|
|
+ $file = request()->pdf;
|
|
|
+ $filename = time() . '_' . $file->getClientOriginalName();
|
|
|
|
|
|
- // Posiziono la notizia se la data non è
|
|
|
- if ($final_date <= date("Y-m-d H:i:s"))
|
|
|
- {
|
|
|
+ if (! File::exists(public_path() . "/files/news"))
|
|
|
+ File::makeDirectory(public_path() . "/files/news");
|
|
|
|
|
|
- if ($_POST["section_position"] != '')
|
|
|
- {
|
|
|
- $s = Section::findOrFail($input["section_id"]);
|
|
|
- $s[$_POST["section_position"]] = $news->id;
|
|
|
- $s->save();
|
|
|
- $news->section_position = '';
|
|
|
+ $path = public_path('files/news');
|
|
|
+ request()->pdf->move($path, $filename);
|
|
|
+ $input["pdf"] = $filename;
|
|
|
+ Log::info('PDF uploaded:', [$filename]);
|
|
|
+ }
|
|
|
|
|
|
+ // Date processing
|
|
|
+ $final_date = null;
|
|
|
+ if ($input["date"] != '') {
|
|
|
+ list($dt, $time) = explode(" ", $input["date"]);
|
|
|
+ list($day, $month, $year) = explode("/", $dt);
|
|
|
+ $final_date = $year . "-" . $month . "-" . $day . " " . $time;
|
|
|
+ Log::info('Date processed:', [$input["date"], $final_date]);
|
|
|
+ }
|
|
|
+ $input["date"] = $final_date;
|
|
|
+
|
|
|
+ // Handle checkboxes
|
|
|
+ $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;
|
|
|
+ $input["no_social"] = isset($input["no_social"]) ? ($input["no_social"] == 'on' ? true : false) : false;
|
|
|
+
|
|
|
+ Log::info('Checkbox values:', [
|
|
|
+ 'homepage' => $input["homepage"],
|
|
|
+ 'live' => $input["live"],
|
|
|
+ 'breaking_news' => $input["breaking_news"],
|
|
|
+ 'no_social' => $input["no_social"]
|
|
|
+ ]);
|
|
|
+
|
|
|
+ Log::info('About to create news record');
|
|
|
+ $news = News::create($input);
|
|
|
+ Log::info('News created with ID:', [$news->id]);
|
|
|
+
|
|
|
+ // Handle publish action
|
|
|
+ if (isset($input['publish'])) {
|
|
|
+ Log::info('Processing publish action');
|
|
|
+ $news->online = true;
|
|
|
+ $news->save();
|
|
|
+ Log::info('News set to online');
|
|
|
+
|
|
|
+ // Position the news if date is not in future
|
|
|
+ if ($final_date <= date("Y-m-d H:i:s")) {
|
|
|
+ Log::info('Date is not in future, processing positions');
|
|
|
+
|
|
|
+ if ($input["section_position"] != '') {
|
|
|
+ Log::info('Processing section position:', [$input["section_position"]]);
|
|
|
+ $s = Section::findOrFail($input["section_id"]);
|
|
|
+ $s[$input["section_position"]] = $news->id;
|
|
|
+ $s->save();
|
|
|
+ $news->section_position = '';
|
|
|
+ }
|
|
|
+ if ($input["region_1_position"] != '') {
|
|
|
+ Log::info('Processing region_1 position:', [$input["region_1_position"]]);
|
|
|
+ $s = Section::findOrFail($input["region_1_id"]);
|
|
|
+ $s[$input["region_1_position"]] = $news->id;
|
|
|
+ $s->save();
|
|
|
+ $news->region_1_position = '';
|
|
|
+ }
|
|
|
+ if ($input["region_2_position"] != '') {
|
|
|
+ Log::info('Processing region_2 position:', [$input["region_2_position"]]);
|
|
|
+ $s = Section::findOrFail($input["region_2_id"]);
|
|
|
+ $s[$input["region_2_position"]] = $news->id;
|
|
|
+ $s->save();
|
|
|
+ $news->region_2_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 = '';
|
|
|
+
|
|
|
+ // Handle social media posting
|
|
|
+ if (!isset($input['no_social'])) {
|
|
|
+ Log::info('Processing social media notifications');
|
|
|
+ try {
|
|
|
+ @$news->notify(new FacebookPost());
|
|
|
+ $news->notify(new TwitterPost());
|
|
|
+ $news->published = true;
|
|
|
+ $news->save();
|
|
|
+ Log::info('Social media notifications sent');
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ Log::error('Error sending social notifications:', [$e->getMessage()]);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ Log::info('Skipping social media (no_social flag set)');
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
+ if (isset($input['unpublish'])) {
|
|
|
+ Log::info('Processing unpublish action');
|
|
|
+ $news->online = false;
|
|
|
+ $news->save();
|
|
|
}
|
|
|
- if (isset($input['no_social']))
|
|
|
- {
|
|
|
+
|
|
|
+ // Handle homepage position
|
|
|
+ if ($input["homepage_position"] != '' && $news->online) {
|
|
|
+ Log::info('Processing homepage position:', [$input["homepage_position"]]);
|
|
|
+ $home = Home::first();
|
|
|
+ if ($home != null) {
|
|
|
+ $home->fill([
|
|
|
+ $input["homepage_position"] => $news->id
|
|
|
+ ]);
|
|
|
+ $home->save();
|
|
|
+ Log::info('Homepage position saved');
|
|
|
+ }
|
|
|
}
|
|
|
- else
|
|
|
- {
|
|
|
- @$news->notify(new FacebookPost());
|
|
|
- $news->notify(new TwitterPost());
|
|
|
- $news->published = true;
|
|
|
- $news->save();
|
|
|
+
|
|
|
+ // Determine redirect based on action
|
|
|
+ Log::info('=== DETERMINING REDIRECT ===');
|
|
|
+
|
|
|
+ if (isset($input['publish'])) {
|
|
|
+ Log::info('Redirecting after publish to news.index');
|
|
|
+ return redirect()->route('news.index')->with('success', 'News published successfully');
|
|
|
}
|
|
|
|
|
|
- }
|
|
|
- if (isset($input['unpublish']))
|
|
|
- {
|
|
|
- $news->online = false;
|
|
|
- $news->save();
|
|
|
- }
|
|
|
+ if (isset($input['unpublish'])) {
|
|
|
+ Log::info('Redirecting after unpublish to news.index');
|
|
|
+ return redirect()->route('news.index')->with('success', 'News unpublished successfully');
|
|
|
+ }
|
|
|
|
|
|
- if ($_POST["homepage_position"] != '' && $news->online)
|
|
|
- {
|
|
|
- $home = Home::first();
|
|
|
- if ($home != null)
|
|
|
- {
|
|
|
- $home->fill([
|
|
|
- $_POST["homepage_position"] => $news->id
|
|
|
- ]);
|
|
|
- $home->save();
|
|
|
+ if (isset($input['save'])) {
|
|
|
+ Log::info('Redirecting after save to news.edit');
|
|
|
+ return redirect()->route('news.edit', $news->id)->with('success', 'News saved successfully');
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- if (isset($input['publish']))
|
|
|
- return redirect()->route('news.index')->with('success','News updated successfully');
|
|
|
+ if (isset($input['save_exit'])) {
|
|
|
+ Log::info('Redirecting after save_exit to news.index');
|
|
|
+ return redirect()->route('news.index')->with('success', 'News saved successfully');
|
|
|
+ }
|
|
|
|
|
|
- if (isset($input['unpublish']))
|
|
|
- return redirect()->route('news.index')->with('success','News updated successfully');
|
|
|
+ Log::info('No specific action, redirecting to news.index');
|
|
|
+ return redirect()->route('news.index')->with('success', 'News created successfully');
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ Log::error('=== ERROR IN STORE METHOD ===');
|
|
|
+ Log::error('Error message:', [$e->getMessage()]);
|
|
|
+ Log::error('Error file:', [$e->getFile()]);
|
|
|
+ Log::error('Error line:', [$e->getLine()]);
|
|
|
+ Log::error('Stack trace:', [$e->getTraceAsString()]);
|
|
|
|
|
|
- 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');
|
|
|
+ return redirect()->back()
|
|
|
+ ->withInput()
|
|
|
+ ->with('error', 'An error occurred while saving the news: ' . $e->getMessage());
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -384,7 +425,7 @@ class NewsController extends Controller
|
|
|
*/
|
|
|
public function show(News $news)
|
|
|
{
|
|
|
- return view('news.show',compact('news'));
|
|
|
+ return view('news.show', compact('news'));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -397,8 +438,7 @@ class NewsController extends Controller
|
|
|
{
|
|
|
|
|
|
// Aggiorno l'utente che sta guardando la news
|
|
|
- if ($news->user_id == null)
|
|
|
- {
|
|
|
+ if ($news->user_id == null) {
|
|
|
session(['current_news' => $news->id]);
|
|
|
$news->user_id = Auth::user()->id;
|
|
|
$news->save();
|
|
|
@@ -410,8 +450,7 @@ class NewsController extends Controller
|
|
|
$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)
|
|
|
- {
|
|
|
+ if ($news->date != null) {
|
|
|
list($dt, $time) = explode(" ", $news->date);
|
|
|
list($year, $month, $day) = explode("-", $dt);
|
|
|
$final_date = $day . "/" . $month . "/" . $year . " " . $time;
|
|
|
@@ -423,8 +462,7 @@ class NewsController extends Controller
|
|
|
$first = '';
|
|
|
$aFirst = array();
|
|
|
$home = Home::first();
|
|
|
- if ($home != null)
|
|
|
- {
|
|
|
+ if ($home != null) {
|
|
|
$pos = '';
|
|
|
if ($home->slide1 == $news->id)
|
|
|
$news->homepage_position = "slide1";
|
|
|
@@ -443,14 +481,11 @@ class NewsController extends Controller
|
|
|
$home->loadData();
|
|
|
if (isset($home->slide1) && $home->slide1 != '')
|
|
|
$aFirst[] = $home->slide1->title . " (immagine grande)";
|
|
|
- for($a=1;$a<=5;$a++)
|
|
|
- {
|
|
|
+ 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++)
|
|
|
- {
|
|
|
+ for ($a = 1; $a <= 5; $a++) {
|
|
|
if (isset($home["right" . $a]) && $home["right" . $a] != '')
|
|
|
$aFirst[] = $home["right" . $a]["title"] . " (slide destra)";
|
|
|
}
|
|
|
@@ -460,7 +495,7 @@ class NewsController extends Controller
|
|
|
|
|
|
$news->date = $final_date;
|
|
|
|
|
|
- return view('news.edit',compact('news', 'sections', 'regions', 'pages', 'events', 'layouts', 'section_position', 'region_1_position', 'region_2_position', 'first'));
|
|
|
+ return view('news.edit', compact('news', 'sections', 'regions', 'pages', 'events', 'layouts', 'section_position', 'region_1_position', 'region_2_position', 'first'));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -472,7 +507,11 @@ class NewsController extends Controller
|
|
|
*/
|
|
|
public function update(Request $request, News $news)
|
|
|
{
|
|
|
+ Log::info('=== NEWS UPDATE METHOD START ===');
|
|
|
+ Log::info('News ID:', [$news->id]);
|
|
|
+ Log::info('Request data:', $request->all());
|
|
|
$request->validate($this->rules);
|
|
|
+ Log::info('Validation passed');
|
|
|
|
|
|
$input = $request->all();
|
|
|
|
|
|
@@ -483,8 +522,7 @@ class NewsController extends Controller
|
|
|
$old_event_id = $news->event_id;
|
|
|
|
|
|
$section_position = '';
|
|
|
- if ($news->section_id > 0)
|
|
|
- {
|
|
|
+ if ($news->section_id > 0) {
|
|
|
if ($news->section->big == $news->id)
|
|
|
$section_position = 'big';
|
|
|
if ($news->section->small1 == $news->id)
|
|
|
@@ -502,12 +540,9 @@ class NewsController extends Controller
|
|
|
|
|
|
if ($section_position == null)
|
|
|
$section_position = $news->section_position;
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
$region_1_position = '';
|
|
|
- if ($news->region_1_id > 0)
|
|
|
- {
|
|
|
+ if ($news->region_1_id > 0) {
|
|
|
if ($news->region_1->big == $news->id)
|
|
|
$region_1_position = 'big';
|
|
|
if ($news->region_1->small1 == $news->id)
|
|
|
@@ -525,11 +560,9 @@ class NewsController extends Controller
|
|
|
|
|
|
if ($region_1_position == '')
|
|
|
$region_1_position = $news->region_1_position;
|
|
|
-
|
|
|
}
|
|
|
$region_2_position = '';
|
|
|
- if ($news->region_2_id > 0)
|
|
|
- {
|
|
|
+ if ($news->region_2_id > 0) {
|
|
|
if ($news->region_2->big == $news->id)
|
|
|
$region_2_position = 'big';
|
|
|
if ($news->region_2->small1 == $news->id)
|
|
|
@@ -547,7 +580,6 @@ class NewsController extends Controller
|
|
|
|
|
|
if ($region_2_position == '')
|
|
|
$region_2_position = $news->region_2_position;
|
|
|
-
|
|
|
}
|
|
|
|
|
|
if ($old_section_id == $input["section_id"] && $section_position == $input["section_position"])
|
|
|
@@ -559,69 +591,62 @@ class NewsController extends Controller
|
|
|
if ($old_region_2_id == $input["region_2_id"] && $region_2_position == $input["region_2_position"])
|
|
|
unset($input["region_2_position"]);
|
|
|
|
|
|
- if(request()->image)
|
|
|
- {
|
|
|
+ if (request()->image) {
|
|
|
+ Log::info('Processing image update');
|
|
|
|
|
|
$file = request()->image;
|
|
|
$filename = time() . '_' . $file->getClientOriginalName();
|
|
|
|
|
|
- if (! File::exists(public_path()."/files/news"))
|
|
|
- File::makeDirectory(public_path()."/files/news");
|
|
|
+ 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]))
|
|
|
- {
|
|
|
+ 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");
|
|
|
+ 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"]))
|
|
|
- {
|
|
|
+ if (isset($input["remove_pdf"])) {
|
|
|
$input["pdf"] = '';
|
|
|
}
|
|
|
- if(request()->pdf)
|
|
|
- {
|
|
|
+ if (request()->pdf) {
|
|
|
|
|
|
$file = request()->pdf;
|
|
|
$filename = time() . '_' . $file->getClientOriginalName();
|
|
|
|
|
|
- if (! File::exists(public_path()."/files/news"))
|
|
|
- File::makeDirectory(public_path()."/files/news");
|
|
|
+ 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"] != '')
|
|
|
- {
|
|
|
+ if ($input["date"] != '') {
|
|
|
list($dt, $time) = explode(" ", $input["date"]);
|
|
|
list($day, $month, $year) = explode("/", $dt);
|
|
|
$final_date = $year . "-" . $month . "-" . $day . " " . $time;
|
|
|
+ Log::info('Date processed for update:', [$input["date"], $final_date]);
|
|
|
}
|
|
|
$input["date"] = $final_date;
|
|
|
|
|
|
@@ -630,42 +655,36 @@ class NewsController extends Controller
|
|
|
$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;
|
|
|
|
|
|
+ Log::info('About to update news record');
|
|
|
$news->update($input);
|
|
|
+ Log::info('News updated');
|
|
|
|
|
|
$news->user_id = null;
|
|
|
$news->save();
|
|
|
$request->session()->forget('current_news');
|
|
|
|
|
|
- if (isset($input['publish']))
|
|
|
- {
|
|
|
+ if (isset($input['publish'])) {
|
|
|
|
|
|
$news->online = true;
|
|
|
$news->save();
|
|
|
|
|
|
- if (isset($input['no_social']))
|
|
|
- {
|
|
|
+ if (isset($input['no_social'])) {
|
|
|
// Non pubblico sui social
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
+ } else {
|
|
|
|
|
|
$news->published = true;
|
|
|
$news->save();
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
- if (isset($input['unpublish']))
|
|
|
- {
|
|
|
+ if (isset($input['unpublish'])) {
|
|
|
$news->online = false;
|
|
|
|
|
|
$news->save();
|
|
|
}
|
|
|
|
|
|
- if ($_POST["homepage_position"] != '' && $news->online)
|
|
|
- {
|
|
|
+ if ($_POST["homepage_position"] != '' && $news->online) {
|
|
|
$home = Home::first();
|
|
|
- if ($home != null)
|
|
|
- {
|
|
|
+ if ($home != null) {
|
|
|
$home->fill([
|
|
|
$_POST["homepage_position"] => $news->id
|
|
|
]);
|
|
|
@@ -673,11 +692,9 @@ class NewsController extends Controller
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if ($news->event_id != $old_event_id)
|
|
|
- {
|
|
|
+ if ($news->event_id != $old_event_id) {
|
|
|
$e = Event::where('id', '=', $old_event_id)->first();
|
|
|
- if ($e)
|
|
|
- {
|
|
|
+ if ($e) {
|
|
|
if ($e->big == $news->id)
|
|
|
$e->big = '';
|
|
|
if ($e->small1 == $news->id)
|
|
|
@@ -692,28 +709,35 @@ class NewsController extends Controller
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if (isset($input['publish']))
|
|
|
- {
|
|
|
+ Log::info('=== DETERMINING REDIRECT FOR UPDATE ===');
|
|
|
|
|
|
- return redirect()->route('news.index')->with('success','News updated successfully');
|
|
|
+ if (isset($input['publish'])) {
|
|
|
+ Log::info('Redirecting after publish to news.index');
|
|
|
+ return redirect()->route('news.index')->with('success', 'News published successfully');
|
|
|
}
|
|
|
- if (isset($input['crop']))
|
|
|
- {
|
|
|
+
|
|
|
+ if (isset($input['crop'])) {
|
|
|
+ Log::info('Redirecting to crop page');
|
|
|
return redirect('/admin/news/crop?news_id=' . $news->id);
|
|
|
}
|
|
|
- if (isset($input['unpublish']))
|
|
|
- {
|
|
|
- return redirect()->route('news.index')->with('success','News updated successfully');
|
|
|
+
|
|
|
+ if (isset($input['unpublish'])) {
|
|
|
+ Log::info('Redirecting after unpublish to news.index');
|
|
|
+ return redirect()->route('news.index')->with('success', 'News unpublished successfully');
|
|
|
}
|
|
|
- if (isset($input['save']))
|
|
|
- {
|
|
|
- return redirect()->route('news.edit', $news->id)->with('success','News updated successfully');
|
|
|
+
|
|
|
+ if (isset($input['save'])) {
|
|
|
+ Log::info('Redirecting after save to news.edit');
|
|
|
+ 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');
|
|
|
+
|
|
|
+ if (isset($input['save_exit'])) {
|
|
|
+ Log::info('Redirecting after save_exit to news.index');
|
|
|
+ return redirect()->route('news.index')->with('success', 'News updated successfully');
|
|
|
}
|
|
|
|
|
|
+ Log::info('No specific action, redirecting to news.edit');
|
|
|
+ return redirect()->route('news.edit', $news->id)->with('success', 'News updated successfully');
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -725,24 +749,21 @@ class NewsController extends Controller
|
|
|
public function destroy(News $news)
|
|
|
{
|
|
|
$section = null;
|
|
|
- if (isset($news->section))
|
|
|
- {
|
|
|
+ if (isset($news->section)) {
|
|
|
$section = $news->section;
|
|
|
}
|
|
|
$region_1 = null;
|
|
|
- if (isset($news->region_1))
|
|
|
- {
|
|
|
+ if (isset($news->region_1)) {
|
|
|
$region_1 = $news->region_1;
|
|
|
}
|
|
|
$region_2 = null;
|
|
|
- if (isset($news->region_2))
|
|
|
- {
|
|
|
+ if (isset($news->region_2)) {
|
|
|
$region_2 = $news->region_2;
|
|
|
}
|
|
|
|
|
|
$news->delete();
|
|
|
|
|
|
return redirect()->route('news.index')
|
|
|
- ->with('success','News deleted successfully');
|
|
|
+ ->with('success', 'News deleted successfully');
|
|
|
}
|
|
|
}
|