<?php
class AdminController extends CI_Controller {
  public function __construct () {
    parent::__construct();
    $this->load->library('parser');

    $this->checkLogin();
    
    $this->load->model('CompanyInformationModel');
    $this->data['companyInformations'] = $this->CompanyInformationModel->getLast();

    $this->data['unreadMessagesLength'] = $this->getUnreadMessagesLength();
  }

  private function getUnreadMessagesLength () {
    $this->load->model('MessageModel');
    return $this->MessageModel->count(['is_read' => false]);
  }

  private function checkLogin () {
    $admin = $this->session->userdata('admin');

    if (!$admin) {
      redirect('admin/login');
    }
  }
}