public function subscribePackage($userId = 1, $packageId = 1) { // loop through packages each events and subscribe $package = $this->packageRepository->findById($packageId); foreach ($package->events as $event) { $this->subscribe($userId, $event->id); } }
/** * @param $id * @return \Illuminate\Http\RedirectResponse * @throws \Acme\Core\Exceptions\EntityNotFoundException * Update Status of the user */ public function update($id) { $status = Input::get('status'); $feedback = Input::get('feedback'); $subscription = $this->subscriptionRepository->findById($id); $userId = $subscription->user_id; // check if the status that is being updated is not the current state if ($subscription->status == $status) { return Redirect::back()->with('error', 'The user is already ' . ucwords(strtolower($status))); } // if package requests try looping through all events if ($subscription->event->package) { // If its a package event, find the package Id $packageId = $subscription->event->package_id; $package = $this->packageRepository->findById($packageId); // Store all the package events in an array foreach ($package->events as $event) { $packageArray[] = $event->id; } // Find all the events subscribed by the user for the current package $packageSubscriptions = $this->subscriptionRepository->findAllPackageSubscriptionsForUser($userId, $packageArray); // Loop through the all the subscription of the user for the current package and store it an array foreach ($packageSubscriptions as $subscription) { $subscriptionArray[] = $subscription->event_id; } // Compare whether user has subscribed to all the events in the package $hasSubscribedToWholePackage = !array_diff($packageArray, $subscriptionArray); if ($hasSubscribedToWholePackage) { for ($i = 0; $i < count($packageArray); $i++) { $this->subscribe($subscription, $status, $feedback); } } else { $this->subscribe($subscription, $status, $feedback); } } else { $this->subscribe($subscription, $status, $feedback); return Redirect::action('AdminSubscriptionsController@index')->with('success', 'Succes'); } }
/** * Display a listing of the resource. * * @return Response */ public function index() { $events = $this->eventRepository->getAll(array('category', 'location.country', 'setting'))->paginate(10); $packages = $this->packageRepository->getAll(); $this->render('admin.events.index', compact('events', 'packages')); }