<commit_before><?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of CompteDegustateurModificationForm
 *
 * @author mathurin
 */
class CompteDegustateurModificationForm extends CompteModificationForm {

    protected $produits;
        private $syndicats;

    public function __construct(\acCouchdbJson $object, $options = array(), $CSRFSecret = null) {
        parent::__construct($object, $options, $CSRFSecret);
        $this->initDefaultProduits();
        $this->initDefaultSyndicats();
    }

    public function configure() {
        parent::configure();
        $this->setWidget("civilite", new sfWidgetFormChoice(array('choices' => $this->getCivilites())));
        $this->setWidget("prenom", new sfWidgetFormInput(array("label" => "Prénom")));
        $this->setWidget("nom", new sfWidgetFormInput(array("label" => "Nom")));

        $this->setWidget("raison_sociale", new sfWidgetFormInput(array("label" => "Société")));

        $this->setValidator('civilite', new sfValidatorChoice(array('required' => true, 'choices' => array_keys($this->getCivilites())), array('required' => "Aucune civilité choisie.")));
        $this->setValidator('prenom', new sfValidatorString(array("required" => false)));
        $this->setValidator('nom', new sfValidatorString(array("required" => false)));

        $this->setValidator('raison_sociale', new sfValidatorString(array("required" => false)));
        
        $this->setWidget("produits", new sfWidgetFormChoice(array('multiple' => true, 'choices' => $this->getAllProduits())));
        $this->setValidator('produits', new sfValidatorChoice(array('required' => false, 'multiple' => true, 'choices' => array_keys($this->getAllProduits()))));
    
         $this->setWidget("syndicats", new sfWidgetFormChoice(array('multiple' => true, 'choices' => $this->getSyndicats())));
        $this->setValidator('syndicats', new sfValidatorChoice(array("required" => false, 'multiple' => true, 'choices' => array_keys($this->getSyndicats()))));

        
    }

    private function getSyndicats() {
        $compteClient = CompteClient::getInstance();
        if (!$this->syndicats) {
            foreach ($compteClient->getAllSyndicats() as $syndicatId) {      
                $syndicat = CompteClient::getInstance()->find($syndicatId);
            $this->syndicats[$syndicatId] = $syndicat->nom_a_afficher;
            }
        }
        return $this->syndicats;
    }
    
    private function getAllProduits() {
        if (!$this->produits) {
            foreach (ConfigurationClient::getConfiguration()->getProduits() as $hash => $produitCepage) {
                $this->produits[str_replace('/', '-', $hash)] = $produitCepage->getLibelleComplet();
            }
        }
        return $this->produits;
    }

    public function save($con = null) {
        if ($produits = $this->values['produits']) {
            $this->getObject()->updateLocalTagsProduits($produits);
        }
        if ($syndicats = $this->values['syndicats']) {
            $this->getObject()->updateLocalSyndicats($syndicats);<commit_msg>Désactivation des produits pour les dégustateurs<commit_after><?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of CompteDegustateurModificationForm
 *
 * @author mathurin
 */
class CompteDegustateurModificationForm extends CompteModificationForm {

    protected $produits;
        private $syndicats;

    public function __construct(\acCouchdbJson $object, $options = array(), $CSRFSecret = null) {
        parent::__construct($object, $options, $CSRFSecret);
        $this->initDefaultProduits();
        $this->initDefaultSyndicats();
    }

    public function configure() {
        parent::configure();
        $this->setWidget("civilite", new sfWidgetFormChoice(array('choices' => $this->getCivilites())));
        $this->setWidget("prenom", new sfWidgetFormInput(array("label" => "Prénom")));
        $this->setWidget("nom", new sfWidgetFormInput(array("label" => "Nom")));

        $this->setWidget("raison_sociale", new sfWidgetFormInput(array("label" => "Société")));

        $this->setValidator('civilite', new sfValidatorChoice(array('required' => true, 'choices' => array_keys($this->getCivilites())), array('required' => "Aucune civilité choisie.")));
        $this->setValidator('prenom', new sfValidatorString(array("required" => false)));
        $this->setValidator('nom', new sfValidatorString(array("required" => false)));

        $this->setValidator('raison_sociale', new sfValidatorString(array("required" => false)));
        
        /*$this->setWidget("produits", new sfWidgetFormChoice(array('multiple' => true, 'choices' => $this->getAllProduits())));
        $this->setValidator('produits', new sfValidatorChoice(array('required' => false, 'multiple' => true, 'choices' => array_keys($this->getAllProduits()))));*/
    
        $this->setWidget("syndicats", new sfWidgetFormChoice(array('multiple' => true, 'choices' => $this->getSyndicats())));
        $this->setValidator('syndicats', new sfValidatorChoice(array("required" => false, 'multiple' => true, 'choices' => array_keys($this->getSyndicats()))));

        
    }

    private function getSyndicats() {
        $compteClient = CompteClient::getInstance();
        if (!$this->syndicats) {
            foreach ($compteClient->getAllSyndicats() as $syndicatId) {      
                $syndicat = CompteClient::getInstance()->find($syndicatId);
            $this->syndicats[$syndicatId] = $syndicat->nom_a_afficher;
            }
        }
        return $this->syndicats;
    }
    
    private function getAllProduits() {
        if (!$this->produits) {
            foreach (ConfigurationClient::getConfiguration()->getProduits() as $hash => $produitCepage) {
                $this->produits[str_replace('/', '-', $hash)] = $produitCepage->getLibelleComplet();
            }
        }
        return $this->produits;
    }

    public function save($con = null) {
        if ($produits = $this->values['produits']) {
            $this->getObject()->updateLocalTagsProduits($produits);
        }
        if ($syndicats = $this->values['syndicats']) {
            $this->getObject()->updateLocalSyndicats($syndicats);
{'fraction_non_alphanumeric': 0.16374269005847952, 'fraction_numerical': 0.0, 'mean_word_length': 3.6059532246633594, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 119, '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': '6723891', 'n_tokens_mistral': 1919, 'n_tokens_neox': 1909, 'n_words': 338}