/**
  * @param array $data
  */
 private function execute(array $data)
 {
     /**
      * User
      */
     foreach ($data as $user) {
         $profile = $user['profile'];
         $events = $user['events'];
         unset($user['profile'], $user['events']);
         $user_data = \Flocc\User::create($user);
         $user_id = $user_data->getId();
         /**
          * User profile
          */
         $profile['user_id'] = $user_id;
         \Flocc\Profile::create($profile);
         /**
          * User events
          */
         foreach ($events as $event) {
             $scoring = $event['scoring'];
             unset($event['scoring']);
             $event['user_id'] = $user_id;
             $event = \Flocc\Events\Events::create($event);
             /**
              * Event activities
              */
             \Flocc\Events\Activities::create(['event_id' => $event->getId(), 'activity_id' => rand(1, 3)]);
             /**
              * Event members
              */
             \Flocc\Events\Members::create(['event_id' => $event->getId(), 'user_id' => $user_id, 'status' => 'member']);
             /**
              * Add scoring
              */
             $scoring['event_id'] = $event->getId();
             \Flocc\Events\Scoring::create([$scoring]);
         }
         /**
          * Mail label
          */
         \Flocc\Mail\Labels::create(['user_id' => $user_id, 'name' => 'Skrzynka odbiorcza', 'type' => 'inbox']);
         \Flocc\Mail\Labels::create(['user_id' => $user_id, 'name' => 'Kosz', 'type' => 'trash']);
         \Flocc\Mail\Labels::create(['user_id' => $user_id, 'name' => 'Archiwum', 'type' => 'archive']);
     }
 }
Beispiel #2
0
 /**
  * Get member and follower events
  *
  * @param string|array $status
  *
  * @return \Illuminate\Pagination\LengthAwarePaginator
  *
  * @throws \Exception
  */
 public function getByMemberId($status)
 {
     $user_id = $this->getParam(1);
     if ($user_id === null) {
         throw new \Exception('Empty user ID');
     }
     /**
      * Display my events
      */
     if ($user_id == 'my') {
         $user_id = (int) \Auth::user()->id;
     }
     $get_events_ids = Members::where('user_id', $user_id);
     if (is_array($status)) {
         $get_events_ids = $get_events_ids->whereIn('status', $status);
     } else {
         $get_events_ids = $get_events_ids->where('status', $status);
     }
     $get_events_ids = $get_events_ids->get();
     $ids = [];
     foreach ($get_events_ids as $event) {
         $ids[] = $event->getEventId();
     }
     return Events::where('status', '<>', 'draft')->whereIn('id', $ids)->orderBy('created_at', 'desc')->paginate($this->on_page);
 }
 /**
  * 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()]);
 }
Beispiel #4
0
 /**
  * Add new member or follower
  *
  * @param int $event_id
  * @param int $user_id
  * @param string $status
  *
  * @return bool
  */
 public function addNew($event_id, $user_id, $status)
 {
     $insert = Members::create(['event_id' => $event_id, 'user_id' => $user_id, 'status' => $status]);
     return $insert === null ? false : true;
 }