Example #1
0
 /**
  * Display the home page.
  *
  * @return Response
  */
 public function index()
 {
     $url = config('medias.image-host');
     $film_url = config('medias.film-host');
     //hien thi film hot, sap xep moi nhat len tren
     $filmCondition = ['publish' => 1, 'isHot' => 1];
     $films = $this->film->where($filmCondition)->orderBy('created_at', 'desc')->get();
     //$banners = $this->getBanner();
     $cond = ['publish' => 1, 'sub_cat_id' => 5];
     $banners = Banner::where($cond)->get();
     return view('front.index', compact('films', 'url', 'film_url', 'banners'));
 }
 public function postUpload(Request $request)
 {
     $input = $request->all();
     $rules = array('image' => 'image|max:204800');
     $validation = \Validator::make($input, $rules);
     if ($validation->fails()) {
         return \Response::json([$validation->errors->first()], 400);
     }
     if ($media = $this->handleMediaUpload($request, 'image')) {
         $tagIDs = [];
         if ($request->has('tags')) {
             $tagList = explode(',', $request->input('tags'));
             foreach ($tagList as $tag) {
                 $tag = trim($tag);
                 $tagORM = \App\Models\Tag::where('name', $tag)->first() ?: new \App\Models\Tag();
                 $tagORM->name = $tag;
                 if (empty($tagORM->slug)) {
                     $tagORM->slug = \App\Helpers\Text::slugify($tagORM->name);
                 }
                 $tagORM->save();
                 $tagIDs[] = $tagORM->id;
             }
             if (count($tagIDs)) {
                 $media->tags()->sync($tagIDs);
             }
         }
         return \Response::json('success', 200);
     } else {
         return \Response::json('error', 400);
     }
 }
Example #3
0
 public function search()
 {
     $ss = Input::get('searchbox');
     $data['orgs'] = Organisation::where('organisation', 'like', '%' . $ss . '%')->get();
     $data['pros'] = Project::where('project', 'like', '%' . $ss . '%')->get();
     $data['tags'] = Tag::where('tag', 'like', '%' . $ss . '%')->get();
     $data['ss'] = $ss;
     return view('search', $data);
 }
 /**
  * Get all tags in sorted order according to number of posts a tag belongs to.
  * @return array [tag1, tag2, ...]
  */
 private function getSortedTags()
 {
     $tags = Tag::where('confession_tag', 'REGEXP', '#[a-z]+')->get()->filter(function ($tag) {
         return $tag->confessions()->approved()->count() > 0;
     })->sortBy(function ($tag) {
         return -$tag->confessions()->approved()->count();
     });
     return array_values($tags->toArray());
 }
Example #5
0
 public function saved($model)
 {
     foreach ($model->tags as $tag) {
         $new_tag = Tag::where('type', '=', $tag->type)->where('tag', '=', $tag->tag)->first();
         if (!$new_tag) {
             $new_tag = new Tag(['type' => $tag->type, 'tag' => $tag->tag]);
             $new_tag->save();
         }
     }
 }
 private function leftMenuCounts()
 {
     view()->composer('dashboard._partials.left.menu_bar', function ($view) {
         $view->with('usersCount', User::count());
         $view->with('categoriesCount', Category::count());
         $view->with('venuesCount', Venue::count());
         $view->with('spacesCount', Space::count());
         $view->with('amenitiesCount', Tag::where('type', 'amenity')->count());
     });
 }
