Beispiel #1
0
<?php

/**
 * Created by PhpStorm.
 * User: Ken
 * Date: 09/06/14
 * Time: 15:02
 */
include '../header/header.php';
if (isset($_GET['id'])) {
    $id = $_GET['id'];
}
$userManager = new UserPdoManager();
$planManager = new RefPlanPdoManager();
$accountManager = new AccountPdoManager();
$allplan = $planManager->findAll();
$account = $accountManager->findById($id);
//id account
$accountUser = $account->getUser();
//id user
$currentPlan = $planManager->findById($account->getRefPlan());
//id du plan
$user = $userManager->findById($accountUser);
//récupère la collection user via id
/*********************************/
$criteria2014 = array('idUser' => $accountUser, 'startDate' => array('$gt' => new MongoDate(strtotime("2014-01-01 00:00:00")), '$lte' => new MongoDate(strtotime("2014-12-30 23:59:59"))));
$filterDate = $accountManager->find($criteria2014);
//foreach($filterDate as $thisAccount)
//{
//
//    var_dump($thisAccount->getStorage());
$refPlanFoundById = $refPlanPdoManager->findById(new MongoId('52eb5e743263d8b6a4395df0'));
var_dump($refPlanFoundById);
echo 'Utilisation du findById avec une string en parametre';
$refPlanFoundById = $refPlanPdoManager->findById('52eb5e743263d8b6a4395df0');
var_dump($refPlanFoundById);
echo '----------------------------------------<br />';
echo 'Retrouver les plans gratuits';
$freePlans = $refPlanPdoManager->findFreePlans();
var_dump($freePlans);
echo '----------------------------------------<br />';
echo 'Retrouver les plans premium';
$premiumPlans = $refPlanPdoManager->findPremiumPlans();
var_dump($premiumPlans);
echo '----------------------------------------<br />';
echo 'Recuperer tous les plans';
$allPlans = $refPlanPdoManager->findAll();
var_dump($allPlans);
echo '----------------------------------------<br />';
echo 'Utilisation du findAndModify puis create<br />';
$searchQuery = array('name' => 'Pro');
$updateCriteria = array('$inc' => array('price' => (int) 1), '$set' => array('maxRatio' => (int) 51));
$fields = array('price' => 1, 'maxRatio' => 1);
$options = array('new' => true);
//pour récupérer le refPlan après modification
echo '____recupere le plan AVANT modification';
$plan = $refPlanPdoManager->findAndModify($searchQuery, $updateCriteria);
var_dump($plan);
echo '____------<br />';
echo '____recupere uniquement les champs price et maxRatio (et id qui est obligatoire) APRES modification';
$updatedPlan = $refPlanPdoManager->findAndModify($searchQuery, $updateCriteria, $fields, $options);
var_dump($updatedPlan);