Esempio n. 1
0
session_start();
$projectRoot = $_SERVER['DOCUMENT_ROOT'] . '/OwlEyes';
require_once $projectRoot . '/required.php';
$id = $_GET['id'];
//Traitement pour l'ajout du plan en bdd
if (isset($_POST['edit_plan'])) {
    $name = $_POST['name'];
    $price = $_POST['price'];
    $maxStorage = $_POST['maxStorage'];
    $dl = $_POST['downL'];
    $up = $_POST['upL'];
    $maxRatio = $_POST['maxRatio'];
    if (!empty($name) && !empty($price) && !empty($maxStorage)) {
        $refPlanManager = new RefPlanPdoManager();
        $criteria = array('_id' => new MongoId($id));
        $updatePlan = array('$set' => array('name' => $name, 'price' => new MongoInt32($price), 'maxStorage' => new MongoInt32($maxStorage), 'downloadSpeed' => new MongoInt32($dl), 'uploadSpeed' => new MongoInt32($up), 'maxRatio' => new MongoInt32($maxRatio), 'state' => new MongoInt32(1)));
        $options = array('new' => true);
        $editPlan = $refPlanManager->findAndModify($criteria, $updatePlan, null, $options);
        if ($editPlan == true) {
            $message = 'Your plan has successfully changed';
            $_SESSION['editPlanMessage'] = $message;
            header('Location: ../pages/plan.php');
            die;
        } else {
            $message = 'Update error';
            $_SESSION['editPlanMessage'] = $message;
            header('Location: ../pages/plan.php');
            die;
        }
    }
}
Esempio n. 2
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);
$refPlanManager = new RefPlanPdoManager();
$criteria = array('_id' => new MongoId($id));
$updateCriteria = array('$set' => array('state' => (int) 0));
$disablePlan = $refPlanManager->findAndModify($criteria, $updateCriteria, NULL, array('new' => TRUE));
header('Location: ../pages/plan.php');
Esempio n. 3
0
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);
echo '____------<br />';
$fields = NULL;
$options = array('remove' => true);
//supprimera au lieu de faire un update
echo '____plan que l\'on supprime';
$result = $refPlanPdoManager->findAndModify($searchQuery, $updateCriteria, $fields, $options);
var_dump($result);
echo '____---------------------<br />';
$plan->setDownloadSpeed(5000);
echo '____Reinsertion de l\'objet precedemment supprime';