Esempio n. 1
0
 /**
  * Display the specified resource.
  *
  * @param int $id
  *
  * @return Response
  */
 public function searchFields(Category $category)
 {
     if (\Request::ajax() && $category->has('fields')) {
         return $category->fields()->whereIsInSearch('1')->with(['search', 'select' => function ($query) {
             $query->orderBy('position', 'asc');
         }])->get();
     } else {
         abort(404);
     }
 }
Esempio n. 2
0
 protected function createCategory($name, $is_private = 0, $is_visible = 1)
 {
     return Category::create(['name' => $name, 'is_private' => $is_private, 'is_visible' => $is_visible]);
 }
Esempio n. 3
0
 /**
  * Update the specified resource in storage.
  *
  * @param int $id
  *
  * @return Response
  */
 public function update(Ad $ad, AdRequest $request)
 {
     $this->restoreIfTrashed($ad);
     $oldStatus = $ad->adstatus->title;
     $geo = new GeolocationHelper($request->get('geolocation_data'));
     $user = User::findOrFail($request->get('user_id'));
     $category = Category::findOrFail($request->get('category_id'));
     $ad->user()->associate($user);
     $ad->category()->associate($category);
     $ad->geolocation->fill($geo->get());
     $ad->content->fill($request->get('content'));
     $ad->price = $this->getPrice($ad, $request);
     event(new AdWillBeUpdated($ad, $this->admin));
     $ad->save();
     $ad->geolocation->save();
     $ad->content->save();
     if ($ad->adtype->can_update_pic) {
         $this->syncAdPhotos($ad, $request);
     }
     if ($ad->adtype->can_update_video) {
         $this->syncAdVideos($ad, $request);
     }
     $this->syncAdFields($ad, $request);
     if ($oldStatus != 'pending') {
         event(new AdWasUpdated($ad, $this->admin));
     }
     return redirect()->route('zxadmin.ad.edit', $ad->id);
 }
Esempio n. 4
0
 /**
  * Update the specified resource in storage.
  *
  * @param int $id
  *
  * @return Response
  */
 public function update(Ad $ad, UpdateAdUserRequest $request)
 {
     if (!$ad->adtype->can_edit) {
         return ['adId' => null];
     }
     $oldStatus = $ad->adstatus->title;
     $geo = new GeolocationHelper($request->get('geolocation_data'));
     $adstatus = Adstatus::whereTitle('pending')->first();
     $category = Category::visible()->findOrFail($request->get('category_id'));
     $ad->category()->associate($category);
     $ad->adstatus()->associate($adstatus);
     $ad->geolocation->fill($geo->get());
     $ad->content->fill($request->get('content'));
     $ad->price = $this->getPrice($ad, $request);
     event(new AdWillBeUpdated($ad, $this->user));
     $ad->save();
     $ad->geolocation->save();
     $ad->content->save();
     if ($ad->adtype->can_update_pic) {
         $this->syncAdPhotos($ad, $request);
     }
     if ($ad->adtype->can_update_video) {
         $this->syncAdVideos($ad, $request);
     }
     $this->syncAdFields($ad, $request);
     if ($oldStatus != 'pending') {
         event(new AdWasUpdated($ad, $this->user));
     }
     return ['adId' => $ad->id];
 }
