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 {
|
|
|
|
private $params = array();
|
|
|
|
|
2024-05-01 15:03:43 -05:00
|
|
|
/*
|
|
|
|
* @assert ('name', 'value')
|
|
|
|
*/
|
2024-04-15 11:38:59 -05:00
|
|
|
public function __set($name, $value)
|
|
|
|
{
|
|
|
|
//echo "Setting '$name' to '$value'\n";
|
|
|
|
$this->params[$name] = $value;
|
|
|
|
}
|
|
|
|
|
2024-05-01 15:03:43 -05:00
|
|
|
/*
|
|
|
|
* @assert ('name') == 'value'
|
|
|
|
*/
|
2024-04-15 11:38:59 -05:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2024-05-01 15:03:43 -05:00
|
|
|
/*
|
|
|
|
* @assert ('name') == 'true'
|
|
|
|
* @assert ('test') == 'false'
|
|
|
|
*/
|
2024-04-15 11:38:59 -05:00
|
|
|
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]);
|
|
|
|
}
|
|
|
|
|
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-01 15:03:43 -05:00
|
|
|
public function insertCustomer($jsonPayLoad)
|
2024-04-15 11:38:59 -05:00
|
|
|
{
|
2024-05-02 02:19:13 -05:00
|
|
|
$rowCount = $this->processStatement("CALL insert_new_customer_proc", $jsonPayLoad);
|
2024-05-02 16:00:15 -05:00
|
|
|
$result = (object) ['rowCount'=>$rowCount];
|
|
|
|
return $result;
|
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-02 02:19:13 -05:00
|
|
|
$rowCount = $this->processStatement("CALL update_existing_customer_proc", $jsonPayLoad);
|
2024-05-02 16:00:15 -05:00
|
|
|
$result = (object) ['rowCount'=>$rowCount];
|
|
|
|
return $result;
|
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-02 16:00:15 -05:00
|
|
|
$rowCount = $this->processStatement("DELETE FROM customer WHERE customer_id = ?", [$this->customerId]);
|
|
|
|
$result = (object) ['rowCount'=>$rowCount];
|
|
|
|
return $result;
|
2024-04-15 11:38:59 -05:00
|
|
|
}
|
|
|
|
}
|