<?php
namespace Modules\Fournisseur\Controller;

use Skeleton\Controller\Controller;
use Entity\Model\Fourniss;
use Modules\Fournisseur\Repository\ReponseAO;
use Modules\Fournisseur\Outil\DroitUtilisateur;
use Entity\Model\Grpfou;
use Helpers\Ariane\Ariane;
use Helpers\Ariane\ArianeSub;
use Helpers\Trad\Trad;

class ReponseAOController extends Controller
{

    
    public function reponseAOAction()
    {
        $id = $this->request->getAttribute('id');
        $MODULE = $this->request->getAttribute('MODULE');
        $article = $this->request->getAttribute('article');
        $post = $this->request->getParsedBody();
        $trad = $this->getTranslationService();
        
        
        $listeAO = new ReponseAO($this->pdo);
        $listeAO = $listeAO->listeReponseAO($id, $post, $MODULE, $article);
        
        $paginator = new \Helpers\Pagination\Paginator();
        $infopagination = $paginator->generate($listeAO, 8, $post, $this->renderer);
        
        $typeConsult = [
            'V' => $trad->t('Variant'),
            'C' => $trad->t('Conforme'),
        ];

        if ($MODULE=='Fournisseur' or $MODULE=='AFO') {
            $menuActive = 'Fournisseur';
            $menuLeft = 'GestionFournisseur';
            $fournis = new Fourniss($this->pdo);
            $fournis = $fournis->find($id);
            $libelle = $fournis["RS"];
            
            $layout = '@layoutFournisseur/fournisseur.twig';
        } else {
            $menuActive = 'Fournisseur';
            $menuLeft = 'GestionGroupement';
            $layout = '@layoutFournisseur/groupement.twig';
            
            $grp = new Grpfou($this->pdo);
            $grp = $grp->find($id);
            $libelle = $grp['RS'];
        }
        
        ArianeSub::generate(2, 0, $trad->t('Reponse AO'), $_SERVER['REQUEST_URI'], 1, $post);
        
        return $this->renderer->render('@Fournisseur/AO/reponsesAO', [
            'menuActive' => $menuActive,
            'menuLeft' => $menuLeft,
            'layout' => $layout,
            
            "code_fournisseur" => $id,
            "id" => $id,
            "libelle" => $libelle??'',
            'infoPagination' => $infopagination,
            "reponseAO" => true,
            'listeReponseAO' => $listeAO,
            'MODULE' => $MODULE,
            'articlesTRUE' => $article? true:false,
            'article' => $article,
            
            'typeConsult' => $typeConsult,
        ]);
    }
}
