143 lines
5.2 KiB
PHP
Executable File
143 lines
5.2 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()
|
|
{
|
|
$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');
|
|
$branchDetails = $this->branch_model->addBranch($details);// 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()
|
|
{
|
|
$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');
|
|
$details['UpdatedBy'] = $this->post('updatedBy');
|
|
$details['UpdatedOn'] = date("Y-m-d", time());
|
|
$updateDetails = $this->branch_model->updateBranch($details,$branchCode);// 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
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
} |