/**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     Advert::destroy($id);
     return redirect('/admin/adverts');
 }
 /**
  * Display the specified resource.
  *
  * @param  int  $id ID of the page to show
  * @return \Illuminate\Http\Response
  */
 public function show($adID, $id)
 {
     $match = ['id' => $id, 'deleted' => 0];
     $page = Page::where($match)->first();
     // one to one only return 1
     if ($page == null) {
         return redirect()->route('dashboard.advert.edit', [$adID])->with('message', 'Error: Could not find page');
     }
     $pageData = $page->PageData->where('id', $page->page_data_id)->orderBy('heading', 'ASC')->first();
     $advert = Advert::find($adID);
     if ($advert == null) {
         return redirect()->route('dashboard.advert.edit', [$adID])->with('message', 'Error: Advert removed before update');
     }
     $background = Background::find($advert->background_id);
     if ($background == null) {
         return redirect()->route('dashboard.advert.edit', [$adID])->with('message', 'Error: Background removed before update');
     }
     $data = array('page' => $page, 'pageData' => $pageData, 'activeTemplate' => $page->Template, 'templates' => Template::all(), 'advertBackground' => $background);
     return view('pages/pageeditor', $data);
 }
 /**
  * Gets an array of all the allowed averts the specified user is able
  * to access and modify because they're admin
  * @param User $user
  * @param array $allowed_departments
  * @return EloquentCollection
  */
 public function getAllowedAdverts($user, $allowed_departments)
 {
     // Check if super or admin
     if ($user->is_super_user) {
         return Advert::all();
         // Return all adverts
     } else {
         $adverts = collect([]);
         // Get every user assigned to every department
         // this admin is responsible for
         foreach ($allowed_departments as $department) {
             $departmentAdverts = $department->Adverts()->get();
             if ($departmentAdverts->count() > 0) {
                 $adverts = $adverts->merge($departmentAdverts);
             }
         }
     }
     // Only return unqiue users
     return $adverts->unique('id');
 }
 /**
  * Displays the add mode page and loads the page
  * with all adverts not associated with the selected playlist
  * @param Illuminate\Http\Request $request
  * @return Illuminate\Http\Response
  */
 public function addMode(Request $request)
 {
     $match_departments = Session::get('match_departments');
     $playlistID = $request->input('playlistID');
     $playlist = Playlist::find($playlistID);
     if ($playlist == null) {
         return redirect()->route('dashboard.playlist.edit', array($playlistID))->with('message', 'Error: Playlist not found');
     }
     $adverts = Advert::leftJoin('advert_playlist', function ($join) use($playlistID) {
         $join->on('advert.id', '=', 'advert_playlist.advert_id');
         $join->where('advert_playlist.playlist_id', '=', $playlistID);
     })->where('advert_playlist.playlist_id', '!=', $playlistID)->orWhereRaw('advert_playlist.playlist_id is null')->whereIn('advert.department_id', $match_departments)->get();
     if ($adverts->count() <= 0) {
         return redirect()->route('dashboard.playlist.edit', array($playlistID))->with('message', 'No available adverts to assign');
     }
     Session::put('playlistID', $playlistID);
     $schedules = Schedule::all();
     $data = array('adverts' => $adverts, 'playlist' => $playlist, 'schedules' => $schedules);
     return view('pages/adverts_addMode', $data);
 }
Exemple #5
-1
 /**
  * Store a newly created resource in storage.
  *
  * @param  Request  $request
  * @return Response
  */
 public function store(Request $request)
 {
     dd(1111);
     $advert = new Advert();
     $advert->create($request->all());
     return redirect()->route('/');
 }