CustomerRewardsRESTAPI/Model/AttributeModel.php
2024-06-03 00:18:25 -05:00

90 lines
2.4 KiB
PHP

<?php
/**
* Description of AttributeModel
*
* @author Mike Howard
*/
require_once PD . "/Model/Database.php";
require_once PD . "/Model/ModelTraits.php";
class AttributeModel extends Database {
use ModelTraits;
public function findAllAttributes()
{
return $this->processQuery("SELECT * FROM loyalty_attribute ORDER BY loyalty_attribute_id ASC");
}
public function findAttributesByMemberId()
{
return $this->processQuery("SELECT * FROM loyalty_member_view WHERE loyalty_member_id = ?", ["i", $this->memberId]);
}
public function findMemberAttribute()
{
$query = "SELECT * FROM loyalty_member_view WHERE loyalty_member_id = " . $this->memberId;
$query .= " AND loyalty_attribute_id = " . $this->attributeId;
return $this->processQuery($query);
}
public function insertAttribute($inputModel)
{
/*
{
"loyalty_attribute_id": 6,
"loyalty_attribute_name": "image_path",
"loyalty_attribute_type_id": 4
}
*/
//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 updateMemberAttribute($jsonPayLoad)
{
/*
{
"LOYALTY_MEMBER_ID": 1,
"FIRST_NAME": "Mike",
"LAST_NAME": "Howard",
"LOYALTY_ATTRIBUTE_ID": 6,
"LOYALTY_ITEM": "image_path",
"LOYALTY_TYPE": "varchar",
"LOYALTY_VALUE": "http://localhost/CustomerRewardsRESTAPI/public/images/1.jpg"
}
*/
$keys = array_keys($jsonPayLoad);
$n = count($keys);
$query = "CALL update_loyalty_member_attribute_proc (" . $jsonPayLoad[$keys[0]] . ", ";
for($i = 1; $i < $n-1; $i++) {
if($i == 3) {
$query .= $jsonPayLoad[$keys[$i]] . ", ";
}
else {
$query .= "'" . $jsonPayLoad[$keys[$i]] . "', ";
}
}
$query .= $jsonPayLoad[$keys[$i]] . ")";
$rowCount = $this->processStatement($query);
return $rowCount;
}
}