Browse Source

Create class Client

master
Lennart Verschelden 2 years ago
parent
commit
434165e20b
7 changed files with 35 additions and 15 deletions
  1. 2
    1
      .gitignore
  2. 9
    6
      public/index.php
  3. BIN
      public/webshop.db
  4. 21
    0
      src/DB/Client.php
  5. 0
    0
      src/DB/Customers.php
  6. 3
    8
      src/DB/DB.php
  7. 0
    0
      src/DB/Shop.php

+ 2
- 1
.gitignore View File

@@ -1 +1,2 @@
vendor/
vendor/
private/

+ 9
- 6
public/index.php View File

@@ -1,10 +1,13 @@
<?php
namespace Store;
namespace Shop;

use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Slim\Factory\AppFactory;
use Store\DB\DB;
use Shop\DB\Client;
use Shop\DB\DB;



require __DIR__ . '/../vendor/autoload.php';

@@ -13,7 +16,7 @@ require __DIR__ . '/../vendor/autoload.php';
$app = AppFactory::create();

$app->map(['GET', 'POST'], "/orders/{client}/create", function (Request $request, Response $response, array $args) {
$db2 = new DB();
$db2 = new Client();
$client = $args['client'];
$a = $db2->getClientInfo($client);
if ($request->getMethod() == "GET") {
@@ -26,10 +29,10 @@ $app->map(['GET', 'POST'], "/orders/{client}/create", function (Request $request

return $response;
} else {
$db2 = new Client();
$ref = $request->getParsedBody()['reference'];
$db2 = new DB();
$sql = "insert into orders (reference, customer_id, vat, subtotal, total) values ('" . $ref . "', " . $args['client'] . ",0,0,0)";
$db2->exec($sql);
$client = $args['client'];
$db2->getClientInfo($client, $ref);
return $response->withHeader('Location', '/orders/' . $args['client']);
};
});

BIN
public/webshop.db View File


+ 21
- 0
src/DB/Client.php View File

@@ -0,0 +1,21 @@
<?php

namespace Shop\DB;

class Client extends DB
{
public function getClientInfo($client) {
$stmt2 = $this->prepare("SELECT * FROM clients WHERE id = " . $client);
$res2 = $stmt2->execute();
$a = $res2->fetchArray(SQLITE3_ASSOC);
return $a;
}

public function getProductId($client, $ref) {
$sql = "insert into orders (reference, customer_id, vat, subtotal, total) values ('" . $ref . "', " . $client . ",0,0,0)";
return $this->exec($sql);
}
}

+ 0
- 0
src/DB/Customers.php View File


+ 3
- 8
src/DB/DB.php View File

@@ -1,6 +1,6 @@
<?php

namespace Store\DB;
namespace Shop\DB;

use SQLite3;

@@ -8,13 +8,8 @@ class DB extends SQLite3
{
public function __construct()
{
$this->open('./webshop.db');
$this->open('../private/webshop.db');
}

public function getClientInfo($client) {
$stmt2 = $this->prepare("SELECT * FROM clients WHERE id = " . $client);
$res2 = $stmt2->execute();
$a = $res2->fetchArray(SQLITE3_ASSOC);
return $a;
}
}

+ 0
- 0
src/DB/Shop.php View File


Loading…
Cancel
Save