<?php

namespace Modules\DemandeAchat\Repository;

class PJ
{
    
    private $pdo;
    
    public function __construct(\PDO $pdo)
    {
        $this->pdo = $pdo;
    }
    
    /**
     * listePJ
     * @param string $numDA
     * @param array<string> $post
     * @return array<mixed>
     * @todo use QueryBuilder instead
     */
    public function listePJ(String $numDA, Array $post) : Array
    {
        $req = "SELECT DA_PIJO.*
            FROM DA_PIJO with (nolock) WHERE NO_DA = :numDA";
        
        $arrayReq = [':numDA' => $numDA];
        
        $whereArray = \Helpers\Filter\FilterTable::splitFilter($post, 0, 0, 1);
        if (count($whereArray)>  0) {
            $req .= $whereArray[0].$whereArray['tri'];
            
            if (count($whereArray[1]) != 0) {
                $arrayReq = array_merge($arrayReq, $whereArray[1]);
            }
        }
                
        $requete = $this->pdo->prepare($req);
        $requete->execute($arrayReq);
        return $requete->fetchAll($this->pdo::FETCH_ASSOC);
    }
}
