Exemple #1
0
 /**
  * Get user ID
  *
  * @return int|null
  */
 public static function getUserId()
 {
     if (\Auth::user() !== null) {
         return (int) \Auth::user()->id;
     }
     return null;
 }
 /**
  * New comment
  *
  * @param \Illuminate\Http\Request $request
  */
 public function save(\Illuminate\Http\Request $request)
 {
     $comment = \Input::get('comment', '');
     $event_id = (int) \Input::get('event_id');
     $parent_id = \Input::get('parent_id', null);
     $label = \Input::get('label', 'public');
     $user_id = (int) \Auth::user()->id;
     $events = new Events();
     $line = new NewLine();
     $event = $events->getById($event_id);
     /**
      * @var $user \Flocc\Profile
      */
     $user = (new User())->getById($user_id)->getProfile();
     if ($event === null) {
         die;
         // @TODO:
     }
     if (!empty($comment)) {
         if ($label === 'private') {
             $comments = new Comments();
             $comments->setEventId($event_id)->setParentId($parent_id)->setLabelAsPrivate()->setUserId($user_id)->setComment($comment)->setLastCommentTimeAsCurrent()->save();
             /**
              * Update last comment time for parent
              */
             if ($parent_id !== null) {
                 $comment = $comments->getById($parent_id);
                 $comment->setLastCommentTimeAsCurrent()->save();
             }
             /**
              * Send notifications
              *
              * @var $member \Flocc\Events\Members
              */
             foreach ($event->getMembers() as $member) {
                 if ($member->getUserId() !== Auth::getUserId()) {
                     (new NewNotification())->setUserId($member->getUserId())->setUniqueKey('events.comment.' . $event->getId() . '.' . md5($comment))->setTypeId('events.comment')->setCallback('/events/' . $event->getId() . '/' . $event->getSlug())->addVariable('user', $user->getFirstName() . ' ' . $user->getLastName())->addVariable('event', $event->getTitle())->save();
                 }
             }
         } else {
             if (empty($comment) === false) {
                 $line->setTypeAsComment()->setEventId($event_id)->setUserId($user_id)->setComment($comment)->save();
                 $comment_id = $line->getLastInsertCommentId();
                 /**
                  * Send notifications
                  *
                  * @var $member \Flocc\Events\Members
                  */
                 foreach ($event->getMembersAndFollowers() as $member) {
                     if ($member->getUserId() !== Auth::getUserId()) {
                         (new NewNotification())->setUserId($member->getUserId())->setUniqueKey('events.comment.' . $event->getId() . '.' . md5($comment))->setTypeId('events.comment')->setCallback('/events/' . $event->getId() . '/' . $event->getSlug())->addVariable('user', $user->getFirstName() . ' ' . $user->getLastName())->addVariable('event', $event->getTitle())->save();
                     }
                 }
             }
         }
         $request->session()->flash('comments_label', $label);
     }
     return redirect()->route('events.event', ['id' => $event->getId(), 'slug' => $event->getSlug()]);
 }
 public function delete($id)
 {
     $notifications = new Notifications();
     $notification = $notifications->getById($id);
     if ($notification) {
         if ($notification->user_id === Auth::getUserId()) {
             $notification->delete();
         }
     }
     return \Redirect::to('notifications');
 }
 /**
  * Edit event
  *
  * @param \Illuminate\Http\Request $request
  * @param int $id
  *
  * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
  */
 public function index(\Illuminate\Http\Request $request, $id)
 {
     $this->init($id);
     $activities = new Activities();
     $budgets = new Budgets();
     $intensities = new Intensities();
     $tribes = new Tribes();
     $travel_ways = new TravelWays();
     $infrastructure = new Infrastructure();
     $tourist = new Tourist();
     $plannings = new Plannings();
     $places = new Places();
     $edit = new EditEvent();
     $routes = new Routes();
     $events_activities = new \Flocc\Events\Activities();
     $users = new User();
     $post = \Input::get();
     $old_event = clone $this->event;
     $is_draft = $this->event->isStatusDraft();
     $user = $users->getById(Auth::getUserId());
     $post_routes = [];
     $months = (new DateHelper())->getMonths();
     if ($this->event->isStatusCanceled()) {
         die;
         // @TODO
     }
     if (!empty($post)) {
         $edit->setData($post);
         $validator = \Validator::make($post, $edit->getValidationRules($post, $this->event), $edit->getValidationMessages());
         $errors = $validator->errors();
         $this->event->setLastUpdateTime(time())->setTitle(\Input::get('title'))->setDescription(\Input::get('description'))->setEventFrom(\Input::get('event_from'))->setEventTo(\Input::get('event_to'))->setEventSpan(\Input::get('event_span'))->setUsersLimit(\Input::get('users_limit'))->setBudgetId(\Input::get('budgets'))->setIntensitiesId(\Input::get('intensities'))->setTravelWaysId(\Input::get('travel_ways_id'))->setInfrastructureId(\Input::get('infrastructure_id'))->setTouristId(\Input::get('tourist_id'))->setPlanningId(\Input::get('planning_id'));
         if (isset($post['fixed'])) {
             if ($post['fixed'] == '1') {
                 $this->event->setAsFixed();
             } else {
                 $this->event->setAsNonFixed();
             }
         }
         if ($this->event->isStatusDraft()) {
             $this->event->setStatus('open');
         }
         if (\Input::get('place_type') == 'place') {
             $place_name = \Input::get('place');
             $find_place = $places->getByName($place_name);
             if ($find_place === null) {
                 $places->addNew($place_name);
                 $find_place = $places->getByName($place_name);
             }
             $place_id = $find_place->getId();
             $this->event->setPlaceId($place_id);
         } else {
             $this->event->setPlaceId(null);
         }
         if (isset($post['voluntary']) and $post['voluntary'] == '1') {
             $this->event->setVoluntaryAsTrue();
         } else {
             $this->event->setVoluntaryAsFalse();
         }
         if (isset($post['language_learning']) and $post['language_learning'] == '1') {
             $this->event->setLanguageLearningAsTrue();
         } else {
             $this->event->setLanguageLearningAsFalse();
         }
         if (isset($post['event_month'])) {
             $this->event->setEventMonth($post['event_month']);
         }
         if ($errors->count() == 0) {
             if ($post['place_type'] == 'place') {
                 unset($post['route']);
             } else {
                 $post['place'] = null;
                 $post['route'] = explode(';', substr($post['route'], 0, -1));
             }
             unset($post['place_type']);
             $is_new_activity = array_search('new', $post['activities']);
             if ($is_new_activity !== false) {
                 unset($post['activities'][$is_new_activity]);
                 $new_activity = $post['new_activities'];
                 unset($post['new_activities']);
             }
             /**
              * Add new activity
              */
             if (isset($new_activity)) {
                 $find_activity = $activities->getByName($new_activity);
                 if ($find_activity === null) {
                     $post['activities'][] = $activities->addNew($new_activity);
                 } else {
                     if (in_array($find_activity->getId(), $post['activities']) === false) {
                         $post['activities'][] = $find_activity->getId();
                     }
                 }
             }
             $post['activities'] = array_unique($post['activities']);
             /**
              * Avatar
              */
             if ($request->hasFile('photo')) {
                 $image = new ImageHelper();
                 $file = $request->file('photo');
                 $this->event->setAvatarUrl($image->uploadFile($file));
             }
             /**
              * Tribes
              */
             $events_tribes = new \Flocc\Events\Tribes();
             $events_tribes->clear($this->event->getId());
             foreach (\Input::get('tribes', []) as $tribe_id) {
                 $events_tribes->add($this->event->getId(), $tribe_id);
             }
             /**
              * Set status as open
              */
             if ((int) $post['users_limit'] > $old_event->getUsersLimit()) {
                 $this->event->setStatusOpen();
             }
             /**
              * Save event
              */
             $this->event->save();
             /**
              * Save route
              */
             if (isset($post['route'])) {
                 $routes->clear($id);
                 foreach ($post['route'] as $place_name) {
                     $find_place = $places->getByName($place_name);
                     if ($find_place === null) {
                         $places->addNew($place_name);
                         $find_place = $places->getByName($place_name);
                     }
                     Routes::create(['event_id' => $id, 'place_id' => $find_place->getId()]);
                 }
             }
             /**
              * Save activities
              */
             $events_activities->clear($id);
             foreach ($post['activities'] as $activity_id) {
                 \Flocc\Events\Activities::create(['event_id' => $id, 'activity_id' => $activity_id]);
             }
             /**
              * Add new time line
              */
             if ($is_draft === true) {
                 $user_name = $user->getProfile()->getFirstName() . ' ' . $user->getProfile()->getLastName();
                 (new TimeLine\NewLine())->setEventId($id)->setTypeAsMessage()->setMessage(sprintf('[b]%s[/b] utworzył wydarzenie dnia %s o %s', $user_name, date('Y-m-d'), date('H:i')))->setUserId(Auth::getUserId())->save();
                 /**
                  * Add owner as member
                  */
                 (new Members())->addNew($id, Auth::getUserId(), 'member');
             } else {
                 /**
                  * Notification if users limits is higher
                  */
                 if ((int) $post['users_limit'] > $old_event->getUsersLimit()) {
                     $notification_type_id = 'events.update.users_limit';
                 } else {
                     $notification_type_id = 'events.update';
                 }
                 /**
                  * Update event date
                  */
                 if ($post['event_from'] !== $old_event->getEventFrom() or $post['event_to'] !== $old_event->getEventTo() or (int) $post['event_span'] !== $old_event->getEventSpan()) {
                     $notification_type_id = 'events.update.date';
                 }
                 /**
                  * Notification
                  *
                  * @var $member \Flocc\Events\Members
                  */
                 foreach ($this->event->getMembers() as $member) {
                     (new NewNotification())->setUserId($member->getUserId())->setUniqueKey('events.update.' . $id . '.' . date('d-m-Y'))->setTypeId($notification_type_id)->setCallback('/events/' . $this->event->getId() . '/' . $this->event->getSlug())->addVariable('event', $this->event->getTitle())->addVariable('users_limit', $post['users_limit'])->addVariable('event_from', $post['event_from'])->addVariable('event_to', $post['event_to'])->addVariable('event_span', (int) $post['event_span'])->save();
                 }
             }
             /**
              * Update scoring
              *
              * @var $scoring \Flocc\Events\Scoring
              */
             $scoring = new Scoring();
             $scoring = $scoring->getByEventId($this->event->getId());
             $scoring = $scoring->setActivityId(reset($post['activities']))->setTribes(\Input::get('tribes', []));
             if (\Input::get('place_type') != 'place') {
                 $scoring = $scoring->setRoute(implode(' > ', $post['route']))->setPlace(null);
             } else {
                 $scoring = $scoring->setPlace(\Input::get('place'))->setRoute(null);
             }
             $scoring->save();
             if ($is_draft === true) {
                 /**
                  * Save user log
                  */
                 (new User\Logs())->setUserId(Auth::getUserId())->setTypeEventsCreate()->setEventId($this->event->getId())->save();
                 return redirect()->route('events.event.share', ['id' => $this->event->getId(), 'slug' => $this->event->getSlug()]);
             }
             return redirect()->route('events.event', ['id' => $this->event->getId(), 'slug' => $this->event->getSlug()]);
         } else {
             if (\Input::get('place_type') != 'place') {
                 foreach (explode(';', $post['route']) as $i => $row) {
                     if (!empty($row)) {
                         $post_routes[$i] = $row;
                     }
                 }
             }
             if (in_array('new', \Input::get('activities', []))) {
                 $post_new_activity = \Input::get('new_activities');
             }
             $post_activities = [];
             if (isset($post['activities'])) {
                 foreach ($post['activities'] as $post_activity) {
                     $post_activities[(int) $post_activity] = (int) $post_activity;
                 }
             }
         }
     }
     return view('events.edit.index', ['event' => $this->event, 'activities' => $activities->all(), 'budgets' => $budgets->all(), 'intensities' => $intensities->all(), 'tribes' => $tribes->all(), 'travel_ways' => $travel_ways->all(), 'infrastructure' => $infrastructure->all(), 'tourist' => $tourist->all(), 'places' => $places->all(), 'plannings' => $plannings->all(), 'errors' => isset($errors) ? $errors : [], 'post_routes' => $post_routes, 'post_new_activity' => isset($post_new_activity) ? $post_new_activity : null, 'post_activities' => isset($post_activities) ? $post_activities : [], 'months' => $months, 'post' => $post]);
 }
 /**
  * Update settings
  *
  * @param int $id
  *
  * @return \Illuminate\Http\Response
  */
 public function editSettings($id)
 {
     /**
      * @var $profile \Flocc\Profile
      */
     $profile = Profile::findOrFail($id);
     $partying = Profile\Partying::all();
     $alcohol = Profile\Alcohol::all();
     $smoking = Profile\Smoking::all();
     $imprecation = Profile\Imprecation::all();
     $plannings = Profile\Plannings::all();
     $plans = Profile\Plans::all();
     $vegetarian = Profile\Vegetarian::all();
     $flexibility = Profile\Flexibility::all();
     $plans_change = Profile\PlansChange::all();
     $verbosity = Profile\Verbosity::all();
     $vigor = Profile\Vigor::all();
     $cool = Profile\Cool::all();
     $rules = Profile\Rules::all();
     $opinions = Profile\Opinions::all();
     $tolerance = Profile\Tolerance::all();
     $compromise = Profile\Compromise::all();
     $feelings = Profile\Feelings::all();
     $emergency = Profile\Emergency::all();
     $features_sets = Profile\Features::where(['is_set' => '1'])->get();
     $features = Profile\Features::where(['is_set' => '0'])->get();
     $free_time = Profile\FreeTime::all();
     if (!empty(\Input::get())) {
         $post = \Input::get();
         if (isset($post['partying_id'])) {
             $profile->setPartyingId($post['partying_id']);
         }
         if (isset($post['alcohol_id'])) {
             $profile->setAlcoholId($post['alcohol_id']);
         }
         if (isset($post['smoking_id'])) {
             $profile->setSmokingId($post['smoking_id']);
         }
         if (isset($post['imprecation_id'])) {
             $profile->setImprecationId($post['imprecation_id']);
         }
         if (isset($post['imprecation_id'])) {
             $profile->setImprecationId($post['imprecation_id']);
         }
         if (isset($post['plannings_id'])) {
             $profile->setPlanningsId($post['plannings_id']);
         }
         if (isset($post['plans_id'])) {
             $profile->setPlansId($post['plans_id']);
         }
         if (isset($post['vegetarian_id'])) {
             $profile->setVegetarianId($post['vegetarian_id']);
         }
         if (isset($post['verbosity_id'])) {
             $profile->setVerbosityId($post['verbosity_id']);
         }
         if (isset($post['vigor_id'])) {
             $profile->setVigorId($post['vigor_id']);
         }
         if (isset($post['cool_id'])) {
             $profile->setCoolId($post['cool_id']);
         }
         if (isset($post['rules_id'])) {
             $profile->setRulesId($post['rules_id']);
         }
         if (isset($post['opinions_id'])) {
             $profile->setOpinionsId($post['opinions_id']);
         }
         if (isset($post['tolerance_id'])) {
             $profile->setToleranceId($post['tolerance_id']);
         }
         if (isset($post['compromise_id'])) {
             $profile->setCompromiseId($post['compromise_id']);
         }
         if (isset($post['feelings_id'])) {
             $profile->setFeelingsId($post['feelings_id']);
         }
         if (isset($post['emergency_id'])) {
             $profile->setEmergencyId($post['emergency_id']);
         }
         //->setFlexibilityId($post['flexibility_id'])
         //->setPlansChangeId($post['plans_change_id'])
         $profile->save();
         $users_features = new Features();
         $free_time_user = new FreeTime();
         $users_features->clear(\Flocc\Auth::getUserId());
         $free_time_user->clear(\Flocc\Auth::getUserId());
         if (isset($post['features'])) {
             foreach ($post['features'] as $feature_id) {
                 $users_features->addNew(\Flocc\Auth::getUserId(), $feature_id);
             }
         }
         if (isset($post['free_time'])) {
             foreach ($post['free_time'] as $free_time_id) {
                 $free_time_user->addNew(\Flocc\Auth::getUserId(), $free_time_id);
             }
         }
         $message = "Successfully updated";
     }
     return view('profiles.edit.settings', compact('message', 'profile', 'partying', 'alcohol', 'smoking', 'imprecation', 'plannings', 'plans', 'vegetarian', 'flexibility', 'plans_change', 'verbosity', 'vigor', 'cool', 'rules', 'opinions', 'tolerance', 'compromise', 'feelings', 'emergency', 'features', 'features_sets', 'errors', 'free_time'));
 }
 /**
  * Is important?
  *
  * @return bool
  */
 public function isImportant()
 {
     $get = Users::where('conversation_id', $this->conversation_id)->where('user_id', Auth::getUserId())->first();
     return $get->is_important == 1;
 }
