<commit_before><?php

class subventionActions extends sfActions {

    public function executeIndex(sfWebRequest $request) {
      $this->operation_en_cours = SubventionConfiguration::getInstance()->getOperationEnCours();
      $this->subventions = SubventionClient::getInstance()->findByAllSortedByDate();
    }

    public function executeEtablissement(sfWebRequest $request) {
        $this->isTeledeclarationMode = $this->isTeledeclarationSubvention();
        $this->operation_en_cours = SubventionConfiguration::getInstance()->getOperationEnCours();
        $this->etablissement = $this->getRoute()->getEtablissement();
        $this->subvention_en_cours = SubventionClient::getInstance()->findByEtablissementAndOperation($this->etablissement->identifiant, $this->operation_en_cours);

    }

    public function executeEtablissementSelection(sfWebRequest $request) {

            $form = new SubventionEtablissementChoiceForm('INTERPRO-declaration');
            $form->bind($request->getParameter($form->getName()));
            if (!$form->isValid()) {

                return $this->redirect('subvention');
            }

            return $this->redirect('subvention_etablissement', $form->getEtablissement());
    }

    public function executeCreation(sfWebRequest $request) {
        $etablissement = $this->getRoute()->getEtablissement();

        $subvention = SubventionClient::getInstance()->createDoc($etablissement->identifiant, $request->getParameter('operation'));
        $subvention->save();

        return $this->redirect('subvention_infos', $subvention);
    }

    public function executeInfos(sfWebRequest $request) {
        $this->subvention = $this->getRoute()->getSubvention();

        if(!$this->subvention->hasXls() && !$this->subvention->hasDefaultXlsPath()){
          throw new sfException("Il n'existe pas de document pour cette opération : ".$this->subvention->operation);
        }

        $this->form = new SubventionsGenericForm($this->subvention,'infos');

        if (!$request->isMethod(sfWebRequest::POST)) {
            return sfView::SUCCESS;
        }
        $this->form->bind($request->getParameter($this->form->getName()));

      	if (!$this->form->isValid()) {
      		return sfView::SUCCESS;
      	}
        $this->form->save();

        $this->redirect('subvention_dossier', $this->subvention);

    }

    public function executeEngagements(sfWebRequest $request) {
        $this->subvention = $this->getRoute()->getSubvention();
        $this->form = new SubventionEngagementsForm($this->subvention);

        if (!$request->isMethod(sfWebRequest::POST)) {
            return sfView::SUCCESS;
        }

        $this->form->bind($request->getParameter($this->form->getName()));

        if (!$this->form->isValid()) {
            return sfView::SUCCESS;
        }

        $this->form->save();

        return $this->redirect($this->generateUrl('subvention_validation', $this->subvention));
    }

    public function executeValidation(sfWebRequest $request) {
        $this->subvention = $this->getRoute()->getSubvention();
        $this->form = new SubventionValidationForm($this->subvention);

        if (!$request->isMethod(sfWebRequest::POST)) {
            return sfView::SUCCESS;
        }

        $this->form->bind($request->getParameter($this->form->getName()));

        if (!$this->form->isValid()) {
            return sfView::SUCCESS;
        }

        $this->form->save();

        return $this->redirect($this->generateUrl('subvention_confirmation', $this->subvention));
    }

    public function executeConfirmation(sfWebRequest $request) {
        $this->subvention = $this->getRoute()->getSubvention();
    }

    public function executeVisualisation(sfWebRequest $request) {
        $this->subvention = $this->getRoute()->getSubvention();
        $this->isTeledeclarationMode = $this->isTeledeclarationSubvention();
        $this->formValidationInterpro = ($this->getUser()->hasCredential(myUser::CREDENTIAL_ADMIN))? new SubventionsGenericForm($this->subvention, 'approbations') : null;
        if (!$request->isMethod(sfWebRequest::POST) || !$this->formValidationInterpro) {

            return sfView::SUCCESS;
        }

        $this->formValidationInterpro->bind($request->getParameter($this->formValidationInterpro->getName()));

        if (!$this->formValidationInterpro->isValid()) {
            return sfView::SUCCESS;
        }

        $this->formValidationInterpro->save();
        $statut = $request->getParameter('statut',null);
        if($statut){
          $this->subvention->statut = $statut;
          $this->subvention->save();
        }

        return $this->redirect($this->generateUrl('subvention_visualisation', $this->subvention));
    }

    public function executeDossier(sfWebRequest $request) {

        $this->subvention = $this->getRoute()->getSubvention();
        $this->form = new SubventionDossierForm($this->subvention);

        if (!$request->isMethod(sfWebRequest::POST)) {
      		return sfView::SUCCESS;
      	}
      	$this->form->bind($request->getParameter($this->form->getName()), $request->getFiles($this->form->getName()));

      	if (!$this->form->isValid()) {
      		return sfView::SUCCESS;
      	}
        $this->form->save();

        $this->redirect('subvention_engagements', array('identifiant' => $this->subvention->identifiant,'operation' => $this->subvention->operation));

    }

