/**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function show($id)
 {
     try {
         $resp = Tags::find($id);
         if (!$resp) {
             return $this->respondNotFound();
         }
         /*foreach ($resp->points as $point) {
             var_dump($point);
           }*/
         return Fractal::item($resp, new \App\Transformers\TagTransformer())->responseJson(200);
     } catch (Exception $e) {
         return $this->respondWithError();
     }
 }
Beispiel #2
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     $tag = \App\Tags::find($id);
     $tag->delete();
     return $tag;
 }
 public function commentDiscussion(Request $request)
 {
     $user = Auth::user();
     if ($user) {
         // Als de gebruiker ingelogd is, anders niets doen
         $filename = uniqid();
         try {
             DB::beginTransaction();
             $comment = new Artefact();
             $comment->author = $user->id;
             // Titel van het artefact zetten
             if ($request->input('answer_title')) {
                 $comment->title = $request->input('answer_title');
             } else {
                 $comment->title = 'No title';
             }
             if ($request->input('answer_copyright')) {
                 $comment->copyright = $request->input('answer_copyright');
             }
             // De eigenlijke inhoud verwerken en het type bepalen en juist zetten
             $at = null;
             switch ($request->input('answer_temp_type')) {
                 case 'text':
                     if ($request->input('answer_text')) {
                         $comment->contents = $request->input('answer_text');
                     }
                     $at = ArtefactType::where('description', 'text')->first();
                     break;
                 case 'video':
                     if ($request->input('answer_url') && $request->input('answer_url') != null && $request->input('answer_url') != '') {
                         // URL meegegeven voor video
                         $url = $request->input('answer_url');
                         if (strpos($url, 'youtube') !== false || strpos($url, 'youtu.be') !== false) {
                             // Youtube video
                             $yt = BmoocController::parseYoutube($url);
                             if ($yt && $yt != '') {
                                 $comment->url = 'http://www.youtube.com/embed/' . $yt;
                                 $at = ArtefactType::where('description', 'video_youtube')->first();
                             } else {
                                 throw new Exception('The URL you entered is not a valid link to a YouTube video');
                             }
                         } elseif (strpos($url, 'vimeo.com') !== false) {
                             // Vimeo video
                             $comment->url = '//player.vimeo.com/video/' . substr($url, strpos($url, 'vimeo.com/') + 10);
                             $at = ArtefactType::where('description', 'video_vimeo')->first();
                         } else {
                             throw new Exception('The URL you entered is not a valid link to a YouTube or Vimeo video.');
                         }
                     } else {
                         // Kan niet voorkomen, maar voor de veiligheid wel fout opwerpen
                         //$topic->url = 'https://www.youtube.com/embed/YecyKnQUcBY'; // Dummy video
                         throw new Exception('No video URL provided for new contribution of type video');
                     }
                     break;
                 case 'image':
                     if (Input::file('answer_upload') && Input::file('answer_upload')->isValid()) {
                         $extension = strtolower(Input::file('answer_upload')->getClientOriginalExtension());
                         if (in_array($extension, ['jpg', 'png', 'gif', 'jpeg'])) {
                             $destinationPath = 'uploads';
                             Input::file('answer_upload')->move($destinationPath, $filename);
                             $comment->url = $filename;
                             $at = ArtefactType::where('description', 'local_image')->first();
                         } else {
                             throw new Exception('Image should be a JPEG, PNG or GIF.');
                         }
                     } elseif ($request->input('answer_url') && $request->input('answer_url') != null && $request->input('answer_url') != '') {
                         // URL voor de afbeelding
                         if (getimagesize($request->input('answer_url'))) {
                             // De afbeelding is een echte afbeelding als dit niet false teruggeeft
                             $comment->url = $request->input('answer_url');
                             $at = ArtefactType::where('description', 'remote_image')->first();
                         }
                     }
                     break;
                 case 'file':
                     if (Input::file('answer_upload') && Input::file('answer_upload')->isValid()) {
                         $extension = strtolower(Input::file('answer_upload')->getClientOriginalExtension());
                         if (in_array($extension, ['pdf'])) {
                             $destinationPath = 'uploads';
                             Input::file('answer_upload')->move($destinationPath, $filename);
                             $comment->url = $filename;
                             $at = ArtefactType::where('description', 'local_pdf')->first();
                         } else {
                             throw new Exception('File should be a PDF.');
                         }
                     } elseif ($request->input('answer_url') && $request->input('answer_url') != null && $request->input('answer_url') != '') {
                         // URL voor de afbeelding
                         if (getimagesize($request->input('answer_url'))) {
                             // De afbeelding is een echte afbeelding als dit niet false teruggeeft
                             $comment->url = $request->input('answer_url');
                             $at = ArtefactType::where('description', 'remote_pdf')->first();
                         } else {
                             throw new Exception('The document in the url is not an image');
                         }
                     }
                     break;
             }
             // Thumbnails opslaan
             if (isset($comment->url)) {
                 // small
                 if ($request->input('thumbnail_small') && $request->input('thumbnail_small') != null && $request->input('thumbnail_small') != '') {
                     $destinationPath = 'uploads/thumbnails/small/' . $comment->url;
                     $data = base64_decode(preg_replace('#^data:image/\\w+;base64,#i', '', $request->input('thumbnail_small')));
                     file_put_contents($destinationPath, $data);
                 }
                 // large
                 if ($request->input('thumbnail_large') && $request->input('thumbnail_large') != null && $request->input('thumbnail_large') != '') {
                     $destinationPath = 'uploads/thumbnails/large/' . $comment->url;
                     $data = base64_decode(preg_replace('#^data:image/\\w+;base64,#i', '', $request->input('thumbnail_large')));
                     file_put_contents($destinationPath, $data);
                 }
             }
             if ($at) {
                 $at->artefacts()->save($comment);
             } else {
                 throw new Exception('Selected file is not a valid image or PDF.');
             }
             // Einde inhoud verwerken en type bepalen
             if ($request->input('answer_parent')) {
                 $vader = Artefact::find($request->input('answer_parent'));
                 $vader->children()->save($comment);
                 $comment->thread = $vader->thread;
             } else {
                 $maxthread = Artefact::max('thread');
                 $comment->thread = $maxthread + 1;
             }
             // Attachment verwerken
             if (Input::file('answer_attachment') && Input::file('answer_attachment')->isValid()) {
                 $extension = strtolower(Input::file('answer_attachment')->getClientOriginalExtension());
                 if (in_array($extension, ['jpg', 'png', 'gif', 'jpeg', 'pdf'])) {
                     $destinationPath = 'uploads/attachments';
                     $filename = base64_encode(Input::file('answer_attachment')->getClientOriginalName() . time()) . '.' . $extension;
                     Input::file('answer_attachment')->move($destinationPath, $filename);
                     $comment->attachment = $filename;
                 } else {
                     throw new Exception('Attachment should be a JPG, PNG, GIF or PDF');
                 }
             }
             $comment->save();
             // Tags verwerken
             // Oude geselecteerde tags komen in answers_tags als array
             if ($request->input('answer_tags')) {
                 foreach ($request->input('answer_tags') as $oldtag) {
                     $t = Tags::find($oldtag);
                     $t->times_used += 1;
                     $comment->tags()->save($t);
                 }
                 // Nieuwe tag
                 if ($request->input('answer_new_tag')) {
                     $t = new Tags(['tag' => $request->input('answer_new_tag'), 'times_used' => 1]);
                     $comment->tags()->save($t);
                 }
             }
             $pater = Artefact::where('thread', $comment->thread)->whereNull('parent_id')->first();
             $pater->last_modified = Carbon::now();
             $pater->last_contributor = $comment->author;
             $pater->save();
             DB::commit();
             // Tel hoeveel kinderen er zijn voor de vader
             if ($comment->child_of) {
                 $aantalKinderen = Artefact::where('parent_id', $comment->child_of->id)->count();
                 $url = 'topic/' . $comment->child_of->id . '/' . ($aantalKinderen - 1);
                 if ($request->isXmlHttpRequest()) {
                     return Response::json(['status' => '200', 'url' => URL::to($url)], 200);
                 } else {
                     return $this->showTopic($comment->child_of->id, $aantalKinderen - 1);
                 }
             } else {
                 if ($request->isXmlHttpRequest()) {
                     return Response::json(['status' => '200', 'url' => URL::to('topic/' . $comment->child_of->id)], 200);
                 } else {
                     return $this->showTopic($comment->id, 0);
                 }
             }
         } catch (Exception $e) {
             DB::rollback();
             //return view('errors.topic', ['error' => $e]);
             throw $e;
         }
     }
 }
Beispiel #4
0
 public static function articleSearchByTags($tagId, $limit = 5)
 {
     return Tags::find($tagId)->articles()->orderBy('published_at', 'DESC')->paginate($limit);
 }