134 lines
4.9 KiB
PHP
Executable File
134 lines
4.9 KiB
PHP
Executable File
<?php
|
|
/**
|
|
* Created by Visual studio code.
|
|
* User: Surendiran
|
|
* Date: 11/27/17
|
|
* Time: 10:40 am
|
|
*/
|
|
|
|
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 Announcement_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['addAnnouncementDetails_get']['limit'] = 500; // 500 requests per hour per user/key
|
|
$this->methods['addAnnouncementDetails_post']['limit'] = 100; // 100 requests per hour per user/key
|
|
$this->methods['addAnnouncementDetails_delete']['limit'] = 50; // 50 requests per hour per user/key
|
|
$this->methods['getAnnouncementDetails_post']['limit'] = 500; // 50 requests per hour per user/key
|
|
$this->methods['updateAnnouncementDetails_post']['limit'] = 500;
|
|
// load the model
|
|
$this->load->model('Announcement_model', 'announcement_model');
|
|
|
|
}
|
|
|
|
/*
|
|
* This method used to add Announcement Details
|
|
* created by Surendiran
|
|
* */
|
|
|
|
public function addAnnouncementDetails_post()
|
|
{
|
|
$details['Heading'] = $this->post('Heading');
|
|
$details['Description'] = $this->post('description');
|
|
$details['CreatedBy'] = $this->post('createdBy');
|
|
$details['IsActive'] = $this->post('status');
|
|
$announcementDetails = $this->announcement_model->addAnnouncement($details);// Check if the users data store contains users (in case the database result returns NULL)
|
|
if ($announcementDetails)
|
|
{
|
|
$announcementDetails['status'] = REST_Controller::HTTP_OK;
|
|
// Set the response and exit
|
|
$this->response($announcementDetails, 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 Announcement Details
|
|
* created by Surendiran
|
|
* */
|
|
public function getAnnouncementDetails_post()
|
|
{
|
|
$requestedBy = $this->post('requestedBy');
|
|
|
|
$getAnnouncement = $this->announcement_model->getAnnouncement();
|
|
|
|
if ($getAnnouncement)
|
|
{
|
|
$getAnnouncement['status'] = REST_Controller::HTTP_OK;
|
|
// Set the response and exit
|
|
$this->response($getAnnouncement, 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 Announcement Details
|
|
* created by Surendiran
|
|
* */
|
|
public function updateAnnouncementDetails_post()
|
|
{
|
|
$updateID = $this->post('updateID');
|
|
// $details['ID'] = $this->post('ID');
|
|
$details['Heading'] = $this->post('Heading');
|
|
$details['Description'] = $this->post('description');
|
|
$details['IsActive'] = $this->post('status');
|
|
$details['UpdatedBy'] = $this->post('createdBy');
|
|
$date = date('Y-m-d H:i:s');
|
|
$details['UpdatedOn'] = $date;
|
|
$announcementDetails = $this->announcement_model->updateAnnouncement($details,$updateID);// Check if the users data store contains users (in case the database result returns NULL)
|
|
|
|
if ($announcementDetails)
|
|
{
|
|
$announcementDetails['status'] = REST_Controller::HTTP_OK;
|
|
// Set the response and exit
|
|
$this->response($announcementDetails, 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
|
|
}
|
|
}
|
|
} |