public function dashboard(Request $request)
 {
     $stat = new \Stdclass();
     $stat->num_ads = Ad::count();
     $stat->num_promo_ads = Ad::where('ad_promo', 1)->count();
     $stat->users = User::count();
     $stat->reports = AdReport::count();
     //get last 10 days ads
     $ads_by_date = Ad::select(DB::raw("count(ad_id) AS ad_count, DATE_FORMAT(ad_publish_date, '%Y-%m-%d') AS date_formated"))->groupBy('date_formated')->orderBy('date_formated', 'desc')->take(10)->get()->toArray();
     $stat->ads_by_date = [];
     if (!empty($ads_by_date)) {
         $stat->ads_by_date = array_reverse($ads_by_date);
     }
     //get last 10 promo days ads
     $promo_ads_by_date = Ad::select(DB::raw("count(ad_id) AS ad_count, DATE_FORMAT(ad_publish_date, '%Y-%m-%d') AS date_formated"))->where('ad_promo', 1)->groupBy('date_formated')->orderBy('date_formated', 'desc')->take(10)->get()->toArray();
     $stat->promo_ads_by_date = [];
     if (!empty($promo_ads_by_date)) {
         $stat->promo_ads_by_date = array_reverse($promo_ads_by_date);
     }
     //get last 10 months ads
     $ads_by_month = Ad::select(DB::raw("count(ad_id) AS ad_count, DATE_FORMAT(ad_publish_date, '%Y-%m') AS date_formated"))->groupBy('date_formated')->orderBy('date_formated', 'desc')->take(10)->get()->toArray();
     $stat->ads_by_month = [];
     if (!empty($ads_by_month)) {
         $stat->ads_by_month = array_reverse($ads_by_month);
     }
     //get last 10 years ads
     $ads_by_year = Ad::select(DB::raw("count(ad_id) AS ad_count, DATE_FORMAT(ad_publish_date, '%Y') AS date_formated"))->groupBy('date_formated')->orderBy('date_formated', 'desc')->take(10)->get()->toArray();
     $stat->ads_by_year = [];
     if (!empty($ads_by_year)) {
         $stat->ads_by_year = array_reverse($ads_by_year);
     }
     return view('admin.dashboard.dashboard', ['stat' => $stat]);
 }
 /**
  * Display the home page.
  */
 public function index()
 {
     $carousel_news = Article::select('id', 'title', 'page_image')->where('is_checked', true)->where('is_carousel', true)->published()->get();
     $latest_news = Article::select('id', 'title', 'intro', 'page_image')->where('is_checked', true)->published()->orderBy('published_at', 'desc')->take(4)->get();
     $ads = Ad::select('url', 'name', 'image_path')->orderBy('created_at', 'desc')->take(2)->get();
     // get the index article
     $tags = Tag::select('id', 'name')->where('show_index', true)->get();
     $index_articles = array();
     foreach ($tags as $tag) {
         $tag['articles'] = $tag->articles()->select('article_id', 'title', 'intro', 'page_image')->where('is_checked', true)->published()->orderBy('published_at', 'desc')->take(3)->get();
         $index_articles[] = $tag;
     }
     return view('front.index')->with('carousel_news', $carousel_news)->with('latest_news', $latest_news)->with('ads', $ads)->with('index_articles', $index_articles);
 }
Exemplo n.º 3
0
 public function getAdDetail($_ad_id, $_active = 1)
 {
     $cache_key = __CLASS__ . '_' . __LINE__ . '_' . md5(config('dc.site_domain') . serialize(func_get_args()));
     $ret = Cache::get($cache_key, '');
     if (empty($ret)) {
         $q = Ad::select('ad.*', 'U.*', 'U.created_at AS user_register_date', 'C.category_title', 'C.category_type', 'L.location_name', 'L.location_slug', 'AC.ad_condition_name', 'AT.ad_type_name', 'ET.estate_type_name', 'ECT.estate_construction_type_name', 'EHT.estate_heating_type_name', 'EFT.estate_furnishing_type_name', 'CB.car_brand_name', 'CM.car_model_name', 'CE.car_engine_name', 'CT.car_transmission_name', 'CC.car_condition_name', 'CMM.car_modification_name')->leftJoin('user AS U', 'U.user_id', '=', 'ad.user_id')->leftJoin('category AS C', 'C.category_id', '=', 'ad.category_id')->leftJoin('location AS L', 'L.location_id', '=', 'ad.location_id')->leftJoin('ad_condition AS AC', 'AC.ad_condition_id', '=', 'ad.condition_id')->leftJoin('ad_type AS AT', 'AT.ad_type_id', '=', 'ad.type_id')->leftJoin('estate_type AS ET', 'ET.estate_type_id', '=', 'ad.estate_type_id')->leftJoin('estate_construction_type AS ECT', 'ECT.estate_construction_type_id', '=', 'ad.estate_construction_type_id')->leftJoin('estate_heating_type AS EHT', 'EHT.estate_heating_type_id', '=', 'ad.estate_heating_type_id')->leftJoin('estate_furnishing_type AS EFT', 'EFT.estate_furnishing_type_id', '=', 'ad.estate_furnishing_type_id')->leftJoin('car_brand AS CB', 'CB.car_brand_id', '=', 'ad.car_brand_id')->leftJoin('car_model AS CM', 'CM.car_model_id', '=', 'ad.car_model_id')->leftJoin('car_engine AS CE', 'CE.car_engine_id', '=', 'ad.car_engine_id')->leftJoin('car_transmission AS CT', 'CT.car_transmission_id', '=', 'ad.car_transmission_id')->leftJoin('car_condition AS CC', 'CC.car_condition_id', '=', 'ad.car_condition_id')->leftJoin('car_modification AS CMM', 'CMM.car_modification_id', '=', 'ad.car_modification_id');
         if ($_active) {
             $q->where('ad_active', 1);
         }
         $ret = $q->findOrFail($_ad_id);
         Cache::put($cache_key, $ret, config('dc.cache_expire'));
     }
     return $ret;
 }