Пример #1
0
<?php

/**
 * Created by PhpStorm.
 * User: Ken
 * Date: 10/06/14
 * Time: 15:02
 * Permet la désactivation d'un Plan
 */
$projectRoot = $_SERVER['DOCUMENT_ROOT'] . '/OwlEyes';
require_once $projectRoot . '/required.php';
$id = $_GET['id'];
var_dump($id);
$accountManager = new AccountPdoManager();
$userManager = new UserPdoManager();
$account = $accountManager->findById($id);
$user = $accountManager->findById($id);
//Critère de recherche pour le compte
$criteriaAccount = array('_id' => new MongoId($account->getId()));
//Critère de recherche pour le user
$criteriaUser = array('_id' => new MongoId($account->getUser()));
$updateCriteria = array('$set' => array('state' => new MongoInt32(0)));
var_dump($criteriaUser);
var_dump($updateCriteria);
$disableUserAccount = $accountManager->findAndModify($criteriaAccount, $updateCriteria, NULL, array('new' => TRUE));
$disableUser = $userManager->findAndModify($criteriaUser, $updateCriteria, NULL, array('new' => TRUE));
header('Location: ../pages/users.php');
Пример #2
0
 //Vérifie si le mail du marchant est == au mail du receveur
 if ($emailAccount == $receiver_email) {
     $refPrice = $refPlan->findById($custom[1])->getPrice();
     //Vérifie la somme en bdd et celle enregistré sur Paypal
     if ($refPrice == $payment_amount) {
         /*
          * Insertion en bdd du plan acheté (state(1), idUser, prix , date, retour paypal
          */
         $payment = array('state' => (int) 1, 'paymentStatus' => $payment_status, 'idUser' => new MongoId($custom[0]), 'amount' => $payment_amount, 'date' => new MongoDate(), 'paypalReturn' => $_POST);
         $paymentPdoManager->create($payment);
         /*
          * Récupère le compte actuel
          */
         $criteria = array('state' => (int) 1, 'idUser' => new MongoId($custom[0]));
         $updateAccount = array('$set' => array('state' => new MongoInt32(0)));
         $account = $accountPdoManager->findAndModify($criteria, $updateAccount, NULL, array('new' => TRUE));
         /*Si le compte existe*/
         if ($account instanceof Account) {
             $time = time();
             $end = $time + 30 * 24 * 60 * 60;
             // + 30 jours
             //Récupère l'id de l'user qui vient d'acheter, le plan qu'il vient d'acheter, son espace
             //de stockage, son ratio. Met à jour sa date d'achat et de fin d'abonnement
             $newAccount = array('_id' => new MongoId(), 'state' => (int) 1, 'idUser' => new MongoId($custom[0]), 'idRefPlan' => new MongoId($custom[1]), 'storage' => $account->getStorage(), 'ratio' => $account->getRatio(), 'startDate' => new MongoDate($time), 'endDate' => new MongoDate($end));
             $accountPdoManager->create($newAccount);
             //critères de recherche
             $searchQuery = array('_id' => new MongoId($custom[0]));
             //les modifications à réaliser
             //en mettant un $set, on change uniquement le champ voulu
             // sans le $set, on ferais un delete puis un insert
             $updateCriteria = array('$set' => array('idCurrentAccount' => $newAccount['_id']));
Пример #3
0
 $planManager = new RefPlanPdoManager();
 //    $sDate = $userManager->formatMongoDate($startDate);
 //    $eDate = $userManager->formatMongoDate($endDate);
 $account = $accountManager->findById($id);
 //récupère l'idAccount
 $user = $account->getUser();
 //récupère l'idUser
 $user = $userManager->findById($user);
 //récupère ensuite les infos user byId
 $criteriaAccount = array('_id' => new MongoId($account->getId()));
 $criteriaUser = array('_id' => new MongoId($user->getId()));
 $updateFieldAccount = array('$set' => array('startDate' => new MongoDate($startDate), 'endDate' => new MongoDate($endDate), 'idRefPlan' => new MongoId(_sanitize($plan)), 'state' => new MongoInt32(1)));
 $updateFieldUser = array('$set' => array('firstName' => _sanitize($firstname), 'lastName' => _sanitize($lastname), 'password' => _sanitize($password), 'email' => _sanitize($email), 'geo' => _sanitize($geo), 'state' => new MongoInt32(1)));
 $options = array('new' => true);
 //    var_dump($updateFieldAccount);
 $editAccount = $accountManager->findAndModify($criteriaAccount, $updateFieldAccount, NULL, $options);
 $editUser = $userManager->findAndModify($criteriaUser, $updateFieldUser, NULL, $options);
 //    var_dump($criteriaAccount);
 //    var_dump($criteriaUser);
 //    echo '</br>';
 //    echo '----------';
 //    var_dump($updateFieldAccount);
 //    var_dump($updateFieldUser);
 // exit();
 if ($editAccount && $editUser == TRUE) {
     if (!array_key_exists('error', $editAccount)) {
         $message = 'User' . ' <strong>' . $firstname . '</strong> ' . 'has been successfully modified';
         $_SESSION['editUserMessage'] = $message;
         header('Location: ../pages/users.php');
         die;
     } else {
Пример #4
0
echo 'Utilisation du findById avec une string en parametre';
$accountFoundById = $accountPdoManager->findById((string) $accountFind[0]->getId());
var_dump($accountFoundById);
echo '----------------------------------------<br />';
echo 'Recuperer tous les comptes';
$allAccounts = $accountPdoManager->findAll();
var_dump($allAccounts);
echo '----------------------------------------<br />';
echo 'Utilisation du findAndModify puis create<br />';
$searchQuery = array('state' => 1);
$updateCriteria = array('$set' => array('storage' => (int) 2));
$fields = array('state' => 1);
$options = array('new' => true);
//pour récupérer l'account après modification
echo '____recupere l\'account AVANT modification';
$account = $accountPdoManager->findAndModify($searchQuery, $updateCriteria);
var_dump($account);
echo '____------<br />';
echo '____recupere uniquement le champ state (et id qui est obligatoire) APRES modification';
$updatedAccount = $accountPdoManager->findAndModify($searchQuery, $updateCriteria, $fields, $options);
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';