Example #7
0
 /**
  * Return data for a tag index page
  *
  * @param string $tag
  * @return array
  */
 protected function tagIndexData($tag)
 {
     $tag = Tag::where('tag', $tag)->firstOrFail();
     $reverse_direction = (bool) $tag->reverse_direction;
     $posts = Post::where('published_at', '<=', Carbon::now())->whereHas('tags', function ($q) use($tag) {
         $q->where('tag', '=', $tag->tag);
     })->where('is_draft', 0)->orderBy('published_at', $reverse_direction ? 'asc' : 'desc')->simplePaginate(config('upload.posts_per_page'));
     $posts->addQuery('tag', $tag->tag);
     $page_image = $tag->page_image ?: config('upload.page_image');
     return ['title' => $tag->title, 'subtitle' => $tag->subtitle, 'posts' => $posts, 'page_image' => $page_image, 'tag' => $tag, 'reverse_direction' => $reverse_direction, 'meta_description' => $tag->meta_description ?: config('upload.description')];
 }
 /**
  * Define your route model bindings, pattern filters, etc.
  *
  * @param  \Illuminate\Routing\Router  $router
  * @return void
  */
 public function boot(Router $router)
 {
     //
     parent::boot($router);
     //$router->model('articles','App\Models\Article');
     $router->bind('articles', function ($id) {
         return Article::published()->findOrFail($id);
     });
     $router->bind('tag', function ($name) {
         return Tag::where('name', $name)->firstOrFail();
     });
 }
Example #9
0
 protected function savePostTags($postID, $tags)
 {
     foreach ($tags as $tag) {
         $resultTag = Tag::where(\DB::Raw('BINARY name'), $tag);
         if ($resultTag->count()) {
             $tagID = $resultTag->first()->id;
         } else {
             $resultTag = Tag::create(array('name' => $tag));
             $tagID = $resultTag->id;
         }
         PostTag::create(array('post_id' => $postID, 'tag_id' => $tagID));
     }
 }
 public function getSearch(Request $request)
 {
     $search = $request->get('query');
     $articles = Article::published()->join('users', 'users.id', '=', 'articles.user_id')->where(function ($q) use($search) {
         $q->where('title', 'like', '%' . $search . '%')->orWhere(function ($query) use($search) {
             $query->where('users.name', 'like', '%' . $search . '%')->orWhere('users.surname', 'like', '%' . $search . '%')->orWhere(\DB::raw('concat(users.name, \' \', users.surname)'), 'like', '%' . $search . '%');
         })->orWhere(function ($query) use($search) {
             $tag = array_flatten(Tag::where('name', 'like', '%' . $search . '%')->get(['id'])->toArray());
             $articleTagMapper = array_flatten(ArticleTagMapper::whereIn('tag_id', $tag)->distinct()->get(['article_id'])->toArray());
             $query->whereIn('id', $articleTagMapper);
         });
     })->get(['articles.id', 'articles.title']);
     return response()->json($articles);
 }
 public function saveTags(Product $product, array $tags)
 {
     $results = [];
     foreach ($tags as $tag) {
         $tag = trim($tag);
         $find = Tag::where('name', $tag)->first();
         if (!$find) {
             $find = Tag::create(['name' => $tag]);
         }
         $results[] = $find;
     }
     $product_ids = collect($results)->pluck('id');
     $product->tags()->attach($product_ids->toArray());
     return $results;
 }
 /**
  * Define your route model bindings, pattern filters, etc.
  *
  * @return void
  */
 public function boot()
 {
     parent::boot();
     Route::bind('article', function ($slug) {
         if (!Auth::user()) {
             return Article::published()->slug($slug)->first();
         }
         return Article::where('slug', $slug)->first() ?: Article::findOrFail((int) $slug);
     });
     Route::bind('tag', function ($slug) {
         if (!Auth::user()) {
             return Tag::slug($slug)->first();
         }
         return Tag::where('slug', $slug)->first() ?: Tag::findOrFail((int) $slug);
     });
     Route::bind('page', function ($id) {
         return Page::find($id);
     });
 }
Example #13
0
 public function store()
 {
     $tags = \Input::get('tags');
     if ($tags && count($tags)) {
         $results = array();
         foreach ($tags as $tag) {
             $resultTag = Tag::where(\DB::Raw('BINARY name'), $tag);
             if (!$resultTag->count()) {
                 $resultTag = Tag::create(array('name' => $tag));
                 array_push($results, array($tag => $resultTag));
             } else {
                 array_push($results, array($tag => 'Exsiting'));
             }
         }
         Cache::forget('all_tag');
         return self::makeResponse($results, 201);
     } else {
         return self::makeResponse(array(), 400, 'Bad Request');
     }
 }
