Example #1
0
 public static function buildRawExamples()
 {
     // Order persons
     echo ' 8: Initial data: <pre>';
     var_dump(\OrderPerson::getListOfTypeOrderPerson(array('forAutocompletion' => false)));
     echo '</pre>';
     // Inserting an order person
     $newOrderPerson = new \OrderPerson();
     $newOrderPerson->setEmail('*****@*****.**');
     $newOrderPerson->setFirstName('lilian');
     $newOrderPerson->setLastName('tikk');
     $newOrderPerson->insert();
     echo ' 10: After insertion: <pre>';
     var_dump(\OrderPerson::getListOfTypeOrderPerson(array('forAutocompletion' => false)));
     echo '</pre>';
     // Querying full data of an order person
     $orderPerson = new OrderPerson();
     $orderPerson->setId(3);
     $orderPerson->setCompleteOrderPerson();
     echo ' 20: Order person #3: <pre>';
     var_dump($orderPerson);
     echo '</pre>';
     // Updating data of an order person
     $orderPerson->setAddress('Pärnu, Pärnu');
     $orderPerson->update();
     echo ' 24: After updating the order person #3: <pre>';
     var_dump(\OrderPerson::getListOfTypeOrderPerson(array('forAutocompletion' => false)));
     echo '</pre>';
     // Deleting the order person #2
     $orderPerson = new \OrderPerson();
     $orderPerson->setId(2);
     $orderPerson->delete();
     echo ' 43: After deleting the order person #2: <pre>';
     var_dump(\OrderPerson::getListOfTypeOrderPerson(array('forAutocompletion' => false)));
     echo '</pre>';
     // Items
     require_once dirname(__FILE__) . '/Item.php';
     $item = new Item();
     $item->setId(1);
     $item->setName('õun');
     $item->setPrice(1.0);
     $item->setAmount(20.0);
     $item->insertItem($item);
     $item = new \shiporder\Item();
     $item->setId(2);
     $item->setName('pirn');
     $item->setPrice(2.0);
     $item->setAmount(10.0);
     $item->insertItem($item);
     $items = $item->getItems();
     var_dump($items);
 }
}
session_start();
$idGroup;
if (isset($_SESSION['idGroup'])) {
    $idGroup = $_SESSION['idGroup'];
    //obtenemos el id del grupo a partir de la sesión
} else {
    if (isset($_POST['idGroup'])) {
        $idGroup = $_POST['idGroup'];
        //obtenemos el id del grupo a partir de la variable POST
    } else {
        die('No se ha seleccionado un grupo');
    }
}
//comprobamos que el usuario se ha autenticado y pertenece al grupo cuyas listas quiere listar
$currentUser = User::getLoggedInUser();
if (!$currentUser) {
    die('Necesitas autenticarte para acceder a esta funcionalidad');
}
if (!Group::userBelongsToGroup($currentUser->id, $idGroup)) {
    die("No perteneces al grupo con id {$idGroup}!");
}
//insertamos la nueva lista en la base de datos
$list = new ShoppingList(array('listName' => $listName, 'idGroup' => $idGroup));
$list->insert();
//insertamos todos los productos iniciales para la lista anteriormente creada
foreach ($newList[1] as $product) {
    $item = new Item(array('idList' => $list->idList, 'itemName' => $product->prodName, 'quantity' => $product->prodQt, 'metric' => 'u'));
    $item->insertItem();
}
echo 'success';