mirror of
https://github.com/sctn4elk/CustomerRewardsRESTAPI.git
synced 2025-01-10 09:04:29 -06:00
81 lines
2.3 KiB
PHP
81 lines
2.3 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()
|
|
{
|
|
return $this->processQuery("SELECT * FROM loyalty_member_view WHERE loyalty_member_id = ? AND loyalty_attribute_id = ?", ["ii", $this->memberId, $this->attributeId]);
|
|
}
|
|
|
|
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_member_attribute_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;
|
|
}
|
|
|
|
}
|