Created
November 17, 2016 10:32
-
-
Save sproogen/90601553c708c935678f43ed24bc9b41 to your computer and use it in GitHub Desktop.
User Gen
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"require": { | |
"nubs/random-name-generator": "^2.0" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once 'vendor/autoload.php'; | |
class UserGen { | |
private $nameGenerator; | |
private $jobRoles = [ | |
'Development', | |
'Planning', | |
'Selling', | |
'Support', | |
'Testing' | |
]; | |
private $workgroups = [ | |
'Back End Developers', | |
'Front End Developers', | |
'Testers', | |
'Support', | |
'Project Management', | |
'Business Management', | |
'Sales' | |
]; | |
public function generateUsers($number) | |
{ | |
//https://github.com/nubs/random-name-generator | |
$this->nameGenerator = \Nubs\RandomNameGenerator\All::create(); | |
$outPutFile = fopen("output.csv", "w") or die("Unable to open file!"); | |
fwrite($outPutFile, "Status,First name,Last name,Employee ID,Primary workgroup,Contributing workgroup,Email address,Primary job role,Other job roles,Use Reviews,Default reviewer employee ID,Start date,Leaving date,Timezone,Advanced user,Have you ever had PPI?,Checkbox\n"); | |
for ($i=0; $i<$number; $i++) { | |
$line = $this->generateUser($i); | |
fwrite($outPutFile, $line."\n"); | |
} | |
fclose($outPutFile); | |
} | |
private function generateUser($id) | |
{ | |
$line = ''; | |
$name = explode(' ',str_replace([",","'"], " ", $this->nameGenerator->getName()), 2); | |
//Status | |
$line .= '1,'; | |
//First Name | |
$line .= $name[0] . ','; | |
//Last Name | |
$line .= $name[1] . ','; | |
//Employee ID | |
$line .= 'employee'. $id . ','; | |
//Primary workgroup | |
$line .= $this->workgroups[rand(0,count($this->workgroups)-1)] . ','; | |
//Contributing workgroup | |
$line .= '' . ','; | |
//Email address | |
$line .= 'employee'. $id . '@simitive.com.notanemail,'; | |
//Primary job role | |
$line .= $this->jobRoles[rand(0,count($this->jobRoles)-1)] . ','; | |
//Other job roles | |
$line .= '' . ','; | |
//Use Reviews | |
$line .= '1' . ','; | |
//Default reviewer employee ID | |
$line .= '' . ','; | |
//Start date | |
$line .= '01/11/2016' . ','; | |
//Leaving date | |
$line .= '' . ','; | |
//Timezone | |
$line .= 'Europe/London' . ','; | |
//Advanced user | |
$line .= '' . ','; | |
//Have you ever had PPI? | |
$line .= 'No' . ','; | |
//Checkbox | |
$line .= '1'; | |
return $line; | |
} | |
} | |
if (php_sapi_name() == 'cli') { | |
$userGen = new UserGen(); | |
echo $userGen->generateUsers($argv[1]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This can be run with 'php userGen.php 100'