CustomerRewardsRESTAPI/Model/CustomerModel.php

84 lines
2.3 KiB
PHP
Raw Normal View History

2024-04-15 11:38:59 -05:00
<?php
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Scripting/PHPClass.php to edit this template
*/
/**
* 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)
*/
require_once PROJECT_ROOT_PATH . "/Model/Database.php";
class CustomerModel extends Database {
2024-05-09 20:25:56 -05:00
use ModelTraits;
2024-04-15 11:38:59 -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]);
}
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
{
//return var_dump($jsonPayLoad);
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
}
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
{
$query = "DELETE FROM customer WHERE customer_id = " . $this->customerId;
$rowCount = $this->processStatement($query);
return $rowCount;
2024-04-15 11:38:59 -05:00
}
}