162 lines
6.1 KiB
PHP
Executable File
162 lines
6.1 KiB
PHP
Executable File
<?php
|
|
/**
|
|
* Created by PhpStorm.
|
|
* User: kms
|
|
* Date: 11/13/17
|
|
* Time: 7:40 PM
|
|
*/
|
|
|
|
defined('BASEPATH') OR exit('No direct script access allowed');
|
|
|
|
// This can be removed if you use __autoload() in config.php OR use Modular Extensions
|
|
/** @noinspection PhpIncludeInspection */
|
|
require_once APPPATH . '/libraries/REST_Controller.php';
|
|
|
|
/**
|
|
* This is an example of a few basic user interaction methods you could use
|
|
* all done with a hardcoded array
|
|
*
|
|
* @package CodeIgniter
|
|
* @subpackage Rest Server
|
|
* @category Controller
|
|
* @author
|
|
* @license MIT
|
|
* @link
|
|
*/
|
|
class Branch_Controller extends REST_Controller {
|
|
|
|
function __construct()
|
|
{
|
|
// Construct the parent class
|
|
parent::__construct();
|
|
|
|
// Configure limits on our controller methods
|
|
// Ensure you have created the 'limits' table and enabled 'limits' within application/config/rest.php
|
|
$this->methods['addBranchDetails_get']['limit'] = 500; // 500 requests per hour per user/key
|
|
$this->methods['addBranchDetails_post']['limit'] = 100; // 100 requests per hour per user/key
|
|
$this->methods['addBranchDetails_delete']['limit'] = 50; // 50 requests per hour per user/key
|
|
$this->methods['getBranchDetails_post']['limit'] = 500; // 50 requests per hour per user/key
|
|
$this->methods['updateBranchDetails_post']['limit'] = 500;
|
|
// load the model
|
|
$this->load->model('Branch_model', 'branch_model');
|
|
|
|
}
|
|
|
|
/*
|
|
* This method used to add branch details
|
|
* created by kms
|
|
* */
|
|
|
|
public function addBranchDetails_post()
|
|
{
|
|
$now = new DateTime();
|
|
$now->setTimezone(new DateTimezone('Asia/Kolkata'));
|
|
$details['BranchCode'] = $this->post('branchCode');
|
|
$details['BranchName'] = $this->post('branchName');
|
|
// $details['LogoPath'] = $this->post('logo');
|
|
$details['MobileNumber'] = $this->post('primaryPhone');
|
|
$details['AlternateNumber'] = $this->post('secondaryPhone');
|
|
$details['LandlineNumber'] = $this->post('landLine');
|
|
$details['Address'] = $this->post('address');
|
|
$details['EmailID'] = $this->post('email');
|
|
$details['CreatedBy'] = $this->post('createdBy');
|
|
$details['IsActive'] = $this->post('status') == "true" ? 1 : 0;
|
|
$details['CreatedOn'] = $now->format('Y-m-d H:i:s');
|
|
|
|
$imageStat = $this->post('imageStatus');
|
|
|
|
$imagename = $imageStat == 1 ? $_FILES['logo']['name'] : '';
|
|
$size = $imageStat == 1 ? $_FILES['logo']['size'] : '';
|
|
$imageSource = $imageStat == 1 ? $_FILES['logo']['tmp_name'] : '';
|
|
|
|
$branchDetails = $this->branch_model->addBranch($details, $imageSource);// Check if the users data store contains users (in case the database result returns NULL)
|
|
if ($branchDetails)
|
|
{
|
|
$branchDetails['status'] = REST_Controller::HTTP_OK;
|
|
// Set the response and exit
|
|
$this->response($branchDetails, REST_Controller::HTTP_OK); // OK (200) being the HTTP response code
|
|
}
|
|
else
|
|
{
|
|
// Set the response and exit
|
|
$this->response([
|
|
'message' => 'Something went wrong.please try again!',
|
|
'status' => REST_Controller::HTTP_NOT_FOUND
|
|
], REST_Controller::HTTP_NOT_FOUND); // NOT_FOUND (404) being the HTTP response code
|
|
}
|
|
|
|
|
|
}
|
|
/*
|
|
* get branch details
|
|
* created by kms
|
|
* */
|
|
public function getBranchDetails_post()
|
|
{
|
|
$requestedBy = $this->post('requestedBy');
|
|
$getBranch = $this->branch_model->getBranch($requestedBy);
|
|
|
|
if ($getBranch)
|
|
{
|
|
$getBranch['status'] = REST_Controller::HTTP_OK;
|
|
// Set the response and exit
|
|
$this->response($getBranch, REST_Controller::HTTP_OK); // OK (200) being the HTTP response code
|
|
}
|
|
else
|
|
{
|
|
// Set the response and exit
|
|
$this->response([
|
|
'message' => 'No records found!',
|
|
'status' => REST_Controller::HTTP_NOT_FOUND
|
|
], REST_Controller::HTTP_NOT_FOUND); // NOT_FOUND (404) being the HTTP response code
|
|
}
|
|
|
|
|
|
}
|
|
/*
|
|
* update the branch details
|
|
* created by kms
|
|
* */
|
|
public function updateBranchDetails_post()
|
|
{
|
|
$now = new DateTime();
|
|
$now->setTimezone(new DateTimezone('Asia/Kolkata'));
|
|
$branchCode = $this->post('branchCode');
|
|
$details['BranchName'] = $this->post('branchName');
|
|
$details['LogoPath'] = $this->post('logo');
|
|
$details['MobileNumber'] = $this->post('primaryPhone');
|
|
$details['AlternateNumber'] = $this->post('secondaryPhone');
|
|
$details['LandlineNumber'] = $this->post('landLine');
|
|
$details['Address'] = $this->post('address');
|
|
$details['EmailID'] = $this->post('email');
|
|
$details['IsActive'] = $this->post('status') == "true" ? 1 : 0;
|
|
$details['UpdatedBy'] = $this->post('createdBy');
|
|
$details['UpdatedOn'] = $now->format("Y-m-d H:i:s");
|
|
|
|
$imageStat = $this->post('imageStatus');
|
|
|
|
$imagename = $imageStat == 1 ? $_FILES['logoEdit']['name'] : '';
|
|
$size = $imageStat == 1 ? $_FILES['logoEdit']['size'] : '';
|
|
$imageSource = $imageStat == 1 ? $_FILES['logoEdit']['tmp_name'] : '';
|
|
|
|
$updateDetails = $this->branch_model->updateBranch($details,$branchCode, $imageSource, $imageStat );// Check if the users data store contains users (in case the database result returns NULL)
|
|
if ($updateDetails)
|
|
{
|
|
$updateDetails['status'] = REST_Controller::HTTP_OK;
|
|
// Set the response and exit
|
|
$this->response($updateDetails, REST_Controller::HTTP_OK); // OK (200) being the HTTP response code
|
|
}
|
|
else
|
|
{
|
|
// Set the response and exit
|
|
$this->response([
|
|
'message' => 'Something went wrong.please try again!',
|
|
'status' => REST_Controller::HTTP_NOT_FOUND
|
|
], REST_Controller::HTTP_NOT_FOUND); // NOT_FOUND (404) being the HTTP response code
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
} |