vendor/theatre/core/src/Repository/PersonsRepository.php line 737

Open in your IDE?
  1. <?php
  2. namespace TheatreCore\Repository;
  3. use TheatreCore\Classes\Images\Images;
  4. use TheatreCore\Entity\ContactPerson;
  5. use TheatreCore\Entity\Directories;
  6. use TheatreCore\Entity\Extranetusers;
  7. use TheatreCore\Entity\Persons;
  8. use TheatreCore\Traits\TheatreTrait;
  9. use DateInterval;
  10. use DateTime;
  11. use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
  12. use Doctrine\Persistence\ManagerRegistry;
  13. use Symfony\Contracts\Translation\TranslatorInterface;
  14. use TheatreCore\Entity\Texts;
  15. /**
  16.  * PersonsRepository
  17.  *
  18.  * This class was generated by the Doctrine ORM. Add your own custom
  19.  * repository methods below.
  20.  */
  21. class PersonsRepository extends ServiceEntityRepository
  22. {
  23.     use TheatreTrait;
  24.     private $em;
  25.     public $__table;
  26.     public $__table_object;
  27.     public $__idtable;
  28.     public $idperson;
  29.     // style de texte
  30.     protected $stylemore_text = array('imagep' => 'width:110px;''desctxt' => 'width:170px;');
  31.     // style de vignette
  32.     protected $format_vignette = array('width' => 130'height' => 100'direction' => 'thumb');
  33.     public function __construct(ManagerRegistry $registryTranslatorInterface $trImages $images)
  34.     {
  35.         parent::__construct($registryPersons::class);
  36.         $this->__table $this->getClassMetadata()->getTableName();
  37.         $this->__table_object $this->getClassMetadata()->name;
  38.         $this->__idtable $this->getClassMetadata()->getSingleIdentifierFieldName();
  39.         $this->idperson null;
  40.         $this->translator $tr;
  41.         $this->images $images;
  42.     }
  43.     /**
  44.      * Prepare attributes for entity
  45.      * replace foreign keys with entity instances
  46.      *
  47.      * @param array $attributes entity attributes
  48.      * @return array modified attributes values
  49.      */
  50.     public function prepareAttributes(array $attributes)
  51.     {
  52.         foreach ($attributes as $fieldName => &$fieldValue) {
  53.             if (!$this->getClassMetadata()->hasAssociation($fieldName)) {
  54.                 continue;
  55.             }
  56.             $association $this->getClassMetadata()
  57.                 ->getAssociationMapping($fieldName);
  58.             if (is_null($fieldValue)) {
  59.                 continue;
  60.             }
  61.             $fieldValue $this->getEntityManager()
  62.                 ->getReference($association['targetEntity'], $fieldValue);
  63.             unset($fieldValue);
  64.         }
  65.         return $attributes;
  66.     }
  67.     //  {{{ findData()
  68.     /** Recherche des personnes
  69.      *
  70.      * Permet de rechercher des personnes en fonction de certains critères :
  71.      * la première lettre, un bout du nom, le type de personne, si il est en ligne ou pas
  72.      *
  73.      * @access  public
  74.      * @see     Theatre::find()
  75.      */
  76.     public function findData($idperson null$lettre null$keywords null$search null)
  77.     {
  78.         $query $this->createQueryBuilder('e');
  79.         // parametres
  80.         if (isset($_REQUEST['idperson']) && is_numeric($_REQUEST['idperson'])) {
  81.             $idperson $_REQUEST['idperson'];
  82.         }
  83.         if (isset($_REQUEST['idcontact_ecole']) && is_numeric($_REQUEST['idcontact_ecole'])) {
  84.             $idcontact_ecole $_REQUEST['idcontact_ecole'];
  85.             $search 'idcontact_ecole';
  86.         }
  87.         if (isset($_REQUEST['lettre']) && !empty($_REQUEST['lettre'])) {
  88.             $lettre $_REQUEST['lettre'];
  89.         }
  90.         if (isset($_REQUEST['keywords']) && $_REQUEST['keywords'] != 'nom' && !empty($_REQUEST['keywords'])) {
  91.             $keywords $_REQUEST['keywords'];
  92.             // si keywords est un entier => recherche par id
  93.             if ($this->my_is_int($keywords)) {
  94.                 $idperson = (int)$keywords;
  95.                 $keywords null;
  96.             }
  97.         }
  98.         if (isset($_REQUEST['search']) && !empty($_REQUEST['search'])) {
  99.             $search $_REQUEST['search'];
  100.         }
  101.         // select ou select as
  102.         if (empty($search) || isset($_REQUEST['typeobj'])) {
  103. //            $this->selectAdd();
  104. //            $this->selectAdd('idperson,lastname,firstname,country,url_clean,language,language2,publish,valid');
  105.         } else {
  106. //            $this->selectAs();
  107. //            $this->selectAs(array('idperson,lastname,firstname,country,url_clean,language,language2,publish,valid'));
  108.         }
  109.         //recherche stricte par id
  110.         if (!empty($idperson)) {
  111. //            $this->whereAdd('persons.idperson='.$idperson);
  112.             $query->andWhere('e.idperson = ' $idperson);
  113.         }
  114.         // recherche par mot cles
  115.         if (!empty($lettre)) {
  116. //            $this->whereAdd('lastname REGEXP \'^'.$lettre.'\' ');
  117. //            $query->andWhere('e.idperson = '.$idperson);
  118.             $query->andWhere(' ( (e.lastname LIKE \'%' $this->escape($lettre) . '%\')');
  119.             $query->andWhere(' ( (e.idperson = ' $idperson);
  120.         }
  121.         if (!empty($keywords)) {
  122.             $list $this->splitKeywords($keywords);
  123.             if ($list) {
  124.                 // si la liste est > 1 alors 0 = prénom et 1 = nom ou le contraire
  125.                 if (count($list[$this->IDSTR]) == 2) {
  126. //                    $this->whereAdd('(lastname LIKE \'%'.$list[$this->IDSTR][0].'%\'
  127. //                                            AND firstname LIKE \'%'.$list[$this->IDSTR][1].'%\')
  128. //                                    OR (firstname LIKE \'%'.$list[$this->IDSTR][0].'%\'
  129. //                                            AND lastname LIKE \'%'.$list[$this->IDSTR][1].'%\')');
  130.                     $query->andWhere(' (e.lastname LIKE \'%' $list[$this->IDSTR][0] . '%\'
  131.                                             AND e.firstname LIKE \'%' $list[$this->IDSTR][1] . '%\')
  132.                                     OR (e.firstname LIKE \'%' $list[$this->IDSTR][0] . '%\'
  133.                                             AND e.lastname LIKE \'%' $list[$this->IDSTR][1] . '%\') ');
  134.                 } else {
  135.                     // mots clés
  136.                     foreach ($list[$this->IDSTR] as $s) {
  137.                         $query->orWhere('e.lastname LIKE \'%' $s '%\'');
  138.                     }
  139.                 }
  140.                 /*if (!empty($list[$this->IDNUM])) {
  141.                     // recherche par numéro d'id pour les mots clés numériques
  142.                     $sql_where[] = array('idperson IN ('.implode(',', $list[$this->IDNUM]).')', 'OR');
  143.                 }*/
  144.             }
  145.         }
  146.         // selectionne uniquement les auteurs
  147.         if ($search == 'author') {
  148. //            $ta = DB_DataObject::factory('text_author');
  149. //            $this->joinAdd($ta);
  150. //            $this->selectAs();
  151. //            $this->selectAs($ta,'ta_%s');
  152. //            $query->addSelect('ta');
  153.         }
  154. //        // selectionne uniquement les traducteurs
  155.         if ($search == 'translator') {
  156. //            $tt = DB_DataObject::factory('text_translator');
  157. //            $this->joinAdd($tt);
  158. //            $this->selectAs();
  159. //            $this->selectAs($tt,'tt_%s');
  160.             $query->join('e.textTranslatortext''ttt');
  161.         }
  162.         // selectionne uniquement les metteurs en scenes
  163.         if ($search == 'director') {
  164. //            $sp = DB_DataObject::factory('spectacle_person');
  165. //            $this->joinAdd($sp);
  166. //            $this->selectAs();
  167. //            $this->selectAs($sp,'tt_%s');
  168.         }
  169. //        // selectionne les élèves d'une école
  170. //        if (!empty($idcontact_ecole)) {
  171. //            $pe = DB_DataObject::factory('person_ecole');
  172. //            $this->joinAdd($pe);
  173. //            $this->selectAs();
  174. //            $this->selectAs($pe,'pe_%s');
  175. //            $this->whereAdd('idcontact='.$idcontact_ecole);
  176. //        }
  177. //
  178. //        // selectionne les fiches hors ligne
  179. //        if (isset($_REQUEST['publish']) && $_REQUEST['publish']=='no') {
  180. //            $this->whereAdd('publish=0');
  181. //        }
  182. //        $this->groupBy('persons.idperson');
  183.         $query->orderBy('e.idperson''DESC');
  184.         // on lance la recherche
  185.         return $query->getQuery();
  186.     }
  187.     // }}}
  188.     //  {{{ setToArray()
  189.     /** Liste des personnes dans un tableau associatif
  190.      *
  191.      * Tableau associatif notament utilisé pour lister les informations sur des personnes
  192.      * Utile pour générer les tableaux HTML de listes de personnes
  193.      *
  194.      * @access  public
  195.      * @return  array
  196.      * @see     findData()
  197.      */
  198.     public function setToArray($spec true)
  199.     {
  200.         // recherche
  201.         if ($spec == true) {
  202.             $this->findData();
  203.         }
  204.         $values = array();
  205.         $color null;
  206.         $nb 0;
  207.         while ($this->fetch()) {
  208.             $values[$nb] = $this->getInfosPerson();
  209.             $values[$nb]['id'] = $this->idperson;
  210.             // couleur de ligne alternative
  211.             $color $this->colorAlternate($color);
  212.             $values[$nb]['colorline'] = $color;
  213.             $nb++;
  214.         }
  215.         return $values;
  216.     }
  217.     // }}}
  218.     //  {{{ getInfosPerson()
  219.     /** Informations sur une personne
  220.      *
  221.      * Permet de récupérer sous forme de tableau associatif
  222.      * les informations complete sur une personne (sauf contenu associe)
  223.      *
  224.      * @access  public
  225.      * @param int $idperson id de la personne pour une recherche hors contexte
  226.      * @return  array
  227.      */
  228.     public function getInfosPerson($idperson null$params = array())
  229.     {
  230.         $infos = array();
  231.         // infos de la table
  232.         if (!empty($idperson)) {
  233.             $query $this->createQueryBuilder('u')
  234.                 ->select('u')
  235.                 ->where('u.' $this->__idtable ' =:value')->setParameter('value'$idperson);
  236.             $datas $query->getQuery()
  237.                 ->getOneOrNullResult();
  238.             $this->idperson $datas->getIdperson();
  239.         } else {
  240.             $idperson $this->idperson;
  241.         }
  242.         $lastname = (!empty($this->lastname)) ? $this->lastname $datas->getLastname();
  243.         $firstname = (!empty($this->firstname)) ? $this->firstname $datas->getFirstname();
  244.         $infos += array(
  245.             'lastname' => (!empty($this->lastname)) ? $this->lastname $datas->getLastname(),
  246.             'firstname' => (!empty($this->firstname)) ? $this->firstname $datas->getFirstname(),
  247.             'sexe' => (!empty($this->sexe)) ? $this->sexe $datas->getSexe(),
  248.             'idperson' => (!empty($this->idperson)) ? $this->idperson $datas->getIdperson(),
  249.             'is_author' => $this->isAuthor(),
  250.             'is_translator' => $this->isTranslator(),
  251.             //'is_adaptateur' => $this->isAdaptateur(),
  252.             'is_director' => $this->isDirector(),
  253.             'publish' => (!empty($this->publish)) ? $this->publish $datas->getPublish(),
  254.             'valid' => (!empty($this->valid)) ? $this->valid $datas->getValid(),
  255.             'url_clean' => (!empty($this->urlClean)) ? $this->urlClean $datas->getUrlClean(),
  256.             'datestart' => (!empty($this->datestart)) ? $this->datestart $datas->getDatestart(),
  257.             'dateend' => (!empty($this->dateend)) ? $this->dateend $datas->getDateend(),
  258.             'idcorvin' => $datas->getIdCorvin(),
  259.         );
  260.         if (!empty($this->country)) {
  261.             $infos['country'] = $this->getNameCountry($this->country);
  262.             $infos['country_code'] = $this->country;
  263.         } else if ($datas->getCountry()) {
  264.             $infos['country'] = $this->getNameCountry($datas->getCountry()->getId());
  265.             $infos['country_code'] = $datas->getCountry()->getId();
  266.         }
  267.         if (!empty($this->language)) {
  268.             $infos['language'] = $this->getNameLanguage($this->language$GLOBALS['lng']);
  269.             $infos['language_code'] = $this->language;
  270.         } else if (!empty($datas->getLanguage())) {
  271.             $infos['language'] = $this->getNameLanguage($datas->getLanguage(), $GLOBALS['lng']);
  272.             $infos['language_code'] = $datas->getLanguage();
  273.         }
  274.         // nom complet
  275.         $has_lastname = !empty($lastname);
  276.         $has_firstname = !empty($firstname);
  277.         if ($has_lastname && $has_firstname) {
  278.             $infos['fullname'] = $firstname ' ' $lastname;
  279.         } else {
  280.             if ($has_lastname) {
  281.                 $infos['fullname'] = $lastname;
  282.             } else if ($has_firstname) {
  283.                 $infos['fullname'] = $firstname;
  284.             } else {
  285.                 $infos['fullname'] = ''// ne devrait pas se produire
  286.             }
  287.         }
  288.         // retrouver les comptes mon théâtre associés
  289.         if (array_key_exists('get_extranetusers'$params)) {
  290.             $infos['extranetusers'] = $this->getEntityManager()->getRepository(Extranetusers::class)->getObjectExtranetusers('person'$infos['idperson']);
  291.             $infos['nb_extranetusers'] = count($infos['extranetusers']);
  292.         }
  293.         // retrouver les fiches annuaires associées
  294.         if (array_key_exists('get_directories'$params)) {
  295.             $infos['directories'] = $this->getEntityManager()->getRepository(Directories::class)->getDirectoriesByObject('person'$infos['idperson']);
  296.             $infos['nb_directories'] = count($infos['directories']);
  297.         }
  298.         // retrouver les contacts associés
  299.         if (array_key_exists('get_contact_persons'$params)) {
  300.             $infos['contact_persons'] = $this->getEntityManager()->getRepository(ContactPerson::class)->getContacts($infos['idperson']);
  301.             $infos['nb_contact_persons'] = count($infos['contact_persons']);
  302.         }
  303.         if (!empty($params_display['carrer_couleurs'])) {
  304.             $infos['carrer'] = $this->getObjectsCarrerDetails($infos['idperson'], 'persons');
  305.         }
  306.         return $infos;
  307.     }
  308.     // }}}
  309.     //  {{{ getTextsPerson()
  310.     /** Textes d'une personne
  311.      *
  312.      * Permet de récupérer sous forme de tableau associatif
  313.      * les enregistrements de la table 'texts' liés à l'auteur
  314.      *
  315.      * @access  public
  316.      * @param string $type Type de texte (original, traduction...)
  317.      * @param int $idtextoriginal id du texte original pour la recherche d'un traduction
  318.      * @param int $idperson id de la personne pour une recherche hors contexte
  319.      * @param int $publish textes publie ou pas ?
  320.      * @return  array
  321.      */
  322.     public function getTextsPerson($idperson null$type 'original'$publish null$language null$idtextoriginal null$std_result false)
  323.     {
  324.         $conn $this->getEntityManager();
  325.         $texts = array();
  326.         // cast
  327.         $idperson = ((int)$idperson);
  328.         $idtextoriginal = ((int)$idtextoriginal);
  329.         $sql null;
  330.         $select_fields_tabs = array('idtext''title''date''type''language''country''idcontact_publisher''isbn''ean''publication_year''nbpages''idgenretext''textorder''url_clean');
  331.         foreach ($select_fields_tabs as $k => $v) {
  332.             $select_fields_tabs_sql[] = 't.`' $v '`';
  333.         }
  334.         $select_fields join(','$select_fields_tabs_sql) . ',contacts.`organisation`, contacts.`url_clean` as url_clean_publisher ';
  335.         // les textes originaux
  336.         if ($type == 'original') {
  337.             $sql 'SELECT ' $select_fields '
  338.                         FROM text_author ta, texts t
  339.                             LEFT JOIN contacts ON contacts.idcontact=t.idcontact_publisher
  340.                         WHERE 1
  341.                         AND t.idtext=ta.idtext
  342.                         AND ta.idperson=' $idperson '
  343.                         AND t.type=0';
  344.             // filtre sur le genre de texte original
  345.             if (isset($this->byGenreText) && $this->byGenreText == 1) {
  346.                 $sql .= ' AND (t.idgenretext=1 OR t.idgenretext IS NULL)';
  347.             } elseif (isset($this->byGenreText) && $this->byGenreText 1) {
  348.                 $sql .= ' AND t.idgenretext=' $this->byGenreText;
  349.             }
  350.         } // toutes les adaptations de texte faites par l'auteur
  351.         elseif ($type == 'adaptation') {
  352.             $sql 'SELECT ' $select_fields ', tad.`idtextadaptation`
  353.                     FROM text_adaptation tad
  354.                         JOIN texts t ON t.idtext=tad.idtextadaptation
  355.                         JOIN text_author ta ON t.idtext=ta.idtext
  356.                         LEFT JOIN contacts contacts ON contacts.idcontact=t.idcontact_publisher
  357.                     WHERE ta.idperson=' . (int)$idperson '
  358.                     AND t.type=2';
  359.         } // toutes les adaptations d'un texte faites par la langue du spectacle
  360.         elseif ($type == 'adaptation_by_language_spectacle') {
  361.             $sql 'SELECT ' $select_fields '
  362.                         FROM texts t
  363.                         LEFT JOIN contacts ON contacts.idcontact=t.idcontact_publisher
  364.                             WHERE (
  365.                             t.idtext IN(
  366.                                 SELECT t.idtext
  367.                                 FROM texts t
  368.                                     LEFT JOIN text_adaptation ta ON ta.idtext = ' $idtextoriginal '
  369.                                     LEFT JOIN text_spectacle ts ON ts.idtext = ta.idtextadaptation
  370.                                     LEFT JOIN spectacles s ON s.idspectacle = ts.idspectacle
  371.                                     LEFT JOIN contacts ON contacts.idcontact=t.idcontact_publisher
  372.                                     WHERE t.idtext = ta.idtextadaptation';
  373.             // on ignore les textes dans une langue
  374.             if (!empty($language)) {
  375.                 $sql .= ' AND s.language != \'' $language '\'';
  376.             }
  377.             $sql .= '
  378.                                 )
  379.                             OR t.idtext IN(
  380.                                 SELECT t.idtext
  381.                                 FROM spectacles s, text_spectacle ts, text_traduction tt, texts t
  382.                                             WHERE 1
  383.                                             AND ts.idtext = t.idtext
  384.                                             AND s.idspectacle = ts.idspectacle
  385.                                             AND t.idtext=tt.idtexttraduction
  386.                                             AND tt.idtext=' $idtextoriginal '
  387.                             )
  388.                         )';
  389.         } // toutes les traductions d'un texte (page 26 du CDC) TODO = voir a mettre dans la classe texte ?
  390.         elseif ($type == 'translation') {
  391.             $sql 'SELECT ' $select_fields '
  392.                         FROM text_traduction tt, texts t
  393.                             LEFT JOIN contacts ON contacts.idcontact=t.idcontact_publisher
  394.                         WHERE 1
  395.                         AND t.idtext=tt.idtexttraduction
  396.                         AND tt.idtext=' $idtextoriginal '
  397.                         AND t.type=1';
  398.             // uniquement les traductions dans une langue
  399.             if (!empty($language)) {
  400.                 $sql .= ' AND t.language=\'' $language '\'';
  401.             }
  402.         } // recuperer les six dernieres traductions (page 59 du CDC)
  403.         elseif ($type == 'search_translation') {
  404.             $sql 'SELECT ' $select_fields '
  405.                         FROM text_traduction tt, texts t
  406.                             LEFT JOIN contacts ON contacts.idcontact=t.idcontact_publisher
  407.                         WHERE 1
  408.                         AND t.idtext=tt.idtexttraduction
  409.                         AND t.type=1
  410.                         AND tt.idtext IN (
  411.                             SELECT DISTINCT(t.idtext) FROM texts t,text_author ta
  412.                             WHERE 1';
  413.             if (!empty($publish)) {
  414.                 $sql .= '   AND t.publish=1';
  415.             }
  416.             $sql .= '
  417.                             AND t.idtext=ta.idtext
  418.                             AND ta.idperson=' $idperson '
  419.                     )';
  420.             // uniquement les traductions dans une langue
  421.             if (!empty($language)) {
  422.                 $sql .= ' AND t.language=\'' $language '\' ';
  423.             }
  424.             //piece recherchee
  425.             if (!empty($idtextoriginal)) {
  426.                 $idtextsearch $idtextoriginal;
  427.                 $sql .= ' AND tt.idtext=' $idtextsearch;
  428.             }
  429.         } // recherche les traductions d'une personne
  430.         elseif ($type == 'translator_translation') {
  431.             $sql 'SELECT ' $select_fields '
  432.                          FROM text_traduction tt, text_translator ttr, texts t
  433.                             LEFT JOIN contacts ON contacts.idcontact=t.idcontact_publisher
  434.                          WHERE 1
  435.                          AND t.idtext=tt.idtexttraduction
  436.                          AND t.idtext=ttr.idtext
  437.                          AND ttr.idperson=' $idperson '
  438.                          AND t.type=1';
  439.         } elseif ($type == 'translator_translation_count') {
  440.             $sql 'SELECT COUNT(t.`idtext`) AS total
  441.                          FROM text_traduction tt, text_translator ttr, texts t
  442.                             LEFT JOIN contacts ON contacts.idcontact=t.idcontact_publisher
  443.                          WHERE 1
  444.                          AND t.idtext=tt.idtexttraduction
  445.                          AND t.idtext=ttr.idtext
  446.                          AND ttr.idperson=' $idperson '
  447.                          AND t.type=1';
  448.             return $this->queryOne($sql);
  449.         } elseif ($type == 'count_all_texts_translations') {
  450.             $sql 'SELECT COUNT(DISTINCT(t.idtext))
  451.                         FROM text_traduction tt, texts t
  452.                         LEFT OUTER JOIN contacts ON contacts.idcontact=t.idcontact_publisher
  453.                         WHERE 1
  454.                         AND tt.idtexttraduction=t.idtext
  455.                         AND t.publish=1
  456.                         AND tt.idtext IN (
  457.                             SELECT idtext
  458.                             FROM text_author
  459.                             WHERE idperson=' $idperson '
  460.                         )
  461.             ';
  462.             return $this->queryOne($sql);
  463.         }
  464.         // uniquement les textes publies
  465.         if (!empty($publish)) {
  466.             $sql .= ' AND t.publish=1';
  467.         }
  468.         // pas les fictifs
  469.         $sql .= ' AND t.textfictif=0';
  470.         // classement
  471.         $order ' ORDER BY date DESC';
  472.         // groupement
  473.         $sql .= ' GROUP BY t.idtext';
  474.         // tri
  475.         $sql .= $order;
  476.         //objet texts
  477.         $txt $conn->getRepository(Texts::class);
  478.         // on lance la recherche
  479.         $txt->query($sql);
  480.         while ($txt->fetch()) {
  481.             $vignette = array('width' => $_ENV['VIGN_TEXT_WIDTH'], 'height' => $_ENV['VIGN_TEXT_HEIGHT'], 'direction' => 'thumb');
  482.             if ($std_result) {
  483.                 $texts[$txt->idtext] = $txt->getInfosTextRow(true$vignettetruetrue);
  484.                 continue;
  485.             }
  486.             $infotxt = array();
  487.             // s'agit-il d'une adaptation
  488.             if ($type == 'adaptation') {
  489.                 $idtext $txt->idtextoriginal;
  490.             } else {
  491.                 $idtext $txt->idtext;
  492.             }
  493.             // infos communes
  494.             if ($GLOBALS['module'] == 'theduc') {
  495.                 $pb_publisher true;
  496.             } else {
  497.                 $pb_publisher false;
  498.             }
  499.             $infotxt $txt->getInfosTextRow(falsefalsetrue$pb_publisher);
  500.             $infotxt['language'] = $txt->getNameLanguage($txt->language);
  501.             $infotxt['country'] = $txt->getNameCountry($txt->country);
  502.             //pour les adapations
  503.             if ($type == 'adaptation') {
  504.                 $infotxt['idtextoriginal'] = $txt->idtextoriginal;
  505.                 $infotxt['idtextadaptation'] = $txt->idtextadaptation;
  506.                 // recuperer les auteurs du text adapte
  507.                 $infotxt['textadaptationauthors'] = $this->getAuthors($txt->idtextoriginal);
  508.                 // recuperer le titre du text adapte et son identifiant (array)
  509.                 $infotxt['textadaptation'] = $this->getInfoText($txt->idtextoriginal);
  510.             }
  511.             // $infotxt = $txt->getInfosTextRow($txt->idtext,$this->format_vignette);
  512.             $infotxt['stylemore'] = array('imagep' => 'width:60px;''desctxt' => 'width:400px;');
  513.             $infotxt['publisher_first'] = true;
  514.             $texts[$idtext] = $infotxt;
  515.         }
  516.         // retourner les enregistrements
  517.         return $texts;
  518.     }
  519.     // }}}
  520.     //  {{{ isAuthor()
  521.     /** Voir si c'est un auteur de texte original (type=0)
  522.      *
  523.      * @access public
  524.      * @return bool
  525.      */
  526.     public function isAuthor($idperson null$idcontact_publisher null)
  527.     {
  528.         if (empty($idperson)) {
  529.             $idperson $this->idperson;
  530.         }
  531.         $sql 'SELECT COUNT(DISTINCT(t.idtext))
  532.                 FROM text_author ta, texts t
  533.                 WHERE t.idtext=ta.idtext AND t.textfictif=0
  534.                 AND ta.idperson=' . (int)$idperson;
  535.         if ($_ENV['CHECK_IF_ONLINE']) {
  536.             $sql .= ' AND t.publish=1';
  537.         }
  538.         // si on recherche spécifiquement chez un editeur
  539.         if ($idcontact_publisher && $this->my_is_int($idcontact_publisher)) {
  540.             $sql .= ' AND t.idcontact_publisher=' $idcontact_publisher;
  541.             // on trouve aussi le nombre de traductions des textes de cet auteur chez cet éditeur
  542.             $sql_trads 'SELECT COUNT(DISTINCT(t.idtext)) as total
  543.                             FROM text_traduction tt, texts t
  544.                             WHERE 1
  545.                             AND t.idtext=tt.idtexttraduction
  546.                             AND t.idcontact_publisher=' $idcontact_publisher '
  547.                             AND t.textfictif=0
  548.                             AND tt.idtext IN (
  549.                                 SELECT idtext FROM text_author WHERE idperson=' $idperson '
  550.                             )';
  551.             if ($_ENV['CHECK_IF_ONLINE']) {
  552.                 $sql .= ' AND t.publish=1';
  553.             }
  554.             $nb_trads $this->queryOne($sql_trads);
  555.         } else {
  556.             // TODO
  557.             $sql .= ' AND t.type IN (0,2) ';
  558.         }
  559.         $nb_textes $this->queryOne($sql);
  560.         if (!empty($nb_trads)) {
  561.             return $nb_textes $nb_trads;
  562.         } else {
  563.             return $nb_textes;
  564.         }
  565.     }
  566.     // }}}
  567.     //  {{{ isAdaptateur()
  568.     /** Voir si c'est un adaptateur (type=2)
  569.      *
  570.      * @access public
  571.      * @return bool
  572.      */
  573.     public function isAdaptateur($idperson null)
  574.     {
  575.         if (empty($idperson)) {
  576.             $idperson $this->idperson;
  577.         }
  578.         $sql 'SELECT COUNT(DISTINCT(t.idtext)) as total
  579.                 FROM text_author ta, texts
  580.                 WHERE 1
  581.                 AND t.idtext=ta.idtext
  582.                 AND t.textfictif=0
  583.                 AND ta.idperson=' $idperson '
  584.                 AND t.type=2';
  585.         if ($_ENV['CHECK_IF_ONLINE']) {
  586.             $sql .= ' AND t.publish=1';
  587.         }
  588.         return $this->queryOne($sql);
  589.     }
  590.     // }}}
  591.     //  {{{ isTranslator()
  592.     /** Voir si c'est un traducteur
  593.      *
  594.      * @access public
  595.      * @return bool
  596.      */
  597.     public function isTranslator($idperson null$idcontact_publisher null)
  598.     {
  599.         if (empty($idperson)) {
  600.             $idperson $this->idperson;
  601.         }
  602.         $sql 'SELECT COUNT(DISTINCT(tt.idtext)) as total
  603.                 FROM text_translator tt, texts t
  604.                 WHERE 1
  605.                 AND t.idtext=tt.idtext
  606.                 AND t.textfictif=0
  607.                 AND tt.idperson=' $idperson;
  608.         if ($_ENV['CHECK_IF_ONLINE']) {
  609.             $sql .= ' AND t.publish=1';
  610.         }
  611.         // si on recherche spécifiquement chez un editeur
  612.         if ($idcontact_publisher) {
  613.             $sql .= ' AND t.idcontact_publisher=' . ((int)$idcontact_publisher);
  614.         }
  615.         return $this->queryOne($sql);
  616.     }
  617.     // }}}
  618.     //  {{{ isDirector()
  619.     /** Voir si c'est un metteur en scene
  620.      *
  621.      * @access public
  622.      * @return bool
  623.      */
  624.     public function isDirector($idperson null)
  625.     {
  626.         if (empty($idperson)) {
  627.             $idperson $this->idperson;
  628.         }
  629.         $sql 'SELECT COUNT(DISTINCT(sp.idspectacle)) as total
  630.                 FROM spectacle_person sp, spectacles s
  631.                 WHERE 1
  632.                 AND sp.idspectacle=s.idspectacle
  633.                 AND sp.idperson=' $idperson '
  634.                 AND sp.idrole=1';
  635.         if ($_ENV['CHECK_IF_ONLINE']) {
  636.             $sql .= ' AND s.publish=1';
  637.         }
  638.         return $this->queryOne($sql);
  639.     }
  640.     // }}}
  641.     //  {{{ getAuthors()
  642.     /** Récupération des auteurs d'un texte
  643.      *
  644.      * @access public
  645.      * @return array
  646.      */
  647.     public function getAuthors($idtext null)
  648.     {
  649.         if (!empty($idtext)) {
  650.             // objet texts
  651.             $text $this->getEntityManager()->getRepository(Texts::class);
  652.             return $text->getAuthors($idtext);
  653.         }
  654.     }
  655.     // }}}
  656.     //  {{{ getTextTitle()
  657.     /** Récupération du titre d'un texte
  658.      *
  659.      * @access public
  660.      * @return array
  661.      */
  662.     public function getInfoText($idtext null)
  663.     {
  664.         if (empty($idtext)) $idtext $this->idtext;
  665.         $texts $this->getEntityManager()->getRepository(Texts::class);
  666.         return $texts->getObjectTitle($idtext, array(), array('noauthor' => true'return_array' => true));
  667.     }
  668.     // }}}
  669.     //  {{{ orderByDefaut()
  670.     /** Classement par défaut
  671.      *
  672.      * Défini le tri par défaut pour les requêtes de type SELECT
  673.      *
  674.      * @access public
  675.      * @return string
  676.      */
  677.     public function orderByDefaut($order null)
  678.     {
  679.         if (empty($order)) $order 'persons.idperson';
  680.         return $order;
  681.     }
  682.     // }}}
  683.     //  {{{ getListSearch()
  684.     /** Liste de personnes
  685.      *
  686.      * Pour les champs Ajax de relations et les recherches diverses
  687.      *
  688.      * @access  public
  689.      * @param string $lettres Pour la recherche alphabetique
  690.      * @param string $type Pour le type recherche (traducteur, auteur...)
  691.      * @param string $keywords Recherche par mots cles
  692.      * @return  array
  693.      */
  694.     public function getListSearch($lettre$type null$keywords null)
  695.     {
  696.         $sql 'SELECT p.`idperson`, p.`firstname`, p.`lastname`
  697.                  FROM ' $this->__table ' p
  698.                  WHERE 1 ';
  699.         // selection par ordre alpha
  700.         if (!empty($lettre)) {
  701.             $sql_where[] = array('LOWER(LEFT(LTRIM(p.`lastname`),1))=\'' $this->escape($lettre) . '\'');
  702.         }
  703.         // recherche avec un mot cle
  704.         $list $this->splitKeywords($keywords);
  705.         if ($list) {
  706.             if (!empty($list[$this->IDSTR])) {
  707.                 // si la liste est > 1 alors 0 = prénom et 1 = nom ou le contraire
  708.                 if (count($list[$this->IDSTR]) == 2) {
  709.                     $sql_where[] = array('(p.`lastname` LIKE \'%' $list[$this->IDSTR][0] . '%\' AND p.`firstname` LIKE \'%' $list[$this->IDSTR][1] . '%\')
  710.                                     OR (p.`firstname` LIKE \'%' $list[$this->IDSTR][0] . '%\' AND p.`lastname` LIKE \'%' $list[$this->IDSTR][1] . '%\')');
  711.                 } else {
  712.                     // mots clés
  713.                     foreach ($list[$this->IDSTR] as $s) {
  714.                         $sql_more_name[] = 'p.`lastname` LIKE \'%' $s '%\'';
  715.                     }
  716.                     $sql_where[] = array('(' join(' OR '$sql_more_name) . ')');
  717.                 }
  718.             }
  719.             if (!empty($list[$this->IDNUM])) {
  720.                 // recherche par numéro d'id pour les mots clés numériques
  721.                 $sql_where[] = array('p.`idperson` IN (' implode(','$list[$this->IDNUM]) . ')''OR');
  722.             }
  723.         }
  724.         // on recherche par type
  725.         if ($type == 'translator') {
  726.             $sql_more 'SELECT DISTINCT(idperson) FROM text_translator';
  727.             $sql_where[] = array('p.`idperson` IN (' $sql_more ')''AND');
  728.         }
  729.         if ($type == 'author') {
  730.             $sql_more 'SELECT DISTINCT(idperson) FROM text_author';
  731.             $sql_where[] = array('p.`idperson` IN (' $sql_more ')''AND');
  732.         }
  733.         // uniquement associé à un multimedia
  734.         if ($type == 'multimedia') {
  735.             $sql_more 'SELECT DISTINCT(idobject) FROM object_multimedia WHERE object=\'persons\'';
  736.             $sql_where[] = array('p.`idperson` IN (' $sql_more ')''AND');
  737.         }
  738.         // recherche AND ou autre
  739.         foreach ($sql_where as $k => $v) {
  740.             if (!empty($v[1])) {
  741.                 $sql .= ' ' $v[1] . ' ' $v[0];
  742.             } else {
  743.                 $sql .= ' AND ' $v[0];
  744.             }
  745.         }
  746.         $sql .= ' ORDER BY p.`lastname`, p.`firstname`';
  747.         $this->query($sql);
  748.         $r = array();
  749.         while ($this->fetch()) {
  750.             $r[$this->idperson] = mb_strtoupper($this->lastname) . ' ' $this->firstname;
  751.             // si trouvé par id, on l'affiche en fin de titre
  752.             if (!empty($list[$this->IDNUM]) && in_array($this->idperson$list[$this->IDNUM])) {
  753.                 $r[$this->idperson] .= ' - n°' $this->idperson;
  754.             }
  755.         }
  756.         $this->free();
  757.         return $r;
  758.     }
  759.     // }}}
  760.     //  {{{ getObjectTitle()
  761.     /** Infos de l'item recherché
  762.      *
  763.      *
  764.      * @access public
  765.      * @param int $idobject Identifiant de l'item
  766.      * @param array $infos_object Informations pour construire le titre
  767.      * @param array $params Paramétres supplémentaires
  768.      * @return string|array
  769.      */
  770.     public function getObjectTitle($idobject null$infos_object = array(), $params = array())
  771.     {
  772.         if (!$idobject && isset($this->idperson)) {
  773.             $idobject $this->idperson;
  774.         }
  775.         if (is_object($idobject)) {
  776.             $idobject $idobject->getIdperson();
  777.         }
  778.         // champs
  779.         $fields = array('idperson''lastname''firstname');
  780.         if (!empty($infos_object)) {
  781.             // Pour les données chargés grace à Doctrine
  782.             $fields[] = 'urlClean';
  783.             foreach ($fields as $k => $v) {
  784.                 if (array_key_exists($v$infos_object)) {
  785.                     $infos[$v] = $infos_object[$v];
  786.                 } else {
  787.                     $infos[$v] = '';
  788.                 }
  789.             }
  790.         } else {
  791.             //charger les infos que si necessaire
  792.             if (empty($this->lastname)) {
  793.                 // Pour les données chargés grace à du SQL native
  794.                 $fields[] = 'url_clean';
  795.                 $sql 'SELECT ' implode(','$fields) . '
  796.                         FROM ' $this->__table '
  797.                         WHERE ' $this->__idtable '=' $idobject;
  798.                 $infos $this->queryRow($sql);
  799.             } else {
  800.                 // Pour les données chargés grace à Doctrine
  801.                 $fields[] = 'urlClean';
  802.                 foreach ($fields as $k => $v) {
  803.                     if (isset($this->$v) && $this->$v != '') {
  804.                         $infos[$v] = trim($this->$v);
  805.                     } else {
  806.                         $infos[$v] = '';
  807.                     }
  808.                 }
  809.             }
  810.         }
  811.         // changer l'ordre si besoin
  812.         if (in_array('inverse'$params)) {
  813.             if (!empty($infos['firstname'])) {
  814.                 $infos['title'] = $infos['firstname'] . ' ' $infos['lastname'];
  815.             } else {
  816.                 $infos['title'] = $infos['lastname'];
  817.             }
  818.         } else {
  819.             $infos $infos ?: [];
  820.             $infos['lastname_oupper'] = mb_strtoupper($infos['lastname']);
  821.             if (!empty($infos['firstname'])) {
  822.                 $infos['title'] = $infos['lastname_oupper'] . ' ' $infos['firstname'];
  823.             } else {
  824.                 $infos['title'] = $infos['lastname_oupper'];
  825.             }
  826.         }
  827.         // renvoyer un array plutôt que le titre (utile si on veux l'url)
  828.         if (array_key_exists('return_array'$params)) {
  829.             return $infos;
  830.         }
  831.         return $infos['title'];
  832.     }
  833.     // }}}
  834.     //  {{{ byGenre()
  835.     /** Genre du texte pour une recherche
  836.      *
  837.      * chercher le titre traduit du texte dans une langue donnée
  838.      *
  839.      * @access  public
  840.      */
  841.     public function byGenre($idgenretext)
  842.     {
  843.         $this->byGenreText $idgenretext;
  844.     }
  845.     // }}}
  846.     //  {{{ getInfosObject()
  847.     /** Alias de getInfosPerson
  848.      *
  849.      * @access  public
  850.      * @param int $idobject identifiant
  851.      * @return  array
  852.      * @see     getInfosPerson()
  853.      */
  854.     public function getInfosObject($idobject null)
  855.     {
  856.         return $this->getInfosPerson($idobject);
  857.     }
  858.     // }}}
  859.     // {{{ getVignettePerson()
  860.     /** Récupére la vignette d'une personne ou la cree si besoin
  861.      *
  862.      * @access   public
  863.      * param     int $idperson identifiant de la fiche persons
  864.      * param     array $format format de l'image
  865.      * param     bool $return_only Ne pas retourner l'image par défaut
  866.      * @return   string
  867.      */
  868.     public function getVignettePerson($idperson null$format = array(), $return_only true)
  869.     {
  870.         if (!$idperson$idperson $this->idperson;
  871.         // par default : image normal 100px x 100px qualite 75
  872.         if ($format) {
  873.             $set_format $format;
  874.         } else {
  875.             $set_format = array('width' => 70'height' => 70'direction' => 'thumb');
  876.         }
  877.         // generation par la classe Images
  878.         $images $this->images;
  879.         $images->setVignetteFormat($set_format);
  880.         return $images->getVignetteObject($idperson'persons''class_photo_person'null1$return_only);
  881.     }
  882.     // }}}
  883.     // {{{ getVignette()
  884.     /** Récupére la vignette d'une personne ou la cree si besoin
  885.      *
  886.      * @see getVignettePerson
  887.      */
  888.     public function getVignette($idperson null$format = array())
  889.     {
  890.         return $this->getVignettePerson($idperson$format);
  891.     }
  892.     // }}}
  893.     //  {{{ getRelationsArray()
  894.     /** Décrit les relations de l'objet
  895.      *
  896.      * @access  public
  897.      * @param string|int $type si on souhaite retourner uniquement un type precis
  898.      * @see     Theatre::getLinkedObject()
  899.      */
  900.     public function getRelationsArray($type null)
  901.     {
  902.         $array_types = array(
  903.             'person_classification' => array(// classifications associées
  904.                 'type_join' => 'multiple',
  905.                 'dest_table' => 'classifications',
  906.                 'join_table' => 'person_classification',
  907.                 'fields' => array('idclassification''classification''type'),
  908.             ),
  909.             'text_person' => array(// persons liées à un texte
  910.                 'type_join' => 'multiple',
  911.                 'dest_table' => 'texts',
  912.                 'join_table' => 'text_person',
  913.                 'field_link' => 'idrole'//TODO
  914.                 'fields' => array('title''url_clean''valid'),
  915.             ),
  916.             // contact_person idcontact/idperson/idrole
  917.             'contact_person' => array(// contact associé à des personnes (direction d'une structure...)
  918.                 'type_join' => 'multiple',
  919.                 'dest_table' => 'contacts',
  920.                 'join_table' => 'contact_person',
  921.                 'fields' => array('idcontact''organisation''url_clean'),
  922.                 'fields_join_table' => array('idoffice''date_start''date_end'),
  923.                 'description' => 'Personne(s) associée(s) au contact',
  924.             ),
  925.             // person annuaire
  926.             'directories' => array(// contact associé à des personnes (direction d'une structure...)
  927.                 'type_join' => 'simple',
  928.                 'dest_table' => 'directories',
  929.                 'fields' => array('idperson''idcontact'),
  930.                 'description' => 'Fiche(s) annuaire(s)',
  931.             ),
  932.             /*bookmark_extranetuser
  933.             contact_person
  934.             dvd_person
  935.             files
  936.             contents
  937.             new_person
  938.             object_content > object/idobject
  939.             object_file => object/idobject
  940.             object_multimedia => object/idobject
  941.             persons
  942.             person_classification
  943.             person_ecole
  944.             person_extranetuser
  945.             spectacle_person
  946.             stats => object/idobject
  947.             text_author
  948.             text_person
  949.             text_translator*/
  950.         );
  951.         // retourne uniquement un type précis
  952.         if (!empty($array_types[$type])) {
  953.             $array_types[$type]['type'] = $type;
  954.             return $array_types[$type];
  955.         } else {
  956.             return $array_types;
  957.         }
  958.     }
  959.     // }}}
  960.     //  {{{ getSQLPersons()
  961.     /** Générer la requete standard pour une person
  962.      *
  963.      * $params = array(
  964.      *  'select' => champs en plus pour le select,
  965.      *  'from' => champs en plus pour le from,
  966.      *  'where' => paramètres en plus le where,
  967.      *  'order' => classement des résultats,
  968.      *  'limit' => limiter le nb de résultats array(debut,fin), (all pour pas de limit)
  969.      * )
  970.      * $special = array(
  971.      *  'alpha' => recherche alphabétique sur le nom
  972.      *  'search' =>  recherche par mots-clés sur le nom
  973.      * )
  974.      *
  975.      *
  976.      * @access   public
  977.      * @param array $params Les paramètres pour la requete
  978.      * @param array $special Les paramètres supplémentaires
  979.      * @param bool $debug afficher la requête TODO
  980.      * @return   string
  981.      */
  982.     public function getSQLPersons($params = array(), $special = array(), $debug false)
  983.     {
  984.         $sql_join '';
  985.         if (empty($params['where'])) {
  986.             $params['where'] = '';
  987.         }
  988.         if (empty($params['from'])) {
  989.             $params['from'] = '';
  990.         }
  991.         if (empty($params['select'])) {
  992.             $params['select'] = '';
  993.         }
  994.         // selon une classification
  995.         if (!empty($special['idclassification'])) {
  996.             // commun
  997.             $params['from'] .= ' person_classification c1';
  998.             $params['where'] .= ' AND T1.idperson= c1.idperson
  999.                                   AND c1.idclassification=' . (int)$special['idclassification'];
  1000.         }
  1001.         // selon une personne
  1002.         if (!empty($special['idperson'])) {
  1003.             $params['where'] .= ' AND c1.idperson = ' . (int)$special['idperson'];
  1004.         }
  1005.         // role special dans un spectacle
  1006.         if (!empty($special['idrole'])) {
  1007.             // commun
  1008.             $params['from'] .= ' spectacle_person sp, spectacles s';
  1009.             $params['where'] .= ' AND T1.idperson=sp.idperson
  1010.                                  AND s.publish=1
  1011.                                  AND s.idspectacle=sp.idspectacle ';
  1012.             // si recherche table role ou direct id
  1013.             if (!$this->my_is_int($special['idrole'])) {
  1014.                 $params['from'] .= ', roles r';
  1015.                 $params['where'] .= ' AND sp.idrole=r.idrole
  1016.                                       AND r.role=\'' $this->escape($special['idrole']) . '\' ';
  1017.             } else {
  1018.                 $params['where'] .= ' AND sp.idrole=' . (int)$special['idrole'];
  1019.             }
  1020.         }
  1021.         // personnes avec photo
  1022.         if (!empty($special['with_photo'])) {
  1023.             $sql_join .= '
  1024.                     JOIN object_file of ON T1.`idperson`=of.`idobject`
  1025.                     JOIN files f ON of.`idfile`=f.`idfile`
  1026.                     JOIN file_classification fc ON f.`idfile`=fc.`idfile` ';
  1027.             // class_photo_person
  1028.             $params['where'] .= '
  1029.                     AND fc.`idclassification`=14
  1030.             ';
  1031.         }
  1032.         // sexe de la personne
  1033.         if (!empty($special['sexe'])) {
  1034.             $params['where'] .= ' AND sexe=' $this->getSexeValue($special['sexe']) . ' ';
  1035.         }
  1036.         // personne ayant un texte édité chez un éditeur
  1037.         if (!empty($special['contacts']['publishers'])) {
  1038.             //Les traducteurs
  1039.             if (!empty($special['translator'])) {
  1040.                 $sql_join .= 
  1041.                     JOIN text_author T3 ON T2.`idperson` = T3.`idperson`
  1042.                     JOIN texts t ON t.`idtext`=T3.`idtext` 
  1043.                 ';
  1044.             } //Les auteurs
  1045.             else if (empty($special['contacts']['desactive_jointure_author'])) {
  1046.                 $sql_join .= 
  1047.                     JOIN text_author T2 ON T2.`idperson` = T1.`idperson`
  1048.                     JOIN texts t ON t.`idtext`=T2.`idtext` 
  1049.                 ';
  1050.             }
  1051.             $params['where'] .= ' AND t.`idcontact_publisher` IN  (' $this->arrayToIn($special['contacts']['publishers']) . ') ';
  1052.         }
  1053.         // personnes à l'affiche
  1054.         if (!empty($special['spectacle'])) {
  1055.             $params['where'] .= '
  1056.                     AND s.`valid`=1
  1057.                     AND s.`publish`=1
  1058.                     AND s.`textfictif`=0
  1059.                     AND T1.`publish`=1 ';
  1060.             $roles_types = array(
  1061.                 'director' => array(1),
  1062.                 'actors' => array(5)
  1063.             );
  1064.             if (!empty($special['spectacle']['type'])) {
  1065.                 if ($special['spectacle']['type'] == 'author') {
  1066.                     $sql_join .= '
  1067.                             JOIN spectacle_author sa ON T1.`idperson`=sa.`idperson`
  1068.                             JOIN spectacles s ON sa.`idspectacle`=s.`idspectacle`
  1069.                             JOIN text_spectacle ts ON s.`idspectacle`=ts.`idspectacle`
  1070.                             JOIN texts t ON t.`idtext`=ts.`idtext` ';
  1071.                     $params['where'] .= ' AND t.`type` IN (0,1) ';
  1072.                 } elseif (array_key_exists($special['spectacle']['type'], $roles_types)) { // autres roles
  1073.                     $sql_join .= '
  1074.                             JOIN spectacle_person sp ON T1.`idperson`=sp.`idperson`
  1075.                             JOIN spectacles s ON sp.`idspectacle`=s.`idspectacle`
  1076.                             JOIN text_spectacle ts ON s.`idspectacle`=ts.`idspectacle`
  1077.                             JOIN texts t ON t.`idtext`=ts.`idtext` ';
  1078.                     $params['where'] .= ' AND sp.`idrole` IN (' join(','$roles_types[$special['spectacle']['type']]) . ') ';
  1079.                 } elseif ($special['spectacle']['type'] == 'all') {
  1080.                     $sql_join .= '
  1081.                             LEFT JOIN spectacle_author sa ON T1.`idperson`=sa.`idperson`
  1082.                             LEFT JOIN spectacle_person sp ON T1.`idperson`=sp.`idperson`
  1083.                             JOIN spectacles s ON s.idspectacle=sp.idspectacle
  1084.                             JOIN text_spectacle ts ON s.`idspectacle`=ts.`idspectacle`
  1085.                             JOIN texts t ON t.`idtext`=ts.`idtext` ';
  1086.                 }
  1087.             } else {
  1088.                 $sql_join .= '
  1089.                         JOIN spectacle_author sa ON T1.`idperson`=sa.`idperson`
  1090.                         JOIN spectacles s ON sa.`idspectacle`=s.`idspectacle`
  1091.                         JOIN text_spectacle ts ON s.`idspectacle`=ts.`idspectacle`
  1092.                         JOIN texts t ON t.`idtext`=ts.`idtext` ';
  1093.             }
  1094.             if (!empty($special['spectacle']['count_date'])) {
  1095.                 $params['select'] .= ' COUNT( sc.`idschedule` ) AS nb_dates ';
  1096.                 $params['groupby'] = ' T1.`idperson`, t.`idtext` ';
  1097.                 $params['order'] = ' nb_dates DESC ';
  1098.             }
  1099.             // uniquement certain type de text
  1100.             if (!empty($special['spectacle']['text']['type'])) {
  1101.                 $params['where'] .= ' AND t.`type` IN  (' $this->arrayToIn($special['spectacle']['text']['type']) . ') ';
  1102.             }
  1103.             $sql_join .= '
  1104.                     JOIN schedules sc ON s.`idspectacle`=sc.`idspectacle` ';
  1105.             if (!empty($special['spectacle']['prochains'])) {
  1106.                 $date = new \DateTime('now');
  1107.                 $date->add(new DateInterval('P' $special['spectacle']['prochains']));
  1108.                 $params['where'] .= ' AND sc.`date` BETWEEN \'' date('Y-m-d') . '\' AND \'' $date->format('Y-m-d') . '\' ';
  1109.             }
  1110.             if (!empty($special['spectacle']['saison'])) {
  1111.                 $s explode('-'$special['spectacle']['saison']);
  1112.                 $params['where'] .= ' AND sc.`date` BETWEEN \'' $s[0] . '-09-01\' AND \'' $s[1] . '-08-31\' ';
  1113.             }
  1114.             if (!empty($special['spectacle']['year'])) {
  1115.                 $params['where'] .= ' AND sc.`date` BETWEEN \'' . (int)$special['spectacle']['year'] . '-01-01\' AND \'' $special['spectacle']['year'] . '-12-31\' ';
  1116.             }
  1117.             if (!empty($special['spectacle']['person_periode'])) {
  1118.                 $date = new \DateTime('now');
  1119.                 $date->sub(new DateInterval('P70Y'));
  1120.                 if ($special['spectacle']['person_periode'] == 'public') {
  1121.                     $params['where'] .= ' AND (T1.`dateend`!=0 AND T1.`dateend`<=\'' $date->format('Y-m-d') . '\') ';
  1122.                 } elseif ($special['spectacle']['person_periode'] == 'contemporain') {
  1123.                     $params['where'] .= ' AND (T1.`dateend` IS NULL OR T1.`dateend` = 0 OR T1.`dateend`>=\'' $date->format('Y') . '\' ) ';
  1124.                 } else {
  1125.                     $params['where'] .= ' AND (T1.`dateend` IN (0,\'\') OR T1.`dateend` IS NULL) ';
  1126.                 }
  1127.             }
  1128.             if (!empty($special['spectacle']['text_edite'])) {
  1129.                 //$params['where'] .= ' AND T1.`idperson` IN (SELECT idperson FROM text_author JOIN texts WHERE text_author.idtext=texts.idtext AND texts.idcontact_publisher IS NOT NULL) ';
  1130.                 $params['where'] .= ' AND t.`idcontact_publisher` IS NOT NULL ';
  1131.             }
  1132.             if (!empty($special['spectacle']['periode'])) {
  1133.                 if (strpos($special['spectacle']['periode']['start'], '/') !== false) {
  1134.                     $datestart DateTime::createFromFormat('d/m/Y'$special['spectacle']['periode']['start']);
  1135.                     $dateend DateTime::createFromFormat('d/m/Y'$special['spectacle']['periode']['end']);
  1136.                 } else {
  1137.                     $datestart DateTime::createFromFormat('Y-m-d'$special['spectacle']['periode']['start']);
  1138.                     $dateend DateTime::createFromFormat('Y-m-d'$special['spectacle']['periode']['end']);
  1139.                 }
  1140.                 $params['where'] .= ' AND sc.`date` BETWEEN \'' $datestart->format('Y-m-d') . '\'
  1141.                                       AND \'' $dateend->format('Y-m-d') . '\' ';
  1142.             }
  1143.             if (!empty($special['spectacle']['idtypestructure'])) {
  1144.                 $sql_join .= ' JOIN contacts ON sc.`idcontact` = contacts.`idcontact` ';
  1145.                 $join_contact true;
  1146.                 if (is_array($special['spectacle']['idtypestructure'])) {
  1147.                     foreach ($special['spectacle']['idtypestructure'] as $k => $v) {
  1148.                         $idtypestructures[$k] = '\'' $v '\'';
  1149.                     }
  1150.                     $params['where'] .= ' AND contacts.`idtypestructure` IN (' join(','$idtypestructures) . ') ';
  1151.                 } else {
  1152.                     $params['where'] .= ' AND contacts.`idtypestructure`=\'' $special['spectacle']['idtypestructure'] . '\' ';
  1153.                 }
  1154.             }
  1155.             if (!empty($special['spectacle']['country'])) {
  1156.                 if (empty($join_contact)) {
  1157.                     $sql_join .= ' JOIN contacts ON sc.`idcontact`= contacts.`idcontact` ';
  1158.                 }
  1159.                 $params['where'] .= ' AND contacts.`country`=\'' $special['spectacle']['country'] . '\' ';
  1160.             }
  1161.         }
  1162.         // étudiants d'une école
  1163.         if (!empty($special['person_ecole'])) {
  1164.             foreach (array('url_clean''idcontact''organisation') as $f) {
  1165.                 $params['select'] .= ' cte.`' $f '` as contact_' $f ', ';
  1166.             }
  1167.             $params['select'] .= ' pe.*, YEAR(pe.`date_start`) as year_start, YEAR(pe.`date_end`) as year_end ';
  1168.             $sql_join .= ' JOIN person_ecole pe ON T1.`idperson`=pe.`idperson`
  1169.                            JOIN contacts cte ON pe.`idcontact`=cte.`idcontact` ';
  1170.             // pour un contact précis
  1171.             if (!empty($special['person_ecole']['idcontact'])) {
  1172.                 $params['where'] .= ' AND pe.`idcontact` IN (' $this->arrayToIn($special['person_ecole']['idcontact']) . ') ';
  1173.             }
  1174.             // pour un role
  1175.             if (!empty($special['person_ecole']['idrole'])) {
  1176.                 $sql_join .= ' JOIN ecole_role er ON pe.`idperson`=er.`idperson` ';
  1177.                 $params['where'] .= ' AND er.`idrole` IN (' $this->arrayToIn($special['person_ecole']['idrole']) . ') ';
  1178.             }
  1179.             if (!empty($special['person_ecole']['exclude_jtn'])) { // pas le JTN
  1180.                 $params['where'] .= ' AND pe.`idcontact`!=3914 ';
  1181.             }
  1182.             if (!empty($special['person_ecole']['periode'])) { // uniquement les actifs => date de fin vide
  1183.                 if ($special['person_ecole']['periode'] == 'actual') {
  1184.                     $params['where'] .= '
  1185.                     AND (
  1186.                         (pe.`date_end` IS NULL OR pe.`date_end`=\'0000-00-00 00:00:00\' OR pe.`date_end`>=\'' date('Y-m-d') . '\')
  1187.                         AND pe.`date_start`<=\'' date('Y-m-d') . '\'
  1188.                     )';
  1189.                 }
  1190.                 if ($this->my_is_int($special['person_ecole']['periode']) && strlen($special['person_ecole']['periode']) == 4) {
  1191.                     $params['where'] .= ' AND YEAR(pe.`date_end`)=\'' $special['person_ecole']['periode'] . '\' ';
  1192.                 }
  1193.             }
  1194.         }
  1195.         // directeur de structure en particulier
  1196.         if (!empty($special['contact_person'])) {
  1197.             $sql_join .= ' JOIN contact_person cp ON T1.`idperson`=cp.`idperson`
  1198.                            JOIN contacts c1 ON c1.`idcontact`=cp.`idcontact` ';
  1199.             $roles_types = array(
  1200.                 'directeur' => array(1),
  1201.                 'actors' => array(5)
  1202.             );
  1203.             // auteurs
  1204.             if (array_key_exists($special['contact_person']['idoffice'], $roles_types)) { // autres roles
  1205.                 $params['where'] .= ' AND cp.`idoffice` IN (' join(','$roles_types[$special['contact_person']['idoffice']]) . ') ';
  1206.             }
  1207.             if (array_key_exists('actual'$special['contact_person'])) { // uniquement les actifs
  1208.                 $params['where'] .= ' AND ((cp.`date_end` IS NULL OR cp.`date_end`=\'0000-00-00 00:00:00\' OR cp.`date_end`>=\'' date('Y-m-d') . '\') AND cp.`date_start`<=\'' date('Y-m-d') . '\')';
  1209.             }
  1210.             if (array_key_exists('idtypestructure'$special['contact_person'])) {
  1211.                 $params['where'] .= ' AND c1.`idtypestructure`=\'' $special['contact_person']['idtypestructure'] . '\' ';
  1212.             }
  1213.         }
  1214.         // recherche auteurs
  1215.         if (!empty($special['author'])) {
  1216.             $params['where'] = ' AND (
  1217.                         (T1.dateend=0 OR T1.dateend IS NULL OR T1.dateend>1970)
  1218.                         AND (
  1219.                                 T1.idperson IN
  1220.                                 (
  1221.                                     SELECT persons.idperson FROM persons, text_author, text_spectacle
  1222.                                     WHERE persons.idperson=text_author.idperson AND text_spectacle.idtext=text_author.idtext
  1223.                                     AND text_spectacle.idtext NOT IN (SELECT idtextadaptation FROM text_adaptation)
  1224.                                 )
  1225.                                 OR T1.idperson IN
  1226.                                 (
  1227.                                     SELECT persons.idperson FROM persons, text_author
  1228.                                     WHERE persons.idperson=text_author.idperson AND text_author.idtext IN (SELECT idtext FROM text_traduction)
  1229.                                 )
  1230.                             )
  1231.                         OR T1.idrole=21) ';
  1232.             if (!empty($special['contacts']['publishers'])) {
  1233.                 $params['where'] .= ' AND t.`idcontact_publisher` IN  (' $this->arrayToIn($special['contacts']['publishers']) . ') ';
  1234.             }
  1235.         }
  1236.         // rechecher traducteurs
  1237.         if (!empty($special['translator'])) {
  1238.             $params['from'] = array('text_translator' => 'join');
  1239.         }
  1240.         // francophone
  1241.         if (isset($special['is_francophone'])) {
  1242.             $params['where'] .= ' AND T1.`language`=\'fr\' ';
  1243.         }
  1244.         if (isset($special['is_non_francophone'])) {
  1245.             $params['where'] .= ' AND T1.`language`!=\'fr\' ';
  1246.         }
  1247.         // publié
  1248.         if (isset($special['publish'])) {
  1249.             $params['where'] .= ' AND T1.`publish`=' . (int)$special['publish'];
  1250.         }
  1251.         // tables et champs
  1252.         $tables_list = array(
  1253.             'persons' => array(
  1254.                 'fields' => array('lastname''firstname''url_clean'),
  1255.             ),
  1256.         );
  1257.         $al 1;
  1258.         foreach ($tables_list as $k => $v) {
  1259.             $tables_list[$k]['table_alias'] = $k ' T' $al;
  1260.             foreach ($v['fields'] as $f) {
  1261.                 $select_fields_array[] = 'T' $al '.' $f;
  1262.             }
  1263.             $al++;
  1264.         }
  1265.         // select de base
  1266.         $sql_select 'SELECT DISTINCT(T1.idperson), ' join(','$select_fields_array) . ' ';
  1267.         // select en plus
  1268.         if (array_key_exists('select'$params) && !empty($params['select'])) {
  1269.             $sql_select .= ',' $params['select'];
  1270.         }
  1271.         // compte seulement
  1272.         if (array_key_exists('count_only'$special)) {
  1273.             $sql_select 'SELECT COUNT(DISTINCT(T1.idperson)) as total ';
  1274.         }
  1275.         // récupère les lettres des prénoms
  1276.         if (array_key_exists('firstname_only'$special)) {
  1277.             $sql_select 'SELECT DISTINCT(UPPER(LEFT(T1.`lastname`, 1))) as letter ';
  1278.         }
  1279.         // from
  1280.         foreach ($tables_list as $k => $v) {
  1281.             $sql_from_tables[] = $v['table_alias'];
  1282.         }
  1283.         $sql_from ' FROM ' join(','$sql_from_tables);
  1284.         // déclaration si besoin de jointer avec la table persons
  1285.         $sql_join_more = array();
  1286.         // selectionde table en plus
  1287.         if (array_key_exists('from'$params) && !empty($params['from'])) {
  1288.             if (is_array($params['from'])) {
  1289.                 foreach ($params['from'] as $k => $v) {
  1290.                     $sql_from .= ',' $k ' T' $al;
  1291.                     // join avec la table principale ?
  1292.                     if ($v == 'join') {
  1293.                         $sql_join_more[] = ' T1.idperson=T' $al '.idperson';
  1294.                     }
  1295.                 }
  1296.                 $al++;
  1297.             } else {
  1298.                 $sql_from .= ',' $params['from'];
  1299.             }
  1300.         }
  1301.         // where standard
  1302.         $sql_where ' WHERE 1 ';
  1303.         if (!empty($sql_join_more)) {
  1304.             $sql_where .= ' AND ' join(' AND '$sql_join_more);
  1305.         }
  1306.         // paramètres en plus
  1307.         if (array_key_exists('where'$params)) {
  1308.             $sql_where .= $params['where'];
  1309.         }
  1310.         // recherche alpha
  1311.         if (array_key_exists('alpha'$special)) {
  1312.             $sql_where .= ' AND T1.lastname REGEXP \'^' $special['alpha'] . '\' ';
  1313.         }
  1314.         // recherche lastname
  1315.         if (array_key_exists('search'$special)) {
  1316.             // on split et on recherche sur les mots de plus de 2 cractères
  1317.             $keywords explode(' 'trim($special['search']));
  1318.             if (!empty($keywords)) {
  1319.                 foreach ($keywords as $k) {
  1320.                     $sql_keywords[] = ' T1.lastname LIKE \'' $this->escape('%' trim($k) . '%') . '\' ';
  1321.                 }
  1322.                 $sql_where .= ' AND (' join(' OR '$sql_keywords) . ') ';
  1323.             } else {
  1324.                 $sql_where .= ' AND T1.lastname LIKE \'' $this->escape('%' $special['search'] . '%') . '\' ';
  1325.             }
  1326.         }
  1327.         if (empty($special['count_only'])) {
  1328.             // groupement par défaut
  1329.             if (!array_key_exists('groupby'$params)) {
  1330.                 $groupby ' GROUP BY T1.idperson ';
  1331.             } else {
  1332.                 $groupby ' GROUP BY ' $params['groupby'];
  1333.             }
  1334.             // classement par défaut
  1335.             if (!array_key_exists('order'$params)) {
  1336.                 // si ancien, classement DESC
  1337.                 if (array_key_exists('desc'$special)) {
  1338.                     $classement 'DESC';
  1339.                 } else {
  1340.                     $classement 'ASC';
  1341.                 }
  1342.                 if (array_key_exists('classement'$params)) {
  1343.                     $classement $params['classement'];
  1344.                 }
  1345.                 $order ' ORDER BY T1.lastname ' $classement;
  1346.             } else {
  1347.                 $order ' ORDER BY ' $params['order'];
  1348.             }
  1349.             // classement aléatoire
  1350.             if (array_key_exists('random'$special)) {
  1351.                 $order ' ORDER BY RAND() ' $special['random'];
  1352.             }
  1353.         } else {
  1354.             $order null;
  1355.             $groupby null;
  1356.         }
  1357.         // limite par défaut
  1358.         if (!array_key_exists('limit'$params)) {
  1359.             $limit ' LIMIT 0,10';
  1360.         } else {
  1361.             if ($params['limit'] != 'all') {
  1362.                 $limit ' LIMIT ' $params['limit'][0] . ',' $params['limit'][1];
  1363.             } else {
  1364.                 $limit ' ';
  1365.             }
  1366.         }
  1367.         $sql_global $sql_select $sql_from $sql_join $sql_where $groupby $order $limit;
  1368.         return $sql_select $sql_from $sql_join $sql_where $groupby $order $limit;
  1369.     }
  1370.     // }}}
  1371.     //  {{{ countListPersons()
  1372.     /** Compter une requête préparée
  1373.      *
  1374.      * @access   public
  1375.      * @param array $params_sql paramètre pour la requete SQL
  1376.      * @param bool $debug mode débugage
  1377.      * @return   int
  1378.      */
  1379.     public function countListPersons($params_sql = array(), $debug false)
  1380.     {
  1381.         // si pas de tableau
  1382.         if (!isset($params_sql['special'])) {
  1383.             $params_sql['special'] = array();
  1384.         }
  1385.         if (!isset($params_sql['params'])) {
  1386.             $params_sql['params'] = array();
  1387.         }
  1388.         // si pas de limite => tout
  1389.         if (empty($params_sql['params']['limit'])) {
  1390.             $params_sql['params']['limit'] = 'all';
  1391.         }
  1392.         $params_sql['special']['count_only'] = true;
  1393.         // construction de la requête avec le passage de paramètres
  1394.         return $this->queryOne($this->getSQLPersons($params_sql['params'], $params_sql['special'], $debug));
  1395.     }
  1396.     // }}}
  1397.     //  {{{ getListPersons()
  1398.     /** Récupére la liste des persons
  1399.      *
  1400.      * Récupére les persons de manière standard
  1401.      *
  1402.      * @access   public
  1403.      * @param array $params_sql paramètre pour la requete SQL
  1404.      * @param array $format de la vignette si pas standard
  1405.      * @param bool $debug mode débugage
  1406.      * @return   array
  1407.      */
  1408.     public function getListPersons($params_sql = array(), $params = array(), $debug false)
  1409.     {
  1410.         // si pas de tableau
  1411.         if (!isset($params_sql['special'])) {
  1412.             $params_sql['special'] = array();
  1413.         }
  1414.         if (!isset($params_sql['params'])) {
  1415.             $params_sql['params'] = array();
  1416.         }
  1417.         // construction de la requête avec le passage de paramètres
  1418.         $sql $this->getSQLPersons($params_sql['params'], $params_sql['special'], $debug);
  1419.         // paramètre de debug
  1420.         $dbg = (empty($params_sql['dbg'])) ? array() : $dbg $params_sql['dbg'];
  1421.         // executer la requete
  1422.         $this->query($sql$dbg);
  1423.         $pers = array();
  1424.         $params_row = array();
  1425.         // debug
  1426.         $start_boucle microtime(true);
  1427.         // style more ?
  1428.         if (!empty($params['stylemore'])) {
  1429.             $params_row['stylemore'] = $params['stylemore'];
  1430.         } else {
  1431.             $params_row['stylemore'] = array('imagep' => 'width:80px;''desctxt' => 'width:200px;');
  1432.         }
  1433.         // format de la vignette
  1434.         if (!empty($params['vignette_format'])) {
  1435.             $vignette_format_flou $vignette_format $params['vignette_format'];
  1436.         } else {
  1437.             $vignette_format_flou $vignette_format = array('width' => $_ENV['VIGN_PERSONS_WIDTH'], 'height' => $_ENV['VIGN_PERSONS_HEIGHT'], 'direction' => 'crop');
  1438.         }
  1439.         $vignette_format_flou['blur'] = true;
  1440.         // mettre en forme chaque reponse
  1441.         $entity = new Persons();
  1442.         while ($attributes $this->fetch()) {
  1443.             // uniquement les années d'étude
  1444.             if (!empty($params_sql['special']['person_ecole']['get_promos'])) {
  1445.                 $pers[$this->year_end]['annee'] = $this->year_end;
  1446.                 continue;
  1447.             }
  1448.             // infos sur la personne
  1449.             $pers[$this->idperson] = $this->getInfosPersonRow($vignette_format$params_row);
  1450.             $pers[$this->idperson]['photo'] = $this->getVignettePerson($this->idperson$vignette_format);
  1451.             $pers[$this->idperson]['photo_flou'] = $this->getVignettePerson($this->idperson$vignette_format_flou);
  1452.             // dates
  1453.             if (isset($this->nb_dates)) {
  1454.                 $pers[$this->idperson]['nb_dates'] = $this->nb_dates;
  1455.             }
  1456.             // écoles
  1457.             if (!empty($params_sql['special']['person_ecole'])) {
  1458.                 $pers[$this->idperson]['person_ecole'] = array(
  1459.                     'date_start' => $this->date_start,
  1460.                     'date_end' => $this->date_end,
  1461.                     'year_start' => $this->year_start,
  1462.                     'year_end' => $this->year_end,
  1463.                     'comments' => $this->comments,
  1464.                     'contact' => array(
  1465.                         'url_clean' => $this->contact_url_clean,
  1466.                         'idcontact' => $this->contact_idcontact,
  1467.                         'organisation' => $this->contact_organisation,
  1468.                     )
  1469.                 );
  1470.             }
  1471.         }
  1472.         // libère
  1473.         $this->free();
  1474.         // debug de la boucle
  1475.         if ($this->isTraceMode('list_object')) {
  1476.             $this->setTraceInfos(array(
  1477.                 'execution_time_boucle' => (microtime(true) - $start_boucle),
  1478.                 'nb_occurence' => count($pers),
  1479.                 'dbg' => $dbg,
  1480.             ));
  1481.         }
  1482.         return $pers;
  1483.     }
  1484.     // }}}
  1485.     // {{{ getInfosPersonRow()
  1486.     /** Retrouner un tableau standard dans les listes
  1487.      *
  1488.      *
  1489.      * @param bool $vignette trouver les vignettes
  1490.      * @param array $params paramètres en plus
  1491.      * @access public
  1492.      * @return array
  1493.      */
  1494.     public function getInfosPersonRow($vignette true$params = array())
  1495.     {
  1496.         $pers = array();
  1497.         $idperson $this->idperson;
  1498.         // id, nom, prenom, url_clean
  1499.         $pers = array(
  1500.             'idperson' => $this->idperson,
  1501.             'lastname' => mb_strtoupper($this->lastname'utf8'),
  1502.             'firstname' => $this->firstname,
  1503.             'url_clean' => $this->url_clean,
  1504.         );
  1505.         return $pers;
  1506.     }
  1507.     // }}}
  1508.     //  {{{ getAssociateTexts()
  1509.     /** Récupére des liste de texte en fonction de classification
  1510.      *
  1511.      * @access   public
  1512.      * @param int $idperson identifiant de la personne
  1513.      * @param int $idrole son role
  1514.      * @param int $classification la classification
  1515.      * @param array $params_link paramètre en plus
  1516.      * @return   array
  1517.      */
  1518.     public function getAssociateTexts($idperson$idrole null$classification null$params_link = array())
  1519.     {
  1520.         if (!empty($classification)) {
  1521.             /*$classifications = Theatre::factory('classifications');
  1522.             $idlist = $classifications->classificationsToList($classification);
  1523.             $where = $classifications->listClassificationsWhere($idlist);*/
  1524.             if (is_array($classification)) {
  1525.                 $constraint_dest 'idclassification IN (' implode(','$classification) . ')';
  1526.             } else {
  1527.                 $constraint_dest 'idclassification=' . (int)$classification;
  1528.             }
  1529.         }
  1530.         $sql 'SELECT DISTINCT(t.idtext)
  1531.                 FROM text_classification tc, text_person tp, classification cl, texts t
  1532.                 WHERE tc.idclassification=cl.idclassification
  1533.                 AND tp.idtext=tc.idtext
  1534.                 AND tp.idtext=t.idtext AND tc.idtext=t.idtext
  1535.                 AND tp.idperson=' . ((int)$idperson) . ' ';
  1536.         $infos_link = array( // liaison avec la table text_classification via la table text_author
  1537.             'type_join' => 'multiple',
  1538.             'dest_table' => 'text_classification',
  1539.             'join_table' => 'text_person',
  1540.             'fields' => array('idtext''idclassification'),
  1541.             'constraint_dest' => (!empty($constraint_dest)) ? $constraint_dest '',
  1542.         );
  1543.         // si c'est pour l'auteur
  1544.         if (!empty($params_link['author'])) {
  1545.             $infos_link['join_table'] = 'text_author';
  1546.         }
  1547.         if (!empty($params['link'])) {
  1548.             $params_link $params['link'];
  1549.         }
  1550.         // $params_link['debug'] = true;
  1551.         if (!empty($infos_link)) {
  1552.             $items $this->getLinkedObject($infos_link$idpersonnull'persons'$params_link);
  1553.         }
  1554.         if (!empty($params_link['count_only'])) {
  1555.             return $items;
  1556.         }
  1557.         // grouper par classification
  1558.         if (!empty($classification) && !empty($params['by_classification'])) {
  1559.             if (is_array($classification)) {
  1560.                 foreach ($classification as $k => $v) {
  1561.                     $by_classification[$v] = array(
  1562.                         'classification' => $v,
  1563.                     );
  1564.                 }
  1565.             } else {
  1566.                 $by_classification[$classification] = array(
  1567.                     'classification' => $classification,
  1568.                 );
  1569.             }
  1570.         }
  1571.         if (!empty($items)) {
  1572.             // reourner uniquement le nb
  1573.             if (!empty($params_link['count_only'])) {
  1574.                 return $items;
  1575.             }
  1576.             // liste des texts
  1577.             foreach ($items as $k => $v) {
  1578.                 $idtext_list[] = $v['idtext'];
  1579.             }
  1580.             $texts $this->getEntityManager()->getRepository(Texts::class);
  1581.             $params_sql = array(
  1582.                 'params' => array(
  1583.                     'where' => ' AND T1.idtext IN (' join(','$idtext_list) . ') ',
  1584.                     'limit' => array(0100)
  1585.                 )
  1586.             );
  1587.             if (!empty($params_link['order'])) {
  1588.                 $params_sql['params']['order'] = $params_link['order'];
  1589.             }
  1590.             $sql_texts $texts->getSQLTexts($params_sql['params']);
  1591.             //$texts_list = $texts->getListTexts($params_sql);
  1592.             $texts->query($sql_texts);
  1593.             while ($texts->fetch($sql)) {
  1594.                 $text $texts->getInfosTextRow($texts->idtext$this->format_vignette);
  1595.                 $text['publisher_first'] = true;
  1596.                 $text['stylemore'] = $this->stylemore_text;
  1597.                 if (!empty($params['by_classification'])) {
  1598.                     foreach ($items as $item) {
  1599.                         if ($item['idtext'] == $texts->idtext) {
  1600.                             $by_classification[$item['idclassification']]['texts'][$texts->idtext] = $text;
  1601.                         }
  1602.                     }
  1603.                 } else {
  1604.                     $infos[$texts->idtext] = $text;
  1605.                 }
  1606.             }
  1607.             //print_r($by_classification);
  1608.             if (!empty($by_classification)) {
  1609.                 return $by_classification;
  1610.             } else {
  1611.                 //print_r($infos);
  1612.                 return $infos;
  1613.             }
  1614.         }
  1615.     }
  1616.     // }}}
  1617.     // {{{ countAuthors()
  1618.     /** Nombre de persons ayant au moins un texte original
  1619.      *
  1620.      * @param bool $sql_only On veut retourner la requête
  1621.      * @return int|string la valeur ou la requete
  1622.      */
  1623.     public function countAuthors($sql_only false)
  1624.     {
  1625.         // compter avers getSQLPersons
  1626.         $params_sql = array(
  1627.             'limit' => 'all'
  1628.         );
  1629.         $params_special = array(
  1630.             'count_only' => true,
  1631.             'author' => true,
  1632.         );
  1633.         $sql $this->getSQLPersons($params_sql$params_special);
  1634.         if (!$sql_only) {
  1635.             return $this->queryOne($sql);
  1636.         } else {
  1637.             return $sql;
  1638.         }
  1639.     }
  1640.     // }}}
  1641.     // {{{ countDirectors()
  1642.     /** Nombre de persons ayant au moins mis en scène
  1643.      *
  1644.      * @param bool $sql_only On veut retourner la requête
  1645.      * @return int|string la valeur ou la requete
  1646.      */
  1647.     public function countDirectors($sql_only false)
  1648.     {
  1649.         // compter avers getSQLPersons
  1650.         $params_sql = array(
  1651.             'limit' => 'all'
  1652.         );
  1653.         $params_special = array(
  1654.             'count_only' => true,
  1655.             'idrole' => 1,
  1656.         );
  1657.         $sql $this->getSQLPersons($params_sql$params_special);
  1658.         if (!$sql_only) {
  1659.             return $this->queryOne($sql);
  1660.         } else {
  1661.             return $sql;
  1662.         }
  1663.     }
  1664.     // }}}
  1665.     // {{{ countTranslators()
  1666.     /** Nombre de persons ayant au moins un texte traduit
  1667.      *
  1668.      * @param bool $sql_only On veut retourner la requête
  1669.      * @return int|string la valeur ou la requete
  1670.      */
  1671.     public function countTranslators($sql_only false)
  1672.     {
  1673.         // compter avers getSQLPersons
  1674.         $params_sql = array(
  1675.             'limit' => 'all'
  1676.         );
  1677.         $params_special = array(
  1678.             'count_only' => true,
  1679.             'translator' => true,
  1680.         );
  1681.         $sql $this->getSQLPersons($params_sql$params_special);
  1682.         if (!$sql_only) {
  1683.             return $this->queryOne($sql);
  1684.         } else {
  1685.             return $sql;
  1686.         }
  1687.     }
  1688.     // }}}
  1689.     // {{{ countActors()
  1690.     /** Nombre de persons ayant au moins un joué un spectacle
  1691.      *
  1692.      * @param bool $sql_only On veut retourner la requête
  1693.      * @return int|string la valeur ou la requete
  1694.      */
  1695.     public function countActors($sql_only false)
  1696.     {
  1697.         // compter avers getSQLPersons
  1698.         $params_sql = array(
  1699.             'limit' => 'all'
  1700.         );
  1701.         $params_special = array(
  1702.             'count_only' => true,
  1703.             'idrole' => 5,
  1704.         );
  1705.         $sql $this->getSQLPersons($params_sql$params_special);
  1706.         if (!$sql_only) {
  1707.             return $this->queryOne($sql);
  1708.         } else {
  1709.             return $sql;
  1710.         }
  1711.     }
  1712.     // }}}
  1713.     // {{{ countPersons()
  1714.     /** Nombre de persons
  1715.      *
  1716.      * @param bool $sql_only On veut retourner la requête
  1717.      * @param string $type On veut compter un type de personne en particulier
  1718.      * @return int|string la valeur ou la requete
  1719.      */
  1720.     public function countPersons($type null$sql_only false)
  1721.     {
  1722.         if (!empty($type)) {
  1723.             $method_name 'count' ucfirst($type);
  1724.             if (method_exists($this$method_name)) {
  1725.                 return $this->$method_name($sql_only);
  1726.             }
  1727.         } else {
  1728.             $sql 'SELECT COUNT(*) as total FROM ' $this->__table;
  1729.             $this->queryOne($sql);
  1730.         }
  1731.     }
  1732.     // }}}
  1733.     // {{{ setStylemoreText()
  1734.     /** Pour l'affichage des listes de texte
  1735.      *
  1736.      */
  1737.     public function setStylemoreText($stylemore_text)
  1738.     {
  1739.         $this->stylemore_text $stylemore_text;
  1740.     }
  1741.     // }}}
  1742.     // {{{ setFormatVignette()
  1743.     /** Pour l'affichage des listes
  1744.      *
  1745.      */
  1746.     public function setFormatVignette($format_vignette)
  1747.     {
  1748.         $this->format_vignette $format_vignette;
  1749.     }
  1750.     // }}}
  1751.     //  {{{ getAssociateContacts()
  1752.     /** Contacts aossociés à la personne
  1753.      *
  1754.      * @access  public
  1755.      * @param int $idperson identifiant de la personne
  1756.      * @param int $idoffice role (exemple : direction)
  1757.      * @param bool $actual_only uniquement les actuels  (contrainte sur la date)
  1758.      * @return  array
  1759.      */
  1760.     public function getAssociateContacts($idperson$idoffice null$actual_only null)
  1761.     {
  1762.         // infos sur la liaison
  1763.         $infos_link $this->getRelationsArray('contact_person');
  1764.         // select egalement l'idrole
  1765.         if ($idoffice) {
  1766.             $infos_link['where'] = ' AND j2.idoffice=' $idoffice;
  1767.         }
  1768.         // qui n'a pas fini son mandat
  1769.         if ($actual_only) {
  1770.             $infos_link['where'] .= ' AND (j2.date_end IS NULL OR j2.date_end>\'' date('Y-m-d') . '\')';
  1771.         }
  1772.         // avec ou sans virgule avec le noPunct
  1773.         if (!empty($infos_link)) {
  1774.             return $this->noPunct($this->getLinkedObject($infos_link$idperson$infos_link['type'], 'persons'));
  1775.         }
  1776.     }
  1777.     // }}}
  1778.     //  {{{ getSexeValue()
  1779.     /** Trouver le sexe à partir de H/F
  1780.      *
  1781.      * @access  public
  1782.      * @param string $sexe sexe
  1783.      * @return  int
  1784.      */
  1785.     public function getSexeValue($sexe)
  1786.     {
  1787.         $sexes = array(
  1788.             'H' => 1,
  1789.             'F' => 2,
  1790.         );
  1791.         if (!empty($sexes[$sexe])) {
  1792.             return $sexes[$sexe];
  1793.         }
  1794.         return 0;
  1795.     }
  1796.     // }}}
  1797.     //  {{{ getPromos()
  1798.     /** Trouver les promos
  1799.      *
  1800.      * @access  public
  1801.      * @param array $params_sql
  1802.      * @return  array
  1803.      */
  1804.     public function getPromos($params_sql)
  1805.     {
  1806.         $conn $this->getEntityManager();
  1807.         $params_sql['special']['person_ecole']['get_promos'] = true;
  1808.         $params_sql['dbg'] = array('get_promos''Les années de promos');
  1809.         $annees $conn->getRepository(Persons::class)->getListPersons($params_sql);
  1810.         ksort($annees);
  1811.         return $annees;
  1812.     }
  1813.     // }}}
  1814.     //  {{{ getSpectacleRoles()
  1815.     /** Trouver les rôles joués par une personne dans un spectacle
  1816.      *
  1817.      * @access  public
  1818.      * @param int $idperson Identifiant personne
  1819.      * @return  array
  1820.      */
  1821.     public function getSpectacleRoles($idperson)
  1822.     {
  1823.         $sql 'SELECT r.idrole, r.role, r.role_male, r.role_female, lg.fr
  1824.                 FROM
  1825.                     spectacle_person sp
  1826.                     JOIN roles r ON sp.idrole=r.idrole
  1827.                     JOIN langterms lg ON lg.id=r.role
  1828.                 WHERE sp.idperson=' $idperson '
  1829.                 GROUP BY r.idrole ';
  1830.         return $this->queryAll($sql);
  1831.     }
  1832.     // }}}
  1833. }