Esempio n. 1
0
 public function onCalcAdTagCount()
 {
     $tag_id = post('id');
     if (!$tag_id) {
         return false;
     }
     TagModel::updateCount($tag_id);
     return true;
 }
Esempio n. 2
0
 public static function getAdAmenities()
 {
     $options = '';
     if (!Cache::has('amenities_options')) {
         $options = Tag::getTagByType('ad_amenities');
         Cache::put('amenities_options', $options, CLF_CACHE);
     } else {
         $options = Cache::get('amenities_options');
     }
     return $options;
 }
Esempio n. 3
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. 4
0
 public function getRefreshTagCount()
 {
     // Get tags
     $tags = Tag::where('crawl', '=', false)->take(self::$limit_crawl_tag_count)->get();
     if (!$tags->count()) {
         // Reset crawl status for all tags
         Tag::all()->update(array('crawl' => false));
         return Response::json(array('status' => 'error'), 500);
     }
     foreach ($tags as $tag) {
         if ($tag->id) {
             // Count ad for tag
             $count = DB::table('dlnlab_classified_ads_tags')->where('tag_id', '=', $tag->id)->count();
             $tag->count = $count;
             $tag->crawl = true;
             $tag->save();
         }
     }
     return Response::json(array('status' => 'success'), 200);
 }
Esempio n. 5
0
 public function run()
 {
     $timestamp = \Carbon\Carbon::now()->toDateTimeString();
     AdCategory::insert([['name' => 'Căn hộ chung cư', 'slug' => 'can-ho-chung-cu', 'status' => 1, 'updated_at' => $timestamp, 'created_at' => $timestamp], ['name' => 'Nhà trọ, phòng trọ', 'slug' => 'nha-tro', 'status' => 1, 'updated_at' => $timestamp, 'created_at' => $timestamp], ['name' => 'Nhà riêng', 'slug' => 'nha-rieng', 'status' => 1, 'updated_at' => $timestamp, 'created_at' => $timestamp], ['name' => 'Nhà mặt phố', 'slug' => 'nha-mat-pho', 'status' => 1, 'updated_at' => $timestamp, 'created_at' => $timestamp], ['name' => 'Văn phòng', 'slug' => 'van-phong', 'status' => 1, 'updated_at' => $timestamp, 'created_at' => $timestamp], ['name' => 'Cửa hàng', 'slug' => 'cua-hang', 'status' => 1, 'updated_at' => $timestamp, 'created_at' => $timestamp], ['name' => 'Nhà kho, xưởng', 'slug' => 'nha-kho', 'status' => 1, 'updated_at' => $timestamp, 'created_at' => $timestamp]]);
     Tag::insert([['name' => 'Ban công', 'slug' => 'ban-cong', 'type' => 'ad_amenities', 'icon' => '', 'status' => 1, 'updated_at' => $timestamp, 'created_at' => $timestamp], ['name' => 'Bảo vệ', 'slug' => 'bao-ve', 'type' => 'ad_amenities', 'icon' => '', 'status' => 1, 'updated_at' => $timestamp, 'created_at' => $timestamp], ['name' => 'Bể bơi', 'slug' => 'be-boi', 'type' => 'ad_amenities', 'icon' => '', 'status' => 1, 'updated_at' => $timestamp, 'created_at' => $timestamp], ['name' => 'Bình nóng lạnh', 'slug' => 'binh-nong-lanh', 'type' => 'ad_amenities', 'icon' => '', 'status' => 1, 'updated_at' => $timestamp, 'created_at' => $timestamp], ['name' => 'Chỗ để xe', 'slug' => 'cho-de-xe', 'type' => 'ad_amenities', 'icon' => '', 'status' => 1, 'updated_at' => $timestamp, 'created_at' => $timestamp], ['name' => 'Điều hòa nhiệt độ', 'slug' => 'dieu-hoa-nhiet-do', 'type' => 'ad_amenities', 'icon' => '', 'status' => 1, 'updated_at' => $timestamp, 'created_at' => $timestamp], ['name' => 'Gara ô tô', 'slug' => 'gara-o-to', 'type' => 'ad_amenities', 'icon' => '', 'status' => 1, 'updated_at' => $timestamp, 'created_at' => $timestamp], ['name' => 'Máy giặt', 'slug' => 'may-giat', 'type' => 'ad_amenities', 'icon' => '', 'status' => 1, 'updated_at' => $timestamp, 'created_at' => $timestamp], ['name' => 'Tivi', 'slug' => 'ti-vi', 'type' => 'ad_amenities', 'icon' => '', 'status' => 1, 'updated_at' => $timestamp, 'created_at' => $timestamp], ['name' => 'Truyền hình cáp', 'slug' => 'truyen-hinh-cap', 'type' => 'ad_amenities', 'icon' => '', 'status' => 1, 'updated_at' => $timestamp, 'created_at' => $timestamp], ['name' => 'Tủ lạnh', 'slug' => 'tu-lanh', 'type' => 'ad_amenities', 'icon' => '', 'status' => 1, 'updated_at' => $timestamp, 'created_at' => $timestamp], ['name' => 'Thang máy', 'slug' => 'thang-may', 'type' => 'ad_amenities', 'icon' => '', 'status' => 1, 'updated_at' => $timestamp, 'created_at' => $timestamp], ['name' => 'Wifi', 'slug' => 'internet', 'type' => 'ad_amenities', 'icon' => '', 'status' => 1, 'updated_at' => $timestamp, 'created_at' => $timestamp]]);
 }