    public function executeXls(sfWebRequest $request) {

      $this->subvention = $this->getRoute()->getSubvention();
      $this->setLayout(false);
      $path = $this->subvention->getXlsPath();
      $this->getResponse()->setHttpHeader('Content-disposition', 'attachment; filename="' . $this->subvention->getXlsPublicName() . '"');
      $this->getResponse()->setHttpHeader('Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');<commit_msg>Test de l'existence du fichier template dans l'action<commit_after><?php

class subventionActions extends sfActions {

    public function executeIndex(sfWebRequest $request) {
      $this->operation_en_cours = SubventionConfiguration::getInstance()->getOperationEnCours();
      $this->subventions = SubventionClient::getInstance()->findByAllSortedByDate();
    }

    public function executeEtablissement(sfWebRequest $request) {
        $this->isTeledeclarationMode = $this->isTeledeclarationSubvention();
        $this->operation_en_cours = SubventionConfiguration::getInstance()->getOperationEnCours();
        $this->etablissement = $this->getRoute()->getEtablissement();
        $this->subvention_en_cours = SubventionClient::getInstance()->findByEtablissementAndOperation($this->etablissement->identifiant, $this->operation_en_cours);

    }

    public function executeEtablissementSelection(sfWebRequest $request) {

            $form = new SubventionEtablissementChoiceForm('INTERPRO-declaration');
            $form->bind($request->getParameter($form->getName()));
            if (!$form->isValid()) {

                return $this->redirect('subvention');
            }

            return $this->redirect('subvention_etablissement', $form->getEtablissement());
    }

    public function executeCreation(sfWebRequest $request) {
        $etablissement = $this->getRoute()->getEtablissement();

        $subvention = SubventionClient::getInstance()->createDoc($etablissement->identifiant, $request->getParameter('operation'));
        $subvention->save();

        return $this->redirect('subvention_infos', $subvention);
    }

    public function executeInfos(sfWebRequest $request) {
        $this->subvention = $this->getRoute()->getSubvention();

        $this->form = new SubventionsGenericForm($this->subvention,'infos');

        if (!$request->isMethod(sfWebRequest::POST)) {
            return sfView::SUCCESS;
        }
        $this->form->bind($request->getParameter($this->form->getName()));

      	if (!$this->form->isValid()) {
      		return sfView::SUCCESS;
      	}
        $this->form->save();

        $this->redirect('subvention_dossier', $this->subvention);

    }

    public function executeEngagements(sfWebRequest $request) {
        $this->subvention = $this->getRoute()->getSubvention();
        $this->form = new SubventionEngagementsForm($this->subvention);

        if (!$request->isMethod(sfWebRequest::POST)) {
            return sfView::SUCCESS;
        }

        $this->form->bind($request->getParameter($this->form->getName()));

        if (!$this->form->isValid()) {
            return sfView::SUCCESS;
        }

        $this->form->save();

        return $this->redirect($this->generateUrl('subvention_validation', $this->subvention));
    }

    public function executeValidation(sfWebRequest $request) {
        $this->subvention = $this->getRoute()->getSubvention();
        $this->form = new SubventionValidationForm($this->subvention);

        if (!$request->isMethod(sfWebRequest::POST)) {
            return sfView::SUCCESS;
        }

        $this->form->bind($request->getParameter($this->form->getName()));

        if (!$this->form->isValid()) {
            return sfView::SUCCESS;
        }

        $this->form->save();

        return $this->redirect($this->generateUrl('subvention_confirmation', $this->subvention));
    }

    public function executeConfirmation(sfWebRequest $request) {
        $this->subvention = $this->getRoute()->getSubvention();
    }

    public function executeVisualisation(sfWebRequest $request) {
        $this->subvention = $this->getRoute()->getSubvention();
        $this->isTeledeclarationMode = $this->isTeledeclarationSubvention();
        $this->formValidationInterpro = ($this->getUser()->hasCredential(myUser::CREDENTIAL_ADMIN))? new SubventionsGenericForm($this->subvention, 'approbations') : null;
        if (!$request->isMethod(sfWebRequest::POST) || !$this->formValidationInterpro) {

            return sfView::SUCCESS;
        }

        $this->formValidationInterpro->bind($request->getParameter($this->formValidationInterpro->getName()));

        if (!$this->formValidationInterpro->isValid()) {
            return sfView::SUCCESS;
        }

        $this->formValidationInterpro->save();
        $statut = $request->getParameter('statut',null);
        if($statut){
          $this->subvention->statut = $statut;
          $this->subvention->save();
        }

        return $this->redirect($this->generateUrl('subvention_visualisation', $this->subvention));
    }

    public function executeDossier(sfWebRequest $request) {

        $this->subvention = $this->getRoute()->getSubvention();
        $this->form = new SubventionDossierForm($this->subvention);

        if(!$this->subvention->hasXls() && !$this->subvention->hasDefaultXlsPath()){
          throw new sfException("Il n'existe pas de document pour cette opération : ".$this->subvention->operation);
        }

        if (!$request->isMethod(sfWebRequest::POST)) {
      		return sfView::SUCCESS;
      	}
      	$this->form->bind($request->getParameter($this->form->getName()), $request->getFiles($this->form->getName()));

      	if (!$this->form->isValid()) {
      		return sfView::SUCCESS;
      	}
        $this->form->save();

        $this->redirect('subvention_engagements', array('identifiant' => $this->subvention->identifiant,'operation' => $this->subvention->operation));

    }

    public function executeXls(sfWebRequest $request) {

      $this->subvention = $this->getRoute()->getSubvention();
      $this->setLayout(false);
      $path = $this->subvention->getXlsPath();
      $this->getResponse()->setHttpHeader('Content-disposition', 'attachment; filename="' . $this->subvention->getXlsPublicName() . '"');
      $this->getResponse()->setHttpHeader('Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
{'fraction_non_alphanumeric': 0.16340310600945307, 'fraction_numerical': 0.0, 'mean_word_length': 3.4916603487490523, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 317, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6747332', 'n_tokens_mistral': 3327, 'n_tokens_neox': 3257, 'n_words': 428}