Пример #1
0
 $accountId = new MongoId();
 $userId = new MongoId();
 //crypte le password
 $password = $userManager->encrypt($password);
 //@link http://www.php.net/manual/en/class.mongodate.php
 $time = time();
 $end = $time + 30 * 24 * 60 * 60;
 // + 30 jours
 //info compte
 $account = array('_id' => $accountId, 'state' => new MongoInt32($state), 'idUser' => $userId, 'idRefPlan' => new MongoId($plan), 'storage' => (int) 0, 'ratio' => (int) 0, 'startDate' => new MongoDate($time), 'endDate' => new MongoDate($end));
 $isAccountAdded = $accountManager->create($account);
 //Si aucun pb apres ajout du compte, ajoute l'user, sinon suppresion de user
 if ($isAccountAdded == TRUE) {
     //infos user
     $user = array('_id' => $userId, 'isAdmin' => $isAdmin, 'state' => new MongoInt32($state), 'idCurrentAccount' => $accountId, 'firstName' => _sanitize($firstname), 'lastName' => _sanitize($lastname), 'password' => $password, 'email' => $email, 'geolocation' => $geo, 'apiKey' => $userManager->generateGUID());
     $isUserAdded = $userManager->create($user);
     if ($isUserAdded != TRUE) {
         //annule l'insertion de l'account
         $removeAccount = $accountManager->remove($account);
         if ($removeAccount == TRUE) {
             $isUserAdded['error'] .= 'The account created for this user has been removed successfully.';
         } else {
             $isUserAdded['error'] .= 'The account created for this user has not been removed successfully: ' . $removeAccount;
         }
         //contient le détail de l'erreur de suppression
     } else {
         $message = 'User <strong>' . $firstname . '</strong> has been inserted in database';
         $_SESSION['addUserMessage'] = $message;
         header('Location: ../pages/users.php');
     }
     return $isUserAdded;
Пример #2
0
var_dump($user);
echo '____------<br />';
echo '____recupere uniquement le champ state (et id qui est obligatoire) APRES modification';
$updatedUser = $userPdoManager->findAndModify($searchQuery, $updateCriteria, $fields, $options);
var_dump($updatedUser);
echo '____------<br />';
$fields = NULL;
$options = array('remove' => true);
//supprimera au lieu de faire un update
echo '____user que l\'on supprime';
$result = $userPdoManager->findAndModify($searchQuery, $updateCriteria, $fields, $options);
var_dump($result);
echo '____---------------------<br />';
$user->setState(0);
echo '____Reinsertion de l\'objet precedemment supprime';
$add = $userPdoManager->create($user);
var_dump($add);
echo '----------------------------------------<br />';
echo 'Utilisation du create, affiche true en cas de succes';
$newInsert = array('test' => TRUE);
$createResult = $userPdoManager->create($newInsert);
var_dump($createResult);
echo '----------------------------------------<br />';
echo 'Utilisation de l\'update, affiche true en cas de succes';
$criteria = array('test' => TRUE);
$update = array('$set' => array('number' => (int) 500));
$updateResult = $userPdoManager->update($criteria, $update);
var_dump($updateResult);
// true si l'update a réussi
echo '----------------------------------------<br />';
echo 'Utilisation du remove, affiche true en cas de succes';