CustomerRewardsRESTAPI/Model/CustomerModel.php
2024-05-02 16:00:15 -05:00

110 lines
2.9 KiB
PHP

<?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
* 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 PROJECT_ROOT_PATH . "/Model/Database.php";
class CustomerModel extends Database {
private $params = array();
/*
* @assert ('name', 'value')
*/
public function __set($name, $value)
{
//echo "Setting '$name' to '$value'\n";
$this->params[$name] = $value;
}
/*
* @assert ('name') == 'value'
*/
public function __get($name)
{
//echo "Getting '$name'\n";
if (array_key_exists($name, $this->params)) {
return $this->params[$name];
}
$trace = debug_backtrace();
trigger_error(
'Undefined property via __get(): ' . $name .
' in ' . $trace[0]['file'] .
' on line ' . $trace[0]['line'],
E_USER_NOTICE);
return null;
}
/*
* @assert ('name') == 'true'
* @assert ('test') == 'false'
*/
public function __isset($name)
{
//echo "Is '$name' set?\n";
return isset($this->params[$name]);
}
public function __unset($name)
{
//echo "Unsetting '$name'\n";
unset($this->params[$name]);
}
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($jsonPayLoad)
{
$rowCount = $this->processStatement("CALL insert_new_customer_proc", $jsonPayLoad);
$result = (object) ['rowCount'=>$rowCount];
return $result;
}
public function updateCustomer($jsonPayLoad)
{
$rowCount = $this->processStatement("CALL update_existing_customer_proc", $jsonPayLoad);
$result = (object) ['rowCount'=>$rowCount];
return $result;
}
public function deleteCustomer()
{
$rowCount = $this->processStatement("DELETE FROM customer WHERE customer_id = ?", [$this->customerId]);
$result = (object) ['rowCount'=>$rowCount];
return $result;
}
}