<?php

class Student extends Controller {

    private $_studentModel;
    private $data;
    
    /* CONSTRUCTOR */
    public function __construct() {
        $this->_studentModel = $this->model('StudentModel');
    }

    /* INDEX */
    public function index() {
        // Obtener la lista de estudiantes
        $this->data['students'] = $this->_studentModel->getAllStudents();
        // Cargar la vista con los datos
        $this->view('Manage/students/index', $this->data);
    }    


    /* EDIT */
    public function edit($id) {
        $this->data['students'] = $this->_studentModel->getStudentById($id);
        $this->data['estados'] = $this->_studentModel->getEstadosAcademicos();
        $this->data['programas'] = $this->_studentModel->getProgramas();
        $this->data['acuerdos'] = $this->_studentModel->getAcuerdos();
        $this->view('Manage/students/edit', $this->data);
    }

    /* UPDATE */
    public function update() {
        $POST = $_POST;
        $this->data['students'] = $this->_studentModel->getAllStudents();
        $this->_studentModel->updateStudent($POST['codigo'], $POST);
        redirect('/Student/index');
    }
}