Esempio n. 1
0
 protected function loadAd()
 {
     // @deprecated remove if year >= 2015
     $deprecatedSlug = $this->propertyOrParam('idParam');
     $slug = $this->property('slug', $deprecatedSlug);
     $arr_slug = preg_split('/-(?=\\d+$)/', $slug);
     if (count($arr_slug) < 2) {
         return false;
     }
     $slug = $arr_slug[0];
     $ad_id = $arr_slug[1];
     if ($ad_id == 0) {
         return false;
     }
     $ad = Ad::find($ad_id);
     if ($ad->user_id == Auth::getUser()->id) {
         $this->allow_edit = true;
     }
     /*
      * Add a "url" helper attribute for linking to each category
      */
     /*if ($post && $post->categories->count()) {
           $post->categories->each(function($category){
               $category->setUrl($this->categoryPage, $this->controller);
           });
       }*/
     return $ad;
 }
Esempio n. 2
0
 public static function updateCountCategory($id)
 {
     if (!$id) {
         return false;
     }
     $count = Ad::where('category_id', '=', (int) $id)->count();
     $find = self::find($id);
     $find->count = $count;
     $find->save();
     return true;
 }
Esempio n. 3
0
 protected function listAds()
 {
     $categories = $this->category ? $this->category->id : null;
     $ads = Ad::with('category')->listFrontEnd(['page' => $this->propertyOrParam('pageParam'), 'sort' => $this->property('AdOrderAttr'), 'perPage' => $this->property('AdsPerPage'), 'categories' => $categories]);
     $ads->each(function ($ad) {
         $ad->setUrl($this->adPage, $this->controller);
         //$ad->categories->each(function ($category) {
         //    $category->setUrl($this->categoryPage, $this->controller);
         //});
     });
     return $ads;
 }
Esempio n. 4
0
 public function onRun()
 {
     //$this->addJs('http://maps.google.com/maps/api/js?sensor=false&libraries=places&language=vi');
     //$this->addJs(CLF_ASSETS . '/js/helper-googlemap.js');
     //$this->addJs(CLF_ASSETS . '/js/com-ad-edit.js');
     $this->addCss(CLF_ASSETS . '/css/com-ad-edit.css');
     $type = $this->property('type', 'quick');
     switch ($type) {
         case 'quick':
             break;
         case 'edit':
             //$asset_script[] = '~/plugins/dlnlab/classified/assets/js/components/ad-edit2.js';
             break;
         case 'edit2':
             $ad_id = intval($this->param('ad_id'));
             if (empty($ad_id)) {
                 Redirect::to('/ad/quick');
             }
             $ad = Ad::find($ad_id);
             $ad_infor = AdInfor::where('ad_id', '=', $ad_id);
             $ad_tags = Tag::getTagsOfAd($ad_id);
             $this->page['ad'] = $ad;
             $this->page['ad_infor'] = $ad_infor;
             $this->page['ad_tags'] = $ad_tags;
             break;
         case 'edit-detail':
             $kind = HelperCache::getAdKind();
             $category = HelperCache::getAdCategory();
             $amenity = HelperCache::getAdAmenities();
             $bed_rooms = AdInfor::getBedRoomOptions();
             $bath_rooms = AdInfor::getBathRoomOptions();
             $direction = AdInfor::getDirectionOptions();
             $caches = new \stdClass();
             $caches->kind = !empty($kind) ? $kind->toJson() : '';
             $caches->category = !empty($category) ? $category->toJson() : '';
             $caches->amenity = !empty($amenity) ? $amenity->toJson() : '';
             $caches->bed = json_encode($bed_rooms);
             $caches->bath = json_encode($bath_rooms);
             $caches->direction = json_encode($direction);
             $this->page['user'] = $this->user();
             $this->page['ad'] = !empty($ad) ? $ad : '';
             $this->page['ad_json'] = !empty($ad) ? $ad->toJson() : '';
             $this->page['dln_caches'] = !empty($caches) ? json_encode($caches) : '';
             break;
     }
     $this->page['type'] = $type;
 }
Esempio n. 5
0
 public function onRun()
 {
     if (Session::has('disable_cookie')) {
         return false;
     }
     if (!Auth::check()) {
         return null;
     }
     $user = Auth::getUser();
     // @deprecated remove if year >= 2015
     $deprecatedSlug = $this->propertyOrParam('idParam');
     $slug = $this->property('slug', $deprecatedSlug);
     $item = Ad::isPublished()->where('slug', '=', $slug)->first();
     if (empty($item)) {
         return null;
     }
     // Get current ad cookie
     $cookie_obj = new \stdClass();
     $cookie = Cookie::get('dln_ad_cookie');
     if ($cookie) {
         // Check current user has exist in cookie
         $cookie_obj = json_decode($cookie);
         $current_time = time();
         if (!empty($cookie_obj->{$item->id}) && $cookie_obj->{$item->id}) {
             if ($current_time >= $cookie_obj->{$item->id} + TIME_DELAY_COUNT_VIEW) {
                 $cookie_obj->{$item->id} = time();
                 $cookie = json_encode($cookie_obj);
                 Cookie::queue('dln_ad_cookie', $cookie, 1440);
                 AdRead::add_read($item, $user);
             }
         } else {
             $cookie_obj->{$item->id} = time();
             $cookie = json_encode($cookie_obj);
             Cookie::queue('dln_ad_cookie', $cookie, 1440);
             AdRead::add_read($item, $user);
         }
     } else {
         $cookie_obj->{$item->id} = time();
         $cookie = json_encode($cookie_obj);
         Cookie::queue('dln_ad_cookie', $cookie, 1440);
         AdRead::add_read($item, $user);
     }
 }
