@@ -4,10 +4,13 @@ namespace Shop; | |||
use Psr\Http\Message\ResponseInterface as Response; | |||
use Psr\Http\Message\ServerRequestInterface as Request; | |||
use Psr\Container\ContainerInterface; | |||
use Slim\Factory\AppFactory; | |||
use DI\Container; | |||
use Shop\DB\myDB; | |||
use Shop\View\Twig; | |||
use Shop\DB\Order; | |||
use Shop\Model\Order as OrderModel; | |||
require __DIR__ . '/../vendor/autoload.php'; | |||
@@ -20,16 +23,23 @@ $container->set('twig', function () { | |||
return $twig; | |||
}); | |||
$container->set('db', function() { | |||
$db = new myDB(); | |||
return $db; | |||
}); | |||
$container->set( | |||
'db', | |||
function () { | |||
$db = new myDB(); | |||
return $db; | |||
} | |||
); | |||
$app->map(['GET', 'POST'], "/orders/{client}/create", function (Request $request, Response $response, array $args) { | |||
if ($request->getMethod() == "GET") { | |||
$db2 = new myDB(); | |||
$stmt2 = $db2->prepare("SELECT * FROM clients WHERE id = " . $args['client']); | |||
$res2 = $stmt2->execute(); | |||
// $db2 = new myDB(); | |||
// $stmt2 = $db2->prepare("SELECT * FROM clients WHERE id = " . $args['client']); | |||
// $res2 = $stmt2->execute(); | |||
// $a = $res2->fetchArray(SQLITE3_ASSOC); | |||
$db2 = new Order($this->container); | |||
$res2 = $db2->getClient($args['client']); | |||
$a = $res2->fetchArray(SQLITE3_ASSOC); | |||
$response->getBody()->write("<h1>Create order for" . $a['firstname'] . " " . $a['lastname'] . "</h1><hr/>"); |
@@ -0,0 +1,19 @@ | |||
<?php | |||
namespace Shop\DB; | |||
use Shop\DB\myDB; | |||
class CLients extends myDB | |||
{ | |||
protected $tableName = 'clients'; | |||
protected $container; | |||
public function getClients($tableName) | |||
{ | |||
$stmt = $this->prepare("SELECT * FROM :tableName;"); | |||
$stmt->bindValue(':tableName', $tableName, SQLITE3_TEXT); | |||
$res = $stmt->execute(); | |||
return $res; | |||
} | |||
} |
@@ -0,0 +1,30 @@ | |||
<?php | |||
namespace Shop\DB; | |||
use Shop\Model\Order as OrderModel; | |||
use Shop\DB\myDB; | |||
class Order | |||
{ | |||
protected $container; | |||
public function __construct($container) { | |||
$this->container = $container; | |||
} | |||
public function createOrder(OrderModel $data) | |||
{ | |||
} | |||
public function getClient($id) | |||
{ | |||
$db = new myDB(); | |||
$sql = "SELECT * FROM clients WHERE id = :id;"; | |||
$stmt = $db->prepare($sql); | |||
$stmt->bindValue(':id', $id, SQLITE3_INTEGER); | |||
$res = $stmt->execute(); | |||
return $res; | |||
} | |||
} |
@@ -0,0 +1,33 @@ | |||
<?php | |||
namespace Shop\Model; | |||
use Shop\DB\Order as DBOrder; | |||
class Order | |||
{ | |||
protected $container; | |||
protected $reference; | |||
protected $id; | |||
public function __container($container) { | |||
$this->container = $container; | |||
} | |||
public function setReference($value) | |||
{ | |||
$this->reference = $value; | |||
} | |||
public function setId($value) | |||
{ | |||
$this->id = $value; | |||
} | |||
public function order() { | |||
$db = new DBOrder($this->container); | |||
$db->createOrder($this); | |||
} | |||
} |
@@ -0,0 +1,5 @@ | |||
<html> | |||
<body> | |||
<div id="main">{% block main %}{% endblock %}</div> | |||
</body> | |||
</html> |