Example #14
0
 public function tagSubscribe(Request $request, $slug)
 {
     $tag = Tag::where('slug', $slug)->first();
     $message = [];
     if ($currentUser = \Auth::user()) {
         if ($tag->subscribers->contains($currentUser)) {
             // $this->dispatch(new RemoveLikeFromAnswer($tag, \Auth::user()));
             $tag->subscribers()->detach($currentUser);
             $message['type'] = 'unsubscribe';
         } else {
             $tag->subscribers()->attach($currentUser);
             $message['type'] = 'subscribe';
             // $this->dispatch(new AddLikeToAnswer($tag, \Auth::user()));
         }
     }
     if ($request->ajax()) {
         $message['count'] = $tag->subscribersCount;
         $message['title'] = count_subscribers($message['count']);
         return $message;
     }
     return back();
 }
 /**
  * Responds to requests to POST /article/create
  *
  * @param Request $request
  * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
  */
 public function postCreate(Request $request)
 {
     $input = $request->all();
     $input['user_id'] = Auth::id();
     $input['tags'] = array_map('trim', explode(',', $input['tags']));
     $input['task_id'] = $input['task_id'] ? $input['task_id'] : null;
     if ($input['action'] == "Odoslať") {
         $input['state'] = Article::PUBLISHED;
     } else {
         $input['state'] = Article::DRAFT;
     }
     if ($article = Article::findBySlugOrId($input['id'])) {
         $article->update($input);
         $article->resluggify()->save();
     } else {
         $article = Article::create($input);
     }
     ArticleTagMapper::where('article_id', '=', $article->id)->delete();
     foreach ($input['tags'] as $tagName) {
         if ($tagName) {
             if (!($tag = Tag::where('name', '=', $tagName)->first())) {
                 $tag = Tag::create(['name' => $tagName]);
             }
             ArticleTagMapper::create(['article_id' => $article->id, 'tag_id' => $tag->id]);
         }
     }
     if ($request->ajax()) {
         $count = Auth::user()->articles()->draft()->count();
         return response()->json(['id' => $article->id, 'status' => 'success', 'count' => $count]);
     } else {
         if ($input['action'] == "Odoslať") {
             flash()->success('Článok bol publikovaný');
             return redirect()->action('UserController@getProfile', ['id' => Auth::user()->slug]);
         } else {
             flash()->success('Článok bol uložený');
             return redirect(URL::action('ArticleController@getDraft', ['id' => $article->slug]));
         }
     }
 }
Example #16
0
 /**
  * @param Request $request
  * @return Article
  */
 public function doPost(Request $request)
 {
     // TODO: Implement doPost() method.
     /** @var \App\Models\ContentBase $newContent */
     $newContent = ContentBase::create(['content_type' => 0]);
     $newArticle = $newContent->article()->create($request->only($this->articleFields));
     if ($request->input('cover_id') != 0) {
         $newArticle['cover_id'] = $request->input('cover_id');
         $newArticle->save();
     }
     // get all checked-in destinations
     /** @var array $dest */
     $dest = array_map(function ($item) {
         $rs = Destination::where('des_name', $item->des_name)->first();
         return $rs;
     }, (array) json_decode($request->input('destinations')));
     foreach ($dest as $d) {
         /** @var Destination $d */
         $m = new ArticleDestination();
         $m->article_id = $newArticle->article_id;
         $m->des_id = $d->des_id;
         $m->save();
     }
     // get all tagged tags
     $tags = array_map(function ($item) {
         return Tag::where('tag_name', $item->tag_name)->first();
     }, (array) json_decode($request->input('tagnames')));
     /** @var Tag $t */
     foreach ($tags as $t) {
         $m = new ArticleTag();
         $m->article_id = $newArticle->article_id;
         $m->tag_id = $t->tag_id;
         $m->save();
     }
     return $newArticle;
 }
Example #17
0
 /**
  * Return all Tags from the DB
  *
  * @param null|User $user
  * @return mixed
  */
 public function all($user = null)
 {
     if ($user) {
         return Tag::where('user_id', $user->id)->get();
     }
     return Tag::all();
 }
