FabioFratini 1 год назад
Родитель
Сommit
fe8d9a7168
2 измененных файлов с 65 добавлено и 471 удалено
  1. 41 447
      app/Http/Controllers/NewsController.php
  2. 24 24
      app/Http/Controllers/PageController.php

+ 41 - 447
app/Http/Controllers/NewsController.php

@@ -1,20 +1,20 @@
 <?php
 <?php
-  
+
 namespace App\Http\Controllers;
 namespace App\Http\Controllers;
-  
+
 use App\News;
 use App\News;
 use App\Section;
 use App\Section;
 use App\Event;
 use App\Event;
 use App\Page;
 use App\Page;
 use App\Home;
 use App\Home;
 use Illuminate\Http\Request;
 use Illuminate\Http\Request;
-use File;
-use Auth;
+use Illuminate\Support\Facades\File;
+use Illuminate\Support\Facades\Auth;
 use App\Notifications\FacebookPost;
 use App\Notifications\FacebookPost;
 use App\Notifications\TwitterPost;
 use App\Notifications\TwitterPost;
 class NewsController extends Controller
 class NewsController extends Controller
 {
 {
-    
+
     protected $rules = [
     protected $rules = [
         //'section_id' => ['required']
         //'section_id' => ['required']
         'title' => ['required'],
         'title' => ['required'],
@@ -44,11 +44,11 @@ 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);
             ->with('i', (request()->input('page', 1) - 1) * 5);
     }
     }
-   
+
     public function load_json()
     public function load_json()
     {
     {
         $start = $_GET["start"];
         $start = $_GET["start"];
@@ -91,7 +91,7 @@ class NewsController extends Controller
 
 
 
 
         $search = $_GET["search"]["value"];
         $search = $_GET["search"]["value"];
-        
+
         if ($sort == '3')
         if ($sort == '3')
         {
         {
             $news = News::with(['section' => function ($query) use ($sort_by, $sort_by_dir) {
             $news = News::with(['section' => function ($query) use ($sort_by, $sort_by_dir) {
@@ -160,7 +160,7 @@ class NewsController extends Controller
                 <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>
                 <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>';
             </form>';
             $x[] = $form;
             $x[] = $form;
-            $aData[] = $x;            
+            $aData[] = $x;
         }
         }
         $aRet = array('recordsTotal' => $total, 'recordsFiltered' => $filtered, 'data' => $aData);
         $aRet = array('recordsTotal' => $total, 'recordsFiltered' => $filtered, 'data' => $aData);
         return json_encode($aRet);
         return json_encode($aRet);
@@ -208,7 +208,7 @@ class NewsController extends Controller
 
 
         return view('news.create', compact('sections', 'regions', 'events', 'pages', 'layouts', 'section_position', 'region_1_position', 'region_2_position', 'first'));
         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.
      * Store a newly created resource in storage.
      *
      *
@@ -229,7 +229,7 @@ class NewsController extends Controller
 
 
             if (! File::exists(public_path()."/files/news"))
             if (! File::exists(public_path()."/files/news"))
                 File::makeDirectory(public_path()."/files/news");
                 File::makeDirectory(public_path()."/files/news");
-            
+
             $path = public_path('files/news');
             $path = public_path('files/news');
 
 
             request()->image->move($path, $filename);
             request()->image->move($path, $filename);
@@ -253,7 +253,7 @@ class NewsController extends Controller
 
 
                 if (! File::exists(public_path()."/files/news"))
                 if (! File::exists(public_path()."/files/news"))
                     File::makeDirectory(public_path()."/files/news");
                     File::makeDirectory(public_path()."/files/news");
-                
+
                 $path = public_path('files/news');
                 $path = public_path('files/news');
 
 
                 $input["image" . $i]->move($path, $filename);
                 $input["image" . $i]->move($path, $filename);
@@ -271,7 +271,7 @@ class NewsController extends Controller
 
 
             if (! File::exists(public_path()."/files/news"))
             if (! File::exists(public_path()."/files/news"))
                 File::makeDirectory(public_path()."/files/news");
                 File::makeDirectory(public_path()."/files/news");
-            
+
             $path = public_path('files/news');
             $path = public_path('files/news');
 
 
             request()->pdf->move($path, $filename);
             request()->pdf->move($path, $filename);
@@ -289,20 +289,19 @@ class NewsController extends Controller
         }
         }
         $input["date"] = $final_date;
         $input["date"] = $final_date;
 
 
-        // $input["online"] = isset($input["online"]) ? ($input["online"] == 'on' ? true : false) : false;
         $input["online"] = false;
         $input["online"] = false;
         $input["homepage"] = isset($input["homepage"]) ? ($input["homepage"] == '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["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["breaking_news"] = isset($input["breaking_news"]) ? ($input["breaking_news"] == 'on' ? true : false) : false;
-  
+
         $news = News::create($input);
         $news = News::create($input);
 
 
         if (isset($input['publish']))
         if (isset($input['publish']))
         {
         {
             $news->online = true;
             $news->online = true;
             $news->save();
             $news->save();
-            
-            // Posiziono la notizia se la data non è 
+
+            // Posiziono la notizia se la data non è
             if ($final_date <= date("Y-m-d H:i:s"))
             if ($final_date <= date("Y-m-d H:i:s"))
             {
             {
 
 
@@ -312,7 +311,7 @@ class NewsController extends Controller
                     $s[$_POST["section_position"]] = $news->id;
                     $s[$_POST["section_position"]] = $news->id;
                     $s->save();
                     $s->save();
                     $news->section_position = '';
                     $news->section_position = '';
-                    
+
                 }
                 }
                 if ($_POST["region_1_position"] != '')
                 if ($_POST["region_1_position"] != '')
                 {
                 {
@@ -360,61 +359,6 @@ class NewsController extends Controller
             }
             }
         }
         }
 
 
-        /*
-        // 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']))
         if (isset($input['publish']))
             return redirect()->route('news.index')->with('success','News updated successfully');
             return redirect()->route('news.index')->with('success','News updated successfully');
 
 
@@ -429,9 +373,9 @@ class NewsController extends Controller
         {
         {
             return redirect()->route('news.index')->with('success','News updated successfully');
             return redirect()->route('news.index')->with('success','News updated successfully');
         }
         }
-   
+
     }
     }
-   
+
     /**
     /**
      * Display the specified resource.
      * Display the specified resource.
      *
      *
@@ -442,7 +386,7 @@ class NewsController extends Controller
     {
     {
         return view('news.show',compact('news'));
         return view('news.show',compact('news'));
     }
     }
-   
+
     /**
     /**
      * Show the form for editing the specified resource.
      * Show the form for editing the specified resource.
      *
      *
@@ -472,75 +416,7 @@ class NewsController extends Controller
             list($year, $month, $day) = explode("-", $dt);
             list($year, $month, $day) = explode("-", $dt);
             $final_date = $day . "/" . $month . "/" . $year . " " . $time;
             $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;
         $section_position = $news->section_position;
         $region_1_position = $news->region_1_position;
         $region_1_position = $news->region_1_position;
         $region_2_position = $news->region_2_position;
         $region_2_position = $news->region_2_position;
@@ -571,7 +447,7 @@ class NewsController extends Controller
             {
             {
                 if (isset($home["left" . $a]) && $home["left" . $a] != '')
                 if (isset($home["left" . $a]) && $home["left" . $a] != '')
                     $aFirst[] = $home["left" . $a]["title"] . " (slide sinistra)";
                     $aFirst[] = $home["left" . $a]["title"] . " (slide sinistra)";
-                
+
             }
             }
             for($a=1;$a<=5;$a++)
             for($a=1;$a<=5;$a++)
             {
             {
@@ -581,12 +457,12 @@ class NewsController extends Controller
             $first = '<li>' . implode("</li><li>", $aFirst) . '</li>';
             $first = '<li>' . implode("</li><li>", $aFirst) . '</li>';
         }
         }
 
 
-        
+
         $news->date = $final_date;
         $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'));
     }
     }
-  
+
     /**
     /**
      * Update the specified resource in storage.
      * Update the specified resource in storage.
      *
      *
@@ -611,12 +487,6 @@ class NewsController extends Controller
         {
         {
             if ($news->section->big == $news->id)
             if ($news->section->big == $news->id)
                 $section_position = 'big';
                 $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)
             if ($news->section->small1 == $news->id)
                 $section_position = 'small1';
                 $section_position = 'small1';
             if ($news->section->small2 == $news->id)
             if ($news->section->small2 == $news->id)
@@ -629,7 +499,7 @@ class NewsController extends Controller
                 $section_position = 'small5';
                 $section_position = 'small5';
             if ($news->section->small6 == $news->id)
             if ($news->section->small6 == $news->id)
                 $section_position = 'small6';
                 $section_position = 'small6';
-            
+
             if ($section_position == null)
             if ($section_position == null)
                 $section_position = $news->section_position;
                 $section_position = $news->section_position;
 
 
@@ -640,12 +510,6 @@ class NewsController extends Controller
         {
         {
             if ($news->region_1->big == $news->id)
             if ($news->region_1->big == $news->id)
                 $region_1_position = 'big';
                 $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)
             if ($news->region_1->small1 == $news->id)
                 $region_1_position = 'small1';
                 $region_1_position = 'small1';
             if ($news->region_1->small2 == $news->id)
             if ($news->region_1->small2 == $news->id)
@@ -668,12 +532,6 @@ class NewsController extends Controller
         {
         {
             if ($news->region_2->big == $news->id)
             if ($news->region_2->big == $news->id)
                 $region_2_position = 'big';
                 $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)
             if ($news->region_2->small1 == $news->id)
                 $region_2_position = 'small1';
                 $region_2_position = 'small1';
             if ($news->region_2->small2 == $news->id)
             if ($news->region_2->small2 == $news->id)
@@ -694,7 +552,7 @@ class NewsController extends Controller
 
 
         if ($old_section_id == $input["section_id"] && $section_position == $input["section_position"])
         if ($old_section_id == $input["section_id"] && $section_position == $input["section_position"])
             unset($input["section_position"]);
             unset($input["section_position"]);
-        
+
         if ($old_region_1_id == $input["region_1_id"] && $region_1_position == $input["region_1_position"])
         if ($old_region_1_id == $input["region_1_id"] && $region_1_position == $input["region_1_position"])
             unset($input["region_1_position"]);
             unset($input["region_1_position"]);
 
 
@@ -709,7 +567,7 @@ class NewsController extends Controller
 
 
             if (! File::exists(public_path()."/files/news"))
             if (! File::exists(public_path()."/files/news"))
                 File::makeDirectory(public_path()."/files/news");
                 File::makeDirectory(public_path()."/files/news");
-            
+
             $path = public_path('files/news');
             $path = public_path('files/news');
 
 
             request()->image->move($path, $filename);
             request()->image->move($path, $filename);
@@ -727,7 +585,7 @@ class NewsController extends Controller
 
 
                 if (! File::exists(public_path()."/files/news"))
                 if (! File::exists(public_path()."/files/news"))
                     File::makeDirectory(public_path()."/files/news");
                     File::makeDirectory(public_path()."/files/news");
-                
+
                 $path = public_path('files/news');
                 $path = public_path('files/news');
 
 
                 $input["image" . $i]->move($path, $filename);
                 $input["image" . $i]->move($path, $filename);
@@ -749,7 +607,7 @@ class NewsController extends Controller
 
 
             if (! File::exists(public_path()."/files/news"))
             if (! File::exists(public_path()."/files/news"))
                 File::makeDirectory(public_path()."/files/news");
                 File::makeDirectory(public_path()."/files/news");
-            
+
             $path = public_path('files/news');
             $path = public_path('files/news');
 
 
             request()->pdf->move($path, $filename);
             request()->pdf->move($path, $filename);
@@ -771,7 +629,7 @@ class NewsController extends Controller
         $input["homepage"] = isset($input["homepage"]) ? ($input["homepage"] == '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["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["breaking_news"] = isset($input["breaking_news"]) ? ($input["breaking_news"] == 'on' ? true : false) : false;
-        
+
         $news->update($input);
         $news->update($input);
 
 
         $news->user_id = null;
         $news->user_id = null;
@@ -780,7 +638,7 @@ class NewsController extends Controller
 
 
         if (isset($input['publish']))
         if (isset($input['publish']))
         {
         {
-            
+
             $news->online = true;
             $news->online = true;
             $news->save();
             $news->save();
 
 
@@ -790,16 +648,16 @@ class NewsController extends Controller
             }
             }
             else
             else
             {
             {
-                @$news->notify(new FacebookPost());
-                $news->notify(new TwitterPost());
+
                 $news->published = true;
                 $news->published = true;
                 $news->save();
                 $news->save();
             }
             }
-            
+
         }
         }
         if (isset($input['unpublish']))
         if (isset($input['unpublish']))
         {
         {
             $news->online = false;
             $news->online = false;
+
             $news->save();
             $news->save();
         }
         }
 
 
@@ -810,11 +668,11 @@ class NewsController extends Controller
             {
             {
                 $home->fill([
                 $home->fill([
                     $_POST["homepage_position"] => $news->id
                     $_POST["homepage_position"] => $news->id
-                ]);                
+                ]);
                 $home->save();
                 $home->save();
             }
             }
         }
         }
-        
+
         if ($news->event_id != $old_event_id)
         if ($news->event_id != $old_event_id)
         {
         {
             $e = Event::where('id', '=', $old_event_id)->first();
             $e = Event::where('id', '=', $old_event_id)->first();
@@ -834,262 +692,14 @@ class NewsController extends Controller
             }
             }
         }
         }
 
 
-        /*
-        // 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']))
         if (isset($input['publish']))
         {
         {
-            
+
             return redirect()->route('news.index')->with('success','News updated successfully');
             return redirect()->route('news.index')->with('success','News updated successfully');
         }
         }
         if (isset($input['crop']))
         if (isset($input['crop']))
         {
         {
             return redirect('/admin/news/crop?news_id=' . $news->id);
             return redirect('/admin/news/crop?news_id=' . $news->id);
-            // return redirect()->route('news.crop')->with('success','News updated successfully');
         }
         }
         if (isset($input['unpublish']))
         if (isset($input['unpublish']))
         {
         {
@@ -1105,7 +715,7 @@ class NewsController extends Controller
         }
         }
 
 
     }
     }
-  
+
     /**
     /**
      * Remove the specified resource from storage.
      * Remove the specified resource from storage.
      *
      *
@@ -1117,38 +727,22 @@ class NewsController extends Controller
         $section = null;
         $section = null;
         if (isset($news->section))
         if (isset($news->section))
         {
         {
-            $section = $news->section;            
+            $section = $news->section;
         }
         }
         $region_1 = null;
         $region_1 = null;
         if (isset($news->region_1))
         if (isset($news->region_1))
         {
         {
-            $region_1 = $news->region_1;            
+            $region_1 = $news->region_1;
         }
         }
         $region_2 = null;
         $region_2 = null;
         if (isset($news->region_2))
         if (isset($news->region_2))
         {
         {
-            $region_2 = $news->region_2;            
+            $region_2 = $news->region_2;
         }
         }
 
 
         $news->delete();
         $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')
         return redirect()->route('news.index')
                         ->with('success','News deleted successfully');
                         ->with('success','News deleted successfully');
     }
     }
-}
+}

+ 24 - 24
app/Http/Controllers/PageController.php

@@ -1,16 +1,16 @@
 <?php
 <?php
-  
+
 namespace App\Http\Controllers;
 namespace App\Http\Controllers;
-  
+
 use App\Page;
 use App\Page;
 use App\PageAdv;
 use App\PageAdv;
 use App\News;
 use App\News;
 use Illuminate\Http\Request;
 use Illuminate\Http\Request;
-use File;
-  
+use Illuminate\Support\Facades\File;
+
 class PageController extends Controller
 class PageController extends Controller
 {
 {
-    
+
     protected $rules = [
     protected $rules = [
         'title' => ['required']
         'title' => ['required']
     ];
     ];
@@ -18,11 +18,11 @@ class PageController extends Controller
     public function index()
     public function index()
     {
     {
         $pages = Page::orderBy('title')->get(); //->paginate(50);
         $pages = Page::orderBy('title')->get(); //->paginate(50);
-  
+
         return view('pages.index',compact('pages'))
         return view('pages.index',compact('pages'))
             ->with('i', (request()->input('page', 1) - 1) * 5);
             ->with('i', (request()->input('page', 1) - 1) * 5);
     }
     }
-   
+
     /**
     /**
      * Show the form for creating a new resource.
      * Show the form for creating a new resource.
      *
      *
@@ -32,7 +32,7 @@ class PageController extends Controller
     {
     {
         return view('pages.create');
         return view('pages.create');
     }
     }
-  
+
     /**
     /**
      * Store a newly created resource in storage.
      * Store a newly created resource in storage.
      *
      *
@@ -42,7 +42,7 @@ class PageController extends Controller
     public function store(Request $request)
     public function store(Request $request)
     {
     {
         $request->validate($this->rules);
         $request->validate($this->rules);
-  
+
         $input = $request->all();
         $input = $request->all();
         $input["online"] = isset($input["online"]) ? ($input["online"] == 'on' ? true : false) : false;
         $input["online"] = isset($input["online"]) ? ($input["online"] == 'on' ? true : false) : false;
 
 
@@ -54,7 +54,7 @@ class PageController extends Controller
 
 
             if (! File::exists(public_path()."/files/pages"))
             if (! File::exists(public_path()."/files/pages"))
                 File::makeDirectory(public_path()."/files/pages");
                 File::makeDirectory(public_path()."/files/pages");
-            
+
             $path = public_path('files/pages');
             $path = public_path('files/pages');
 
 
             request()->image->move($path, $filename);
             request()->image->move($path, $filename);
@@ -64,11 +64,11 @@ class PageController extends Controller
         }
         }
 
 
         Page::create($input);
         Page::create($input);
-   
+
         return redirect()->route('pages.index')
         return redirect()->route('pages.index')
                         ->with('success','Page created successfully.');
                         ->with('success','Page created successfully.');
     }
     }
-   
+
     /**
     /**
      * Display the specified resource.
      * Display the specified resource.
      *
      *
@@ -79,7 +79,7 @@ class PageController extends Controller
     {
     {
         return view('pages.show',compact('page'));
         return view('pages.show',compact('page'));
     }
     }
-   
+
     /**
     /**
      * Show the form for editing the specified resource.
      * Show the form for editing the specified resource.
      *
      *
@@ -90,7 +90,7 @@ class PageController extends Controller
     {
     {
         return view('pages.edit',compact('page'));
         return view('pages.edit',compact('page'));
     }
     }
-  
+
     /**
     /**
      * Update the specified resource in storage.
      * Update the specified resource in storage.
      *
      *
@@ -101,7 +101,7 @@ class PageController extends Controller
     public function update(Request $request, Page $page)
     public function update(Request $request, Page $page)
     {
     {
         $request->validate($this->rules);
         $request->validate($this->rules);
-  
+
         $input = $request->all();
         $input = $request->all();
         $input["online"] = isset($input["online"]) ? ($input["online"] == 'on' ? true : false) : false;
         $input["online"] = isset($input["online"]) ? ($input["online"] == 'on' ? true : false) : false;
 
 
@@ -113,7 +113,7 @@ class PageController extends Controller
 
 
             if (! File::exists(public_path()."/files/pages"))
             if (! File::exists(public_path()."/files/pages"))
                 File::makeDirectory(public_path()."/files/pages");
                 File::makeDirectory(public_path()."/files/pages");
-            
+
             $path = public_path('files/pages');
             $path = public_path('files/pages');
 
 
             request()->image->move($path, $filename);
             request()->image->move($path, $filename);
@@ -121,13 +121,13 @@ class PageController extends Controller
             $input["image"] = $filename;
             $input["image"] = $filename;
 
 
         }
         }
-        
+
         $page->update($input);
         $page->update($input);
-  
+
         return redirect()->route('pages.index')
         return redirect()->route('pages.index')
                         ->with('success','Page updated successfully');
                         ->with('success','Page updated successfully');
     }
     }
-  
+
     /**
     /**
      * Remove the specified resource from storage.
      * Remove the specified resource from storage.
      *
      *
@@ -136,24 +136,24 @@ class PageController extends Controller
      */
      */
     public function destroy(Page $page)
     public function destroy(Page $page)
     {
     {
-        
+
         $news = News::where('page_id', '=', $page->id)->get();
         $news = News::where('page_id', '=', $page->id)->get();
         foreach($news as $n)
         foreach($news as $n)
         {
         {
             $n->page_id = null;
             $n->page_id = null;
             $n->save();
             $n->save();
         }
         }
-        
+
         $advs = PageAdv::where('page_id', '=', $page->id)->get();
         $advs = PageAdv::where('page_id', '=', $page->id)->get();
         foreach($advs as $adv)
         foreach($advs as $adv)
         {
         {
             $adv->page_id = null;
             $adv->page_id = null;
             $adv->save();
             $adv->save();
         }
         }
-        
+
         $page->delete();
         $page->delete();
-  
+
         return redirect()->route('pages.index')
         return redirect()->route('pages.index')
                         ->with('success','Page deleted successfully');
                         ->with('success','Page deleted successfully');
     }
     }
-}
+}