Пример #1
0
 /**
  * - Insère un compte gratuit.
  * - Insère l'utilisateur qui va posséder ce compte.
  * - Gestion des exceptions MongoCursor: {@link http://www.php.net/manual/en/class.mongocursorexception.php}
  * - Gestion des erreurs, avec notamment:
  *       Annulation de l'insertion du compte gratuit si l'insertion de l'utilisateur a échoué
  * @author Alban Truc
  * @param string $lastName
  * @param string $firstName
  * @param string $email
  * @param string $password
  * @param string $geolocation
  * @since 02/2014
  * @return bool TRUE si l'insertion a réussi, FALSE sinon
  */
 public function addFreeUser($lastName, $firstName, $email, $password, $geolocation)
 {
     $accountId = new MongoId();
     $userId = new MongoId();
     //@link http://www.php.net/manual/en/class.mongodate.php
     $time = time();
     $end = $time + 30 * 24 * 60 * 60;
     // + 30 jours
     //Caractéristiques du compte gratuit
     $account = array('_id' => $accountId, 'state' => (int) 1, 'idUser' => $userId, 'idRefPlan' => new MongoId('52eb5e743263d8b6a4395df0'), 'storage' => (int) 0, 'ratio' => (int) 0, 'startDate' => new MongoDate($time), 'endDate' => new MongoDate($end));
     $isAccountAdded = $this->accountPdoManager->create($account);
     if ($isAccountAdded == TRUE) {
         //Caractéristiques de l'utilisateur
         $user = array('_id' => $userId, 'state' => (int) 0, 'isAdmin' => false, 'idCurrentAccount' => $accountId, 'lastName' => $lastName, 'firstName' => $firstName, 'password' => $password, 'email' => $email, 'geolocation' => $geolocation, 'apiKey' => $this->generateGUID());
         $info = self::create($user);
         if ($info != TRUE) {
             //annuler l'insertion de l'account
             $removeInfo = $this->accountPdoManager->remove($account);
             if ($removeInfo == TRUE) {
                 $info['error'] .= 'The account created for this user has been removed successfully.';
             } else {
                 $info['error'] .= 'The account created for this user has not been removed successfully: ' . $removeInfo;
             }
             //contient le détail de l'erreur de suppression
         }
         return $info;
     } else {
         return $isAccountAdded;
     }
     //Message d'erreur approprié
 }
Пример #2
0
 $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;
 } else {
     return $isAccountAdded;
 }
Пример #3
0
var_dump($updatedAccount);
echo '____------<br />';
$fields = NULL;
$options = array('remove' => true);
//supprimera au lieu de faire un update
echo '____account que l\'on supprime';
$result = $accountPdoManager->findAndModify($searchQuery, $updateCriteria, $fields, $options);
var_dump($result);
echo '____---------------------<br />';
$account->setState(0);
echo '____Reinsertion de l\'objet precedemment supprime';
$add = $accountPdoManager->create($account);
var_dump($add);
echo '----------------------------------------<br />';
echo 'Utilisation du create, affiche true en cas de succes';
$newInsert = array('test' => TRUE);
$createResult = $accountPdoManager->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 = $accountPdoManager->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';
$criteria = array('test' => TRUE);
$removeResult = $accountPdoManager->remove($criteria);
var_dump($removeResult);
echo '----------------------------------------<br />';