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; }
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 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; }
public function putAdInfor($id) { if (!Auth::check()) { return Response::json(array('status' => 'error', 'message' => trans(CLF_LANG_MESSAGE . 'require_signin')), 500); } $data = post(); try { DB::beginTransaction(); $default = array('area' => 0, 'tier' => 0, 'direction' => 0, 'bed' => 0, 'bath' => 0); $merge = array_merge($default, $data); $merge = HelperClassified::trim_value($merge); extract($merge); $rules = ['area' => 'required|numeric', 'bed' => 'required|numeric', 'bath' => 'required|numeric', 'direction' => 'required|numeric', 'tier' => 'required|numeric']; $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); } $record->area = intval($area); $record->tier = intval($tier); $record->direction = intval($direction); $record->bed = intval($bed); $record->bath = intval($bath); $record->save(); 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); } }