Ejemplo n.º 1
0
 /**
  * Gets a inventory
  *
  * @return [InventoryEntity]  List of items
  */
 public function getItems()
 {
     $sql = "SELECT * FROM Inventory";
     $stmt = $this->db->query($sql);
     $results = [];
     while ($row = $stmt->fetch()) {
         $inv_item = new InventoryEntity($row);
         $item_mapper = new ItemMapper($this->db);
         $item = $item_mapper->getItemById($inv_item->getId());
         $inv_item->setItem($item);
         $results[] = $inv_item;
     }
     return $results;
 }
Ejemplo n.º 2
0
    $data['id'] = filter_var($post_data['id'], FILTER_SANITIZE_STRING);
    $data['name'] = filter_var($post_data['name'], FILTER_SANITIZE_STRING);
    $data['color'] = filter_var($post_data['color'], FILTER_SANITIZE_STRING);
    $mapper = new ItemMapper($this->db);
    $item = $mapper->getItemById($data['id']);
    $item->setName($data['name']);
    $item->setColor($data['color']);
    $mapper->update($item);
    $response = $response->withRedirect("/index.php/items");
    return $response;
});
// Delete Item
$app->get('/item/{id}/delete', function ($request, $response, $args) {
    $id = (int) $args['id'];
    $mapper = new ItemMapper($this->db);
    $item = $mapper->getItemById($id);
    $this->logger->info("Deleting Item " . $id);
    $mapper->delete($item);
    $response = $response->withRedirect("/index.php/items");
    return $response;
});
/**********************IVENTORY**********************/
// Inventory
$app->get('/inventory', function ($request, $response, $args) {
    $this->logger->info("Inventory page");
    $mapper = new InventoryMapper($this->db);
    $items = $mapper->getItems();
    return $this->renderer->render($response, 'inventory/inventory.phtml', [$args, "inventoryItems" => $items]);
});
// Add Item GET
$app->get('/inventory/add', function ($request, $response, $args) {