Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Generator {
- public $prenoms = array('kevin', 'mathieu', 'leslie', 'florent', 'fanny', 'antoine', 'axel', 'guillaume');
- public $noms = array('delemme', 'brisebarre', 'martinez', 'moreau', 'lagarde', 'chekroun', 'legua', 'cozic');
- public $mots = array('pellentesque', 'ligula', 'tortor', 'pulvinar', 'vel', 'varius', 'at', 'adipiscing', 'in', 'sapien', 'In', 'hac', 'habitasse', 'proin', 'at', 'mi', 'in', 'lectus', 'cursus', 'aliquam', 'eu', 'et', 'metus', 'vestibulum', 'ante', 'ipsum', 'primis', 'in', 'faucibus', 'orci', 'luctus');
- public $mails = array('@gmail.com', '@yahoo.fr', '@facebook.com', '@isen.fr');
- public function Generator() { }
- /**
- * $maxsize = taille maximum de la chaine générée. Prendre -20 que la valeur maximum possible reelle.
- * $nbelt = nombre de mots dans la chaine.
- * la génération s'arrete quand $nbelt est attend ou quand $maxsize est attend.
- */
- public function gen_str($nbelt, $maxsize)
- {
- $str = '';
- for ($i = 0; $i<$nbelt || strlen($str) < $maxsize; $i++)
- $str .= $this->mots[rand(0,count($this->mots)-1)]. ' ';
- return '\''.$str.'\'';
- }
- public function gen_prenom()
- {
- return '\''.$this->prenoms[rand(0, count($this->prenoms)-1)].'\'';
- }
- public function gen_nom()
- {
- return '\''.$this->noms[rand(0, count($this->noms)-1)].'\'';
- }
- public function gen_villeid() {
- return '\''.rand(1, 30000).'\'';
- }
- public function gen_date_futur() {
- return '\''.date('Y-m-d', time() + rand(1814400, 5443200)).'\'';
- }
- public function gen_date_passee() {
- return '\''.date('Y-m-d', time() - rand(200*1814400, 300*5443200)).'\'';
- }
- public function gen_mail() {
- return '\''.$this->prenoms[rand(0,count($this->prenoms)-1)]. '.' .$this->noms[rand(0,count($this->noms)-1)] . $this->mails[rand(0,count($this->mails)-1)].'\'';
- }
- public function gen_phone() {
- $number = '06';
- for ($i=0; $i<8; $i++)
- $number .= rand(0,9);
- return '\''.$number.'\'';
- }
- public function gen_url() {
- return '\'www.' . $this->mots[rand(0,count($this->mots)-1)] . '.com\'';
- }
- /**
- *
- * Generation des INSERT
- * Penser a générer moins de prestataires que d'utilisateurs par exemple ^^
- */
- /**
- * TODO:
- * Créer une fonction par table pour générer N * INSERT INTO table(champs1, .., champs12) VALUES($gen->gen_phrase(nb, size champs1), .., $gen->gen_phrase(nb, size champs12));
- */
- public function gen_utilisateurs($nb) {
- for ($i = 1; $i <= $nb; $i++)
- {
- echo 'INSERT INTO utilisateurs(id, ut_nom, ut_prenom, ut_adresse, ut_telephone_fixe, ut_telephone_mobile, ut_adresse_mail, ut_site_internet, ut_blog, ut_date_naissance, ut_sexe, ut_est_actif, ut_secteur_activite, ut_cat_sociopro, ut_situation_famille, ut_centre_interet, ut_est_professionnel, ut_compte_actif) VALUE';
- echo '('.$i.', '.$this->gen_nom().', '.$this->gen_prenom().', '.$this->gen_str(10, 80).', '.$this->gen_phone().', '.$this->gen_phone().', '.$this->gen_mail().',';
- echo $this->gen_url().', '.$this->gen_url().', '.$this->gen_date_passee().', 1, \'true\', '.$this->gen_str(4, 20).', '.$this->gen_str(4, 20).', '.$this->gen_str(4, 20).',';
- echo $this->gen_str(4, 20).', \'true\', \'true\');';
- echo '<br />';
- }
- }
- }
- $gen = new Generator();
- $gen->gen_utilisateurs(20);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement