Esempio n. 1
0
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index()
 {
     if ($this->user->subscription_expired_at) {
         if ($this->user->subscription_expired_at->diffInDays(null, false) >= 0) {
             return redirect()->route('user.subscription.index');
         }
     }
     if ($this->user->hasOnlyOneFreeAdtype()) {
         return redirect()->route('user.ad.create', $this->user->adtypes->first());
     }
     $page = (object) $this->pageService->show('user.adtype.index', true);
     return view('__templates::' . $page->templateFile, $page->data);
 }
Esempio n. 2
0
 /**
  * Attach An Adtype To Users.
  *
  * @param Adtype $adtype
  *
  * @return void
  */
 protected function attachToUsers(Adtype $adtype)
 {
     $subscriptions = User::all();
     foreach ($subscriptions as $subscription) {
         $subscription->adtypes()->attach($adtype, ['number' => 0]);
     }
 }
Esempio n. 3
0
 protected function syncProviderUser($driver, $userProvider)
 {
     $userProviderId = $userProvider->getId();
     $user = Auth::user();
     $socialId = $driver . '_id';
     $userAlreadyConnectedToProvider = User::where($socialId, '=', $userProviderId)->first();
     if ($userAlreadyConnectedToProvider) {
         Auth::loginUsingId($userAlreadyConnectedToProvider->id);
     } elseif (Auth::check()) {
         $this->connectUsertoProvider($user, $socialId, $userProviderId);
     } else {
         $request = ['email' => $userProvider->getEmail() ?: $userProviderId . '@' . $driver, 'password' => str_random(10), 'name' => $userProvider->getName(), 'is_validate' => $userProvider->getEmail() ? '1' : '0'];
         $userService = new UserService();
         $item = $userService->store($request, ucfirst($driver));
         $user = $item['user'];
         $userService->makeAvatarFor($user, $userProvider->getAvatar());
         $this->connectUsertoProvider($user, $socialId, $userProviderId);
         Auth::loginUsingId($user->id);
     }
     return redirect()->route('user.ad.index');
 }
Esempio n. 4
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  User  $user
  *
  * @return Response
  */
 protected function destroy(User $user)
 {
     $admin = Auth::guard('admin')->user();
     event(new UserWillBeDeleted($user, $admin));
     $user->delete();
     event(new UserWasDeleted($user, $admin));
 }
Esempio n. 5
0
 /**
  * Store new user.
  *
  * @param array      $data
  * @param Admin/User $actor
  *
  * @return array
  */
 public function store(array $data, $actor, $provider = false)
 {
     $subscription = Subscription::whereIsDefault(1)->firstOrFail();
     $role = Role::whereName('user')->firstOrFail();
     $adtypes = [];
     foreach ($subscription->adtypes as $adtype) {
         $adtypes[$adtype->id] = ['number' => $adtype->pivot->number];
     }
     if (!isset($data['phone']) || empty($data['phone'])) {
         $data['is_phone'] = false;
     }
     $user = new User();
     $user->fill($data);
     if ($provider) {
         $user->is_validate = $data['is_validate'];
     }
     $user->subscription_id = $subscription->id;
     $user->role_id = $role->id;
     $user->subscribed_at = Carbon::now()->format('d/m/Y');
     $user->subscription_expired_at = $subscription->days >= 9999 ? null : Carbon::createFromFormat('d/m/Y', $user->subscribed_at)->addDays($subscription->days + 1);
     event(new UserWillBeCreated($user, $actor, $adtypes));
     $user->save();
     $user->adtypes()->sync($adtypes);
     event(new UserWasCreated($user, $actor));
     return ['user' => $user];
 }
Esempio n. 6
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. 7
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. 8
0
 protected function saveUserAdtype(User $user, $adtypes)
 {
     $user->adtypes()->sync($adtypes);
 }
Esempio n. 9
0
File: Widget.php Progetto: zedx/zedx
 /**
  * Display widget.
  *
  * @return Response
  */
 public function run()
 {
     return view('widget_backend_zedx_latestmembers::index', ['config' => $this->config, 'users' => User::limit(10)->get()]);
 }