138 lines
4.9 KiB
PHP
Executable File
138 lines
4.9 KiB
PHP
Executable File
<?php
|
|
/**
|
|
* Created by Visual Studio Code.
|
|
* User: Surendiran
|
|
* Date: 12/11/17
|
|
* Time: 03:26 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 Certificate_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['addCertificateDetails_get']['limit'] = 500; // 500 requests per hour per user/key
|
|
$this->methods['addCertificateDetails_post']['limit'] = 100; // 100 requests per hour per user/key
|
|
$this->methods['addCertificateDetails_delete']['limit'] = 50; // 50 requests per hour per user/key
|
|
$this->methods['getCertificateDetails_post']['limit'] = 500; // 50 requests per hour per user/key
|
|
$this->methods['updateCertificateDetails_post']['limit'] = 500;
|
|
// load the model
|
|
$this->load->model('Certificate_model', 'certificate_model');
|
|
|
|
}
|
|
|
|
/*
|
|
* This method used to add Certificate details
|
|
* created by Surendiran
|
|
* */
|
|
|
|
public function addCertificateDetails_post()
|
|
{
|
|
$now = new DateTime();
|
|
$now->setTimezone(new DateTimezone('Asia/Kolkata'));
|
|
$details['CertificateName'] = $this->post('certificateName');
|
|
$details['CreatedBy'] = $this->post('createdBy');
|
|
$details['IsActive'] = $this->post('status');
|
|
$details['CreatedOn'] = $now->format('Y-m-d H:i:s');
|
|
$certificateDetails = $this->certificate_model->addcertificate($details);// Check if the users data store contains users (in case the database result returns NULL)
|
|
if ($certificateDetails)
|
|
{
|
|
$certificateDetails['status'] = REST_Controller::HTTP_OK;
|
|
// Set the response and exit
|
|
$this->response($certificateDetails, 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 Certificate details
|
|
* created by Surendiran
|
|
* */
|
|
public function getCertificateDetails_post()
|
|
{
|
|
$requestedBy = $this->post('requestedBy');
|
|
$getCertificate = $this->certificate_model->getCertificate($requestedBy);
|
|
|
|
if ($getCertificate)
|
|
{
|
|
$getCertificate['status'] = REST_Controller::HTTP_OK;
|
|
// Set the response and exit
|
|
$this->response($getCertificate, 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 Certificate details
|
|
* created by Surendiran
|
|
* */
|
|
public function updateCertificateDetails_post()
|
|
{
|
|
$now = new DateTime();
|
|
$now->setTimezone(new DateTimezone('Asia/Kolkata'));
|
|
$updateID = $this->post('updateID');
|
|
$details['CertificateName'] = $this->post('certificateName');
|
|
$details['IsActive'] = $this->post('status');
|
|
$details['UpdatedBy'] = $this->post('updatedBy');
|
|
$details['UpdatedOn'] = $now->format("Y-m-d H:i:s");
|
|
$certificateDetails = $this->certificate_model->update($details,$updateID);// Check if the users data store contains users (in case the database result returns NULL)
|
|
|
|
if ($certificateDetails)
|
|
|
|
{
|
|
$certificateDetails['status'] = REST_Controller::HTTP_OK;
|
|
// Set the response and exit
|
|
$this->response($certificateDetails, 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
|
|
}
|
|
|
|
|
|
}
|
|
} |