<commit_before><?php
class revendicationActions extends sfActions {
  
    public function executeIndex(sfWebRequest $request) {
        if(!isset($this->formEtablissement)) {
            $this->formEtablissement = null;
        }
        $this->form = new CreateRevendicationForm();
        $this->historiqueImport = RevendicationClient::getInstance()->getHistory(null);
        if ($request->isMethod(sfWebRequest::POST) && is_null($this->formEtablissement)) {
            $this->form->bind($request->getParameter($this->form->getName()), $request->getFiles($this->form->getName()));
            if ($this->form->isValid()) {
                    $revendication = RevendicationClient::getInstance()->createOrFind($this->form->getValue('odg'), $this->form->getValue('campagne'));
                    $revendication->etape = 1;
                    $revendication->save();

                    return $this->redirect('revendication_upload', $revendication);
            }
        }

        $this->setTemplate('index');
    }
    
    public function executeMonEspace(sfWebRequest $request) {
        $this->revendication_etablissement = null;
    	
        $this->etablissement = $this->getRoute()->getEtablissement();
    	if(!$this->etablissement) {
    	  throw new sfException("Cet établissement n'a pas de volume renvendiqué");
    	}

        $this->formCampagne($request, 'revendication_etablissement');

        $this->odg = RevendicationEtablissementView::getInstance()->getOdgByEtablissementAndCampagne($this->etablissement->identifiant, $this->campagne);

        if(!$this->odg) {
            $this->odg = $this->etablissement->region;
        }
        
        $this->revendication = RevendicationClient::getInstance()->findByOdgAndCampagne($this->odg, $this->campagne, acCouchdbClient::HYDRATE_JSON);

        $this->revendications = RevendicationEtablissementView::getInstance()->findByEtablissementAndCampagne($this->etablissement->identifiant, $this->campagne);
    }

    public function executeChooseEtablissement(sfWebRequest $request) {
        $this->formEtablissement = new RevendicationEtablissementChoiceForm('INTERPRO-inter-loire');
        if ($request->isMethod(sfWebRequest::POST)) {
	        $this->formEtablissement->bind($request->getParameter($this->formEtablissement->getName()));
	        if ($this->formEtablissement->isValid()) {
	           
               return $this->redirect('revendication_etablissement', $this->formEtablissement->getEtablissement());
	        }
       }

       $this->executeIndex($request);
    }

    public function executeUpload(sfWebRequest $request) {
        ini_set('memory_limit','2048M');
        set_time_limit(0);
        $this->errors = array();
        $this->not_valid_file = false;
        $this->revendication = $this->getRoute()->getRevendication();
        $this->form = new UploadCSVRevendicationForm($this->revendication);
        if ($request->isMethod(sfWebRequest::POST)) {
            $this->form->bind($request->getParameter($this->form->getName()), $request->getFiles($this->form->getName()));
            if ($this->form->isValid()) {
                $file = $this->form->getValue('file');
                $this->md5 = $file->getMd5();

                $path = sfConfig::get('sf_data_dir') . '/upload/' . $this->md5;           
                RevendicationCsvFile::convertTxtToCSV($path);
                $this->csv = new RevendicationCsvFile($path);
                $this->revendication->updateCSV($path);
                if(!$this->csv->check())
                {
                    $this->errors = $this->csv->getErrors(); 
                    $this->revendication->etape = 1;
                    $this->form = new UploadCSVRevendicationForm($this->revendication);
                    return sfView::SUCCESS;
                }
                    
                $this->revendication->save();
                return $this->redirect('revendication_update', $this->revendication);
           }else{
               $this->not_valid_file = true; 
           }
        }
    }

    public function executeDownloadCSV(sfWebRequest $request) {
        $revendication = $this->getRoute()->getRevendication();
        $this->getResponse()->setHttpHeader('Content-type', 'text/csv');
        $this->getResponse()->setHttpHeader('Content-Disposition', sprintf('filename="DREV-%s-%s-%s.csv"', $revendication->odg, $revendication->campagne, $revendication->_rev));
	$this->csv = $revendication->getAttachmentUri('revendication.csv');
        $this->setLayout(false);
    }
    
    public function executeDownloadImportedRowsCSV(sfWebRequest $request) {
        $this->setLayout(false);
        $this->revendication = $this->getRoute()->getRevendication();
        $attachement = 'attachment; filename='.sprintf('DREV-%s-%s-%s-importee.csv', $this->revendication->odg, $this->revendication->campagne, $this->revendication->_rev);
        header("content-type: application/pdf\n");
        header("content-disposition: $attachement\n\n");
        echo RevendicationClient::getCsvImportedRows($this->revendication);
        exit;
    }

    public function executeUpdate(sfWebRequest $request) {
        ini_set('memory_limit','2048M');
        set_time_limit(0);
        $this->revendication = $this->getRoute()->getRevendication();
        $this->revendication->storeDatas();
        $this->revendication->save();
        return $this->redirect('revendication_view_erreurs', $this->revendication);
    }

