<commit_before><?php

class compteActions extends sfCredentialActions {

    public function executeAjout(sfWebRequest $request) {
        $this->societe = $this->getRoute()->getSociete();
        $this->compte = CompteClient::getInstance()->createCompteInterlocuteurFromSociete($this->societe);
        $this->applyRights();
        if(!$this->modification && !$this->reduct_rights){

          return $this->forward('acVinCompte','forbidden');
        }
        $this->processFormCompte($request);
        $this->setTemplate('modification');
    }

    public function executeModification(sfWebRequest $request) {
        $this->compte = $this->getRoute()->getCompte();
        $this->societe = $this->compte->getSociete();
        $this->applyRights();
        if(!$this->modification && !$this->reduct_rights){

          return $this->forward('acVinCompte','forbidden');
        }
        $this->processFormCompte($request);
    }

    protected function processFormCompte(sfWebRequest $request) {
        $this->compteForm = new InterlocuteurForm($this->compte);
        if (!$request->isMethod(sfWebRequest::POST)) {
          return;
        }

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

        if (!$this->compteForm->isValid()) {
          return;
        }

        $this->compteForm->save();
        return $this->redirect('compte_visualisation', $this->compte);
    }

    public function executeModificationCoordonnee(sfWebRequest $request) {
        $this->compte = $this->getRoute()->getCompte();
        $this->societe = $this->compte->getSociete();
        $this->compteForm = new CompteCoordonneeForm($this->compte);
        if ($request->isMethod(sfWebRequest::POST)) {
            $this->compteForm->bind($request->getParameter($this->compteForm->getName()));
            if ($this->compteForm->isValid()) {
                if($this->compte->isNew()){
                    $this->compte->setStatut(EtablissementClient::STATUT_ACTIF);
                }
                $this->compteForm->save();
                $this->redirect('compte_visualisation', $this->compte);
            }
        }
    }

    public function executeVisualisation(sfWebRequest $request) {
        if(!SocieteConfiguration::getInstance()->isVisualisationTeledeclaration() && !$this->getUser()->hasCredential(myUser::CREDENTIAL_CONTACT)) {
            return $this->forwardSecure();
        }

        $this->compte = $this->getRoute()->getCompte();
        $this->societe = $this->compte->getSociete();
        $this->formAjoutGroupe = new CompteGroupeAjoutForm('INTERPRO-declaration');
        $this->applyRights();
        if(!$this->compte->lat && !$this->compte->lon){
          $this->compte->updateCoordonneesLongLat();
          $this->compte->save();
        }
        if($this->compte->isEtablissementContact()) {
            return $this->redirect('etablissement_visualisation', $this->compte->getEtablissement());
        }
        if($this->compte->isSocieteContact()) {
            return $this->redirect('societe_visualisation',array('identifiant' => $this->societe->identifiant));
        }
        $this->modifiable = $this->getUser()->hasCredential('contacts');
    }

    public function executeSwitchStatus(sfWebRequest $request) {
        $this->compte = $this->getRoute()->getCompte();
        $newStatus = "";
        if($this->compte->isActif()){
           $newStatus = CompteClient::STATUT_SUSPENDU;
        }
        if($this->compte->isSuspendu()){<commit_msg>Utilisation de l'exception 403 plutot que la redirection<commit_after><?php

class compteActions extends sfCredentialActions {

    public function executeAjout(sfWebRequest $request) {
        $this->societe = $this->getRoute()->getSociete();
        $this->compte = CompteClient::getInstance()->createCompteInterlocuteurFromSociete($this->societe);
        $this->applyRights();
        if(!$this->modification && !$this->reduct_rights){

          return $this->forward('acVinCompte','forbidden');
        }
        $this->processFormCompte($request);
        $this->setTemplate('modification');
    }

    public function executeModification(sfWebRequest $request) {
        $this->compte = $this->getRoute()->getCompte();
        $this->societe = $this->compte->getSociete();
        $this->applyRights();
        if(!$this->modification && !$this->reduct_rights){

          return $this->forward('acVinCompte','forbidden');
        }
        $this->processFormCompte($request);
    }

    protected function processFormCompte(sfWebRequest $request) {
        $this->compteForm = new InterlocuteurForm($this->compte);
        if (!$request->isMethod(sfWebRequest::POST)) {
          return;
        }

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

        if (!$this->compteForm->isValid()) {
          return;
        }

        $this->compteForm->save();
        return $this->redirect('compte_visualisation', $this->compte);
    }

    public function executeModificationCoordonnee(sfWebRequest $request) {
        $this->compte = $this->getRoute()->getCompte();
        $this->societe = $this->compte->getSociete();
        $this->compteForm = new CompteCoordonneeForm($this->compte);
        if ($request->isMethod(sfWebRequest::POST)) {
            $this->compteForm->bind($request->getParameter($this->compteForm->getName()));
            if ($this->compteForm->isValid()) {
                if($this->compte->isNew()){
                    $this->compte->setStatut(EtablissementClient::STATUT_ACTIF);
                }
                $this->compteForm->save();
                $this->redirect('compte_visualisation', $this->compte);
            }
        }
    }

    public function executeVisualisation(sfWebRequest $request) {
        if(!SocieteConfiguration::getInstance()->isVisualisationTeledeclaration() && !$this->getUser()->hasCredential(myUser::CREDENTIAL_CONTACT)) {

            throw new sfError403Exception();
        }

        $this->compte = $this->getRoute()->getCompte();
        $this->societe = $this->compte->getSociete();
        $this->formAjoutGroupe = new CompteGroupeAjoutForm('INTERPRO-declaration');
        $this->applyRights();
        if(!$this->compte->lat && !$this->compte->lon){
          $this->compte->updateCoordonneesLongLat();
          $this->compte->save();
        }
        if($this->compte->isEtablissementContact()) {
            return $this->redirect('etablissement_visualisation', $this->compte->getEtablissement());
        }
        if($this->compte->isSocieteContact()) {
            return $this->redirect('societe_visualisation',array('identifiant' => $this->societe->identifiant));
        }
        $this->modifiable = $this->getUser()->hasCredential('contacts');
    }

    public function executeSwitchStatus(sfWebRequest $request) {
        $this->compte = $this->getRoute()->getCompte();
        $newStatus = "";
        if($this->compte->isActif()){
           $newStatus = CompteClient::STATUT_SUSPENDU;
        }
        if($this->compte->isSuspendu()){
{'fraction_non_alphanumeric': 0.16816901408450705, 'fraction_numerical': 0.0008450704225352113, 'mean_word_length': 2.912396694214876, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 206, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '3405078', 'n_tokens_mistral': 2155, 'n_tokens_neox': 2101, 'n_words': 235}