141 lines
4.8 KiB
PHP
141 lines
4.8 KiB
PHP
<?php
|
|
/**
|
|
* Created by Visual Studio Code.
|
|
* User: Surendiran
|
|
* Date: 12/05/17
|
|
* Time: 01:05 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 Status_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['addStatusDetails_get']['limit'] = 500; // 500 requests per hour per user/key
|
|
$this->methods['addStatusDetails_post']['limit'] = 100; // 100 requests per hour per user/key
|
|
$this->methods['addStatusDetails_delete']['limit'] = 50; // 50 requests per hour per user/key
|
|
$this->methods['getStatusDetails_post']['limit'] = 500; // 50 requests per hour per user/key
|
|
$this->methods['updateStatusDetails_post']['limit'] = 500;
|
|
// load the model
|
|
$this->load->model('Status_model', 'status_model');
|
|
|
|
}
|
|
|
|
/*
|
|
* This method used to add status details
|
|
* created by Surendiran
|
|
* */
|
|
|
|
public function addStatusDetails_post()
|
|
{
|
|
$now = new DateTime();
|
|
$now->setTimezone(new DateTimezone('Asia/Kolkata'));
|
|
$details['ListCode'] = $this->post('statusID');
|
|
$details['ListName'] = $this->post('statusName');
|
|
$details['ListGroup'] = "1";
|
|
$details['CreatedBy'] = $this->post('createdBy');
|
|
$details['IsActive'] = $this->post('status');
|
|
$details['CreatedOn'] = $now->format('Y-m-d H:i:s');
|
|
$statusDetails = $this->status_model->addstatus($details);// Check if the users data store contains users (in case the database result returns NULL)
|
|
if ($statusDetails)
|
|
{
|
|
$statusDetails['status'] = REST_Controller::HTTP_OK;
|
|
// Set the response and exit
|
|
$this->response($statusDetails, 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 status details
|
|
* created by Surendiran
|
|
* */
|
|
public function getStatusDetails_post()
|
|
{
|
|
$requestedBy = $this->post('requestedBy');
|
|
$getStatus = $this->status_model->getStatus($requestedBy);
|
|
|
|
if ($getStatus)
|
|
{
|
|
$getStatus['status'] = REST_Controller::HTTP_OK;
|
|
// Set the response and exit
|
|
$this->response($getStatus, 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 status details
|
|
* created by Surendiran
|
|
* */
|
|
public function updateStatusDetails_post()
|
|
{
|
|
$now = new DateTime();
|
|
$now->setTimezone(new DateTimezone('Asia/Kolkata'));
|
|
$ListCode = $this->post('ListCode');
|
|
$details['ListName'] = $this->post('ListName');
|
|
$details['IsActive'] = $this->post('status');
|
|
$details['UpdatedBy'] = $this->post('updatedBy');
|
|
$details['UpdatedOn'] = $now->format("Y-m-d H:i:s");
|
|
$statusDetails = $this->status_model->update($details,$ListCode);// Check if the users data store contains users (in case the database result returns NULL)
|
|
|
|
if ($statusDetails)
|
|
|
|
{
|
|
$statusDetails['status'] = REST_Controller::HTTP_OK;
|
|
// Set the response and exit
|
|
$this->response($statusDetails, 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
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} |