2018-12-10 07:32:53 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* Created by PhpStorm.
|
|
|
|
|
* User: merdan
|
|
|
|
|
* Date: 12/9/2018
|
|
|
|
|
* Time: 12:39 PM
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
2019-09-16 12:55:29 +00:00
|
|
|
use App\Http\Requests\AddEventRequest;
|
|
|
|
|
use App\Http\Requests\SearchRequest;
|
|
|
|
|
use App\Http\Requests\SubscribeRequest;
|
|
|
|
|
use App\Models\EventRequest;
|
|
|
|
|
use App\Models\Subscriber;
|
2019-09-11 14:33:07 +00:00
|
|
|
use Illuminate\Http\Request;
|
2019-09-10 13:33:55 +00:00
|
|
|
use App\Models\Category;
|
2018-12-10 07:32:53 +00:00
|
|
|
use App\Models\Event;
|
2019-08-28 06:34:37 +00:00
|
|
|
use App\Models\Slider;
|
2018-12-10 07:32:53 +00:00
|
|
|
use Carbon\Carbon;
|
2019-11-16 11:26:11 +00:00
|
|
|
use App;
|
2018-12-10 07:32:53 +00:00
|
|
|
|
|
|
|
|
class PublicController extends Controller
|
|
|
|
|
{
|
|
|
|
|
public function showHomePage(){
|
2019-09-28 07:05:26 +00:00
|
|
|
$cinema = Category::where('view_type','cinema')
|
|
|
|
|
->categoryLiveEvents(21)
|
|
|
|
|
->first();
|
2019-09-10 13:33:55 +00:00
|
|
|
|
2019-09-28 07:05:26 +00:00
|
|
|
$theatre = Category::where('view_type','theatre')
|
|
|
|
|
->categoryLiveEvents(6)
|
|
|
|
|
->first();
|
2019-09-10 13:33:55 +00:00
|
|
|
|
2019-09-28 07:05:26 +00:00
|
|
|
$musical =Category::where('view_type','concert')
|
|
|
|
|
->categoryLiveEvents(12)
|
|
|
|
|
->first();
|
2019-09-10 13:33:55 +00:00
|
|
|
|
2019-08-28 06:34:37 +00:00
|
|
|
$sliders = Slider::where('active',1)->get();
|
2019-09-28 07:05:26 +00:00
|
|
|
//dd($cinema->events->first());
|
2019-08-28 06:34:37 +00:00
|
|
|
return view('Bilettm.Public.HomePage')->with([
|
|
|
|
|
'cinema' => $cinema,
|
|
|
|
|
'theatre' => $theatre,
|
|
|
|
|
'musical' => $musical,
|
|
|
|
|
'sliders' => $sliders
|
|
|
|
|
]);
|
2018-12-10 07:32:53 +00:00
|
|
|
}
|
|
|
|
|
|
2019-10-05 11:05:56 +00:00
|
|
|
public function showCategoryEvents($cat_id){
|
2019-09-10 13:33:55 +00:00
|
|
|
|
2019-10-05 11:05:56 +00:00
|
|
|
// dd(Carbon::parse('aasddwawda') ?? null);/
|
2019-10-02 14:08:07 +00:00
|
|
|
// setlocale(LC_TIME, 'tk');
|
|
|
|
|
// Carbon::setLocale('tk');
|
|
|
|
|
// dd(Carbon::parse('2019-01-01',config('app.timezone')) ->formatLocalized('%d %B'));
|
|
|
|
|
// Carbon::
|
|
|
|
|
$category = Category::select('id','title_tk','title_ru','view_type','events_limit','parent_id')
|
2019-09-28 07:05:26 +00:00
|
|
|
->findOrFail($cat_id);
|
|
|
|
|
|
2019-10-05 11:05:56 +00:00
|
|
|
[$order, $data] = $this->sorts_filters();
|
|
|
|
|
$data['category'] = $category;
|
|
|
|
|
$data['sub_cats'] = $category->children()
|
|
|
|
|
->withLiveEvents($order, $data['start'], $data['end'], $category->events_limit)
|
|
|
|
|
->whereHas('cat_events',
|
|
|
|
|
function ($query) use($data){
|
|
|
|
|
$query->onLive($data['start'], $data['end']);
|
|
|
|
|
})->get();
|
2019-10-03 09:18:21 +00:00
|
|
|
|
|
|
|
|
|
2019-10-05 11:05:56 +00:00
|
|
|
return view("Bilettm.Public.EventsPage")->with($data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function showSubCategoryEvents($cat_id){
|
|
|
|
|
$category = Category::select('id','title_tk','title_ru','view_type','events_limit','parent_id')
|
|
|
|
|
->findOrFail($cat_id);
|
|
|
|
|
|
|
|
|
|
[$order, $data] = $this->sorts_filters();
|
|
|
|
|
|
|
|
|
|
$data['category'] = $category;
|
|
|
|
|
|
|
|
|
|
$data['events'] = $category->cat_events()
|
|
|
|
|
->onLive($data['start'],$data['end'])
|
|
|
|
|
->orderBy($order['field'],$order['order'])
|
|
|
|
|
->get();
|
|
|
|
|
|
|
|
|
|
return view("Bilettm.Public.CategoryEventsPage")->with($data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function sorts_filters(){
|
|
|
|
|
$data['start'] = \request()->get('start') ?? Carbon::today();
|
2019-10-21 06:43:45 +00:00
|
|
|
$data['end'] = \request()->get('end')?? Carbon::today()->endOfCentury();
|
2019-10-05 11:05:56 +00:00
|
|
|
$sort = \request()->get('sort');
|
2019-10-03 09:18:21 +00:00
|
|
|
|
2019-10-05 11:05:56 +00:00
|
|
|
if($sort == 'new')
|
|
|
|
|
$orderBy = ['field'=>'created_at','order'=>'desc'];
|
|
|
|
|
if ($sort =='popular')
|
|
|
|
|
$orderBy = ['field'=>'views','order'=>'desc'];
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
$orderBy =['field'=>'start_date','order'=>'asc'];
|
|
|
|
|
$sort = 'start_date';
|
2019-09-28 07:05:26 +00:00
|
|
|
}
|
2019-10-05 11:05:56 +00:00
|
|
|
$data['sort'] = $sort;
|
|
|
|
|
//todo check date formats;
|
|
|
|
|
return [$orderBy, $data];
|
2019-09-28 07:05:26 +00:00
|
|
|
}
|
|
|
|
|
|
2019-09-16 12:55:29 +00:00
|
|
|
public function search(SearchRequest $request){
|
|
|
|
|
//todo implement with elastick search and scout
|
2019-09-11 14:33:07 +00:00
|
|
|
$query = $request->get('q');
|
2019-09-23 10:35:40 +00:00
|
|
|
$events = Event::where('title','like',"%{$query}%")->paginate(10);
|
2019-09-16 12:55:29 +00:00
|
|
|
|
|
|
|
|
return view('Bilettm.Public.SearchResults')
|
|
|
|
|
->with([
|
|
|
|
|
'events' => $events,
|
|
|
|
|
'query' => $query
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function postAddEvent(AddEventRequest $request){
|
|
|
|
|
|
|
|
|
|
$addEvent = EventRequest::create([
|
|
|
|
|
'name' => $request->get('name'),
|
|
|
|
|
'email' => $request->get('email'),
|
|
|
|
|
'phone' => $request->get('phone'),
|
|
|
|
|
'detail' => $request->get('detail')
|
|
|
|
|
]);
|
|
|
|
|
return view('Bilettm.Public.AddEventResult',compact('addEvent'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function subscribe(SubscribeRequest $request){
|
|
|
|
|
$email = $request->get('email');
|
2019-09-28 07:05:26 +00:00
|
|
|
//todo validate email
|
2019-09-16 12:55:29 +00:00
|
|
|
$subscribe = Subscriber::updateOrCreate(['email'=>$email,'active'=>1]);
|
|
|
|
|
|
|
|
|
|
if($subscribe){
|
2019-09-28 07:05:26 +00:00
|
|
|
session()->flash('message','Subscription successfully');
|
2019-09-16 12:55:29 +00:00
|
|
|
}
|
|
|
|
|
|
2019-09-28 07:05:26 +00:00
|
|
|
return response()->json([
|
|
|
|
|
'status' => 'success',
|
|
|
|
|
'message' => 'Subscription successfully',
|
|
|
|
|
]);
|
2019-09-11 14:33:07 +00:00
|
|
|
}
|
2019-11-16 11:26:11 +00:00
|
|
|
|
|
|
|
|
//locale
|
|
|
|
|
public function setLocale($locale){
|
|
|
|
|
App::setLocale($locale);
|
|
|
|
|
|
|
|
|
|
return redirect()->back();
|
|
|
|
|
}
|
2018-12-10 07:32:53 +00:00
|
|
|
}
|