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 ()
{
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 ;
}
2024-05-21 12:43:37 -05:00
}