mirror of
https://github.com/sctn4elk/CustomerRewardsRESTAPI.git
synced 2025-01-10 09:24:31 -06:00
Work on getting image from database
This commit is contained in:
parent
a3bff0e30e
commit
49dd152914
|
@ -45,7 +45,7 @@ class BaseController {
|
||||||
/*
|
/*
|
||||||
* Set the error description when an unknown method is called
|
* Set the error description when an unknown method is called
|
||||||
*/
|
*/
|
||||||
public function unprocessableRequestResponse($msg)
|
public function unprocessableRequestResponse($msg = "Unknown Error")
|
||||||
{
|
{
|
||||||
$response['status_code_header'] = 'HTTP/1.1 405 Method Not Supported';
|
$response['status_code_header'] = 'HTTP/1.1 405 Method Not Supported';
|
||||||
$response['body'] = json_encode([
|
$response['body'] = json_encode([
|
||||||
|
@ -60,7 +60,7 @@ class BaseController {
|
||||||
/*
|
/*
|
||||||
* Set the error description when the payload does not contain the required info
|
* Set the error description when the payload does not contain the required info
|
||||||
*/
|
*/
|
||||||
public function unprocessableEntityResponse($msg)
|
public function unprocessableEntityResponse($msg = "Unknown Error")
|
||||||
{
|
{
|
||||||
$response['status_code_header'] = 'HTTP/1.1 422 Unprocessable Payload';
|
$response['status_code_header'] = 'HTTP/1.1 422 Unprocessable Payload';
|
||||||
$response['body'] = json_encode([
|
$response['body'] = json_encode([
|
||||||
|
@ -75,7 +75,7 @@ class BaseController {
|
||||||
/*
|
/*
|
||||||
* Set the error description when the
|
* Set the error description when the
|
||||||
*/
|
*/
|
||||||
public function notFoundResponse($msg)
|
public function notFoundResponse($msg = "Unknown Error")
|
||||||
{
|
{
|
||||||
$response['status_code_header'] = 'HTTP/1.1 404 Entity Not Found';
|
$response['status_code_header'] = 'HTTP/1.1 404 Entity Not Found';
|
||||||
$response['body'] = null;
|
$response['body'] = null;
|
||||||
|
|
|
@ -31,6 +31,10 @@ class ImageController extends BaseController {
|
||||||
$this->imageModel = new ImageModel();
|
$this->imageModel = new ImageModel();
|
||||||
|
|
||||||
switch($this->action) {
|
switch($this->action) {
|
||||||
|
case "select":
|
||||||
|
$response = $this->selectImage();
|
||||||
|
break;
|
||||||
|
|
||||||
case "upload":
|
case "upload":
|
||||||
$response = $this->uploadImage();
|
$response = $this->uploadImage();
|
||||||
break;
|
break;
|
||||||
|
@ -69,18 +73,45 @@ class ImageController extends BaseController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function selectImage(){
|
||||||
|
if ($this->checkRequestType('GET') == 'false') {
|
||||||
|
return $this->unprocessableRequestResponse("Request type is not GET");
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->arrQueryStringParams = $this->getQueryStringParams();
|
||||||
|
|
||||||
|
if (isset($this->arrQueryStringParams['member_id'])) {
|
||||||
|
$response = $this->selectByIdAction();
|
||||||
|
} else {
|
||||||
|
$this->imageModel->limit = 20;
|
||||||
|
|
||||||
|
if (isset($this->arrQueryStringParams['limit'])) {
|
||||||
|
$this->imageModel->limit = $this->arrQueryStringParams['limit'];
|
||||||
|
}
|
||||||
|
$response = $this->imageModel->findAllImages();
|
||||||
|
unset($this->imageModel->limit);
|
||||||
|
}
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function selectByIdAction(){
|
||||||
|
if (isset($this->arrQueryStringParams['member_id'])) {
|
||||||
|
$this->imageModel->memberId = $this->arrQueryStringParams['member_id'];
|
||||||
|
$response = $this->imageModel->findImageByMemberId();
|
||||||
|
unset($this->imageModel->memberId);
|
||||||
|
} else {
|
||||||
|
$response = $this->notFoundResponse("selectByIdAction");
|
||||||
|
}
|
||||||
|
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
|
|
||||||
/* Upload the image and store on server as file */
|
/* Upload the image and store on server as file */
|
||||||
private function uploadImage(){
|
private function uploadImage(){
|
||||||
if ($this->checkRequestType('POST') == 'false') {
|
if ($this->checkRequestType('POST') == 'false') {
|
||||||
return $this->unprocessableRequestResponse();
|
return $this->unprocessableRequestResponse();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* array(1) {
|
|
||||||
["MemberImageModel"]=>
|
|
||||||
string(240) "{"CustomerID":1,"ImagePath":"C:\\DEV\\CustomerRewardsAdminPortal\\Resources\\Images\\headshot.jpg","ImageName":"headshot.jpg","ImageType":"image/jpg","ImageBlob":{"Headers":[{"Key":"Content-Type","Value":["image/jpg"]}]},"SourceImage":null}"
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
// reads the raw POST data
|
// reads the raw POST data
|
||||||
$jsonPayload = filter_input_array(INPUT_POST);
|
$jsonPayload = filter_input_array(INPUT_POST);
|
||||||
$input = json_decode($jsonPayload['MemberImageModel'], TRUE);
|
$input = json_decode($jsonPayload['MemberImageModel'], TRUE);
|
||||||
|
@ -169,6 +200,22 @@ class ImageController extends BaseController {
|
||||||
return $check;
|
return $check;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function updateImage(){
|
||||||
|
if ($this->checkRequestType('PUT') == 'false') {
|
||||||
|
return $this->unprocessableRequestResponse("Request type is not PUT");
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->unprocessableRequestResponse("updateImage is not implemented");
|
||||||
|
}
|
||||||
|
|
||||||
|
private function deleteImage(){
|
||||||
|
if ($this->checkRequestType('DELETE') == 'false') {
|
||||||
|
return $this->unprocessableRequestResponse("Request type is not DELETE");
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->unprocessableRequestResponse("deleteImage is not implemented");
|
||||||
|
}
|
||||||
|
|
||||||
private function validateImage(){
|
private function validateImage(){
|
||||||
$validtion = false;
|
$validtion = false;
|
||||||
if(in_array($this->imageModel->fileType, $this->imageModel->allowFileType)){
|
if(in_array($this->imageModel->fileType, $this->imageModel->allowFileType)){
|
||||||
|
|
|
@ -28,6 +28,10 @@ require_once PD . "/Model/ModelTraits.php";
|
||||||
class CustomerModel extends Database {
|
class CustomerModel extends Database {
|
||||||
use ModelTraits;
|
use ModelTraits;
|
||||||
|
|
||||||
|
function __construct() {
|
||||||
|
parent::__construct();
|
||||||
|
}
|
||||||
|
|
||||||
public function findAllCustomers()
|
public function findAllCustomers()
|
||||||
{
|
{
|
||||||
return $this->processQuery("SELECT * FROM customer_view ORDER BY customer_id ASC LIMIT ?", ["i", $this->limit]);
|
return $this->processQuery("SELECT * FROM customer_view ORDER BY customer_id ASC LIMIT ?", ["i", $this->limit]);
|
||||||
|
|
|
@ -70,13 +70,13 @@ class Database {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function processImage($query = "", $imageModel) {
|
public function processImage($query, $imageModel) {
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if($this->connection == null)
|
/*if($this->connection == null)
|
||||||
{
|
{
|
||||||
$this->connection = new mysqli(DB_HOST, DB_USERNAME, DB_PASSWORD, DB_DATABASE_NAME);
|
$this->connection = new mysqli(DB_HOST, DB_USERNAME, DB_PASSWORD, DB_DATABASE_NAME);
|
||||||
}
|
}*/
|
||||||
|
|
||||||
$data = $this->connection->real_escape_string($imageModel->imageBlob);
|
$data = $this->connection->real_escape_string($imageModel->imageBlob);
|
||||||
$result = $this->connection->query($query."(".$imageModel->memberId.", '".$imageModel->imageType."', '".$data."')");
|
$result = $this->connection->query($query."(".$imageModel->memberId.", '".$imageModel->imageType."', '".$data."')");
|
||||||
|
|
|
@ -35,6 +35,7 @@ class ImageModel extends Database {
|
||||||
public $fileType;
|
public $fileType;
|
||||||
|
|
||||||
function __construct() {
|
function __construct() {
|
||||||
|
parent::__construct();
|
||||||
$this->uploadTo = PD . "\\public\\images\\";
|
$this->uploadTo = PD . "\\public\\images\\";
|
||||||
//$this->uploadTo = PD . '/public/images/';
|
//$this->uploadTo = PD . '/public/images/';
|
||||||
$this->allowFileType = array('jpg','png','jpeg','gif');
|
$this->allowFileType = array('jpg','png','jpeg','gif');
|
||||||
|
@ -43,31 +44,29 @@ class ImageModel extends Database {
|
||||||
/* Process the uploaded image and store in database */
|
/* Process the uploaded image and store in database */
|
||||||
public function insertImage()
|
public function insertImage()
|
||||||
{
|
{
|
||||||
//$escaped_string = mysql_real_escape_string($this->imageBlob);
|
|
||||||
//$escaped_string = addslashes($this->imageBlob);
|
|
||||||
//return var_dump($escaped_string);
|
|
||||||
//$sql = "INSERT INTO ImageStore(ImageId,Image) VALUES('$this->image_id','" . mysql_escape_string(file_get_contents($tmp_image)) . "')";
|
|
||||||
|
|
||||||
//$fp=addslashes(file_get_contents($_FILES['image']['tmp_name'])); //will store the image to fp
|
|
||||||
//$query = "CALL insert_loyalty_member_image_proc('{$fileName}','{$fp}');";
|
|
||||||
|
|
||||||
/*
|
|
||||||
* $data = mysql_real_escape_string(fread(fopen($form_data, "r"), filesize($form_data)));
|
|
||||||
|
|
||||||
$result = mysql_query("INSERT INTO binary_data (description, bin_data, filename, filesize, filetype) ".
|
|
||||||
"VALUES ('$form_description', '$data', '$form_data_name', '$form_data_size', '$form_data_type')");
|
|
||||||
|
|
||||||
$id= mysql_insert_id();
|
|
||||||
*
|
|
||||||
* UPDATE t
|
|
||||||
SET blob_col=LOAD_FILE('/tmp/picture')
|
|
||||||
WHERE id=1;
|
|
||||||
*/
|
|
||||||
//$query = "CALL insert_loyalty_member_image_proc (" . $this->memberId . ", '" . $escaped_string . "');";
|
|
||||||
$query = "CALL insert_loyalty_member_image_proc";
|
$query = "CALL insert_loyalty_member_image_proc";
|
||||||
//return var_dump($query);
|
|
||||||
|
|
||||||
$rowCount = $this->processImage($query, $this);
|
$rowCount = $this->processImage($query, $this);
|
||||||
return $rowCount;
|
return $rowCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function findImageByMemberId()
|
||||||
|
{
|
||||||
|
return $this->processQuery("SELECT loyalty_value_id,
|
||||||
|
loyalty_member_id,
|
||||||
|
loyalty_attribute_id,
|
||||||
|
loyalty_value_mime_type
|
||||||
|
FROM toast_schema.loyalty_value_blob
|
||||||
|
WHERE loyalty_member_id = ?", ["i", $this->memberId]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function findAllImages()
|
||||||
|
{
|
||||||
|
return $this->processQuery("SELECT
|
||||||
|
loyalty_value_id,
|
||||||
|
loyalty_member_id,
|
||||||
|
loyalty_attribute_id,
|
||||||
|
loyalty_value_mime_type
|
||||||
|
FROM toast_schema.loyalty_value_blob
|
||||||
|
ORDER BY loyalty_member_id ASC LIMIT ?", ["i", $this->limit]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user