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-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;
|
2019-11-16 11:26:11 +00:00
|
|
|
use App;
|
2020-02-18 12:30:16 +00:00
|
|
|
use Illuminate\Support\Facades\Config;
|
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')
|
2020-01-09 12:45:20 +00:00
|
|
|
->categoryLiveEvents(16)
|
2019-09-28 07:05:26 +00:00
|
|
|
->first();
|
2019-09-10 13:33:55 +00:00
|
|
|
|
2020-02-10 12:32:10 +00:00
|
|
|
$cartoon = Category::where('view_type','exhibition')//todo change to cartoon multik
|
2020-02-10 09:57:56 +00:00
|
|
|
->categoryLiveEvents(16)
|
2019-09-28 07:05:26 +00:00
|
|
|
->first();
|
2019-09-10 13:33:55 +00:00
|
|
|
|
2019-09-28 07:05:26 +00:00
|
|
|
$musical =Category::where('view_type','concert')
|
2020-02-10 10:14:16 +00:00
|
|
|
->categoryLiveEvents(8)
|
2019-09-28 07:05:26 +00:00
|
|
|
->first();
|
2019-09-10 13:33:55 +00:00
|
|
|
|
2020-02-18 12:30:16 +00:00
|
|
|
$sliders = Slider::where('active',1)
|
|
|
|
|
->where(Config::get('app.locale'),1)
|
|
|
|
|
->get();
|
2019-09-28 07:05:26 +00:00
|
|
|
//dd($cinema->events->first());
|
2020-02-13 15:20:40 +00:00
|
|
|
// return view('desktop.Pages.HomePage')->with([
|
|
|
|
|
// 'cinema' => $cinema,
|
|
|
|
|
// 'cartoon' => $cartoon,
|
|
|
|
|
// 'musical' => $musical,
|
|
|
|
|
// 'sliders' => $sliders
|
|
|
|
|
// ]);
|
|
|
|
|
|
|
|
|
|
return $this->render("Pages.HomePage",[
|
2019-08-28 06:34:37 +00:00
|
|
|
'cinema' => $cinema,
|
2020-02-10 11:00:26 +00:00
|
|
|
'cartoon' => $cartoon,
|
2019-08-28 06:34:37 +00:00
|
|
|
'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-02 14:08:07 +00:00
|
|
|
$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()
|
2020-02-25 13:03:41 +00:00
|
|
|
->withLiveEvents($order, $data['start'], $data['end'], $category->events_limit + 3)//wiered
|
2020-01-09 12:47:28 +00:00
|
|
|
->whereHas('cat_events',
|
|
|
|
|
function ($query) use($data){
|
|
|
|
|
$query->onLive($data['start'], $data['end']);
|
|
|
|
|
})
|
2020-01-09 12:45:20 +00:00
|
|
|
->get();
|
2019-10-03 09:18:21 +00:00
|
|
|
|
2020-02-18 12:13:32 +00:00
|
|
|
return $this->render("Pages.EventsPage",$data);
|
2019-10-05 11:05:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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'])
|
2020-02-10 12:32:10 +00:00
|
|
|
->paginate(16);
|
2019-10-05 11:05:56 +00:00
|
|
|
|
2020-02-18 12:13:32 +00:00
|
|
|
return $this->render("Pages.CategoryEventsPage",$data);
|
2019-10-05 11:05:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function sorts_filters(){
|
2020-01-09 12:55:03 +00:00
|
|
|
$data['start'] = \request()->get('start');
|
|
|
|
|
$data['end'] = \request()->get('end');
|
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
|
2020-02-07 14:57:12 +00:00
|
|
|
$query = sanitise($request->get('q'));
|
2020-02-01 17:47:51 +00:00
|
|
|
$events = Event::onLive()
|
2020-02-07 14:57:12 +00:00
|
|
|
->where('title_ru','like',"%{$query}%")
|
|
|
|
|
->orWhere('title_tk','like',"%{$query}%")
|
2020-02-01 17:47:51 +00:00
|
|
|
->paginate(10);
|
2019-09-16 12:55:29 +00:00
|
|
|
|
2020-02-18 12:13:32 +00:00
|
|
|
return $this->render('Pages.SearchResults',[
|
|
|
|
|
'events' => $events,
|
|
|
|
|
'query' => $query
|
|
|
|
|
]);
|
2019-09-16 12:55:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function postAddEvent(AddEventRequest $request){
|
|
|
|
|
|
|
|
|
|
$addEvent = EventRequest::create([
|
2019-11-30 08:35:37 +00:00
|
|
|
'name' => sanitise($request->get('name')),
|
|
|
|
|
'email' => sanitise($request->get('email')),
|
|
|
|
|
'phone' => sanitise($request->get('phone')),
|
2020-03-03 17:07:37 +00:00
|
|
|
'details' => sanitise($request->get('details'))
|
2019-09-16 12:55:29 +00:00
|
|
|
]);
|
2020-03-03 17:02:15 +00:00
|
|
|
|
2020-03-03 18:40:09 +00:00
|
|
|
if($addEvent)
|
|
|
|
|
return response()->json([
|
|
|
|
|
'status' => 'success',
|
|
|
|
|
'message' => trans('ClientSide.add_event_success_message'),
|
|
|
|
|
]);
|
|
|
|
|
else
|
|
|
|
|
return response()->json([
|
|
|
|
|
'status' => 'error',
|
|
|
|
|
'message' => trans('ClientSide.add_event_error_message'),
|
|
|
|
|
]);
|
2019-09-16 12:55:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function subscribe(SubscribeRequest $request){
|
2019-11-30 08:35:37 +00:00
|
|
|
$email = sanitise($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]);
|
|
|
|
|
|
2020-03-03 18:40:09 +00:00
|
|
|
if($subscribe)
|
|
|
|
|
return response()->json([
|
|
|
|
|
'status' => 'success',
|
|
|
|
|
'message' => trans('ClientSide.subscribe_success_message'),
|
|
|
|
|
]);
|
|
|
|
|
else
|
|
|
|
|
return response()->json([
|
|
|
|
|
'status' => 'error',
|
|
|
|
|
'message' => trans('ClientSide.subscribe_error_message'),
|
|
|
|
|
]);
|
2019-09-11 14:33:07 +00:00
|
|
|
}
|
2020-01-09 12:45:20 +00:00
|
|
|
}
|