<?php
namespace Modules\Index\Controller;

use Entity\Model\Langues;
use Helpers\Trad\Trad;
use Skeleton\Controller\Controller;

class WinCacheController extends Controller
{

 
    public function suppressionCacheUserAction() : bool
    {
        
        $type = $this->request->getAttribute('type');

        if (!\extension_loaded('wincache')) {
            return true;
        } else {
            if ($type) {
                switch ($type) {
                    case 'PARAM':
                        if (\wincache_ucache_exists('PARAM'.$_SESSION['_brokernumber'])) {
                            \wincache_ucache_delete('PARAM'.$_SESSION['_brokernumber']);
                        }
                        break;
                    
                    default:
                        if (\wincache_ucache_exists($type.$_SESSION['_brokernumber'])) {
                            \wincache_ucache_delete($type.$_SESSION['_brokernumber']);
                        }
                        break;
                }
            } else {
                $langues = new Langues($this->pdo);

                $trad = $this->getTranslationService();
                if ($trad instanceof Trad) {
                    foreach ($langues->fetchAll() as $langue) {
                        $trad->setLang($langue['COD_LNG']);
                        $trad->deleteCache();
                    }
                }
                
                \wincache_ucache_delete('PARAM'.$_SESSION['_brokernumber']);
            }
            
            return true;
        }
    }
}