Esempio n. 6
0
 public function onRun()
 {
     $asset_css = array();
     $asset_script = array();
     $type = Input::has('type') ? Input::get('type') : '';
     switch ($type) {
         case 'ad-location':
             $asset_script[] = '~/plugins/dlnlab/classified/assets/js/helpers/helper-googlemap.js';
             $asset_script[] = '~/plugins/dlnlab/classified/assets/js/modals/ad-location.js';
             break;
         case 'ad-photo':
             $asset_script[] = 'assets/vendor/jquery-ui/jquery-ui.min.js';
             $asset_script[] = 'assets/vendor/jquery-fileupload/js/vendor/jquery.ui.widget.js';
             $asset_script[] = 'assets/vendor/jquery-fileupload/js/jquery.fileupload.js';
             $asset_script[] = '~/plugins/dlnlab/classified/assets/js/modals/ad-photo.js';
             // Get photos of Ad
             $ad_id = Input::has('ad_id') ? Input::get('ad_id') : '';
             $records = null;
             if ($ad_id) {
                 $ad = Ad::find($ad_id);
                 $records = $ad->ad_images;
             }
             $this->page['photos'] = $records;
             break;
         case 'ad-amenity':
             $asset_script[] = '~/plugins/dlnlab/classified/assets/js/modals/ad-amenity.js';
             $arr_selected = Input::has('values') ? explode(',', Input::get('values')) : '';
             $this->page['arr_selected'] = $arr_selected;
             $this->page['amenities'] = HelperCache::getAdAmenities();
             break;
         case 'ad-title':
             break;
     }
     $this->page['type'] = $type;
     $this->page['asset_css'] = $asset_css;
     $this->page['asset_script'] = $asset_script;
 }
Esempio n. 7
0
 public function getAdShareCount()
 {
     $records = AdShareCount::whereRaw('status = ? AND crawl = ?', array(1, false))->take(100)->get();
     if (!count($records)) {
         AdShareCount::all()->update(array('crawl' => false));
         return Response::json(array('status' => 'error'), 500);
     }
     $continue = true;
     foreach ($records as $record) {
         if ($record->ad_id) {
             if ($continue) {
                 $link = Ad::get_ad_link($record->ad_id);
                 if (!isset($obj->Facebook)) {
                     $continue = false;
                     return false;
                 }
                 $obj = AdShareCount::get_obj_share_count($link);
                 $record->share_count = $obj->Facebook->share_count;
                 $record->comment_count = $obj->Facebook->comment_count;
                 $record->like_count = $obj->Facebook->like_count;
                 $record->gp_count = $obj->GooglePlusOne;
                 $record->tw_count = $obj->Twitter;
                 $record->pin_count = $obj->Pinterest;
                 $record->crawl = true;
                 $record->save();
             }
         }
     }
     return Response::json(array('status' => 'success'), 200);
 }
Esempio n. 8
0
 public function getAdAroundState($ad_id)
 {
     $data = get();
     $default = array('page' => 0, 'state_id' => 0);
     $merge = array_merge($default, $data);
     $merge = \DLNLab\Classified\Classes\HelperClassified::trim_value($merge);
     extract($merge);
     $records = Ad::getAdAroundState($state_id, $ad_id, $page);
     return Response::json(array('status' => 'success', 'data' => $records));
 }
Esempio n. 9
0
 public static function getNearbyAd($ad_id = '', $page = 0)
 {
     if (empty($ad_id)) {
         return false;
     }
     $record = self::find($ad_id);
     if (empty($record)) {
         return false;
     }
     $lat = $record->lat;
     $lng = $record->lng;
     $limit = CLF_LIMIT;
     $skip = $page * $limit;
     $records = null;
     if (empty($lat) || empty($lng)) {
         // Get by country tag
     } else {
         // Get by lat long
         $records = Ad::where('1', '=', '1')->select('*', "((ACOS(SIN({$lat} * PI() / 180) * SIN(lat * PI() / 180) + COS({$lat} * PI() / 180) * COS(lat * PI() / 180) * COS(({$lng} - lng) * PI() / 180)) * 180 / PI()) * 60 * 1.1515 * 1.609344) as distance")->having('distance ', '<=', CLF_DISTANCE)->orderBy('distance', 'ASC')->skip($skip)->take($limit)->get();
     }
     return $records;
 }
Esempio n. 10
0
 public static function query($search_id = '', $is_count = false)
 {
     if (!$searches) {
         return null;
     }
     $record = self::find($search_id);
     if (!$record) {
         return null;
     }
     $arr_query = json_decode($record->query);
     // Build query ads
     $ad_query = 'null';
     $ad_params = array();
     foreach ($arr_query as $param => $value) {
         switch ($param) {
             case 'price_min':
                 $ad_query .= 'price >= ?';
                 $ad_params[] = $value;
                 break;
             case 'price_max':
                 $ad_query .= 'price <= ?';
                 $ad_params[] = $value;
                 break;
             case 'area_min':
                 $ad_query .= 'area >= ?';
                 $ad_params[] = $value;
                 break;
             case 'area_max':
                 $ad_query .= 'area <= ?';
                 $ad_params[] = $value;
                 break;
             case 'user_id':
                 $ad_query .= 'user_id = ?';
                 $ad_params[] = $value;
                 break;
             case 'category_id':
                 $ad_query .= 'category_id = ?';
                 $ad_params[] = $value;
                 break;
             case 'ad_type_id':
                 $ad_query .= 'ad_type_id = ?';
                 $ad_params[] = $value;
                 break;
         }
     }
     if (!$is_count) {
         $results = Ad::whereRaw($ad_query, $ad_params)->paginate(10)->get();
     } else {
         $results = Ad::whereRaw($ad_query, $ad_params)->count();
     }
     return $results;
 }