@@ -20,16 +20,15 @@ class Customers | |||
public function getCustomers(ServerRequestInterface $request, ResponseInterface $response, array $args): ResponseInterface | |||
{ | |||
$db = new Client($this->container); | |||
$res = $db->getClients(); | |||
$response->getBody()->write("<h1>CUSTOMERS LIST </h1>"); | |||
$response->getBody()->write('<hr/>'); | |||
$response->getBody()->write("<table>"); | |||
while ($row = $res->fetchArray(SQLITE3_ASSOC)) { | |||
// maak hier een deftige tabel van | |||
$response->getBody()->write("<tr><td>" . " " . " <a href=\"/orders/" . $row['id'] . "\">" . $row["id"] . "</a> " . " " . $row['firstname'] . " " . $row['lastname'] . " " . $row['street'] . " " . $row['street2'] . " " . $row['zipcode'] . " " . $row['city'] . " " . $row['country'] . "</td></tr>"); | |||
} | |||
$response->getBody()->write("</table>"); | |||
$customers = $db->getClients(); | |||
$container = $this->container; | |||
$twig = $container->get('twig'); | |||
$vars = ["clients" => $customers]; | |||
$a = $twig->render('customers.html.twig', $vars); | |||
$response->getBody()->write($a); | |||
return $response; | |||
} |
@@ -2,10 +2,11 @@ | |||
namespace Shop\DB; | |||
use Shop\Model\Client as ModelClient; | |||
class Client extends DB | |||
{ | |||
protected $container; | |||
// protected $clients = []; | |||
protected $clients = []; | |||
public function __construct($container) | |||
{ | |||
@@ -25,6 +26,21 @@ class Client extends DB | |||
$sql = "SELECT * FROM clients"; | |||
$stmt = $db->prepare($sql); | |||
$res = $stmt->execute(); | |||
return $res; | |||
while($result = $res->fetchArray(SQLITE3_ASSOC)) { | |||
$client = new ModelClient($this->container); | |||
$client->setId($result['id']); | |||
$client->setFirstname($result['firstname']); | |||
$client->setLastname($result['lastname']); | |||
$client->setCompany($result['company']); | |||
$client->setVatnumber($result['vatnumber']); | |||
$client->setStreet($result['street']); | |||
$client->setStreet2($result['street2']); | |||
$client->setZipcode($result['zipcode']); | |||
$client->setCity($result['city']); | |||
$client->setState($result['state']); | |||
$client->setCountry($result['country']); | |||
$this->clients[] = $client; | |||
} | |||
return $this->clients; | |||
} | |||
} |
@@ -8,13 +8,9 @@ use \Shop\DB\Order_lines as DB_Order_lines; | |||
class Order_lines | |||
{ | |||
protected $orderLines; | |||
public function loadOrderLines() | |||
{ | |||
$db = new DB_Order_lines(); | |||
// | |||
} | |||
protected $container; | |||
protected $id; | |||
protected $orderId; | |||
} | |||
@@ -1,10 +1,36 @@ | |||
{% extends "base.html.twig" %} {% block main %} | |||
<h1>CUSTOMERS LIST </h1> | |||
<hr/> | |||
<table> | |||
while ($row = $res->fetchArray(SQLITE3_ASSOC)) { | |||
// maak hier een deftige tabel van | |||
<tr><td> . . <a href=\"/orders/" . $row['id'] . "\"> . $row["id"] . </a> . . $row['firstname'] . . $row['lastname'] . . $row['street'] . . $row['street2'] . . $row['zipcode'] . . $row['city'] . . $row['country'] . </td></tr> | |||
} | |||
</table> | |||
{% extends "base.html.twig" %} {% block main %} | |||
<h1>CUSTOMERS LIST</h1> | |||
<hr /> | |||
<table> | |||
<tr> | |||
<th>id</th> | |||
<th>First Name</th> | |||
<th>Last Name</th> | |||
<th>Company</th> | |||
<th>VAT Number</th> | |||
<th>Street</th> | |||
<th>Street 2</th> | |||
<th>ZIP Code</th> | |||
<th>City</th> | |||
<th>State</th> | |||
<th>Country</th> | |||
</tr> | |||
{% for customer in customers %} | |||
<tr> | |||
<td> | |||
<a href="/orders/{{ customer.id }}">{{ customer.id }}</a> | |||
</td> | |||
<td>{{ customer.firstname }}</td> | |||
<td>{{ customer.lastname }}</td> | |||
<td>{{ customer.company }}</td> | |||
<td>{{ customer.vatnumber }}</td> | |||
<td>{{ customer.street }}</td> | |||
<td>{{ customer.street2 }}</td> | |||
<td>{{ customer.zipcode }}</td> | |||
<td>{{ customer.city }}</td> | |||
<td>{{ customer.state }}</td> | |||
<td>{{ customer.country }}</td> | |||
</tr> | |||
{% endfor %} | |||
</table> | |||
{% endblock %} |