Esempio n. 5
0
 /**
  * Define your route model bindings, pattern filters, etc.
  *
  * @param  \Illuminate\Routing\Router  $router
  *
  * @return void
  */
 public function boot(Router $router)
 {
     $router->bind('adWithTrashed', function ($id) {
         return Ad::with('content')->withTrashed()->findOrFail($id);
     });
     $router->bind('ad', function ($id) {
         return Ad::with('content')->findOrFail($id);
     });
     $router->bind('adCollection', function ($ids) {
         $ids = explode(',', $ids);
         return Ad::with('content')->withTrashed()->findMany($ids);
     });
     $router->bind('adstatus', function ($title) {
         return Adstatus::whereTitle($title)->firstOrFail();
     });
     $router->bind('adValidated', function ($id) {
         return Ad::with('content')->validate()->findOrFail($id);
     });
     $router->bind('adPreview', function ($id) {
         if (Auth::guard('admin')->check()) {
             return Ad::with('content')->withTrashed()->findOrFail($id);
         }
         if (Auth::guard('user')->check()) {
             return Auth::user()->ads()->with('content')->findOrFail($id);
         }
         abort(404);
     });
     $router->bind('adtypeNotCustomized', function ($id) {
         return Adtype::whereIsCustomized(0)->findOrFail($id);
     });
     $router->bind('adtypeCollection', function ($ids) {
         $ids = explode(',', $ids);
         return Adtype::findMany($ids);
     });
     $router->bind('templateCollection', function ($ids) {
         $ids = explode(',', $ids);
         return Template::findMany($ids);
     });
     $router->bind('encryptedOrderId', function ($enc) {
         $orderId = Crypt::decrypt($enc);
         return Order::findOrFail($orderId);
     });
     $router->bind('fieldCollection', function ($ids) {
         $ids = explode(',', $ids);
         return Field::findMany($ids);
     });
     $router->bind('subscriptionCollection', function ($ids) {
         $ids = explode(',', $ids);
         return Subscription::findMany($ids);
     });
     $router->bind('userCollection', function ($ids) {
         $ids = explode(',', $ids);
         return User::findMany($ids);
     });
     $router->bind('adUser', function ($id) {
         if (Auth::check()) {
             return Auth::user()->ads()->with('content')->findOrFail($id);
         } else {
             abort(404);
         }
     });
     $router->bind('field', function ($id) {
         return Field::with('search')->findOrFail($id);
     });
     $router->bind('visibleCategory', function ($id) {
         return Category::visible()->findOrFail($id);
     });
     $router->bind('templateblock', function ($identifier) use($router) {
         $page = $router->input('page');
         return Templateblock::whereIdentifier($identifier)->whereTemplateId($page->template->id)->firstOrFail();
     });
     $router->bind('widgetnode', function ($id) use($router) {
         $pageId = $router->input('page')->id;
         $templateblockId = $router->input('templateblock')->id;
         return Widgetnode::whereTemplateblockId($templateblockId)->wherePageId($pageId)->findOrFail($id);
     });
     $router->model('adtype', 'ZEDx\\Models\\Adtype');
     $router->model('template', 'ZEDx\\Models\\Template');
     $router->model('category', 'ZEDx\\Models\\Category');
     $router->model('country', 'ZEDx\\Models\\Country');
     $router->model('page', 'ZEDx\\Models\\Page');
     $router->model('menu', 'ZEDx\\Models\\Menu');
     $router->model('gateway', 'ZEDx\\Models\\Gateway');
     $router->model('themepartial', 'ZEDx\\Models\\Themepartial');
     $router->model('dashboardWidget', 'ZEDx\\Models\\Dashboardwidget');
     $router->model('searchfield', 'ZEDx\\Models\\SearchField');
     $router->model('selectfield', 'ZEDx\\Models\\SelectField');
     $router->model('subscription', 'ZEDx\\Models\\Subscription');
     $router->model('user', 'ZEDx\\Models\\User');
     parent::boot($router);
 }
Esempio n. 6
0
 /**
  * Remove the specified resource from storage.
  *
  * @param Category $category
  *
  * @return Response
  */
 public function destroy(Category $category)
 {
     $category->delete();
 }
Esempio n. 7
0
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function search($params)
 {
     $filters = (object) $this->getFilters($params);
     $ads = Ad::where('adstatus_id', '=', 1);
     if (!is_null($filters->user_status)) {
         $ads = $ads->join('users', function ($join) use($filters) {
             $join->on('ads.user_id', '=', 'users.id')->where('users.status', '=', $filters->user_status);
         });
     }
     if ($category = Category::visible()->find($filters->category_id)) {
         $categories = $category->getDescendantsAndSelf(['id'])->keyBy('id')->keys()->toArray();
         $ads = $ads->whereIn('category_id', $categories);
     }
     $ads = $ads->join('adcontents', function ($join) {
         $join->on('ads.id', '=', 'adcontents.ad_id')->on('ads.adstatus_id', '=', \DB::raw('1'));
     });
     /*
             // Fulltext (valid only on MySql)
             $ads = $query ? $ads->whereRaw('MATCH('.\DB::getTablePrefix().'adcontents.title,'.\DB::getTablePrefix().'adcontents.body) AGAINST(? IN BOOLEAN MODE)', [str_replace(' ', ' +', $query) . "*"]) : $ads;
     */
     // Like (valid on all SGBD)
     $ads = $filters->query ? $ads->where('adcontents.title', 'like', '%' . $filters->query . '%')->orWhere('adcontents.body', 'like', '%' . $filters->query . '%') : $ads;
     if (is_numeric($filters->lat) && is_numeric($filters->lng) && is_numeric($filters->radius)) {
         $ads = $ads->join('geolocations', 'ads.id', '=', 'geolocations.ad_id')->whereRaw('? >= (SELECT ((? - `location_lat`) * (? - `location_lat`)) + ((? - `location_lng`) * (? - `location_lng`)))', [pow($filters->radius, 2), $filters->lat, $filters->lat, $filters->lng, $filters->lng]);
     }
     $ads = $this->joinFields($ads, $filters->fields);
     $ads = $ads->join('adtypes', 'ads.adtype_id', '=', 'adtypes.id')->orderBy('is_headline', 'desc')->orderBy($filters->order['field'], $filters->order['type'])->select('ads.*', 'adcontents.title', 'is_headline')->groupBy('ads.id')->paginate(20);
     $fields = Collection::make($filters->fields);
     return ['data' => compact('ads', 'query', 'category_id', 'lat', 'lng', 'radius', 'location', 'fields')];
 }