Exemple #7
0
 /**
  * Can i resign
  *
  * @return bool
  */
 public function canUnJoin()
 {
     foreach ($this->getMembers() as $user) {
         if ($user->getUserId() == Auth::getUserId()) {
             return true;
         }
     }
     return false;
 }
 public function getLogout()
 {
     (new User\Logs())->setUserId(\Flocc\Auth::getUserId())->setTypeUsersLogout()->save();
     Auth::logout();
     return redirect('/auth/login');
 }
 /**
  * Resign
  *
  * @param \Illuminate\Http\Request $request
  * @param int $id
  * @param string $slug
  *
  * @return mixed
  */
 public function resign(\Illuminate\Http\Request $request, $id, $slug)
 {
     $events = new Events();
     $members = new Members();
     $event = $events->getById($id);
     $member = $members->where('event_id', $event->getId())->where('user_id', Auth::getUserId())->first();
     if ($event === null) {
         die;
         // @TODO:
     }
     if ($member->status == 'member') {
         $ids = [];
         foreach ($event->getMembers() as $user) {
             if ($user->getUserId() !== Auth::getUserId()) {
                 $ids[] = $user->getUserId();
             }
         }
         foreach ($ids as $user_id) {
             /**
              * @var $user \Flocc\Profile
              */
             $user = (new User())->getById(Auth::getUserId())->getProfile();
             (new NewNotification())->setUserId($user_id)->setUniqueKey('events.resign.' . Auth::getUserId())->setCallback('/events/' . $event->getId() . '/' . $event->getSlug())->setTypeId('events.resign')->addVariable('user', $user->getFirstName() . ' ' . $user->getLastName())->addVariable('event', $event->getTitle())->save();
         }
         /**
          * Notification to owner
          */
         (new NewNotification())->setUserId($event->getUserId())->setUniqueKey('events.reopen.' . $event->getId())->setCallback('/events/' . $event->getId() . '/' . $event->getSlug())->setTypeId('events.reopen')->addVariable('user', $user->getFirstName() . ' ' . $user->getLastName())->addVariable('event', $event->getTitle())->save();
         /**
          * Reopen event
          */
         if ($event->isStatusClose()) {
             $event->setStatusOpen()->save();
         }
     }
     $member->delete();
     $request->session()->flash('message', 'Wypisałeś się z wydarzenia');
     return redirect()->route('events.event', ['id' => $event->getId(), 'slug' => $event->getSlug()]);
 }
 /**
  * Select as important / not
  *
  * @param int $id
  * @param int $is
  *
  * @return mixed
  */
 public function important($id, $is)
 {
     $users = new Users();
     $users->where('conversation_id', $id)->where('user_id', Auth::getUserId())->update(['is_important' => (string) $is]);
     return \Redirect::to('mail/' . $id);
 }
 /**
  * New inspiration
  *
  * @return mixed
  */
 public function newInspirationEvent()
 {
     $events = new Events();
     $user_id = \Flocc\Auth::getUserId();
     $draft = $events->getUserDraft($user_id, true);
     if ($draft !== null) {
         $draft->delete();
     }
     $draft = $events->createDraft($user_id, true);
     return redirect()->route('events.edit', ['id' => $draft->getId()]);
 }
Exemple #12
0
 public function testIsNull()
 {
     $this->assertEquals(null, \Flocc\Auth::getUserId());
 }