/** * @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']); } }
private function findOrCreateUser($facebookUser) { $authUser = User::where('facebook_id', $facebookUser->id)->first(); if ($authUser) { return $authUser; } return User::create(['name' => $facebookUser->name, 'email' => $facebookUser->email, 'facebook_id' => $facebookUser->id, 'activation_code' => 'facebook', 'active' => 1]); }
private function findOrCreateUser($providerUser, $provider) { $user = null; $emailCheck = User::where('email', $providerUser->email)->first(); if (!empty($emailCheck)) { $soc = SocialProvider::where('provider_id', $providerUser->id)->where('provider', $provider)->first(); if ($soc && $soc->user()) { return $soc->user; } // User email already in use, create new SocialProvider record $social = SocialProvider::create(['provider' => $provider, 'provider_id' => $providerUser->id, 'user_id' => $emailCheck->id]); return $emailCheck; } $user = User::create(['name' => $providerUser->name, 'email' => $providerUser->email, 'active' => 1]); /** * mail_labels */ (new Labels())->createDefaultLabels($user->id); $firstname = ""; $lastname = ""; if (!empty($providerUser->user['first_name'])) { $firstname = $providerUser->user['first_name']; } if (!empty($providerUser->user['last_name'])) { $lastname = $providerUser->user['last_name']; } $avatar = null; switch ($provider) { case 'facebook': $avatar = preg_replace('/=[\\d]*$/', '=320', $providerUser->avatar_original); break; case 'google': $avatar = preg_replace('/\\?sz=[\\d]*$/', '', $providerUser->avatar); break; } $fileName = (new ImageHelper())->cloneSocial($avatar); if (empty($fileName)) { $fileName = $avatar; } $profile = Profile::create(['firstname' => $firstname, 'lastname' => $lastname, 'avatar_url' => $fileName, 'user_id' => $user->id]); $social = SocialProvider::create(['provider' => $provider, 'provider_id' => $providerUser->id, 'user_id' => $user->id]); return $user; }