    public function executeViewErreurs(sfWebRequest $request) {
        $this->revendication = $this->getRoute()->getRevendication();
        $this->erreurs = $this->revendication->erreurs;<commit_msg>mis a jour du content-type pour l'export des CSV de volumeRev<commit_after><?php
class revendicationActions extends sfActions {
  
    public function executeIndex(sfWebRequest $request) {
        if(!isset($this->formEtablissement)) {
            $this->formEtablissement = null;
        }
        $this->form = new CreateRevendicationForm();
        $this->historiqueImport = RevendicationClient::getInstance()->getHistory(null);
        if ($request->isMethod(sfWebRequest::POST) && is_null($this->formEtablissement)) {
            $this->form->bind($request->getParameter($this->form->getName()), $request->getFiles($this->form->getName()));
            if ($this->form->isValid()) {
                    $revendication = RevendicationClient::getInstance()->createOrFind($this->form->getValue('odg'), $this->form->getValue('campagne'));
                    $revendication->etape = 1;
                    $revendication->save();

                    return $this->redirect('revendication_upload', $revendication);
            }
        }

        $this->setTemplate('index');
    }
    
    public function executeMonEspace(sfWebRequest $request) {
        $this->revendication_etablissement = null;
    	
        $this->etablissement = $this->getRoute()->getEtablissement();
    	if(!$this->etablissement) {
    	  throw new sfException("Cet établissement n'a pas de volume renvendiqué");
    	}

        $this->formCampagne($request, 'revendication_etablissement');

        $this->odg = RevendicationEtablissementView::getInstance()->getOdgByEtablissementAndCampagne($this->etablissement->identifiant, $this->campagne);

        if(!$this->odg) {
            $this->odg = $this->etablissement->region;
        }
        
        $this->revendication = RevendicationClient::getInstance()->findByOdgAndCampagne($this->odg, $this->campagne, acCouchdbClient::HYDRATE_JSON);

        $this->revendications = RevendicationEtablissementView::getInstance()->findByEtablissementAndCampagne($this->etablissement->identifiant, $this->campagne);
    }

    public function executeChooseEtablissement(sfWebRequest $request) {
        $this->formEtablissement = new RevendicationEtablissementChoiceForm('INTERPRO-inter-loire');
        if ($request->isMethod(sfWebRequest::POST)) {
	        $this->formEtablissement->bind($request->getParameter($this->formEtablissement->getName()));
	        if ($this->formEtablissement->isValid()) {
	           
               return $this->redirect('revendication_etablissement', $this->formEtablissement->getEtablissement());
	        }
       }

       $this->executeIndex($request);
    }

    public function executeUpload(sfWebRequest $request) {
        ini_set('memory_limit','2048M');
        set_time_limit(0);
        $this->errors = array();
        $this->not_valid_file = false;
        $this->revendication = $this->getRoute()->getRevendication();
        $this->form = new UploadCSVRevendicationForm($this->revendication);
        if ($request->isMethod(sfWebRequest::POST)) {
            $this->form->bind($request->getParameter($this->form->getName()), $request->getFiles($this->form->getName()));
            if ($this->form->isValid()) {
                $file = $this->form->getValue('file');
                $this->md5 = $file->getMd5();

                $path = sfConfig::get('sf_data_dir') . '/upload/' . $this->md5;           
                RevendicationCsvFile::convertTxtToCSV($path);
                $this->csv = new RevendicationCsvFile($path);
                $this->revendication->updateCSV($path);
                if(!$this->csv->check())
                {
                    $this->errors = $this->csv->getErrors(); 
                    $this->revendication->etape = 1;
                    $this->form = new UploadCSVRevendicationForm($this->revendication);
                    return sfView::SUCCESS;
                }
                    
                $this->revendication->save();
                return $this->redirect('revendication_update', $this->revendication);
           }else{
               $this->not_valid_file = true; 
           }
        }
    }

    public function executeDownloadCSV(sfWebRequest $request) {
        $revendication = $this->getRoute()->getRevendication();
        $this->getResponse()->setHttpHeader('Content-type', 'text/csv');
        $this->getResponse()->setHttpHeader('Content-Disposition', sprintf('filename="DREV-%s-%s-%s.csv"', $revendication->odg, $revendication->campagne, $revendication->_rev));
	$this->csv = $revendication->getAttachmentUri('revendication.csv');
        $this->setLayout(false);
    }
    
    public function executeDownloadImportedRowsCSV(sfWebRequest $request) {
        $this->setLayout(false);
        $this->revendication = $this->getRoute()->getRevendication();
        $attachement = 'attachment; filename='.sprintf('DREV-%s-%s-%s-importee.csv', $this->revendication->odg, $this->revendication->campagne, $this->revendication->_rev);
        header("content-type: text/csv\n");
        header("content-disposition: $attachement\n\n");
        echo RevendicationClient::getCsvImportedRows($this->revendication);
        exit;
    }

    public function executeUpdate(sfWebRequest $request) {
        ini_set('memory_limit','2048M');
        set_time_limit(0);
        $this->revendication = $this->getRoute()->getRevendication();
        $this->revendication->storeDatas();
        $this->revendication->save();
        return $this->redirect('revendication_view_erreurs', $this->revendication);
    }

    public function executeViewErreurs(sfWebRequest $request) {
        $this->revendication = $this->getRoute()->getRevendication();
        $this->erreurs = $this->revendication->erreurs;
{'fraction_non_alphanumeric': 0.15637860082304528, 'fraction_numerical': 0.002626740215392698, 'mean_word_length': 2.9009562841530054, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 285, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3441058', 'n_tokens_mistral': 3344, 'n_tokens_neox': 3272, 'n_words': 391}