CustomerRewardsRESTAPI/Model/CustomerModel.php
2024-05-24 23:33:31 -05:00

81 lines
2.2 KiB
PHP

<?php
/**
* 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
* customer_street varchar(255)
* 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)
*/
require_once PD . "/Model/Database.php";
require_once PD . "/Model/ModelTraits.php";
class CustomerModel extends Database {
use ModelTraits;
public function findAllCustomers()
{
return $this->processQuery("SELECT * FROM customer_view ORDER BY customer_id ASC LIMIT ?", ["i", $this->limit]);
}
public function findByCustomerId()
{
return $this->processQuery("SELECT * FROM customer_view WHERE customer_id = ?", ["i", $this->customerId]);
}
public function insertCustomer($inputModel)
{
//return var_dump($inputModel);
$keys = array_keys($inputModel);
$n = count($keys);
$query .= "CALL insert_new_customer_proc (";
for($i = 0; $i < $n-1; $i++) {
$query .= "'" . $inputModel[$keys[$i]] . "', ";
}
$query .= $inputModel[$keys[$i]] . ")";
//return var_dump($query);
$rowCount = $this->processStatement($query);
return $rowCount;
}
public function updateCustomer($jsonPayLoad)
{
$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;
}
public function deleteCustomer()
{
$query = "DELETE FROM customer WHERE customer_id = " . $this->customerId;
$rowCount = $this->processStatement($query);
return $rowCount;
}
}