<?php
namespace App\Http\Controllers\Frontend;
use App\Content;
use App\Http\Controllers\Controller as BaseController;
use Illuminate\Support\Facades\Input;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Redirect;
use App\News;
use App\Upload;
use App\HomeOption;
use App\TradingData;
use App\Comment;
use App\FeedChannel;
use App\ForumThread;
use App\Agency;
use App\User;
use App\Setting;
use App\CustomHelper\QuestHelper;
use App\CustomHelper\Helper;
class HomeController extends BaseController {
public static $CACHE_KEY = 'HomeController_index';
/**
* Default URL of website
* Homepage
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function index()
{
return view('frontend.home', $this->indexGetData());
}
/**
* Get the vars required for the homepage
* @return mixed
*/
public function indexGetData()
{
$data = cache()->remember(HomeController::$CACHE_KEY, 60, function() {
$news = News::orderBy('id', 'desc')
->where('published', 1)
->take(10)
->get();
$newsAll = News::orderBy('id', 'desc')
->where('published', 1)
->where('is_advert', 0)
->take(4)
->get();
$popularQuests = Upload::where('type', 'guide')
->where('approved', 1)
->where('published', 1)
->where('deleted', 0)
->orderBy('rating', 'desc')
->take(3)
->get();
$guides = HomeOption::getGuides(10);
$uploads = Upload::whereNull('parent_id')
->where('approved', 1)
->where('published', 1)
->where('deleted', 0)
->where(function($q) {
//$q->orWhere('type', 'guide');
$q->orWhere('type', 'tutorial');
$q->orWhere('type', 'room');
$q->orWhere('type', 'video');
$q->orWhere('type', 'picture');
})
->orderBy('created_at', 'desc')
->take(16)
->get();
$spotlight = HomeOption::getSpotlight();
$trades = TradingData::where(function($q) {
$q->where('type', 'buying');
$q->orWhere('type', 'selling');
})
->where('hotel', 'com')
->orderBy('id', 'desc')
->orderByRaw('RAND()')
->take(16)
->get();
$feedComments = Comment::where('url', FeedChannel::getFirstFeedChannelURL())
->whereNull('parent_id')
->whereNull('comment_feed_id')
->orderBy('id', 'desc')
->take(10)
->get();
// latest threads
$threads = ForumThread::orderBy('id', 'desc')
->select(DB::raw('forum_threads.*'))
->where('deleted', 0);
$threads = ForumThread::addJoinsToQuery($threads);
$threads = ForumThread::addMemberOnlyPermsToQuery($threads);
$threads = $threads->take(4)->get();
// hottest thread
$hotThread = ForumThread::orderBy('forum_activity.updated_at', 'desc')
->select(DB::raw('forum_threads.*'))
->where('deleted', 0);
$hotThread = ForumThread::addJoinsToQuery($hotThread);
$hotThread = ForumThread::addMemberOnlyPermsToQuery($hotThread);
$hotThread = $hotThread->first();
$furniture = HomeOption::getFurniture();
$agencies = Agency::getPartnershipAgencies();
return array(
'title' => 'Home',
'newss' => $news,
'newsAll' => $newsAll,
'popularQuests' => $popularQuests,
'spotlight' => $spotlight,
'guides' => $guides,
'uploads' => $uploads,
'trades' => $trades,
'feedComments' => $feedComments,
'threads' => $threads,
'hotThread' => $hotThread,
'guidedBadges' => [],
'furniture' => $furniture,
'agencies' => $agencies,
'homeContent' => Content::getContent('home_notification', null, true),
'questLevel' => null,
'questLevelName' => null,
'questPercentInfo' => null,
'collectedBadges' => null,
'cacheTimestamp' => date('Y-m-d H:i:s'),
);
});
if(Auth::check()) {
$questLevel = Auth::user()->getQuestLevel();
$questLevelName = Auth::user()->getQuestLevelName();
$questPercentInfo = QuestHelper::getPercentInformation();
$collectedBadges = QuestHelper::getCollectedBadges();
$guidedBadges = HomeOption::getGuidedBadges(8);
$data['guidedBadges'] = $guidedBadges;
$data['questPercentInfo'] = $questPercentInfo;
$data['questLevel'] = $questLevel;
$data['questLevelName'] = $questLevelName;
$data['collectedBadges'] = $collectedBadges;
}
return $data;
}
....
}
Comments