public function onRun() { $user = $this->user(); if (!$user) { return false; } $name = trim($user->name); $parts = explode(" ", $name); $last_name = array_pop($parts); $first_name = implode(" ", $parts); $path = !empty($user->avatar) ? $user->avatar->getPath() : ''; $this->page['user'] = $user; $this->page['last_name'] = $last_name; $this->page['first_name'] = $first_name; $this->page['avatar'] = $path; $asset_script[] = '~/plugins/dlnlab/classified/assets/js/components/headerbar.js'; $asset_css[] = '~/plugins/dlnlab/classified/assets/css/components/headerbar.css'; $this->page['asset_css'] = $asset_css; $this->page['asset_script'] = $asset_script; $this->page['types'] = HelperCache::getAdType(); $this->page['categories'] = HelperCache::getAdCategory(); $this->page['amenities'] = HelperCache::getAdAmenities(); $this->page['bed_rooms'] = AdInfor::getBedRoomOptions(); $this->page['bath_rooms'] = AdInfor::getBathRoomOptions(); $this->page['directions'] = AdInfor::getDirectionOptions(); }
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; }
public function postAdQuick() { $data = post(); $default = array('category_id' => '', 'type_id' => 2, 'address' => '', 'lat' => '', 'lng' => '', 'price' => 0, 'area' => 0); $merge = array_merge($default, $data); $merge = \DLNLab\Classified\Classes\HelperClassified::trim_value($merge); extract($merge); $user = Auth::getUser(); // Kiem tra user hien tai da > 3 ad draft chua $counts = Ad::whereRaw('user_id = ? AND status = 0', array($user->id))->count(); if ($counts >= CLF_LIMIT_AD_PRIVATE) { return Response::json(array('status' => 'error', 'message' => trans(CLF_LANG_MESSAGE . 'not_create_ad')), 500); } $rules = ['category_id' => 'required|numeric|min:1', 'type_id' => 'required|numeric|min:1', 'address' => 'required', 'price' => 'required|numeric', 'area' => 'numeric']; $error = HelperClassified::valid($rules); if ($error != null) { return Response::json(array('status' => 'error', 'message' => $error), 500); } // Format lai tag ids if ($tag_ids) { foreach ($tag_ids as $id) { if (!empty($id) || intval($id) > 0 || !in_array($id, $tags)) { $tags[] = $id; } } if (!count($tags)) { return Response::json(array('status' => 'error', 'message' => trans(CLF_LANG_MESSAGE . 'not_create_ad')), 500); } } $name = Ad::gen_auto_ad_name($merge); $slug = HelperClassified::slug_utf8($name); try { DB::beginTransaction(); $record = new Ad(); $record->name = $name; $record->slug = $slug; $record->address = $address; $record->category_id = $category_id; $record->type_id = $type_id; $record->price = $price; $record->lat = $lat; $record->lng = $lng; $record->save(); // Them vao bang ads_tags /*$arr_insert = array(); if (! empty($tags)) { foreach ($tags as $id) { $arr_insert[] = array('ad_id' => $record->id, 'tag_id' => $id); } DB::table('dlnlab_classified_ads_tags')->insert($arr_insert); }*/ if ($area) { $record = new AdInfor(); $record->area = $area; $record->save(); } DB::commit(); return Response::json(array('status' => 'success', 'data' => $record->id)); } catch (Exception $ex) { DB::rollback(); return Response::json(array('status' => 'error', 'message' => $error), 500); } }