Example #18
0
 /**
  * Save tag
  */
 private function __saveTags($post, $tags)
 {
     if (strlen($tags) == 0) {
         return;
     }
     $tagsArray = [];
     $tagsArray = explode(',', $tags);
     foreach ($tagsArray as $tag) {
         $tagObj = Tag::where('tag', $tag)->first();
         if (is_null($tagObj)) {
             $tagModel = new Tag();
             $tagModel->tag = $tag;
             $post->tags()->save($tagModel);
         } else {
             $post->tags()->attach($tagObj->id);
         }
     }
 }
Example #19
0
 /**
  * Handle the form for adding/editing a picture
  */
 public function postEdit(Request $request, $id = null)
 {
     // Are we editing an existing image or creating one ?
     $newPicture = $id === null;
     $picture = $newPicture ? new Picture() : Picture::findOrFail($id);
     // Validate the request, if invalid this will return to the form wih errors
     $this->validate($request, ['title' => 'required', 'description' => 'required', 'picture' => $newPicture ? 'required|image' : 'image']);
     // If the file has been uploaded in the form
     if ($request->hasFile('picture')) {
         // The uploaded picture file
         $pictureFile = $request->file('picture');
         // The filename of the picture
         $pictureFilename = $pictureFile->getClientOriginalName();
         // If the file already exists, prepend a random string in the filename
         if (file_exists(public_path('uploads/' . $pictureFilename))) {
             $pictureFilename = str_random(5) . $pictureFilename;
         }
         // Move the temp file to the uploads directory
         $pictureFile->move(public_path('uploads'), $pictureFilename);
         // Set the filename in the model
         $picture->filename = $pictureFilename;
     }
     // Setting the title and description
     $picture->title = $request->input('title');
     $picture->description = $request->input('description');
     // Save the model in the db
     $picture->save();
     // Handles tags, this must be done after creating the picture in the db,
     // because we need the picture's id
     // Remove whitespace and make the string lowercase
     $tagsRaw = strtolower(trim($request->input('tags')));
     // If the tags are empty, that means the user is trying to remove all tags
     if (empty($tagsRaw)) {
         // Remove all tags
         $picture->tags()->sync([]);
     } else {
         // Explode the string on spaces
         $tags = explode(' ', $tagsRaw);
         // Will be filled with tags id
         $tagIds = [];
         foreach ($tags as $tagName) {
             // Try to get the tag in the db
             $tag = Tag::where('name', $tagName)->first();
             // If the tag doesn't exist, create it
             if ($tag == null) {
                 // Create a new model
                 $tag = new Tag();
                 $tag->name = $tagName;
                 // Insert the model in the db
                 $tag->save();
             }
             // Keep the tag id
             $tagIds[] = $tag->id;
         }
         // Update the relationship with the tags' ids
         if (count($tagIds) > 0) {
             $picture->tags()->sync($tagIds);
         }
     }
     // Return to the image
     return redirect('images/show/' . $picture->id);
 }
 public function search_by(array $data)
 {
     return Tag::where($data)->get();
 }
