vendor/theatre/core/src/Repository/ContactsRepository.php line 1442

Open in your IDE?
  1. <?php
  2. namespace TheatreCore\Repository;
  3. use Symfony\Contracts\Translation\TranslatorInterface;
  4. use TheatreCore\Classes\Images\Images;
  5. use TheatreCore\Entity\Bigregions;
  6. use TheatreCore\Entity\ContactAide;
  7. use TheatreCore\Entity\Contacts;
  8. use TheatreCore\Entity\Spectacles;
  9. use TheatreCore\Traits\TheatreTrait;
  10. use TheatreCore\Entity\Directories;
  11. use TheatreCore\Entity\Extranetusers;
  12. use TheatreCore\Entity\Files;
  13. use TheatreCore\Entity\Typesstructures;
  14. use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
  15. use Doctrine\Persistence\ManagerRegistry;
  16. use Doctrine\ORM\Query;
  17. use Theatre_Extranetusers;
  18. use DateTime;
  19. /**
  20.  * ContactsRepository
  21.  *
  22.  * This class was generated by the Doctrine ORM. Add your own custom
  23.  * repository methods below.
  24.  */
  25. class ContactsRepository extends ServiceEntityRepository
  26. {
  27.     use TheatreTrait {
  28.         getRelationsArray as protected getRelationsArrayTrait;
  29.     }
  30.     private $em;
  31.     public $__table;
  32.     public $__table_object;
  33.     public $__idtable;
  34.     public function __construct(ManagerRegistry $registryTranslatorInterface $translatorImages $images)
  35.     {
  36.         parent::__construct($registryContacts::class);
  37.         $this->__table $this->getClassMetadata()->getTableName();
  38.         $this->__table_object $this->getClassMetadata()->name;
  39.         $this->__idtable $this->getClassMetadata()->getSingleIdentifierFieldName();
  40.         $this->translator $translator;
  41.         $this->images $images;
  42.     }
  43.     //  {{{ findData()
  44.     /** Recherche des contacts
  45.      *
  46.      * Permet de rechercher des contacts en fonction de certains critères :
  47.      * la première lettre, un bout du nom, le type de contact, si il est en ligne ou pas
  48.      *
  49.      * @access  public
  50.      * @see     Theatre::find()
  51.      */
  52.     public function findData($lettre null$idtypestructure null$publish null$keywords null)
  53.     {
  54.         // requete perso
  55.         $query null;
  56.         $query $this->createQueryBuilder('c');
  57.         // parametre
  58.         if (!empty($_REQUEST['idcontact']) && my_is_int($_REQUEST['idcontact'])) {
  59.             $idcontact = (int)$_REQUEST['idcontact'];
  60.         }
  61.         if (isset($_REQUEST['lettre']) && !empty($_REQUEST['lettre'])) {
  62.             $lettre filter_var($_REQUEST['lettre']);
  63.         }
  64.         if (isset($_REQUEST['keywords']) && $_REQUEST['keywords'] != 'nom') {
  65.             $keywords filter_var(trim($_REQUEST['keywords']), FILTER_SANITIZE_STRINGFILTER_FLAG_NO_ENCODE_QUOTES);
  66.             if ($this->my_is_int($keywords)) {
  67.                 $idcontact = (int)$keywords;
  68.                 $keywords null;
  69.             }
  70.         }
  71.         if (!empty($_REQUEST['idtypestructure']) && strlen($_REQUEST['idtypestructure']) < 5) {
  72.             $idtypestructure $_REQUEST['idtypestructure'];
  73.         }
  74.         if (isset($_REQUEST['publish']) && !empty($_REQUEST['publish'])) {
  75.             $publish filter_var($_REQUEST['publish']);
  76.         }
  77.         if (isset($_REQUEST['city']) && $_REQUEST['city'] != 'ville' && !empty($_REQUEST['city'])) {
  78.             $city filter_var(trim($_REQUEST['city']));
  79.         }
  80.         if (isset($_REQUEST['is_ecole'])) {
  81.             $is_ecole true;
  82.         }
  83. //
  84. //        // on précise les champs pour le SELECT
  85. //        $query = 'SELECT c.idcontact,c.type,c.lastname,c.firstname,c.organisation,c.email1,c.country,c.city,c.publish,c.valid,c.dateupdate
  86. //                  FROM contacts c WHERE 1 ';
  87. //
  88.         //recherche stricte par id
  89.         if (!empty($idcontact)) {
  90.             $query->andWhere('c.idcontact=' . ((int)$idcontact));
  91.         }
  92. //        // premiere lettre
  93.         if (!empty($lettre)) {
  94.             $query->andWhere('(c.lastname REGEXP \'^' $this->escape($lettre) . '\' OR c.organisation REGEXP \'^' $this->escape($lettre) . '\') ');
  95.         }
  96.         // mots cles
  97.         if (!empty($keywords)) {
  98.             $query->andWhere('(c.lastname LIKE \'%' $this->escape($keywords) . '%\' OR c.organisation LIKE \'%' $this->escape($keywords) . '%\') ');
  99.         }
  100.         // selectionne par type de structure
  101.         if (!empty($idtypestructure)) {
  102.             $query->andWhere('c.idtypestructure=\'' $this->escape($idtypestructure) . '\' ');
  103.         }
  104.         // selectionne les fiches hors ligne
  105.         if (!empty($publish) && $publish == 'no') {
  106.             $publish 0;
  107.             $query->andWhere('c.publish=' . ((int)$publish));
  108.         }
  109.         // ville
  110.         if (!empty($city)) {
  111.             $query->andWhere('c.city LIKE \'%' $this->escape($city) . '%\'');
  112.         }
  113. //        // ecoles
  114.         if (!empty($is_ecole)) {
  115.             $conn $this->getEntityManager()->getConnection();
  116.             $queryIN $conn->executeQuery('SELECT idcontact FROM person_ecole')->fetchAll(\PDO::FETCH_COLUMN | \PDO::FETCH_ASSOC);
  117.             $query->andWhere(' c.idcontact IN (' implode(','$queryIN) . ') ');
  118.         }
  119. //
  120. //        if(isset($_REQUEST['idaide']) && my_is_int($_REQUEST['idaide'])) {
  121. //            $query .= ' AND c.`idcontact` IN (
  122. //                SELECT idcontact FROM contact_aide
  123. //                WHERE idaide='.(int)$_REQUEST['idaide'].'
  124. //            ) ';
  125. //        }
  126. //
  127. //        // que les contacts publiés ou non et pas les anciens/supprimés
  128. //        $query .= ' AND c.publish<2';
  129.         if ($this->getCount()) {
  130.             $query->select('COUNT(c.idcontact)');
  131.             $this->setCount(false);
  132.             return $query;
  133.         }
  134.         // on lance la recherche
  135.         return $query->getQuery();
  136.     }
  137.     //  }}}
  138.     //  {{{ setToArray()
  139.     /** liste des structures partenaires => CDN, classification 113
  140.      *
  141.      * @access  public
  142.      * @return  array
  143.      */
  144.     public function getStructuresPartenaires($idtypestructure null$prospection null)
  145.     {
  146.         $conn $this->getEntityManager()->getConnection();
  147.         $sql 'SELECT *, c.`idcontact` as idcontact FROM  contacts c
  148.         LEFT JOIN contact_classification cc ON cc.`idcontact`=c.`idcontact`
  149.         WHERE 1 ';
  150.         if (is_null($idtypestructure) && !empty($idtypestructure)) {
  151.             $sql .= ' AND c.`idtypestructure`=\'' filter_var($idtypestructureFILTER_SANITIZE_STRING) . '\' ';
  152.         } else {
  153.             //$sql .= ' AND c.`idtypestructure` IN (\'CDN\') OR cc.`idclassification`=113 ';
  154.             $sql .= ' AND cc.`idclassification`=113 ';
  155.         }
  156.         // voir les partenaires en cours de prospection
  157.         if (!is_null($prospection)) {
  158.             $sql 'SELECT *, c.`idcontact` as idcontact FROM  contacts c
  159.         LEFT JOIN contact_classification cc ON cc.`idcontact`=c.`idcontact`
  160.         WHERE 1 ';
  161.             $sql .= ' AND c.`idtypestructure` IN (\'CDN\') AND c.`idcontact` NOT IN (
  162.                         SELECT idcontact FROM contact_classification WHERE idclassification=113
  163.                     ) OR cc.`idclassification`=124 ';
  164.         }
  165.         $sql .= 'GROUP BY c.`idcontact` ';
  166.         $stmt $conn->prepare($sql);
  167.         $stmt->execute();
  168.         return $stmt->fetchAll();
  169.     }
  170.     //  {{{ setToArray()
  171.     /** Liste des contacts dans un tableau associatif
  172.      *
  173.      * Tableau associatif notament utilisé pour lister les informations sur des contacts
  174.      * Utile pour générer les tableaux HTML de listes de contacts
  175.      *
  176.      * @access  public
  177.      * @return  array
  178.      * @see     findData()
  179.      */
  180.     public function setToArray($spec true)
  181.     {
  182.         if ($spec == true) {
  183.             $this->findData();
  184.         }
  185.         $values = array();
  186.         $color null;
  187.         $nb 0;
  188.         while ($this->fetch()) {
  189.             $values[$nb] = $this->getInfosContact(null, array('get_extranetusers' => true));
  190.             $values[$nb]['id'] = $this->idcontact;
  191.             // couleur de ligne alternative
  192.             $color $this->colorAlternate($color);
  193.             $values[$nb]['colorline'] = $color;
  194.             $nb++;
  195.         }
  196.         return $values;
  197.     }
  198.     // }}}
  199.     //  {{{ getInfosContact()-
  200.     /** Informations sur un contact
  201.      *
  202.      * @access public
  203.      * @param int $idcontact Identifiant du contact
  204.      * @return array
  205.      */
  206.     public function getInfosContact($idcontact null$params = array())
  207.     {
  208.         $infos = array();
  209.         $con $this->getEntityManager();
  210.         ////////////// infos de la table
  211.         if (empty($this->idcontact) || $idcontact != $this->idcontact) {
  212.             if (!empty($params['get_idtypestructure_TODO'])) {
  213.                 $sql 'SELECT *
  214.                         FROM ' $this->__table ', typesstructures
  215.                         WHERE typesstructures.idtypestructure=' $this->__table '.idtypestructure
  216.                         AND ';
  217.                 if (!my_is_int($idcontact)) {
  218.                     $sql .= $this->__table '.url_clean=' $this->escape($idcontact);
  219.                 } else {
  220.                     $sql .= $this->__table '.' $this->__idtable '=' . (int)$idcontact;
  221.                 }
  222.                 //$this->queryRow($sql, null, MDB2_FETCHMODE_OBJECT);
  223.             } else {
  224.                 $query $this->createQueryBuilder('u')
  225.                     ->select('u, cc')
  226.                     ->leftJoin('u.country''cc');
  227.                 if (!$this->my_is_int($idcontact)) {
  228.                     $query->where('u.urlClean = :value')->setParameter('value'$idcontact['urlClean']);
  229.                 } else {
  230.                     $query->where('u.' $this->__idtable ' =:value')->setParameter('value'$idcontact);
  231.                 }
  232.                 $infos $query->getQuery()->getOneOrNullResult(Query::HYDRATE_ARRAY);
  233.                 $this->loadResult($infos);
  234.             }
  235.         }
  236.         if (empty($infos['organisation']) && empty($infos['lastname']) && !isset($this->idcontact)) {
  237.             return array();
  238.         }
  239.         $infos += array(
  240.             'idcontact' => $this->idcontact,
  241.             'idtypestructure' => $this->idtypestructure,
  242.             'link_on_video' => $this->linkOnVideo,
  243.             'city' => $this->city,
  244.             'nom_suite' => $this->nomSuite,
  245.             'email' => $this->email1,
  246.             'phone1' => $this->phone1,
  247.             'url' => $this->url,
  248.             'type_view' => $this->typeView,
  249.             'stats_access' => $this->statsAccess,
  250.             'is_festival' => $this->isFestival,
  251.             'is_partenaire' => $this->isPartenaire,
  252.             'valid' => $this->valid,
  253.             'publish' => $this->publish,
  254.             'dateupdate' => $this->dateupdate,
  255.             'url_clean' => $this->urlClean,
  256.             'address1' => $this->address1,
  257.             'idmultimedia' => $this->idmultimedia,
  258.             'zip' => $this->zip,
  259.         );
  260.         if (!empty($this->country['id'])) {
  261.             $infos['country'] = $this->getNameCountry($this->country['id']);
  262.             $infos['country_code'] = $this->country['id'];
  263.         }
  264.         // affichage de l'organisation et/ou du nom
  265.         $infos_object = array(
  266.             'lastname' => $this->lastname,
  267.             'firstname' => $this->firstname,
  268.             'organisation' => $this->organisation,
  269.             'title' => $this->organisation,
  270.             'fullname' => $this->organisation,
  271.             'type' => $this->type,
  272.         );
  273.         $infos += $infos_object;
  274.         // type de structure
  275.         if (array_key_exists('get_idtypestructure'$params) && !empty($infos['idtypestructure'])) {
  276.             $typesstructures $con->getRepository(Typesstructures::class);
  277.             $infos['typestructure'] = $typesstructures->getInfosTypeStructure($infos['idtypestructure']);
  278.             $infos['typestructure_string'] = $infos['typestructure'];
  279.         }
  280.         // retrouver les comptes mon théâtre associés
  281.         if (array_key_exists('get_extranetusers'$params)) {
  282.             $infos['extranetusers'] = $con->getRepository(Extranetusers::class)->getObjectExtranetusers('contact'$infos['idcontact']);
  283.             $infos['nb_extranetusers'] = count($infos['extranetusers']);
  284.         }
  285.         // retrouver les fiches annuaires associées
  286.         if (array_key_exists('get_directories'$params)) {
  287.             $infos['directories'] = $con->getRepository(Directories::class)->getDirectoriesByObject('contact'$infos['idcontact']);
  288.             $infos['nb_directories'] = count($infos['directories']);
  289.         }
  290.         // tester si il y a un bandeau custom
  291.         if (array_key_exists('get_bandeau'$params)) {
  292.             $files $con->getRepository(Files::class);
  293.             $files->setPublishStatus(1);
  294.             if (!empty($params['get_bandeau'])) {
  295.                 $bandeau $files->getObjectFiles($infos['idcontact'], 'contacts'100);
  296.                 $infos['bandeau'] = URL_DIRECTORYUPLOAD $this->getThumbnail($bandeau[0]['file'], $params['get_bandeau']['size'], $params['get_bandeau']['direction']);
  297.             } else {
  298.                 $bandeau $files->getObjectFiles($infos['idcontact'], 'contacts'100);
  299.                 $infos['bandeau'] = $bandeau[0]['file'];
  300.             }
  301.         }
  302.         // retrouver les personnes associées
  303.         if (array_key_exists('get_persons'$params)) {
  304.             $infos['persons'] = $this->getAssociatePersons($infos['idcontact']);
  305.             $infos['nb_persons'] = count($infos['persons']);
  306.         }
  307.         // retrouver les personnes associées
  308.         if (array_key_exists('get_boss'$params)) {
  309.             $infos['boss_all'] = $this->getCurrentBoss($infos['idcontact'], true);
  310.             if (!empty($infos['boss_all'])) {
  311.                 foreach ($infos['boss_all'] as $k => $v) {
  312.                     $infos['boss'] = $v;
  313.                     break;
  314.                 }
  315.             }
  316.         }
  317.         // retrouver le logo/avatar
  318.         if (array_key_exists('get_profile_picture'$params)) {
  319.             $infos['profile_picture'] = $this->getVignetteContact($infos['idcontact'], array(), 'class_pp');
  320.             if (strpos($infos['profile_picture'], 'normal-def.jpg') !== false) {
  321.                 $infos['profile_picture'] = $_ENV['URL_THNET'] . '/images/menu/interface/no_contact-100x100.png';
  322.             }
  323.         }
  324.         // voir si il y a des aides
  325.         if (!empty($params['get_aides'])) {
  326.             $infos['nb_aides'] = $this->getEntityManager()->getRepository(ContactAide::class)->countAides(null$infos['idcontact']);
  327.             if ($infos['nb_aides'] > 0) {
  328.                 $infos['aides'] = $this->getEntityManager()->getRepository(Contacts::class)->getListContactAide(array(
  329.                     'idcontact' => array($infos['idcontact']),
  330.                     'get_contacts_with_aides' => true,
  331.                     'dbg' => array('liste_aides''Liste des aides de la structure')
  332.                 ));
  333.                 $infos['nb_aides'] = count($infos['aides']);
  334.             }
  335.         }
  336.         $infos['nameview'] = $this->getObjectTitle($this->idcontact$infos_object);
  337.         return $infos;
  338.     }
  339.     // }}}
  340.     // {{{ orderByDefaut()
  341.     /** Classement par défaut
  342.      *
  343.      * Défini le tri par défaut pour les requêtes de type SELECT
  344.      *
  345.      * @access public
  346.      * @return string
  347.      */
  348.     public function orderByDefaut($order null)
  349.     {
  350.         // tri par défaut
  351.         if (empty($order)) {
  352.             $order 'organisation';
  353.         }
  354.         return $order;
  355.     }
  356.     // }}}
  357.     //  {{{ getListSearch()
  358.     /** Liste de contacts
  359.      *
  360.      * Pour les champs Ajax de relations et les recherches diverses
  361.      *
  362.      * @access  public
  363.      * @param string $lettres Pour la recherche alphabetique
  364.      * @param string $type Pour le type recherche (editeurs, revues...)
  365.      * @param string $keywords Recherche par mots cles
  366.      * @return  array
  367.      */
  368.     public function getListSearch($lettre null$type null$keywords null$only null$strict false)
  369.     {
  370.         $sql 'SELECT `idcontact`, `type`, `organisation`, `firstname`, `lastname`, `city`
  371.                 FROM ' $this->__table '
  372.                 WHERE ';
  373.         // selection par ordre alpha
  374.         if (!empty($lettre)) {
  375.             $sql_where[] = 'LOWER(LEFT(LTRIM(organisation),1))=\'' $this->escape($lettre) . '\'';
  376.         }
  377.         // recherche avec un mot cle
  378.         if (!empty($keywords) && $strict) {
  379.             $sql_where[] = '`organisation` LIKE \'%' $keywords '%\'';
  380.         } else {
  381.             $list $this->splitKeywords($keywords);
  382.             if ($list) {
  383.                 // recherche avec les mots clés
  384.                 if (!empty($list[$this->IDSTR])) {
  385.                     //$sql_where[]  = '`organisation` LIKE \''.$this->escape('%'.$keywords.'%').'\'';
  386.                     foreach ($list[$this->IDSTR] as $s) {
  387.                         // si on veut supprimer les pronoms et autres trucs du genre
  388.                         //if(strlen($s)>3) {
  389.                         $sql_more_name[] = '`organisation` LIKE \'%' $s '%\'';
  390.                         //}
  391.                         // essai avec soundhex
  392.                         //$sql_more_name[] = '`organisation` LIKE \'%'.$s.'%\' OR SOUNDEX(`organisation`)=SOUNDEX(\''.$s.'\')';
  393.                     }
  394.                     //$sql_where[]  = 'SOUNDEX(`organisation`)=SOUNDEX(\''.$this->escape($keywords).'\') OR ('.join(' OR ', $sql_more_name).')';
  395.                     //$sql_where[]  = '('.join(' OR ', $sql_more_name).') OR SOUNDEX(`organisation`)=SOUNDEX(\''.$this->escape($keywords).'\')';
  396.                     if (!empty($sql_more_name)) {
  397.                         $sql_where[] = '(' join(' AND '$sql_more_name) . ')';
  398.                     }
  399.                 }
  400.                 // recherche par numéro d'id pour les mots clés numériques
  401.                 if (!empty($list[$this->IDNUM])) {
  402.                     $sql_where[] = '`idcontact` IN (' implode(','$list[$this->IDNUM]) . ')';
  403.                 }
  404.             }
  405.         }
  406.         $sql .= join(' OR '$sql_where);
  407.         // on recherche par type
  408.         /*if($type=='idcontact_publisher') {
  409.             $sql .= ' AND idcontact IN (SELECT DISTINCT(idcontact_publisher) FROM texts) ';
  410.         }*/
  411.         //echo $sql;
  412.         $sql .= ' ORDER BY organisation';
  413.         $this->query($sql);
  414.         $r = array();
  415.         while ($this->fetch()) {
  416.             // le titre
  417.             $r[$this->idcontact] = $this->getObjectTitle($this->idcontact);
  418.             // optionnellement, la ville
  419.             if ($this->city != '') {
  420.                 $r[$this->idcontact] .= ' - ' $this->city;
  421.             }
  422.             // si trouvé par id, on l'affiche en fin de titre
  423.             if (!empty($list[$this->IDNUM]) && in_array($this->idcontact$list[$this->IDNUM])) {
  424.                 $r[$this->idcontact] .= ' - n°' $this->idcontact;
  425.             }
  426.         }
  427.         $this->free();
  428.         return $r;
  429.     }
  430.     // }}}
  431.     //  {{{ getObjectTitle()
  432.     /** Infos de l'item recherché
  433.      *
  434.      * Affichage standard du titre de l'objet
  435.      *
  436.      * @access public
  437.      * @param int $idobject Identifiant de l'item
  438.      * @param array $infos_object Informations pour construire le titre
  439.      * @param array $params Paramétres supplémentaires
  440.      * @return string
  441.      */
  442.     public function getObjectTitle($idobject null$infos_object = array(), $params = array())
  443.     {
  444.         if (!$idobject) {
  445.             $idobject $this->idcontact;
  446.         }
  447.         // champs
  448.         $fields = array('type''organisation''firstname''lastname''url_clean''valid');
  449.         if (empty($infos_object)) {
  450.             //charger les infos que si necessaire
  451.             if (empty($this->organisation) && empty($this->lastname)) {
  452. //                $this->selectAdd();
  453. //                $this->selectAdd(join($fields, ','));
  454.                 $infos_object $this->get($idobject);
  455.             }
  456.             if (empty($infos_object)) {
  457.                 foreach ($fields as $k => $v) {
  458.                     if (empty($this->$v)) {
  459.                         $infos_object[$v] = '';
  460.                     } else {
  461.                         $infos_object[$v] = trim($this->$v);
  462.                     }
  463.                 }
  464.             }
  465.         } else {
  466.             foreach ($fields as $k => $v) {
  467.                 if (empty($infos_object[$v])) {
  468.                     $infos_object[$v] = '';
  469.                 } else {
  470.                     $infos_object[$v] = trim($infos_object[$v]);
  471.                 }
  472.             }
  473.         }
  474.         // id
  475.         $infos_object['idcontact'] = $idobject;
  476.         // nom en majuscules suivi par le prénom
  477.         $name '';
  478.         if (!array_key_exists('url_clean'$params)) {
  479.             if ($infos_object['lastname']) {
  480.                 $name .= mb_strtoupper($infos_object['lastname']);
  481.             }
  482.             if ($infos_object['firstname']) {
  483.                 if ($name$name .= ' ';
  484.                 $name .= $infos_object['firstname'];
  485.             }
  486.         } else { // on souhaite un affichage nom/prenom
  487.             if ($infos_object['firstname']) {
  488.                 $name .= $infos_object['lastname'];
  489.             }
  490.             if ($infos_object['lastname']) {
  491.                 if ($name$name .= ' ';
  492.                 $name .= $infos_object['lastname'];
  493.             }
  494.         }
  495.         //si c'est une personne (type=0), nom, prenom et organisation entre parenthese si elle existe
  496.         $return '';
  497.         if ($infos_object['type'] == 0) {
  498.             // on ajoute le nom
  499.             $return .= $name;
  500.             if ($infos_object['organisation']) {
  501.                 if ($name) {
  502.                     // nom _et_ organisation
  503.                     $return .= ' (' $infos_object['organisation'] . ')';
  504.                 } else {
  505.                     // organisation seulement
  506.                     $return .= $infos_object['organisation'];
  507.                 }
  508.             }
  509.         } elseif ($infos_object['type'] == 1) {//organisation
  510.             if ($infos_object['organisation']) {
  511.                 // on ajoute l'organisation
  512.                 $return .= $infos_object['organisation'];
  513.             }
  514.             if ($name && !array_key_exists('noname'$params)) {
  515.                 if ($return) {
  516.                     // organisation _et_ nom
  517.                     $return .= ' (' $name ')';
  518.                 } else {
  519.                     // nom seulement
  520.                     $return .= $name;
  521.                 }
  522.             }
  523.         }
  524.         if (!empty($infos_object['organisation'])) {
  525.             $infos_object['title'] = $infos_object['organisation'];
  526.         }
  527.         if (!$return$return '???'// vide, bug?...
  528.         // renvoyer un array plutôt que le titre (utile si on veux l'url)
  529.         if (array_key_exists('return_array'$params)) {
  530.             return $infos_object;
  531.         }
  532.         //retour
  533.         return $return;
  534.     }
  535.     // }}}
  536.     // {{{ countObjects()
  537.     /** Compter le nombre d'objet lié à un contact
  538.      *
  539.      *
  540.      * @param string $object Type
  541.      * @param string $associate_field Champ associé
  542.      * @param string $idcontact id du contact
  543.      * @access public
  544.      * @return int
  545.      */
  546.     public function countObjects($object$associate_field$idcontact null)
  547.     {
  548.         if (!$idcontact && isset($this->idcontact)) {
  549.             $idcontact $this->idcontact;
  550.         }
  551.         if (!$idcontact) {
  552.             return false;
  553.         }
  554.         // ajout du 's'
  555.         $sql 'SELECT COUNT(DISTINCT(id' $object ')) as total
  556.                 FROM ' $object 's
  557.                 WHERE ' $associate_field '=' . ((int)$idcontact);
  558.         $nbCount $this->queryOne($sql);
  559.         return $nbCount;
  560.     }
  561.     // }}}
  562.     // {{{ getContactsByClassification()
  563.     /** Retourne la liste des contacts par tag(s)
  564.      *
  565.      *
  566.      * @param string|array $tagnames
  567.      * @param string $classification_name
  568.      * @access public
  569.      * @return array
  570.      */
  571.     public function getContactsByClassification($classification_name null$order_by null$limit null$idgroupclassification null$area null)
  572.     {
  573.         // requete classique si pas idclassification
  574.         $sql 'SELECT ct.idcontact,ct.url_clean, ct.link_on_video, ct.url, ct.organisation, ct.idtypestructure, f.file, tf.titre AS extension
  575.                 FROM ' $this->__table ' ct, object_file of, files f, classifications cl, file_classification fc, typesfiles tf
  576.                 WHERE 1
  577.                 AND of.idobject=ct.' $this->__idtable '
  578.                 AND f.idfile=of.idfile
  579.                 AND f.publish=1
  580.                 AND f.idtype=tf.idtype
  581.                 AND f.idfile=fc.idfile
  582.                 AND cl.idclassification=fc.idclassification
  583.                 AND of.object=\'contacts\' ';
  584.         // recherche par classifications
  585.         if (!empty($classification_name)) {
  586.             // recherche simple par idclassification
  587.             if (is_array($classification_name) || $this->my_is_int($classification_name)) {
  588.                 $sql 'SELECT ct.idcontact,ct.url_clean, ct.url, ct.organisation, ct.idtypestructure, cc.idclassification, cl.classification
  589.                         FROM ' $this->__table ' ct
  590.                             JOIN contact_classification cc ON cc.idcontact=ct.idcontact
  591.                             JOIN classifications cl ON cl.idclassification=cc.idclassification
  592.                         WHERE ct.publish=1 ';
  593.                 if (is_array($classification_name)) {
  594.                     $sql .= ' AND cc.idclassification IN (' join(','$classification_name) . ') ';
  595.                 } else {
  596.                     $sql .= ' AND cc.idclassification=' . (int)$classification_name;
  597.                 }
  598.             } else {
  599.                 $sql .= ' AND cl.classification=\'' $this->escape($classification_name) . '\'';
  600.             }
  601.         }
  602.         // recherche par idgroupclassification
  603.         if (!empty($idgroupclassification)) {
  604.             $sql .= ' AND cl.idgroupclassification=\'' $this->escape($idgroupclassification) . '\'';
  605.         }
  606.         // recherche par regions
  607.         if (!empty($area)) {
  608.             $bigregions $this->getEntityManager()->getRepository(Bigregions::class);
  609.             $sql .= ' AND ' $bigregions->getZipCode($area'ct') . ' ';
  610.         }
  611.         if (empty($order_by)) {
  612.             $sql .= ' ORDER BY ct.idcontact';
  613.         } else {
  614.             $sql .= ' ORDER BY ' $order_by;
  615.         }
  616.         if (!empty($limit)) {
  617.             $sql .= ' LIMIT ' $limit;
  618.         }
  619.         $res $this->queryAll($sql);
  620.         return $res;
  621.     }
  622.     // }}}
  623.     //  {{{ setRelationContact()
  624.     /** Enregistrement dans les table relationnelle
  625.      *
  626.      * Permet l'enregistrement multiple de valeur dans les tables
  627.      * de relation
  628.      *
  629.      * @access   public
  630.      * @param string $table Nom de la table de relation
  631.      * @param string $key Clé dans le tableau
  632.      * @param string $col Colonne
  633.      * @param array $array_values Valeur à enregistrer
  634.      * @param int $id Id de l'enregistrement principal
  635.      * @return   bool
  636.      */
  637.     public function setRelationContact($table_liaison$fields$array_values$allRights true)
  638.     {
  639.         if ($allRights) {
  640.             $rights = array('update' => 1);
  641.         }
  642.         // on vérifie les droits
  643.         if ($this->isCheckRights() || !$allRights) {
  644.             $extranetusers Theatre_Extranetusers::factory('extranetusers');
  645.             $rights $extranetusers->getRights();
  646.         }
  647.         if (isset($rights) && $rights['update'] == 1) {
  648.             $where null;
  649.             // construire
  650.             $i 0;
  651.             foreach ($fields as $k => $v) {
  652.                 // le premier champ et les champs après 1 construisent le WHERE du delete
  653.                 if ($i != 1) {
  654.                     if (is_null($v)) {
  655.                         $where .= ' AND ' $k ' IS NULL';
  656.                     } else {
  657.                         $where .= ' AND ' $k '=\'' $v '\'';
  658.                     }
  659.                 }
  660.                 $insert_fields[] = $k;
  661.                 $interro_fields[] = '?';
  662.                 $i++;
  663.             }
  664.             if (empty($where)) {
  665.                 throw new \Exception('Il n\'y a pas de clause WHERE pour relationSelect');
  666.             }
  667.             // on supprime puis on insère (replace ne marche pas)
  668.             $sql_delete 'DELETE FROM ' $table_liaison ' WHERE 1 ' $where;
  669.             $prep $this->_em->getConnection()->prepare($sql_delete);
  670.             $prep->execute();
  671.             // si le tableau est vide on sort
  672.             if (empty($array_values)) {
  673.                 return true;
  674.             }
  675.             // on prepare
  676.             $sql_prepare 'INSERT INTO ' $table_liaison ' (' implode(','$insert_fields) . ') VALUES ( ' implode(','$interro_fields) . ')';
  677.             $prep $this->_em->getConnection()->prepare($sql_prepare);
  678.             // le premier index de 'fields' correspond à la clé
  679.             reset($fields);
  680.             $idt current($fields);
  681.             $i 0;
  682.             foreach ($array_values as $k => $v) {
  683.                 $prep_values[$i] = array($idt$v);
  684.                 // si le nombre de champ déclaré est sup à 2
  685.                 if (count($fields) > 2) {
  686.                     $j 0;
  687.                     foreach ($fields as $kb => $vb) {
  688.                         if ($j 1) {
  689.                             $prep_values[$i][] = $vb;
  690.                         }
  691.                         $j++;
  692.                     }
  693.                 }
  694.                 $i++;
  695.             }
  696.             foreach ($prep_values as $value) {
  697.                 $res $prep->execute($value);
  698.             }
  699.             if (!empty($res)) {
  700.                 return true;
  701.             } else {
  702.                 throw new \Exception($res->getDebugInfo());
  703.             }
  704.         } else {
  705.             throw new \Exception($GLOBALS['tr']->trans('no_right') . ' setRelationSelect');
  706.         }
  707.     }
  708.     // }}}
  709.     //  {{{ getRelationsArray()
  710.     /** Décrit les relations de l'objet
  711.      *
  712.      * @access  public
  713.      * @param string|int $type si on souhaite retourner uniquement un type precis
  714.      * @see     Theatre::getLinkedObject()
  715.      */
  716.     public function getRelationsArray($type)
  717.     {
  718.         // où trouve t'on ce contact ?
  719.         if ($type == 'direct_relation') {
  720.             $relation_fields = array(array(
  721.                 'table' => 'bookmark_extranetuser',
  722.                 'where_object' => true,
  723.             ), array(
  724.                 'table' => 'comments',
  725.                 'where_object' => true,
  726.             ), array(
  727.                 'table' => 'contact_classification',
  728.             ), array(
  729.                 'table' => 'contact_contactassocie',
  730.             ), array(
  731.                 'table' => 'contact_contactassocie',
  732.                 'field' => 'idcontactassocie',
  733.             ), array(
  734.                 'table' => 'contact_extranetuser',
  735.             ), array(
  736.                 'table' => 'contact_person',
  737.             ), array(
  738.                 'table' => 'contact_extranetuser',
  739.             ), array(
  740.                 'table' => 'contents',
  741.             ), array(
  742.                 'table' => 'content_contact',
  743.             ), array(
  744.                 'table' => 'new_contact',
  745.             ), array(
  746.                 'table' => 'newschedules',
  747.             ), array(
  748.                 'table' => 'object_content',
  749.                 'where_object' => true,
  750.             ), array(
  751.                 'table' => 'object_file',
  752.                 'where_object' => true,
  753.             ), array(
  754.                 'table' => 'object_multimedia',
  755.                 'where_object' => true,
  756.             ), array(
  757.                 'table' => 'schedules',
  758.             ), array(
  759.                 'table' => 'spectacles',
  760.                 'field' => 'idcontact_creation',
  761.             ), array(
  762.                 'table' => 'spectacles',
  763.                 'field' => 'idcontact_production',
  764.             ), array(
  765.                 'table' => 'spectacle_contact',
  766.             ), array(
  767.                 'table' => 'reflexions',
  768.                 'field' => 'idcontact_signature',
  769.             ), array(
  770.                 'table' => 'faqgroups',
  771.                 'where_object' => true,
  772.             ), array(
  773.                 'table' => 'quizgroups',
  774.                 'where_object' => true,
  775.             ), array(
  776.                 'table' => 'stats',
  777.                 'where_object' => true,
  778.             ), array(
  779.                 'table' => 'statscumul',
  780.                 'where_object' => true,
  781.             ), array(
  782.                 'table' => 'texts',
  783.                 'field' => 'idcontact_publisher',
  784.             ), array(
  785.                 'table' => 'texts',
  786.                 'field' => 'idcontact_translation',
  787.             ), array(
  788.                 'table' => 'multimedias',
  789.                 'field' => 'idcontact_producteur',
  790.             ), array(
  791.                 'table' => 'texts',
  792.                 'field' => 'idcontact_performing',
  793.             ), array(
  794.                 'table' => 'user_action',
  795.                 'where_object' => true,
  796.             )
  797.             );
  798.             return $relation_fields;
  799.         }
  800.         // récupérer les relations communes
  801.         $array_types $this->getRelationsArrayTrait('all');
  802.         // quelques trucs spécifiques
  803.         if ($type == 'contact_festivals') {
  804.             $sql_idtypestructure '=\'FT\'';
  805.             $type 'contact_contactassocie';
  806.         } elseif ($type == 'contact_anciennestructure') {
  807.             $sql_idtypestructure 'IS NULL';
  808.             $type 'contact_contactassocie';
  809.         } else {
  810.             $sql_idtypestructure null;
  811.         }
  812.         $array_types += array(
  813.             // contact_contactassocie idcontactassocie/idcontact/idstructure
  814.             'contact_contactassocie' => array(// contacts associés
  815.                 'type_join' => 'multiple',
  816.                 'dest_table' => 'contacts',
  817.                 'join_table' => 'contact_contactassocie',
  818.                 'join_field_src' => 'idcontactassocie',
  819.                 'fields' => array('idcontact''organisation''lastname''firstname''type'),
  820.                 'where' => ' AND j2.idtypestructure ' $sql_idtypestructure// j2 = alias dans Items_list::getItemListResult
  821.                 'description' => 'Contact associé à d\'autre(s) contact(s)',
  822.             ),
  823.             // contact_classification idcontact/idclassification
  824.             'contact_classification' => array(// classifications associées
  825.                 'type_join' => 'multiple',
  826.                 'dest_table' => 'classifications',
  827.                 'join_table' => 'contact_classification',
  828.                 'fields' => array('idclassification''classification''type'),
  829.                 'description' => 'Classification(s) associée(s) à ce contact',
  830.                 'silent_delete_relation' => true,
  831.             ),
  832.             // content_contact idcontact/idcontact/idrole
  833.             'content_contact' => array(// contact associé à des contenus (journal, journaliste...)
  834.                 'type_join' => 'multiple',
  835.                 'dest_table' => 'contents',
  836.                 'join_table' => 'content_contact',
  837.                 'fields' => array('idcontent''title''text'),
  838.                 'description' => 'Contenu(s) associé(s) au contact',
  839.             ),
  840.             // contact_person idcontact/idperson/idrole
  841.             'contact_person' => array(// contact associé à des personnes (direction d'une structure...)
  842.                 'type_join' => 'multiple',
  843.                 'dest_table' => 'persons',
  844.                 'join_table' => 'contact_person',
  845.                 'fields' => array('idperson''lastname''firstname''url_clean'),
  846.                 'fields_join_table' => array('idoffice''date_start''date_end'),
  847.                 'description' => 'Personne(s) associée(s) au contact',
  848.             ),
  849.             // contact_extranetuser idcontact/idextranetuser
  850.             'contact_extranetuser' => array(// contact associé à des utilisateurs (administrateur d'une fiche de structure...)
  851.                 'type_join' => 'multiple',
  852.                 'dest_table' => 'extranetusers',
  853.                 'join_field_dest' => 'contact_idextranetuser',
  854.                 'join_table' => 'contact_extranetuser',
  855.                 'fields' => array('idextranetuser''login''firstname''lastname'),
  856.                 'description' => 'Utilisateur(s) associée(s) au contact',
  857.             ),
  858.             // contents publisher
  859.             'content_publisher' => array(// contact associé à un contenu comme producteur du contenu
  860.                 'type_join' => 'multiple',
  861.                 'dest_table' => 'contents',
  862.                 'join_table' => 'content_publisher',
  863.                 'fields' => array('idcontent''title''text'),
  864.             ),
  865.             // contents idcontact_journalist
  866.             'content_idcontact_journalist' => array(// contact associé à un contenu comme journaliste
  867.                 'type_join' => 'simple',
  868.                 'dest_table' => 'contents',
  869.                 'dest_table_field' => 'idcontact_journalist',
  870.                 'fields' => array('idcontent''title''text'),
  871.                 'description' => 'Contenu(s) associé(s) au contact comme journaliste',
  872.             ),
  873.             // multimedias idcontact_journalist
  874.             'multimedia_idcontact_producteur' => array(// contact associé à un contenu comme journaliste
  875.                 'type_join' => 'simple',
  876.                 'dest_table' => 'multimedias',
  877.                 'dest_table_field' => 'idcontact_producteur',
  878.                 'fields' => array('idmultimedia''sujet_titre''url_clean'),
  879.                 'description' => 'Mulimédia(s) associé(s) au contact comme producteur',
  880.             ),
  881.             // contents idcontact_newspaper
  882.             'content_idcontact_newspaper' => array(// contact associé à un contenu comme journal
  883.                 'type_join' => 'simple',
  884.                 'dest_table' => 'contents',
  885.                 'dest_table_field' => 'idcontact_newspaper',
  886.                 'fields' => array('idcontent''title''text'),
  887.                 'description' => 'Contenu(s) associé(s) au contact comme journal',
  888.             ),
  889.             // reflexions idcontact_signature
  890.             'content_idcontact_signature' => array(// contact associé à une réfléxion
  891.                 'type_join' => 'simple',
  892.                 'dest_table' => 'reflexions',
  893.                 'dest_table_field' => 'idcontact_signature',
  894.                 'fields' => array('idreflexion''title''module'),
  895.                 'description' => 'Contenu(s) associé(s) à une piste de réflexion comme signature',
  896.             ),
  897.             // contact associé à un calendrier
  898.             'schedule_idcontact' => array(// contact associé à une réfléxion
  899.                 'type_join' => 'simple',
  900.                 'dest_table' => 'schedules',
  901.                 'dest_table_field' => 'idcontact',
  902.                 'fields' => array('idschedule''idspectacle''note'),
  903.                 'description' => 'Contact(s) associé(s) à une date dans un calendrier',
  904.                 'only_message' => true,
  905.                 'silent_delete_relation' => true,
  906.             ),
  907.             // spectacles idcontact_creation/idcontact_production
  908.             'spectacle_production' => array(// contacts associés à des spectacles
  909.                 'type_join' => 'simple',
  910.                 'dest_table' => 'spectacles',
  911.                 'dest_table_field' => 'idcontact_production',
  912.                 'fields' => array('idspectacle''title''url_clean'),
  913.                 'description' => 'Spectacle(s) dont le contact est producteur',
  914.             ),
  915.             // spectacles idcontact_creation/idcontact_production
  916.             'spectacle_creation' => array(// contacts associés à des spectacles
  917.                 'type_join' => 'simple',
  918.                 'dest_table' => 'spectacles',
  919.                 'dest_table_field' => 'idcontact_creation',
  920.                 'fields' => array('idspectacle''title''url_clean'),
  921.                 'description' => 'Spectacle(s) dont le contact est le lieu de création',
  922.             ),
  923.             // spectacle_contact idspectacle/idcontact/idrole
  924.             'spectacle_contact' => array(// contacts associés à des spectacles
  925.                 'type_join' => 'multiple',
  926.                 'dest_table' => 'spectacles',
  927.                 'join_table' => 'spectacle_contact',
  928.                 'fields' => array('idspectacle''title''url_clean'),
  929.                 'description' => 'Spectacle(s) lié(s) à ce contact',
  930.             ),
  931.             // texts idcontact_publisher/idcontact_translation/idcontact_performing
  932.             'text_idcontact_publisher' => array(// contacts associés à une fiche texte comme publisher
  933.                 'type_join' => 'simple',
  934.                 'dest_table' => 'texts',
  935.                 'dest_table_field' => 'idcontact_publisher',
  936.                 'fields' => array('idtext''title''url_clean'),
  937.                 'description' => 'Texte(s) ou traduction(s) dont le contact est l\'éditeur',
  938.             ),
  939.             // texts idcontact_publisher/idcontact_translation/idcontact_performing
  940.             'text_idcontact_translation' => array(// contacts associés à une fiche texte comme autorisation de traduction
  941.                 'type_join' => 'simple',
  942.                 'dest_table' => 'texts',
  943.                 'dest_table_field' => 'idcontact_translation',
  944.                 'fields' => array('idtext''title''url_clean'),
  945.                 'description' => 'Texte(s) ou traduction(s) dont le contact est l\'autorisation de traduction',
  946.             ),
  947.             // texts idcontact_publisher/idcontact_translation/idcontact_performing
  948.             'text_idcontact_performing' => array(// contacts associés à une fiche texte comme autorisation de représentation
  949.                 'type_join' => 'simple',
  950.                 'dest_table' => 'texts',
  951.                 'dest_table_field' => 'idcontact_performing',
  952.                 'fields' => array('idtext''title''url_clean'),
  953.                 'description' => 'Texte(s) ou traduction(s) dont le contact est l\'autorisation de représentation',
  954.             ),
  955.             // multimedias idmultimedia
  956.             'idmultimedia' => array(// video de tête
  957.                 'type_join' => 'simple',
  958.                 'dest_table' => 'multimedias',
  959.                 'join_field_src' => 'idmultimedia',
  960.                 'dest_table_field' => 'idmultimedia',
  961.                 'fields' => array('idmultimedia''sujet_titre''url_clean'),
  962.                 'description' => 'Contenu multimedias associé au contact',
  963.             ),
  964.         );
  965.         // retourne uniquement un type précis
  966.         if ($type == 'all') {
  967.             return $array_types;
  968.         }
  969.         if (!empty($array_types[$type])) {
  970.             $array_types[$type]['type'] = $type;
  971.             return $array_types[$type];
  972.         } else {
  973.             return null;
  974.         }
  975.     }
  976.     // }}}
  977.     //  {{{ getContactSpectacles()
  978.     /** Trouve les spectacles associés à un contact
  979.      *
  980.      * @access  public
  981.      * @param string|int $type si on souhaite retourner uniquement un type precis
  982.      * @see     Theatre::getLinkedObject()
  983.      */
  984.     public function getContactSpectacles($idcontact$get_array true)
  985.     {
  986.         // id du contact
  987.         $idcontact = (int)$idcontact;
  988.         /* trouver les spectacles dont le contact à pu être
  989.             - producteur / coprod / prod delegue
  990.             - compagnie / lieu de création
  991.             - lieu de représentation */
  992.         $sql '
  993.             SELECT DISTINCT(spectacles.idspectacle) FROM spectacles
  994.                 LEFT JOIN schedules ON schedules.idspectacle=spectacles.idspectacle
  995.                 LEFT JOIN spectacle_contact ON spectacle_contact.idspectacle=spectacles.idspectacle
  996.             WHERE
  997.                 schedules.idcontact=' $idcontact '
  998.                 OR (spectacle_contact.idcontact=' $idcontact ' AND spectacle_contact.idrole IN (17,18,19))
  999.                 OR spectacles.idcontact_production=' $idcontact '
  1000.                 OR spectacles.idcontact_creation=' $idcontact;
  1001.         // avec une jointure sur multimedias
  1002.         $sql '
  1003.             SELECT DISTINCT(spectacles.idspectacle), object_multimedia.idmultimedia FROM spectacles
  1004.                 LEFT JOIN schedules ON schedules.idspectacle=spectacles.idspectacle
  1005.                 LEFT JOIN spectacle_contact ON spectacle_contact.idspectacle=spectacles.idspectacle
  1006.                 INNER JOIN object_multimedia ON spectacles.idspectacle=object_multimedia.idobject
  1007.             WHERE
  1008.                 object_multimedia.object=\'spectacles\'
  1009.                 AND (
  1010.                     schedules.idcontact=' $idcontact '
  1011.                     OR (spectacle_contact.idcontact=' $idcontact ' AND spectacle_contact.idrole IN (17,18,19))
  1012.                     OR spectacles.idcontact_production=' $idcontact '
  1013.                     OR spectacles.idcontact_creation=' $idcontact '
  1014.                 )';
  1015.         if ($this->isTraceMode('get_sql_object')) {
  1016.             $this->setTraceInfos(array(
  1017.                 'sql_query' => $sql,
  1018.                 'dbg' => array('spectacles_contact_' uniqid(), 'Spectacles associés à un contact'),
  1019.             ));
  1020.         }
  1021.         $list_spectacles $this->queryAll($sql);
  1022.         if (!empty($list_spectacles)) {
  1023.             /*foreach($list_spectacles as $k=>$v) {
  1024.                 $list_spectacles_array[] = $v['idspectacle'];
  1025.             }*/
  1026.             if ($get_array) {
  1027.                 return $list_spectacles;
  1028.             } else {
  1029.                 return join(','$list_spectacles);
  1030.             }
  1031.         }
  1032.         return false;
  1033.     }
  1034.     // }}}
  1035.     //  {{{ getInfosObject()
  1036.     /** Alias de getInfosContact
  1037.      *
  1038.      * @access  public
  1039.      * @param int $idobject identifiant
  1040.      * @return  array
  1041.      * @see     getInfosContact()
  1042.      */
  1043.     public function getInfosObject($idobject null)
  1044.     {
  1045.         return $this->getInfosContact($idobject);
  1046.     }
  1047.     // }}}
  1048.     //  {{{ getAssociatePersons()
  1049.     /** Personnes aossociées au contact
  1050.      *
  1051.      * @access  public
  1052.      * @param int $idcontact identifiant du contact
  1053.      * @param int $idoffice role (exemple : direction)
  1054.      * @param bool $actual_only uniquement les actuels  (contrainte sur la date)
  1055.      * @return  array
  1056.      */
  1057.     public function getAssociatePersons($idcontact$idoffice null$actual_only null)
  1058.     {
  1059.         // infos sur la liaison
  1060.         $infos_link $this->getRelationsArray('contact_person');
  1061.         // select egalement l'idrole
  1062.         if ($idoffice) {
  1063.             $infos_link['where'] = ' AND j2.idoffice=' $idoffice;
  1064.         }
  1065.         // qui n'a pas fini son mandat
  1066.         if ($actual_only) {
  1067.             $infos_link['where'] .= ' AND (j2.date_end IS NULL OR j2.date_end>=\'' date('Y-m-d') . '\')';
  1068.         }
  1069.         // avec ou sans virgule avec le noPunct
  1070.         if (!empty($infos_link)) {
  1071.             return $this->noPunct($this->getLinkedObject($infos_link$idcontact$infos_link['type'], 'contacts'));
  1072.         }
  1073.     }
  1074.     // }}}
  1075.     //  {{{ getSQLContacts()
  1076.     /** Générer la requete standard pour des vidéos
  1077.      *
  1078.      *
  1079.      * @access   public
  1080.      * @param array $query Les paramètres pour la requete
  1081.      * @param bool $debug afficher la requête
  1082.      * @return   string
  1083.      */
  1084.     public function getSQLContacts($query = array(), $debug false)
  1085.     {
  1086.         // on prepare les tableaux
  1087.         foreach (array('select''from''where''order''group''limit') as $t) {
  1088.             if (!empty($query[$t])) {
  1089.                 if (!is_array($query[$t])) {
  1090.                     $query[$t][] = $query[$t];
  1091.                 } else {
  1092.                     $query[$t] = $query[$t];
  1093.                 }
  1094.             } else {
  1095.                 $query[$t] = array();
  1096.             }
  1097.         }
  1098.         // champs par défaut
  1099.         $this->addSQLParams('select'$query, array(
  1100.             array('contacts' => '*')
  1101.         ));
  1102.         // publié ou pas
  1103.         if (empty($query['publish']) && $_ENV['CHECK_IF_ONLINE']) {
  1104.             $this->addSQLParams('where'$query, array(
  1105.                 array('contacts''publish'1)
  1106.             ));
  1107.         } elseif (!empty($query['publish'])) {
  1108.             $this->addSQLParams('where'$query, array(
  1109.                 array('contacts''publish'$query['publish'])
  1110.             ));
  1111.         }
  1112.         // recherche par type de structure
  1113.         if (!empty($query['idtypestructure'])) {
  1114.             $this->addSQLParams('where'$query, array(
  1115.                 array('contacts''idtypestructure'$query['idtypestructure'], 'AND'),
  1116.             ));
  1117.         }
  1118.         // recherche par contacts
  1119.         if (!empty($query['idcontact'])) {
  1120.             $this->addSQLParams('where'$query, array(
  1121.                 array('contacts''idcontact'$query['idcontact'], 'AND'),
  1122.             ));
  1123.         }
  1124.         // recherche par classification
  1125.         if (!empty($query['classification']) || !empty($query['idclassification'])) {
  1126.             if (!empty($query['idclassification']['NOT'])) {
  1127.                 // TODO
  1128.             } else {
  1129.                 $this->addSQLParams('from'$query, array(
  1130.                     'contact_classification',
  1131.                     'classifications',
  1132.                 ));
  1133.                 // jointure entre les 3 tables
  1134.                 $this->addSQLParams('join'$query, array(
  1135.                     'contacts.`idcontact`' => 'contact_classification.`idcontact`',
  1136.                     'contact_classification.`idclassification`' => 'classifications.`idclassification`',
  1137.                 ));
  1138.                 // recherche
  1139.                 if (!empty($query['classification']) && is_array($query['classification'])) {
  1140.                     if (!empty($query['classification']['NOT'])) {
  1141.                         $condition_classification 'NOT IN';
  1142.                         $query['classification'] = $query['classification']['NOT'];
  1143.                     } else {
  1144.                         $condition_classification 'IN';
  1145.                     }
  1146.                     $this->addSQLParams('where'$query, array(
  1147.                         array('classifications''classification'$query['classification'], 'AND'$condition_classification),
  1148.                     ));
  1149.                 }
  1150.                 if (!empty($query['idclassification']) && is_array($query['idclassification'])) {
  1151.                     if (!empty($query['idclassification']['NOT'])) {
  1152.                         $condition_classification 'NOT IN';
  1153.                         $query['idclassification'] = $query['idclassification']['NOT'];
  1154.                     } else {
  1155.                         $condition_classification 'IN';
  1156.                     }
  1157.                     $this->addSQLParams('where'$query, array(
  1158.                         array('classifications''idclassification'$query['idclassification'], 'AND'$condition_classification),
  1159.                     ));
  1160.                 }
  1161.             }
  1162.         }
  1163.         return $this->getSQLObject($query);
  1164.     }
  1165.     // }}}
  1166.     //  {{{ getListContacts()
  1167.     /** Retourne des listes de contacts
  1168.      *
  1169.      * Retourne des listes de contact au format "standard""
  1170.      *
  1171.      * @access   public
  1172.      * @param array $params_sql paramètre pour la requete SQL
  1173.      * @param array $format de la vignette si pas standard
  1174.      * @param bool $debug mode débugage
  1175.      * @return   array
  1176.      */
  1177.     public function getListContacts($params_sql = array(), $format_vignette = array(), $params = array())
  1178.     {
  1179.         // tout dans params_sql
  1180.         if (!empty($params_sql['special'])) {
  1181.             foreach ($params_sql['special'] as $k => $v) {
  1182.                 if (empty($params_sql[$k])) {
  1183.                     $params_sql[$k] = $v;
  1184.                 }
  1185.             }
  1186.         }
  1187.         // construction de la requête avec le passage de paramètres
  1188.         $sql $this->getSQLContacts($params_sql);
  1189.         // paramètre de debug
  1190.         $dbg = (empty($params_sql['dbg'])) ? array() : $dbg $params_sql['dbg'];
  1191.         // executer la requete
  1192.         $datas $this->queryAll($sql$dbg);
  1193.         $contacts = array();
  1194.         // debug
  1195.         $start_boucle microtime(true);
  1196.         // on boucle
  1197.         foreach ($datas as $data) {
  1198.             $idcontact $data['idcontact'];
  1199.             if (!empty($params_sql['fields'])) {
  1200.                 foreach ($params_sql['fields'] as $f) {
  1201.                     $contacts[$idcontact][$f] = $data[$f];
  1202.                 }
  1203.             } else {
  1204.                 $contacts[$idcontact] = $this->getInfosContact($idcontact$params);
  1205.             }
  1206.         }
  1207.         // debug de la boucle
  1208.         if ($this->isTraceMode('list_object')) {
  1209.             $this->setTraceInfos(array(
  1210.                 'execution_time_boucle' => microtime(true) - $start_boucle,
  1211.                 'nb_occurence' => count($contacts),
  1212.                 'dbg' => $dbg,
  1213.             ));
  1214.         }
  1215.         $this->free();
  1216.         return $contacts;
  1217.     }
  1218.     // }}}
  1219.     //  {{{ getVignetteContact()
  1220.     /** Récupère la vignette d'un contact ou la cree si besoin
  1221.      *
  1222.      * @access   public
  1223.      * param     int idcontact identifiant du contact
  1224.      * param     array format $format de la vignette
  1225.      * @return   string
  1226.      */
  1227.     public function getVignetteContact($idcontact null$format = array(), $classification 'class_pp')
  1228.     {
  1229.         // id du spectacle
  1230.         if (empty($idcontact)) {
  1231.             $idcontact $this->idcontact;
  1232.         }
  1233.         $idcontact = (int)$idcontact;
  1234.         // par default : image arrondie crop 100px x 100px qualite 75
  1235.         if (!empty($format)) {
  1236.             $set_format $format;
  1237.         } else {
  1238.             if ($classification == 'class_pp') {
  1239.                 $set_format = array('width' => 100'height' => 100'direction' => 'crop');
  1240.             } else {
  1241.                 $set_format = array('width' => 100'height' => 100'direction' => 'crop');
  1242.             }
  1243.         }
  1244.         // generation par la classe Images
  1245.         $this->images->setVignetteFormat($set_format);
  1246.         return $this->images->getVignetteObject($idcontact'contacts'$classificationnull$this->publish_status);
  1247.     }
  1248.     // }}}
  1249.     // {{{ getSpectaclesIn()
  1250.     /** Récupérer les ids des spectacles dans le lieu
  1251.      *
  1252.      * @params int $idcontact Identifiant
  1253.      * @return array
  1254.      */
  1255.     public function getSpectaclesIn($idcontact$count_only false$idclassification null)
  1256.     {
  1257.         $params_sql = array(
  1258.             'from' => 'schedules, spectacles ',
  1259.             'where' => 'schedules.idspectacle=spectacles.idspectacle
  1260.                 AND spectacles.publish=1
  1261.                 AND (schedules.idcontact=' $idcontact ' OR schedules.idcontact_festival=' $idcontact ')',
  1262.         );
  1263.         return $this->getSpectaclesCommon($idcontact$params_sql$count_only$idclassification);
  1264.     }
  1265.     // }}}
  1266.     // {{{ getSpectaclesProd()
  1267.     /** Récupérer les ids des spectacles coproduits par le lieu
  1268.      *
  1269.      * @params int $idcontact Identifiant
  1270.      * @params bool $count_only Compter seulement
  1271.      * @params int|array $idclassification Classification(s)
  1272.      * @return array
  1273.      */
  1274.     public function getSpectaclesProd($idcontact$count_only false$idclassification null$roles null)
  1275.     {
  1276.         $params_sql = array(
  1277.             'from' => 'spectacles INNER JOIN spectacle_contact ON spectacle_contact.`idspectacle`=spectacles.`idspectacle` ',
  1278.         );
  1279.         if (is_array($idcontact)) {
  1280.             $params_sql['where'] = ' spectacles.`publish`=1 AND (spectacle_contact.`idcontact` IN (' implode(','$idcontact) . ') OR spectacles.`idcontact_production` IN (' implode(','$idcontact) . '))';
  1281.         } else {
  1282.             $params_sql['where'] = ' spectacles.`publish`=1 AND (spectacle_contact.`idcontact`=' $idcontact ' OR spectacles.`idcontact_production`=' $idcontact ')';
  1283.         }
  1284.         if (!is_null($roles)) {
  1285.             if (is_array($roles)) {
  1286.                 $params_sql['where'] .= ' AND spectacle_contact.`idrole` IN (' implode(','$roles) . ')';
  1287.             } else {
  1288.                 $params_sql['where'] .= ' AND spectacle_contact.`idrole` = ' $roles '';
  1289.             }
  1290.         } else {
  1291.             $params_sql['where'] .= ' AND spectacle_contact.`idrole` IN (17,18,19)';
  1292.         }
  1293.         return $this->getSpectaclesCommon($idcontact$params_sql$count_only$idclassification);
  1294.     }
  1295.     // }}}
  1296.     // {{{ getSpectaclesSoutien()
  1297.     /** Récupérer les ids des spectacles avec le soutien de
  1298.      *
  1299.      * @params int $idclassification_soutien Type de classification
  1300.      * @params int|array $idclassification Classification(s)
  1301.      * @return array
  1302.      */
  1303.     public function getSpectaclesSoutien($idclassification_soutien$idclassification null$idcontact null$count_only null)
  1304.     {
  1305.         // les spectacles avec le soutien du JTN
  1306.         $params_sql = array(
  1307.             'from' => ' spectacles INNER JOIN spectacle_classification ON spectacle_classification.idspectacle=spectacles.idspectacle',
  1308.             'where' => ' spectacles.publish=1 AND spectacle_classification.idclassification=' $idclassification_soutien,
  1309.         );
  1310.         return $this->getSpectaclesCommon($idcontact$params_sql$count_only$idclassification);
  1311.     }
  1312.     // }}}
  1313.     // {{{ getSpectaclesAide()
  1314.     /** Récupérer les ids des spectacles avec une aide pour cette structure
  1315.      *
  1316.      * @params int $idclassification_soutien Type de classification
  1317.      * @params int|array $idclassification Classification(s)
  1318.      * @return array
  1319.      */
  1320.     public function getSpectaclesAide($idcontact$count_only null$type_aide = array())
  1321.     {
  1322.         // les spectacles avec une aide associée à ce contact
  1323.         $sql_where ' spectacles.`publish`=1 AND aides.`idcontact`=' $idcontact;
  1324.         // pour des types d'aide en particulier
  1325.         if (!empty($type_aide)) {
  1326.             $sql_where .= ' AND aides.type_aide IN (' $this->arrayToIn($type_aide) . ') ';
  1327.         }
  1328.         $params_sql = array(
  1329.             'from' => 'spectacles INNER JOIN spectacle_aide ON spectacle_aide.`idspectacle`=spectacles.`idspectacle`
  1330.                                   INNER JOIN aides ON aides.`idaide`=spectacle_aide.`idaide` ',
  1331.             'where' => $sql_where,
  1332.         );
  1333.         return $this->getSpectaclesCommon($idcontact$params_sql$count_only);
  1334.     }
  1335.     // }}}
  1336.     // {{{ getSpectaclesPublisher()
  1337.     /** Récupérer les ids des spectacles d'une maison d'édition
  1338.      *
  1339.      * @params int $idcontact Identifiant
  1340.      * @params bool $count_only Compter seulement
  1341.      * @params int|array $idclassification Classification(s)
  1342.      * @return array
  1343.      */
  1344.     public function getSpectaclesPublisher($idcontact$count_only false$idclassification null)
  1345.     {
  1346.         $params_sql = array(
  1347.             'from' => 'spectacles
  1348.                     INNER JOIN text_spectacle ON text_spectacle.idspectacle=spectacles.idspectacle
  1349.                     INNER JOIN texts ON texts.idtext=text_spectacle.idtext',
  1350.             'where' => 'spectacles.publish=1 AND texts.idcontact_publisher=' $idcontact,
  1351.         );
  1352.         return $this->getSpectaclesCommon($idcontact$params_sql$count_only$idclassification);
  1353.     }
  1354.     // }}}
  1355.     // {{{ getSpectaclesCommon()
  1356.     /** Récupérer les ids des spectacles
  1357.      *
  1358.      * @params int $idcontact Identifiant
  1359.      * @params bool $count_only Compter seulement
  1360.      * @params int|array $idclassification Classification(s)
  1361.      * @return array
  1362.      */
  1363.     public function getSpectaclesCommon($idcontact$params_sql$count_only false$idclassification null)
  1364.     {
  1365.         // les spectacles coproduits ou lieu de crée ou compagnie
  1366.         $sql_select 'SELECT DISTINCT(spectacles.`idspectacle`) ';
  1367.         if (!empty($count_only)) {
  1368.             $sql_select 'SELECT COUNT(DISTINCT(spectacles.`idspectacle`)) as total ';
  1369.         }
  1370.         $sql_from ' FROM ' $params_sql['from'];
  1371.         $sql_where ' WHERE ' $params_sql['where'];
  1372.         // uniquement s'ils ont une classification particulière
  1373.         if (!empty($idclassification)) {
  1374.             // caster pour avoir un array
  1375.             if (!is_array($idclassification)) {
  1376.                 $idclassification = (array)$idclassification;
  1377.             }
  1378.             if (strpos($params_sql['from'], 'spectacle_contact') === false) {
  1379.                 $sql_from .= ' JOIN spectacle_contact ON spectacle_contact.`idspectacle`=spectacles.`idspectacle` ';
  1380.             }
  1381.             $sql_from .= ' JOIN object_content ON spectacle_contact.`idspectacle`=object_content.`idobject`
  1382.                            JOIN contents ON contents.`idcontent`=object_content.`idcontent`
  1383.                            JOIN content_classification ON contents.`idcontent`=content_classification.`idcontent` ';
  1384.             // uniquement les contenus publiés
  1385.             $sql_where .= '
  1386.                 AND contents.`publish`=1
  1387.                 AND contents.`valid`=1
  1388.                 AND object_content.`object`=\'spectacles\'
  1389.                 AND content_classification.`idclassification` IN (' join(','$idclassification) . ') ';
  1390.         }
  1391.         // construction de la requête
  1392.         $sql $sql_select $sql_from $sql_where;
  1393.         if (!empty($count_only)) {
  1394.             return $this->queryOne($sql);
  1395.         }
  1396.         $ids_spectacle $this->queryCol($sql);
  1397.         return $ids_spectacle;
  1398.     }
  1399.     // }}}
  1400.     // {{{ countAllSpectacles()
  1401.     /** compter tous les spectacles d'un contact
  1402.      *
  1403.      * @return array
  1404.      */
  1405.     public function countAllSpectacles($idcontact$idclassification null)
  1406.     {
  1407.         return $this->getSpectaclesProd($idcontacttrue$idclassification) + $this->getSpectaclesIn($idcontacttrue$idclassification);
  1408.     }
  1409.     // }}}
  1410.     // {{{ countContacts()
  1411.     /** compter tous les contacts
  1412.      *
  1413.      * @return int
  1414.      */
  1415.     public function countContacts()
  1416.     {
  1417.         return $this->queryOne('SELECT COUNT(DISTINCT(idcontact)) FROM contacts');
  1418.     }
  1419.     // }}}
  1420.     // {{{ countSpectaclesIn()
  1421.     /** compter le nombre de spectacle d'un contact pour une saison
  1422.      *
  1423.      * @return int
  1424.      */
  1425.     public function countSpectaclesIn($idcontacts = array(), $special = array())
  1426.     {
  1427.         $param_sql = array(
  1428.             'limit' => 'all',
  1429.         );
  1430.         $param_special = array(
  1431.             'count_only' => true,
  1432.         );
  1433.         if (!empty($idcontacts)) {
  1434.             if (!is_array($idcontacts)) {
  1435.                 $idcontacts = (array)$idcontacts;
  1436.             }
  1437.             $param_special['idcontacts'] = array('IN'$idcontacts);
  1438.         }
  1439.         if (array_key_exists('saison'$special)) {
  1440.             $param_special['saison'] = $special['saison'];
  1441.         }
  1442.         if (!empty($special['idtypestructure'])) {
  1443.             $param_special['idtypestructure'] = $special['idtypestructure'];
  1444.         }
  1445.         $query $this->getEntityManager()->getRepository(Spectacles::class)->getSQLSpectacles($param_sql$param_special);
  1446.         return $query->getSingleResult(Query::HYDRATE_SCALAR)['total'];
  1447.     }
  1448.     // }}}
  1449.     // {{{ getBoss()
  1450.     /** Retrouver le directeur actuel
  1451.      *
  1452.      * @param int $idcontact Identifiant du contact
  1453.      * @return int
  1454.      */
  1455.     public function getCurrentBoss($idcontact$multiple false)
  1456.     {
  1457.         // trouver le directeur actuel de la structure
  1458.         $boss $this->getAssociatePersons($idcontact1false);
  1459.         foreach ($boss as $k => $v) {
  1460.             $date_current = new Datetime(date('Y-m-d H:i:s'));
  1461.             $date_current $date_current->format('Y-m-d');
  1462.             if ($v['date_start'] != '0000-00-00 00:00:00') {
  1463.                 $date_start = new Datetime($v['date_start']);
  1464.                 $date_start $date_start->format('Y-m-d');
  1465.                 if ($date_start $date_current) {
  1466.                     unset($boss[$k]);
  1467.                 }
  1468.             }
  1469.             if ($v['date_end'] != '0000-00-00 00:00:00') {
  1470.                 $date_end = new Datetime($v['date_end']);
  1471.                 $date_end $date_end->format('Y-m-d');
  1472.                 if ($date_end $date_current) {
  1473.                     unset($boss[$k]);
  1474.                 }
  1475.             }
  1476.         }
  1477.         // un seul
  1478.         if (!$multiple) {
  1479.             foreach ($boss as $b) {
  1480.                 return $b;
  1481.             }
  1482.         } else {
  1483.             return $boss;
  1484.         }
  1485.     }
  1486.     // }}}
  1487. }