diff --git a/app/routes.php b/app/routes.php index 9be67f536d6bd438bfa36d03852b721a8046a420..e5d766d6f73451bcd8ff9f2b4022f52168ad75c3 100644 --- a/app/routes.php +++ b/app/routes.php @@ -22,6 +22,7 @@ use App\Application\Actions\Group\DeleteUserGroupAction; use App\Application\Actions\Search\SearchAction; use App\Application\Actions\Search\ListUsersJson; +use App\Application\Actions\Search\CreateDB; use App\Application\Actions\Message\CreateMessageAction; use App\Application\Actions\Message\ListMessagesAction; @@ -63,6 +64,9 @@ return function (App $app) { return $this->get(Twig::class)->render($response, "/map/map.twig", []); } ); + + // $app->get('/createdb', CreateDB::class); + $app->group('/search', function (Group $group) { $group->get('', function (Request $request, Response $response) { return $this->get(Twig::class)->render($response, "/home/search.twig", []); diff --git a/src/Application/Actions/Search/CreateDB.php b/src/Application/Actions/Search/CreateDB.php new file mode 100644 index 0000000000000000000000000000000000000000..3927d909a3517d5e158eca539e3bc0f3dabcdb6f --- /dev/null +++ b/src/Application/Actions/Search/CreateDB.php @@ -0,0 +1,137 @@ +<?php +declare(strict_types=1); + +namespace App\Application\Actions\Search; + +use App\Application\Actions\Action; +use Psr\Http\Message\ResponseInterface as Response; +use Psr\Http\Message\ServerRequestInterface as Request; +use Doctrine\ORM\EntityManager; +use Psr\Log\LoggerInterface; +use Slim\Views\Twig; +use Slim\Flash\Messages; +use App\Domain\User\User ; +use App\Domain\Group\Group ; + +use DateTime; + +class CreateDB extends Action{ + + public function __construct(LoggerInterface $logger, EntityManager $em, Twig $twig, Messages $flash){ + + parent::__construct($logger); + $this->em = $em; + $this->userRepository = $em->getRepository('App\Domain\User\User'); + $this->groupRepository = $em->getRepository('App\Domain\Group\Group'); + + $this->number = rand(0,50); + + $this->usernames = [ + 'Rerunner', 'Poltergeisha', 'Urchinchilla', 'Dragonightmare', 'MerryLarva', 'GrizzlySeal', + 'ExoticHorse', 'RapidOstrich', 'MerryPig', 'OriginalLark', + 'Sailorc', 'Toucanoe', 'Geckoco', 'Wrathhawk', 'IdenticalArmadillo', 'RedStitches', 'DeliriousSparks', + 'PrettySwan', 'FirstDoughnut', 'HandsomePrincess', 'Sultank', 'Specterminate', 'Troutwards', 'Bullfrogert', + 'AdviseHurricane', 'ThroneFishy', 'BreakfastSheep', 'GloomySaint', 'FoolishAntelope', 'ArcticMutant', + 'Devile', 'Sailord', 'Unbandit', 'Aromaster', 'ThunderApe', 'MysteryMoose', 'GrumpyHooper', 'ConsultChick', + 'FrighteningRaider', 'FurApe', 'Herogue', 'Beastern', 'Bingoddess', 'Orangutango', 'FlameButterfly', + 'AcrobaticPanther', 'MessyCherry', 'SleepingEmu', 'CannonLord', 'ActionWombat', 'SwallowRider', + 'Orangutitan', 'Parascythe', 'Sharctic', 'AmazingPetal', 'BadMeerkat', 'SmallFry', 'InsecureHydra', + 'WarFoal', 'LostBloodElf', 'Ostritches', 'Eyewearwolf', 'Gorillala', 'Gangstereo', 'BigCat', + 'CopperQueen', 'SpotlessBot', 'ForceHerring', 'AmusingFledgling', 'HeartHatchling', + 'Dinosause', 'Phantomfool', 'Woodpecan', 'Cowhale', 'PunyPirate', 'BakingPup', 'LoneOyster', 'AmazingHooper', + 'ControlWarhawk', 'FlameRogue' ]; + + $this->firstnames = [ + 'Hana', 'Zoya', 'Willie', 'Nettie', 'Kara', 'Lara', 'Halima', 'Laila', 'Alicia', 'Caroline', + 'Carla', 'Julie', 'Katherine', 'Holly', 'Rebekah', 'Lachlan', 'Millie', 'Chantelle', 'Robin', 'Aminah', + 'Ashley', 'Fern', 'Agnes', 'Harley', 'Rhiannon', 'Fannie', 'Brianna', 'Niamh', 'Tanisha', 'Sally', + 'Amelia', 'Molly', 'Aliyah', 'Violet', 'Aisha', 'Libby', 'Alana', 'Danielle', 'Tiana', 'Zaynab', + 'Rebecca', 'Anais', 'Ida', 'Hanna', 'Jean', 'Josie', 'Maya', 'Jodie', 'Joyce', 'Amina', + 'Dewey', 'Simon', 'Kira', 'Taylor', 'Declan', 'Andrew', 'Brandon', 'Milo', 'Edwin', 'Miles', + 'Hasan', 'Matthew', 'Seth', 'Antonio', 'Chester', 'Darren', 'Nicolas', 'Xavier', 'Abraham', + 'Jeremiah', 'Joel', 'Alexander', 'David', 'Zachary', 'Shane', 'Matteo', 'Jon', 'Amaan', 'Ryan', + 'Conner', 'Zachariah', 'Josiah', 'Stefan', 'Bryan', 'Alex', 'Aron', 'Charlie', 'Phillip', 'Clayton', + 'Calvin', 'Guy', 'Russell', 'Bailey', 'Kristian', 'Gerald', 'Christian', 'Jak', 'Aiden', 'Homer', 'Brett']; + + $this->lastnames = [ + 'Hughes', 'Cassidy', 'Farmer', 'Chavez', 'Santiago', 'Payne', 'Rice', 'Li', 'Hamilton', + 'Singh', 'Simmons', 'Little', 'Mcdaniel', 'Ramsey', 'Garner', 'Harrison', 'Fernandez', + 'Strickland', 'Read', 'Gilbert', 'Owen', 'Maxwell', 'Schwartz', 'Crawford', 'Hubbard', 'Gibbs', + 'Wilkes', 'O', 'Lindsey', 'Greene', 'Fisher', 'Park', 'Ortega', 'Manning', 'Logan', 'Woodward', + 'Lewis', 'Huff', 'Gill', 'Terry', 'Riley', 'Powers', 'Cole', 'Flores', 'Huang', 'Barrett', + 'Cannon', 'Carr']; + + $this->groupnames = [ + 'Abandoned Thugs', 'Desired Alliance', 'Bitter Devils', 'Killers of the Ocean', 'Relics of Life', + 'Dawn of the Horse', 'Birth of Darkness', 'Solar Eagles', 'Rainstars', 'Highcry', 'Mislead Moguls', + 'Brave Entities', 'Harmonious Anomalies', 'Sorcerers of Tricks', 'Patience of Disease', 'Shepherds of Shadows', + 'Attack of the Fallen', 'Shiver Hearts', 'Killingwell', 'Forgearrows', 'Searing Blow', 'Ordinary Intent', + 'Devoted Punks', 'Grudge of Trust', 'Illusions of the Furious', 'Archers of Promises', 'Witches of Tricks', + 'Monsterlanders', 'Shimmerskulls', 'Twindeath' + ]; + } + + public function create_user(){ + $date = new DateTime('now'); + $username = $this->usernames[rand(0, count($this->usernames)- 1)]; + $firstname = $this->firstnames[rand(0, count($this->firstnames)- 1)]; + $lastname = $this->lastnames[rand(0, count($this->lastnames)- 1)]; + $mail = $firstname . '.' . $lastname . '@mail.com'; + $password = password_hash($firstname . $lastname, PASSWORD_DEFAULT); + + while ($this->userRepository->findOneBy(array('username' => $username))){ + $username = $this->usernames[rand(0, count($this->usernames)- 1)]; + } + + $user = new User(null, $username, $firstname, $lastname, $mail, $password, $date); + $this->em->persist($user); + $this->em->flush(); + } + + public function create_group($groupname){ + $groupname = $this->groupnames[rand(0, count($this->groupnames)- 1)]; + $i = 0; + while ($this->groupRepository->findOneBy(array('name' => $groupname))){ + $groupname = $this->groupnames[rand(0, count($this->groupnames)- 1)]; + } + $description = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus dui elit, venenatis ac laoreet blandit, pretium at est. + Cras dignissim vestibulum ornare. Donec eget pharetra dolor. Nunc egestas vitae magna vitae sollicitudin. + Suspendisse sodales suscipit elit vel dignissim. Praesent quis justo purus. Fusce gravida dictum nunc eu eleifend. + Proin id gravida orci, hendrerit egestas diam.'; + $adminId = $this->userRepository->find($this->number); + + $group = new Group(null, $groupname, $description, $adminId, rand(0,1)); + $adminId->addGroup($group); + $this->em->persist($group); + $this->em->flush(); + } + + protected function action(): Response + { + // for($i = 0; $i < count($this->usernames); $i += 1){ + // $this->create_user(); + // } + // for($i = 0; $i < count($this->groupnames); $i += 1){ + // $this->create_group( $this->groupnames[$i]); + // } + + $group_number = rand(0, count($this->groupnames) - 1); + for ($i = 0; $i < 100; $i += 1){ + $group_number = rand(0, count($this->groupnames) - 1); + $group = $this->groupRepository->find($group_number); + $currentUser = $this->userRepository->find(rand(5,84)); + while ($group->hasUser($currentUser->getId())){ + $group_number = rand(0, count($this->groupnames) - 1); + $group = $this->groupRepository->find($group_number); + } + $currentUser->addGroup($group); + $this->em->persist($group); + $this->em->flush(); + } + return $this->respondWithData(); + } + + +} + +