2024-05-21 12:43:37 -05:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Description of AttributeModel
|
|
|
|
*
|
|
|
|
* @author Mike Howard
|
|
|
|
*/
|
|
|
|
|
|
|
|
require_once PD . "/Model/Database.php";
|
|
|
|
require_once PD . "/Model/ModelTraits.php";
|
|
|
|
|
2024-05-22 14:55:08 -05:00
|
|
|
class AttributeModel extends Database {
|
2024-05-21 12:43:37 -05:00
|
|
|
use ModelTraits;
|
|
|
|
|
|
|
|
public function findAllAttributes()
|
|
|
|
{
|
2024-05-22 14:55:08 -05:00
|
|
|
return $this->processQuery("SELECT * FROM loyalty_attribute ORDER BY loyalty_attribute_id ASC");
|
2024-05-21 12:43:37 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
public function findAttributesByMemberId()
|
|
|
|
{
|
|
|
|
return $this->processQuery("SELECT * FROM loyalty_member_view WHERE loyalty_member_id = ?", ["i", $this->memberId]);
|
|
|
|
}
|
2024-06-02 20:09:40 -05:00
|
|
|
|
|
|
|
public function findMemberAttribute()
|
|
|
|
{
|
2024-06-03 00:18:25 -05:00
|
|
|
$query = "SELECT * FROM loyalty_member_view WHERE loyalty_member_id = " . $this->memberId;
|
|
|
|
$query .= " AND loyalty_attribute_id = " . $this->attributeId;
|
|
|
|
|
|
|
|
return $this->processQuery($query);
|
2024-06-02 20:09:40 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
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"
|
|
|
|
}
|
|
|
|
*/
|
2024-06-03 00:18:25 -05:00
|
|
|
|
2024-06-02 20:09:40 -05:00
|
|
|
$keys = array_keys($jsonPayLoad);
|
|
|
|
$n = count($keys);
|
|
|
|
|
2024-06-03 00:18:25 -05:00
|
|
|
$query = "CALL update_loyalty_member_attribute_proc (" . $jsonPayLoad[$keys[0]] . ", ";
|
2024-06-02 20:09:40 -05:00
|
|
|
for($i = 1; $i < $n-1; $i++) {
|
2024-06-03 00:18:25 -05:00
|
|
|
if($i == 3) {
|
|
|
|
$query .= $jsonPayLoad[$keys[$i]] . ", ";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$query .= "'" . $jsonPayLoad[$keys[$i]] . "', ";
|
|
|
|
}
|
2024-06-02 20:09:40 -05:00
|
|
|
}
|
|
|
|
$query .= $jsonPayLoad[$keys[$i]] . ")";
|
2024-06-03 00:18:25 -05:00
|
|
|
|
2024-06-02 20:09:40 -05:00
|
|
|
$rowCount = $this->processStatement($query);
|
|
|
|
return $rowCount;
|
|
|
|
}
|
|
|
|
|
2024-05-21 12:43:37 -05:00
|
|
|
}
|