/** * Create new event * * @param null|int $id * * @return mixed */ public function newEvent($id = null) { $events = new Events(); $user_id = \Flocc\Auth::getUserId(); $draft = $events->getUserDraft($user_id); if ($draft !== null) { $scoring = (new Scoring())->getByEventId($draft->getId()); $draft->delete(); $scoring->delete(); } if ($id !== null) { $event = $events->getById((int) $id); $event_data = json_decode(json_encode($event), true); unset($event_data['id'], $event_data['views'], $event_data['status'], $event_data['is_inspiration'], $event_data['user_id']); $event_data['user_id'] = $user_id; $draft = $events->createFilledDraft($event_data); /** * Add activities */ foreach ($event->getActivities() as $activity) { (new \Flocc\Events\Activities())->setEventId($draft->getId())->setActivityId($activity->getId())->save(); } /** * Route */ if ($event->getPlaceId() !== null) { $routes = new Routes(); $event_route = $routes->getByEventId($event->getId()); foreach ($event_route as $route) { $routes->addNew($draft->getId(), $route->getPlaceId()); } } } else { $draft = $events->createDraft($user_id); } return redirect()->route('events.edit', ['id' => $draft->getId()]); }