examen MVC (model view controller)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CustomerOrderDB.php 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace Shop\DB;
  3. use Shop\DB\DB;
  4. use Psr\Container\ContainerInterface;
  5. use Shop\Model\CustomerOrder;
  6. class CustomerOrderDB extends DB {
  7. protected $container;
  8. protected $customerOrder = [];
  9. protected $customerName = [];
  10. public function __construct(ContainerInterface $container)
  11. {
  12. $this->container = $container;
  13. }
  14. public function customerOrders($args)
  15. {
  16. $stmt = $this->container->get('db')->prepare
  17. ("SELECT firstname,lastname, o.* FROM orders o
  18. LEFT JOIN clients c on o.customer_id = c.id
  19. WHERE o.customer_id =". $args['client']);
  20. $stmt ->bindValue(':id',SQLITE3_NUM);
  21. $stmt ->bindValue(':customer',SQLITE3_TEXT);
  22. $stmt ->bindValue(':reference', SQLITE3_TEXT);
  23. $stmt ->bindValue(':customer_id', SQLITE3_INTEGER);
  24. $stmt ->bindValue(':subtotal', SQLITE3_NUM);
  25. $stmt ->bindValue(':vat', SQLITE3_NUM);
  26. $stmt ->bindValue(':total', SQLITE3_NUM);
  27. $res = $stmt->execute();
  28. while($result = $res->fetchArray(SQLITE3_ASSOC)){
  29. $customerOrder = new CustomerOrder($this->container);
  30. $customerOrder->setId($result['id']);
  31. $customerOrder->setRef($result['reference']);
  32. $customerOrder->setCustomerId($result['customer_id']);
  33. $customerOrder->setSubtotal($result['subtotal']);
  34. $customerOrder->setVat($result['vat']);
  35. $customerOrder->setTotal($result['total']);
  36. $this->customerOrders[] = $customerOrder;
  37. }
  38. return $this->customerOrders;
  39. }
  40. public function nameCustomer($args){
  41. $stmt2 = $this->container->get('db')->prepare("SELECT * FROM clients WHERE id = " . $args['client']);
  42. $stmt2 ->bindValue(':firstname', SQLITE3_TEXT);
  43. $stmt2 ->bindValue(':lastname', SQLITE3_TEXT);
  44. $res2 = $stmt2->execute();
  45. while($result = $res2->fetchArray(SQLITE3_ASSOC));{
  46. $customerName = new CustomerOrder($this->container);
  47. $customerName->setFirstname($result['firstname']);
  48. $customerName->setLastname($result['lastname']);
  49. $this->customersName[] = $customerName;
  50. }
  51. }
  52. }
  53. //vergeet args niet zie index route order/id , gebruik psr container; done