Example #21
0
| and give it the controller to call when that URI is requested.
|
*/
use App\Models\Article;
use App\Models\ArticleTagMapper;
use App\Models\Tag;
use App\Models\User;
Route::get('/', function () {
    $articles = Article::published();
    $search = false;
    if ($search = Request::get('search')) {
        $articles->join('users', 'users.id', '=', 'articles.user_id')->where(function ($q) use($search) {
            $q->where('title', 'like', '%' . $search . '%')->orWhere(function ($query) use($search) {
                $query->where('users.name', 'like', '%' . $search . '%')->orWhere('users.surname', 'like', '%' . $search . '%')->orWhere(DB::raw('concat(users.name, \' \', users.surname)'), 'like', '%' . $search . '%');
            })->orWhere(function ($query) use($search) {
                $tag = array_flatten(Tag::where('name', 'like', '%' . $search . '%')->get(['id'])->toArray());
                $articleTagMapper = array_flatten(ArticleTagMapper::whereIn('tag_id', $tag)->distinct()->get(['article_id'])->toArray());
                $query->whereIn('articles.id', $articleTagMapper);
            });
        });
    }
    $articles = $articles->orderBy('articles.updated_at', 'desc')->select(DB::raw('articles.id, articles.text, articles.title, articles.slug, articles.user_id, articles.updated_at'))->paginate(5);
    $topUsers = Article::published()->limit(3)->groupBy('user_id')->orderByRaw('count(user_id) DESC')->get();
    $bestUsers = User::all();
    $bestUsers = collect($bestUsers->sortByDesc(function ($user) {
        return $user->average_rating;
    }))->reject(function ($user) {
        return $user->average_rating == 0;
    });
    $bestUsers = $bestUsers->slice(0, 3);
    return view('index', ['articles' => $articles, 'topUsers' => $topUsers, 'bestUsers' => $bestUsers, 'search' => $search]);
 private function updateTags($ticket)
 {
     TagTicket::where('ticket_id', $ticket->id)->forceDelete();
     if (Input::get('tagit')) {
         $tags = explode(",", Input::get('tagit'));
         foreach ($tags as $new_tag) {
             $tag = Tag::where('name', $new_tag)->first();
             if (!isset($tag->id)) {
                 $tag = new Tag();
                 $tag->name = $new_tag;
                 $tag->save();
             }
             $tag_ticket = new TagTicket();
             $tag_ticket->ticket_id = $ticket->id;
             $tag_ticket->tag_id = $tag->id;
             $tag_ticket->save();
         }
     }
 }
Example #23
0
 /**
  * @param $id
  * @param $attributes
  * @return bool|mixed
  * @throws \App\Exceptions\Validation\ValidationException
  */
 public function update($id, $attributes)
 {
     $this->article = $this->find($id);
     $attributes['is_published'] = isset($attributes['is_published']) ? true : false;
     if ($this->isValid($attributes)) {
         //-------------------------------------------------------
         if (isset($attributes['image'])) {
             $file = $attributes['image'];
             // delete old image
             $destinationPath = public_path() . $this->imgDir;
             File::delete($destinationPath . $this->article->file_name);
             File::delete($destinationPath . "thumb_" . $this->article->file_name);
             $destinationPath = public_path() . $this->imgDir;
             $fileName = $file->getClientOriginalName();
             $fileSize = $file->getClientSize();
             $upload_success = $file->move($destinationPath, $fileName);
             if ($upload_success) {
                 // resizing an uploaded file
                 Image::make($destinationPath . $fileName)->resize($this->width, $this->height)->save($destinationPath . $fileName);
                 // thumb
                 Image::make($destinationPath . $fileName)->resize($this->thumbWidth, $this->thumbHeight)->save($destinationPath . "thumb_" . $fileName);
                 $this->article->file_name = $fileName;
                 $this->article->file_size = $fileSize;
                 $this->article->path = $this->imgDir;
             }
         }
         //-------------------------------------------------------
         if ($this->article->fill($attributes)->save()) {
             $this->article->resluggify();
             $category = Category::find($attributes['category']);
             $category->articles()->save($this->article);
         }
         $articleTags = explode(',', $attributes['tag']);
         foreach ($articleTags as $articleTag) {
             if (!$articleTag) {
                 continue;
             }
             $tag = Tag::where('name', '=', $articleTag)->first();
             if (!$tag) {
                 $tag = new Tag();
             }
             $tag->lang = $this->getLang();
             $tag->name = $articleTag;
             //$tag->slug = Str::slug($articleTag);
             $this->article->tags()->save($tag);
         }
         return true;
     }
     throw new ValidationException('Article validation failed', $this->getErrors());
 }
 /**
  * search tag from database on the basis of query string
  *
  * @return search result from database in json format
  */
 public function searchTag($q)
 {
     $q = '%' . $q . '%';
     $tags = Tag::where('tagname', 'like', $q)->get();
     return json_encode($tags);
 }