sid/xdoc/generateur_100_etudiants.php

97 lines
2.1 KiB
PHP
Executable File

<?php define('__ROOT__', dirname(dirname(__FILE__)) );
require_once __ROOT__.'/manager/database.php';
require_once __ROOT__.'/manager/user.php';
require_once __ROOT__.'/manager/groups.php';
debug();
/* LECTURE DU JSON */
$sampleFile = file_get_contents('../src/userlistSample.json');
$sample = JSON_decode($sampleFile);
/*** CRÉATION D'UTILISATEUR ***/
foreach( $sample as $user ){
$answer1 = new stdClass();
$answer2 = new stdClass();
$request1 = new stdClass();
$request1->level_1 = 'create';
$request2 = new stdClass();
$request2->level_1 = 'add';
foreach($user as $k=>$v)
switch($k){
case 'identifiant': $request1->identifiant = $v; break;
case 'prenom' : $request1->prenom = $v; break;
case 'nom' : $request1->nom = $v; break;
case 'mail' : $request1->mail = $v; break;
case 'mdp' : $request1->mdp = $v; break;
case 'droits' : $request1->droits = $v; break;
}
user_switch_level_1($request1, $answer1);
echo $request1->identifiant;
if( $answer1->request == 'success' ){
/* AJOUT A UN GROUPE */
$rang = ''.(rand(1,4));
$request2->etudiant = $request1->identifiant; // utilisateur.identifiant
$request2->groupe ='S'.$rang.chr(rand(65,70)); // groupe entre S1A - S4F
$request2->semestre = $rang; // semestre.rang
$request2->annee = '2015'; // semestre.annee
groups_switch_level_1($request2, $answer2);
if( $answer2->request == 'success' )
echo '['.$request2->groupe.']<br>';
else
echo '[ERROR_2: '.$answer2->request.']<br>';
}else
echo ' [ERROR_1: '.$answer1->request.']<br>';
}
// user_switch_level_1($request, $answer);
// echo var_dump( $answer );
// echo '<br><br><br><br><br><br><br>It works !';
/*** AJOUT D'UN UTILISATEUR À UN GROUPE ***/
//
// $request = new stdClass();
// $answer = new stdClass();
// $request->level_1 = 'add';
// $request->utilisateur = 'fvg1856a'; // utilisateur.username
// $request->groupe = 'A'; // groupe.nom
// groups_switch_level_1($request, $answer);
// echo var_dump( $answer );
// echo "<br><br><br><br><br><br><br>It works !";
?>