<?php
defined('BASEPATH') or exit('No direct script access allowed');

class Posts extends CI_Controller
{
	public function get_posts()
	{
		$this->load->model('Post_model');
		$productArray = [];
		$headers = $this->input->request_headers();
			if (is_null($this->Post_model->get_all_posts()))
				$productArray = ['code' => '99', 'message' => 'No Posts available!', 'data' => ''];
			else {
				$productArray = ['code' => '00', 'message' => 'All Posts Retrieved', 'data' => $this->Post_model->get_all_posts()];
			}
		header('Content-Type: application/json');
		echo json_encode($productArray);
	}
	
		public function get_active_posts()
	{
		$this->load->model('Post_model');
		$productArray = [];
		$headers = $this->input->request_headers();
			if (is_null($this->Post_model->get_all_active_posts()))
				$productArray = ['code' => '99', 'message' => 'No Posts available!', 'data' => ''];
			else {
				$productArray = ['code' => '00', 'message' => 'All Posts Retrieved', 'data' => $this->Post_model->get_all_active_posts()];
			}
		header('Content-Type: application/json');
		echo json_encode($productArray);
	} 


	public function get_posts_recent()
	{

		$this->load->model('Post_model');
		$this->load->library('Token');
		$productArray = [];
		$headers = $this->input->request_headers();

			if (is_null($this->Post_model->get_recent_posts()))
				$productArray = ['code' => '99', 'message' => 'No Posts available!', 'data' => ''];
			else {
				$productArray = ['code' => '00', 'message' => 'All Posts Retrieved', 'data' => $this->Post_model->get_recent_posts()];
			}
		header('Content-Type: application/json');
		echo json_encode($productArray);
	}
	
		public function get_last_post()
	{

		$this->load->model('Post_model');
		$this->load->library('Token');
		$productArray = [];
		$headers = $this->input->request_headers();

			if (is_null($this->Post_model->get_last_post()))
				$productArray = ['code' => '99', 'message' => 'No Posts available!', 'data' => ''];
			else {
				$productArray = ['code' => '00', 'message' => 'All Posts Retrieved', 'data' => $this->Post_model->get_last_post()];
			}
		header('Content-Type: application/json');
		echo json_encode($productArray);
	}

	
}
