apollodec/Apollo/api/application/controllers/Subject_Controller.php
2019-01-24 17:34:48 +05:30

163 lines
5.5 KiB
PHP
Executable File

<?php
/**
* Created by PhpStorm.
* User: subaram
*/
class Subject_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['addSubjectDetails_get']['limit'] = 500; // 500 requests per hour per user/key
$this->methods['addSubjectDetails_post']['limit'] = 100; // 100 requests per hour per user/key
$this->methods['addSubjectDetails_delete']['limit'] = 50; // 50 requests per hour per user/key
$this->methods['getSubjectDetails_post']['limit'] = 500; // 50 requests per hour per user/key
$this->methods['updateSubjectDetails_post']['limit'] = 500;// 500 requests per hour per user/key
$this->methods['getSubjectDetails1_post']['limit'] =500;
// load the model
$this->load->model('Subject_model', 'subject_model');
}
/*
* This method used to add Subject details
*
* */
public function addSubjectDetails_post()
{
$now = new DateTime();
$now->setTimezone(new DateTimezone('Asia/Kolkata'));
$details['SubjectCode'] = $this->post('SubjectCode');
$details['SubjectName'] = $this->post('SubjectName');
$details['IsActive'] = $this->post('Status');
$details['CreatedBy'] = $this->post('createdBy');
$details['BranchCode'] = $this->post('branchCode');
$details['CreatedOn'] = $now->format('Y-m-d H:i:s');
$subjectDetails = $this->subject_model->addSubject($details);// Check if the users data store contains users (in case the database result returns NULL)
if ($subjectDetails)
{
$subjectDetails['status'] = REST_Controller::HTTP_OK;
// Set the response and exit
$this->response($subjectDetails, 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 Subject details
*
* */
public function getSubjectDetails_post()
{
$requestedBy = $this->post('requestedBy');
$branchCode = $this->post('branchCode');
$getSubject = $this->subject_model->getSubject($requestedBy,$branchCode);
if ($getSubject)
{
$getSubject['status'] = REST_Controller::HTTP_OK;
// Set the response and exit
$this->response($getSubject, 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 Subject details
*
* */
public function updateSubjectDetails_post()
{
$now = new DateTime();
$now->setTimezone(new DateTimezone('Asia/Kolkata'));
$details['SubjectCode'] = $this->post('SubjectCode');
$details['SubjectName'] = $this->post('SubjectName');
$SubjectID = $this->post('SubjectID');
$details['IsActive'] = $this->post('Status');
$details['UpdatedBy'] = $this->post('updatedBy');
$details['BranchCode'] = $this->post('branchCode');
$details['UpdatedOn'] = $now->format('Y-m-d H:i:s');
// print_r($SubjectID);die();
$updateDetails = $this->subject_model->updateSubject($details,$SubjectID);// Check if the users data store contains users (in case the database result returns NULL)
// print_r($details,$SubjectID);die();
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
}
}
public function getSubjectDetails1_post()
{
$requestedBy = $this->post('requestedBy');
$branchCode = $this->post('branchCode');
$getSubject = $this->subject_model->getSubject1($requestedBy,$branchCode);
if ($getSubject)
{
$getSubject['status'] = REST_Controller::HTTP_OK;
// Set the response and exit
$this->response($getSubject, 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
}
}
}