Esempio n. 6
0
 public function putAd($id)
 {
     $data = post();
     try {
         DB::beginTransaction();
         $default = array('name' => '', 'slug' => '', 'description' => '', 'price' => '', 'address' => '', 'category_id' => '', 'type_id' => '', 'tag_ids' => '', 'lat' => '', 'lng' => '', 'step' => 0, 'action' => '');
         $merge = array_merge($default, $data);
         $merge = HelperClassified::trim_value($merge);
         extract($merge);
         switch ($action) {
             case 'desc':
                 $rules = ['name' => 'required', 'description' => 'required', 'category_id' => 'required|numeric|min:1', 'type_id' => 'required|numeric|min:1', 'price' => 'required|numeric', 'step' => ''];
                 break;
             case 'location':
                 $rules = ['address' => 'required', 'lat' => 'required', 'lng' => 'required'];
                 break;
             case 'property':
                 $rules = ['tag_ids' => 'array'];
                 break;
             default:
                 $rules = ['name' => 'required', 'description' => 'required', 'category_id' => 'required|numeric|min:1', 'type_id' => 'required|numeric|min:1', 'address' => 'required', 'price' => 'required|numeric', 'lat' => 'required', 'lng' => 'required', 'tag_ids' => 'array', 'area' => 'numeric'];
                 break;
         }
         $error = HelperClassified::valid($rules);
         if ($error != null) {
             return Response::json(array('status' => 'error', 'message' => $error), 500);
         }
         $record = Ad::find($id);
         if (empty($record) || $record->user_id != Auth::getUser()->id) {
             return Response::json(array('status' => 'error', 'message' => trans(CLF_LANG_MESSAGE . 'error_user')), 500);
         }
         $lat = is_float($lat) ? floatval($lat) : '';
         $lng = is_float($lng) ? floatval($lng) : '';
         if (empty($lat) && empty($lng)) {
             $record->name = str_limit($name, $limit = 125);
             $record->slug = empty($slug) ? HelperClassified::slug_utf8($name) : $slug;
             $record->description = str_limit($description, $limit = 500);
             $record->price = preg_replace("/[^0-9]/", "", $price);
             $record->address = $address;
             $record->category_id = intval($category_id);
             $record->type_id = intval($type_id);
             $record->lat = $lat;
             $record->lng = $lng;
             $record->save();
         }
         if (!$record->validate()) {
             $message = $record->errors()->all();
             return Response::json(array('status' => 'error', 'message_array' => $message), 500);
         }
         $city = '';
         $state = '';
         if ($lat && $lng && ($lat != $record->lat && $lng != $record->lng)) {
             $response = @file_get_contents(sprintf('https://maps.googleapis.com/maps/api/geocode/json?latlng=%s,%s&language=vi_VN', $lat, $lng));
             $json_resp = json_decode($response);
             if (isset($json_resp->results[0]->address_components) && is_array($json_resp->results[0]->address_components)) {
                 $allow = true;
                 foreach ($json_resp->results[0]->address_components as $i => $component) {
                     if (!empty($component->types) && in_array('country', $component->types) && $component->short_name != 'VN') {
                         $allow = false;
                     }
                     if ($allow && !empty($component->types) && in_array('administrative_area_level_1', $component->types)) {
                         $city = $component->short_name;
                     }
                     if ($allow && !empty($component->types) && in_array('administrative_area_level_2', $component->types)) {
                         $state = $component->long_name;
                     }
                 }
             }
         }
         if ($record->id) {
             $default = array('ad_id' => $record->id, 'tag_ids' => $tag_ids, 'city_tag' => $city, 'state_tag' => $state);
             Tag::save_tag($default);
         }
         DB::commit();
         return Response::json(array('status' => 'success', 'data' => $record));
     } catch (Exception $ex) {
         DB::rollback();
         return Response::json(array('status' => 'error', 'message' => $ex->getMessage()), 500);
     }
 }