2024-04-15 11:38:59 -05:00
|
|
|
<?php
|
2024-05-15 14:54:33 -05:00
|
|
|
|
2024-04-15 11:38:59 -05:00
|
|
|
/**
|
|
|
|
* Description of CustomerModel
|
|
|
|
*
|
|
|
|
* @author Mike Howard
|
|
|
|
* CREATED DATE: 04/10/2024
|
|
|
|
*
|
|
|
|
* customer
|
|
|
|
* customer_id bigint AI PK
|
|
|
|
* customer_name varchar(255)
|
|
|
|
* customer_email varchar(255)
|
|
|
|
* customer_phone varchar(12)
|
|
|
|
* customer_birthday datetime
|
2024-04-20 09:33:27 -05:00
|
|
|
* customer_street varchar(255)
|
2024-04-15 11:38:59 -05:00
|
|
|
* address_code_id bigint
|
|
|
|
* loyalty_member tinyint
|
|
|
|
*
|
|
|
|
* address_code
|
|
|
|
* address_code_id bigint AI PK
|
|
|
|
* address_city varchar(45)
|
|
|
|
* address_state varchar(45)
|
|
|
|
* address_zip varchar(10)
|
|
|
|
*/
|
2024-05-13 14:36:49 -05:00
|
|
|
|
2024-05-21 12:43:37 -05:00
|
|
|
require_once PD . "/Model/Database.php";
|
|
|
|
require_once PD . "/Model/ModelTraits.php";
|
|
|
|
|
2024-04-15 11:38:59 -05:00
|
|
|
class CustomerModel extends Database {
|
2024-05-14 11:38:57 -05:00
|
|
|
use ModelTraits;
|
2024-04-15 11:38:59 -05:00
|
|
|
|
2024-04-30 12:36:23 -05:00
|
|
|
public function findAllCustomers()
|
2024-04-15 11:38:59 -05:00
|
|
|
{
|
|
|
|
return $this->processQuery("SELECT * FROM customer_view ORDER BY customer_id ASC LIMIT ?", ["i", $this->limit]);
|
|
|
|
}
|
|
|
|
|
2024-04-30 12:36:23 -05:00
|
|
|
public function findByCustomerId()
|
|
|
|
{
|
|
|
|
return $this->processQuery("SELECT * FROM customer_view WHERE customer_id = ?", ["i", $this->customerId]);
|
|
|
|
}
|
|
|
|
|
2024-05-03 19:27:12 -05:00
|
|
|
public function insertCustomer($inputModel)
|
2024-05-03 12:41:39 -05:00
|
|
|
{
|
2024-05-24 23:33:31 -05:00
|
|
|
//return var_dump($inputModel);
|
2024-05-03 19:27:12 -05:00
|
|
|
$keys = array_keys($inputModel);
|
2024-05-03 12:41:39 -05:00
|
|
|
$n = count($keys);
|
|
|
|
|
2024-05-03 19:27:12 -05:00
|
|
|
$query .= "CALL insert_new_customer_proc (";
|
|
|
|
for($i = 0; $i < $n-1; $i++) {
|
|
|
|
$query .= "'" . $inputModel[$keys[$i]] . "', ";
|
2024-05-03 12:41:39 -05:00
|
|
|
}
|
2024-05-03 19:27:12 -05:00
|
|
|
$query .= $inputModel[$keys[$i]] . ")";
|
|
|
|
//return var_dump($query);
|
|
|
|
|
2024-05-03 12:41:39 -05:00
|
|
|
$rowCount = $this->processStatement($query);
|
|
|
|
return $rowCount;
|
2024-04-15 11:38:59 -05:00
|
|
|
}
|
|
|
|
|
2024-05-01 15:03:43 -05:00
|
|
|
public function updateCustomer($jsonPayLoad)
|
2024-04-15 11:38:59 -05:00
|
|
|
{
|
2024-05-03 12:41:39 -05:00
|
|
|
$keys = array_keys($jsonPayLoad);
|
|
|
|
$n = count($keys);
|
|
|
|
|
|
|
|
$query .= "CALL update_existing_customer_proc (" . $jsonPayLoad[$keys[0]] . ", ";
|
|
|
|
for($i = 1; $i < $n-1; $i++) {
|
|
|
|
$query .= "'" . $jsonPayLoad[$keys[$i]] . "', ";
|
|
|
|
}
|
|
|
|
$query .= $jsonPayLoad[$keys[$i]] . ")";
|
|
|
|
|
|
|
|
$rowCount = $this->processStatement($query);
|
|
|
|
return $rowCount;
|
2024-04-15 11:38:59 -05:00
|
|
|
}
|
|
|
|
|
2024-04-30 22:54:04 -05:00
|
|
|
public function deleteCustomer()
|
2024-04-15 11:38:59 -05:00
|
|
|
{
|
2024-05-04 00:22:26 -05:00
|
|
|
$query = "DELETE FROM customer WHERE customer_id = " . $this->customerId;
|
|
|
|
$rowCount = $this->processStatement($query);
|
|
|
|
return $rowCount;
|
2024-04-15 11:38:59 -05:00
|
|
|
}
|
|
|
|
}
|