<commit_before><?php

class Etablissement extends BaseEtablissement {

    protected $_interpro = null;
    protected $droit = null;

    const STATUT_ACTIF = "ACTIF";
    const STATUT_ARCHIVE = "ARCHIVE";
    const STATUT_DELIE = "DELIE";
    const STATUT_CSV = "CSV";

    /**
     * @return _Compte
     */
    public function getInterproObject() {
        if (is_null($this->_interpro)) {
            $this->_interpro = InterproClient::getInstance()->find($this->interpro);
        }

        return $this->_interpro;
    }

    public function constructId() {
        $this->set('_id', 'ETABLISSEMENT-' . $this->identifiant);
    }

    public function getAllDRM() {
        return acCouchdbManager::getClient()->startkey(array($this->identifiant, null))
                        ->endkey(array($this->identifiant, null))
                        ->getView("drm", "all");
    }

    private function cleanPhone($phone, $idcompte) {
        $phone = preg_replace('/[^0-9\+]+/', '', $phone);
        $phone = preg_replace('/^00/', '+', $phone);
        $phone = preg_replace('/^0/', '+33', $phone);

        if (strlen($phone) == 9 && preg_match('/^[64]/', $phone))
            $phone = '+33' . $phone;

        if (!preg_match('/^\+/', $phone) || (strlen($phone) != 12 && preg_match('/^\+33/', $phone)))
            echo("$phone n'est pas un téléphone correct pour " . $this->_id . "\n");

        return $phone;
    }

    public function getContact() {
        if ($this->compte)
            return CompteClient::getInstance()->find($this->compte);
        return CompteClient::getInstance()->find($this->getSociete()->compte_societe);
    }

    public function getSociete() {
      return SocieteClient::getInstance()->find($this->id_societe);
    }

    public function contactIsSocieteContact() {
        return is_null($this->compte);
    }

    public function setFax($fax) {
        if ($fax)
            $this->_set('fax', $this->cleanPhone($fax));
    }

    public function setTelephone($phone, $idcompte = null) {
        if ($phone)
            $this->_set('telephone', $this->cleanPhone($phone));
    }

    public function getDenomination() {

        return ($this->nom) ? $this->nom : $this->raison_sociale;
    }

    public function addLiaison($type, $etablissement) {
      if (!in_array($type, EtablissementClient::listTypeLiaisons()))
	throw new sfException("liaison type \"$type\" unknown");
      $liaison = $this->liaisons_operateurs->add($type.'_'.$etablissement->_id);
      $liaison->type_liaison = $type;
      $liaison->id_etablissement = $etablissement->_id;
      $liaison->libelle_etablissement = $etablissement->nom;
    }

    public function getFamilleType() {
        $familleType = array(EtablissementFamilles::FAMILLE_PRODUCTEUR => 'vendeur',
            EtablissementFamilles::FAMILLE_NEGOCIANT => 'acheteur',
            EtablissementFamilles::FAMILLE_COURTIER => 'mandataire');
        return $familleType[$this->famille];
    }

    public function getDepartement() {
        if ($this->siege->code_postal) {
            return substr($this->siege->code_postal, 0, 2);
        }
        return null;
    }

    public function getDroit() {
        if (is_null($this->droit)) {

            $this->droit = new EtablissementDroit($this);
        }

        return $this->droit;
    }

    public function hasDroit($droit) {

        return $this->getDroit()->has($droit);
    }

    public function getDroits() {<commit_msg>Ajout de isNegociant()<commit_after><?php

class Etablissement extends BaseEtablissement {

    protected $_interpro = null;
    protected $droit = null;

    const STATUT_ACTIF = "ACTIF";
    const STATUT_ARCHIVE = "ARCHIVE";
    const STATUT_DELIE = "DELIE";
    const STATUT_CSV = "CSV";

    /**
     * @return _Compte
     */
    public function getInterproObject() {
        if (is_null($this->_interpro)) {
            $this->_interpro = InterproClient::getInstance()->find($this->interpro);
        }

        return $this->_interpro;
    }

    public function constructId() {
        $this->set('_id', 'ETABLISSEMENT-' . $this->identifiant);
    }

    public function getAllDRM() {
        return acCouchdbManager::getClient()->startkey(array($this->identifiant, null))
                        ->endkey(array($this->identifiant, null))
                        ->getView("drm", "all");
    }

    private function cleanPhone($phone, $idcompte) {
        $phone = preg_replace('/[^0-9\+]+/', '', $phone);
        $phone = preg_replace('/^00/', '+', $phone);
        $phone = preg_replace('/^0/', '+33', $phone);

        if (strlen($phone) == 9 && preg_match('/^[64]/', $phone))
            $phone = '+33' . $phone;

        if (!preg_match('/^\+/', $phone) || (strlen($phone) != 12 && preg_match('/^\+33/', $phone)))
            echo("$phone n'est pas un téléphone correct pour " . $this->_id . "\n");

        return $phone;
    }

    public function getContact() {
        if ($this->compte)
            return CompteClient::getInstance()->find($this->compte);
        return CompteClient::getInstance()->find($this->getSociete()->compte_societe);
    }

    public function getSociete() {
      return SocieteClient::getInstance()->find($this->id_societe);
    }

    public function contactIsSocieteContact() {
        return is_null($this->compte);
    }

    public function setFax($fax) {
        if ($fax)
            $this->_set('fax', $this->cleanPhone($fax));
    }

    public function setTelephone($phone, $idcompte = null) {
        if ($phone)
            $this->_set('telephone', $this->cleanPhone($phone));
    }

    public function getDenomination() {

        return ($this->nom) ? $this->nom : $this->raison_sociale;
    }

    public function addLiaison($type, $etablissement) {
      if (!in_array($type, EtablissementClient::listTypeLiaisons()))
	throw new sfException("liaison type \"$type\" unknown");
      $liaison = $this->liaisons_operateurs->add($type.'_'.$etablissement->_id);
      $liaison->type_liaison = $type;
      $liaison->id_etablissement = $etablissement->_id;
      $liaison->libelle_etablissement = $etablissement->nom;
    }

    public function isNegociant() {
      return ($this->famille == EtablissementFamilles::FAMILLE_NEGOCIANT);
    }

    public function getFamilleType() {
        $familleType = array(EtablissementFamilles::FAMILLE_PRODUCTEUR => 'vendeur',
            EtablissementFamilles::FAMILLE_NEGOCIANT => 'acheteur',
            EtablissementFamilles::FAMILLE_COURTIER => 'mandataire');
        return $familleType[$this->famille];
    }

    public function getDepartement() {
        if ($this->siege->code_postal) {
            return substr($this->siege->code_postal, 0, 2);
        }
        return null;
    }

    public function getDroit() {
        if (is_null($this->droit)) {

            $this->droit = new EtablissementDroit($this);
        }

        return $this->droit;
    }

    public function hasDroit($droit) {

        return $this->getDroit()->has($droit);
    }

    public function getDroits() {
{'fraction_non_alphanumeric': 0.16338666289112275, 'fraction_numerical': 0.005096984284298457, 'mean_word_length': 2.6791666666666667, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 104, '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': '2132920', 'n_tokens_mistral': 2337, 'n_tokens_neox': 2244, 'n_words': 396}