<?php

class Revenus_BiensController {
  private $model;

  public function __construct() {
    require_once '/home/dykqnvjf/public_html/bewise/app/models/Revenus_BiensModel.php';
    $this->model = new Revenus_BiensModel();
  }

  public function index() {
    @session_start();
    $id_user = $_SESSION['user']['id_utilisateur'];

    require_once '/home/dykqnvjf/public_html/bewise/app/models/BiensModel.php';
    $biensModel = new BiensModel();
    $biens = $biensModel->getByUser($id_user);

    $revenus = $this->model->getAll(); // à adapter selon ta logique
    require '/home/dykqnvjf/public_html/bewise/app/views/Revenus_BiensView.php';
  }

  public function create() {
    @session_start();
    $id_user = $_SESSION['user']['id_utilisateur'];

    require_once '/home/dykqnvjf/public_html/bewise/app/models/BiensModel.php';
    $biensModel = new BiensModel();
    $biens = $biensModel->getByUser($id_user);

    require '/home/dykqnvjf/public_html/bewise/app/views/CreateRevenus_BiensView.php';
  }

  public function filterByBien($id_bien) {
    @session_start();
    $id_user = $_SESSION['user']['id_utilisateur'];

    require_once '/home/dykqnvjf/public_html/bewise/app/models/BiensModel.php';
    $biensModel = new BiensModel();
    $biens = $biensModel->getByUser($id_user);

    $revenus = $this->model->getByBien($id_bien);

    require '/home/dykqnvjf/public_html/bewise/app/views/Revenus_BiensView.php';
  }

  public function store() {
    $this->model->store($_POST);
    header('Location: ../index.php/revenus_biens');
    exit;
  }

  public function edit($id) {
    @session_start();
    $id_user = $_SESSION['user']['id_utilisateur'];

    require_once '/home/dykqnvjf/public_html/bewise/app/models/BiensModel.php';
    $biensModel = new BiensModel();
    $biens = $biensModel->getByUser($id_user);

    $revenu = $this->model->find($id);
    require '/home/dykqnvjf/public_html/bewise/app/views/EditRevenus_BiensView.php';
  }

  public function update($id) {
    $this->model->update($id, $_POST);
    header('Location: ../revenus_biens');
    exit;
  }

  public function delete($id) {
    $this->model->delete($id);
    header('Location: ../revenus_biens');
    exit;
  }
}
?>
