mirror of
https://github.com/sctn4elk/CustomerRewardsRESTAPI.git
synced 2025-01-09 15:04:29 -06:00
101 lines
3.1 KiB
PHP
101 lines
3.1 KiB
PHP
<?php
|
|
/**
|
|
* Description of AttributeController
|
|
*
|
|
* @author Mike Howard
|
|
*/
|
|
|
|
header("Content-Type: application/json");
|
|
require_once PD . "/Model/AttributeModel.php";
|
|
|
|
class AttributeController extends BaseController {
|
|
public $attributeModel;
|
|
public $action;
|
|
|
|
function __construct() {
|
|
parent::__construct();
|
|
$this->basename = "AttributeController";
|
|
}
|
|
|
|
public function processAction() {
|
|
$this->strErrorDesc = '';
|
|
$this->strErrorHeader = '';
|
|
$this->strErrorMessage = '';
|
|
|
|
try {
|
|
$this->requestMethod = $this->getServerRequestMethod();
|
|
$this->attributeModel = new AttributeModel();
|
|
|
|
switch($this->action) {
|
|
case "select":
|
|
$response = $this->selectAction();
|
|
break;
|
|
|
|
case "insert":
|
|
$response = $this->insertAttribute();
|
|
break;
|
|
|
|
case "update":
|
|
$response = $this->updateAttribute();
|
|
break;
|
|
|
|
case "delete":
|
|
$response = $this->deleteAttribute();
|
|
break;
|
|
|
|
default:
|
|
$response = $this->unprocessableRequestResponse("processAction");
|
|
break;
|
|
}
|
|
|
|
$responseData = json_encode($response);
|
|
|
|
} catch (Error $e) {
|
|
$this->internalErrorResponse($e);
|
|
}
|
|
|
|
// send output
|
|
if (!$this->strErrorDesc) {
|
|
$this->sendOutput(
|
|
$responseData,
|
|
array('Content-Type: application/json', 'HTTP/1.1 200 OK')
|
|
);
|
|
} else {
|
|
$this->sendOutput(json_encode(
|
|
array('error' => $this->strErrorDesc,
|
|
'message' => $this->strErrorMessage,
|
|
'controller' => $this->basename)),
|
|
array('Content-Type: application/json', $this->strErrorHeader)
|
|
);
|
|
}
|
|
}
|
|
|
|
private function selectAction(){
|
|
if ($this->checkRequestType('GET') == 'false') {
|
|
$response = $this->unprocessableRequestResponse("selectAction");
|
|
return $response;
|
|
}
|
|
|
|
$this->arrQueryStringParams = $this->getQueryStringParams();
|
|
|
|
if (isset($this->arrQueryStringParams['loyalty_member_id'])) {
|
|
$response = $this->selectByMemberIdAction();
|
|
} else {
|
|
$response = $this->attributeModel->findAllAttributes();
|
|
}
|
|
return $response;
|
|
}
|
|
|
|
private function selectByMemberIdAction(){
|
|
if (isset($this->arrQueryStringParams['loyalty_member_id'])) {
|
|
$this->attributeModel->memberId = $this->arrQueryStringParams['loyalty_member_id'];
|
|
$response = $this->attributeModel->findAttributesByMemberId();
|
|
unset($this->attributeModel->memberId);
|
|
} else {
|
|
$response = $this->notFoundResponse("selectByMemberIdAction");
|
|
}
|
|
|
|
return $response;
|
|
}
|
|
}
|