Inheritance: extends Controller
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     $posts = PostsController::getFriendsAndUsersPosts();
     if (Auth::check()) {
         $user = User::find(Auth::id());
         return view('pages.index')->with(['posts' => $posts, 'new_notifications_count' => $user->notifications()->unread()->not_type('message')->get()->count(), 'notifications' => $user->notifications()->not_type('message')->get(), 'new_messagesNotifications_count' => $user->notifications()->unread()->type('message')->get()->count(), 'messagesNotifications' => $user->notifications()->type('message')->get()]);
     }
     return view('pages.index');
 }
 public function show($id)
 {
     if (Auth::user()->can('read-ticket')) {
         $data['ticket'] = self::API()->find(['id' => $id]);
         if ($data['ticket']) {
             $data['title'] = "Ticket #" . $data['ticket']->id;
             $data['menu_actions'] = [Form::editItem(route('tickets.edit', $id), "Edit This Ticket", Auth::user()->can('update-ticket'))];
             $data['ticket']['posts'] = PostsController::API()->all(['where' => ['ticket_id|=|' . $id], "order" => ['posts.created_at|ASC'], "paginate" => "false"]);
             $data['ticket']['history'] = TicketHistory::where('ticket_id', '=', $id)->orderBy('created_at')->get();
             $data['statuses'] = Status::where('id', TICKET_WFF_STATUS_ID)->orWhere('id', TICKET_SOLVED_STATUS_ID)->get();
             $data['draft_post'] = Post::where("ticket_id", $id)->where("status_id", POST_DRAFT_STATUS_ID)->where("author_id", Auth::user()->active_contact->id)->first();
             $data['important_post'] = null;
             if (in_array($data['ticket']->status_id, [TICKET_SOLVED_STATUS_ID, TICKET_WFF_STATUS_ID])) {
                 foreach ($data['ticket']['posts']->reverse() as $post) {
                     if ($post->ticket_status_id != $data['ticket']->status_id) {
                         break;
                     } else {
                         $data['important_post'] = $post;
                     }
                 }
             }
             $links = [];
             $temp = TicketLink::where("ticket_id", "=", $id)->get();
             foreach ($temp as $elem) {
                 $links[] = $elem->linked_ticket_id;
             }
             $data['ticket']['links'] = self::API()->all(['where' => ['tickets.id|IN|' . implode(":", $links)]]);
             $linked_to = [];
             $temp = TicketLink::where("linked_ticket_id", "=", $id)->get();
             foreach ($temp as $elem) {
                 $linked_to[] = $elem->ticket_id;
             }
             $data['ticket']['linked_to'] = self::API()->all(['where' => ['tickets.id|IN|' . implode(":", $linked_to)]]);
             if (isset($data['important_post'])) {
                 switch ($data['ticket']->status_id) {
                     case TICKET_WFF_STATUS_ID:
                         $data['important_post']->alert_type = "danger";
                         break;
                     case TICKET_SOLVED_STATUS_ID:
                         $data['important_post']->alert_type = "success";
                         break;
                 }
             }
             return view('tickets/show', $data);
         } else {
             return redirect()->back()->withErrors(['404 The following Ticket coudn\'t be found']);
         }
     } else {
         return redirect()->back()->withErrors(['Access denied to tickets show page']);
     }
 }
Example #3
0
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $id)
 {
     if (!AuthController::checkPermission()) {
         return redirect('/');
     }
     $data = $request->all();
     $post = Posts::find($id);
     if (count($post) < 1) {
         return redirect('/');
     }
     if (array_key_exists('Hidden', $data) && $data['Hidden'] == 'on') {
         $post->Hidden = 1;
     } else {
         $post->Hidden = 0;
     }
     $post->CourseID = $data['CourseID'];
     $post->ThumbnailID = $data['ThumbnailID'];
     $post->NoOfFreeQuestions = $data['NoOfFreeQuestions'];
     $post->Title = $data['Title'];
     if ($post->ThumbnailID == '2') {
         // Thumbnail Quizz Video
         $post->Video = PostsController::getYoutubeVideoID($data['Video']);
     }
     $post->Description = $data['Description'];
     $post->update();
     if ($post->ThumbnailID == '1') {
         // Thumbnail Quizz Plain Text
         // if admin upload new photo
         if ($request->file('Photo') != null) {
             $post = Posts::find($id);
             $file = $request->file('Photo');
             //        $file = Request::file('Photo');
             $post->Photo = 'Post_' . $data['CourseID'] . '_' . $post->id . "_-Evangels-English-www.evangelsenglish.com_" . "." . $file->getClientOriginalExtension();
             $file->move(base_path() . '/public/images/imagePost/', $post->Photo);
             // (intval(Posts::orderBy('created_at', 'desc')->first()->id) + 1)
             $post->update();
         }
     }
     // Update tags
     TagsController::removeTag($post->id);
     TagsController::tag($data['Hashtag'], $post->id);
     return redirect(route('user.viewpost', $post->id));
 }
Example #4
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public static function destroy($id)
 {
     if (!AuthController::checkPermission()) {
         return redirect('/');
     }
     $course = Courses::find($id);
     $posts = Posts::where('CourseID', '=', $id)->get()->toArray();
     //        dd($posts);
     foreach ($posts as $post) {
         PostsController::destroy($post['id']);
         //            dd($post['id']);
     }
     $course->delete();
     return redirect(route('admin'));
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $id)
 {
     if (!AuthController::checkPermission()) {
         return redirect('/');
     }
     $data = $request->all();
     $question = Questions::find($id);
     $question->Question = $data['Question'];
     $question->ThumbnailID = $data['ThumbnailID'];
     $question->Description = $data['Description'];
     $question->update();
     switch ($data['ThumbnailID']) {
         case '1':
             // Photo
             // if admin upload new photo
             if ($request->file('Photo') != null) {
                 $question = Questions::find($id);
                 $file = $request->file('Photo');
                 $question->Photo = 'Question_' . $question['PostID'] . '_' . $question->id . "_-Evangels-English-www.evangelsenglish.com_" . "." . $file->getClientOriginalExtension();
                 $file->move(base_path() . '/public/images/imageQuestion/', $question->Photo);
                 $question->update();
             }
             break;
         case '2':
             $question->Video = PostsController::getYoutubeVideoID($data['Video']);
             $question->update();
     }
     return redirect(route('user.viewquestion', $question->id));
 }
 /**
  * Handle the request to update {provider}_id field "Users" table.
  *
  * @return $updatedOrNot
  */
 public function updateDB(Request $request)
 {
     /* Checking if user is not authorized. */
     if (\Auth::guest()) {
         return redirect('auth/login');
     }
     /* Get new {provider}_id values from request */
     $provider = $request->input('provider');
     $providerId = $request->input('provider_id');
     /* Update user with new {provider}_id values from request. */
     $updatedOrNot = PostsController::findAndUpdateUser($provider, $providerId);
     return $updatedOrNot;
 }