<?php
namespace App\Controller;


use App\Utility\PdfWriter;
use Cake\I18n\FrozenTime;
use Cake\I18n\FrozenDate;
use Cake\View\View;


/**
 * Student Controller
 *
 * @property \App\Model\Table\StudentsTable $Students
 * @property \App\Model\Table\StudentSessionsTable $StudentSessions
 * @property \App\Model\Table\StudentCoursesTable $StudentCourses
 * @property \App\Model\Table\CoursesTable $Courses
 * @property \App\Model\Table\SessionsTable $Sessions
 * @property \App\Model\Table\RegistrationPaymentsTable $RegistrationPayments
 * @property \App\Model\Table\PassportDetailsTable $PassportDetails

 */
class PortalController extends AppsController
{

    public function initialize(): void
    {
        parent::initialize();
        $this->loadModel('Students');
        $this->loadModel('StudentSessions');
        $this->loadModel('StudentCourses');
        $this->loadModel('Courses');
        $this->loadModel('Sessions');
        $this->loadModel('RegistrationPayments');
        $this->loadModel('PassportDetails');


    }

    public function index()
    {
        $id = $this->Auth->user('crm_contact_user_id');

        $student = $this->Students->get($id, [
            'contain' => []
        ]);

        $student_session = $this->StudentSessions->find()
            ->where(['student_id' => $id])
            ->first();
        $student_course = $this->StudentCourses->find()
            ->where(['student_id' => $id])
            ->first();

        $sessions = $this->Sessions->find()
            ->where(['id' => $student_session['session_id']])
            ->first();
        $courses = $this->Courses->find()
            ->where(['id' => $student_course['course_id']])
            ->first();

        $this->set(compact('sessions','courses','student_session','student_course'));
        $this->set('student', $student);
        $this->set('_serialize', ['student']);

        $user_permissions = $this->request->session()->read('user_permissions');
        $this->set('languages', $this->languages);
        $this->set('module_pages', $this->getPages());
        $this->set('user_permission', $user_permissions);
    }


    public function view($id=null)
    {
        $student = $this->Students->get($id, [
            'contain' => []
        ]);

        $student_session = $this->StudentSessions->find()
            ->where(['student_id' => $id])
            ->first();
        $student_course = $this->StudentCourses->find()
            ->where(['student_id' => $id])
            ->first();

        $sessions = $this->Sessions->find()
            ->where(['id' => $student_session['session_id']])
            ->first();
        $courses = $this->Courses->find()
            ->where(['id' => $student_course['course_id']])
            ->first();

        $this->set(compact('sessions','courses','student_session','student_course'));
        $this->set('student', $student);
        $this->set('_serialize', ['student']);

        $user_permissions = $this->request->session()->read('user_permissions');
        $this->set('languages', $this->languages);
        $this->set('module_pages', $this->getPages());
        $this->set('user_permission', $user_permissions);
    }




}
