vendor/theatre/core/src/Repository/TextsRepository.php line 2068

Open in your IDE?
  1. <?php
  2. namespace TheatreCore\Repository;
  3. use TheatreCore\Classes\Images\Images;
  4. use TheatreCore\Entity\Aides;
  5. use TheatreCore\Entity\Contents;
  6. use TheatreCore\Entity\TextAide;
  7. use TheatreCore\Entity\Texts;
  8. use TheatreCore\Traits\TheatreTrait;
  9. use DateTime;
  10. use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
  11. use Doctrine\Persistence\ManagerRegistry;
  12. use Doctrine\ORM\Query;
  13. use Symfony\Contracts\Translation\TranslatorInterface;
  14. /**
  15.  * TextsRepository
  16.  *
  17.  * This class was generated by the Doctrine ORM. Add your own custom
  18.  * repository methods below.
  19.  */
  20. class TextsRepository extends ServiceEntityRepository
  21. {
  22.     use TheatreTrait {
  23.         getLinkedObject as protected getLinkedObjectTrait;
  24.     }
  25.     private $em;
  26.     public $__table;
  27.     public $__table_object;
  28.     public $__idtable;
  29.     public function __construct(ManagerRegistry $registryTranslatorInterface $trImages $images)
  30.     {
  31.         parent::__construct($registryTexts::class);
  32.         $this->__table $this->getClassMetadata()->getTableName();
  33.         $this->__table_object $this->getClassMetadata()->name;
  34.         $this->__idtable $this->getClassMetadata()->getSingleIdentifierFieldName();
  35.         $this->translator $tr;
  36.         $this->images $images;
  37.     }
  38.     //  {{{ findData()
  39.     /** Recherche des texts
  40.      *
  41.      * Permet de rechercher des textes en fonction de certains critères :
  42.      * la première lettre, un bout du titre, le type de texte, si il est en ligne ou pas
  43.      *
  44.      * @access  public
  45.      * @see     Theatre::find()
  46.      */
  47.     public function findData($idtext null$idperson null$typetxt null$keywords null$lettre null)
  48.     {
  49.         // query perso
  50.         $query null;
  51.         $query $this->createQueryBuilder('e');
  52.         // l'id du texte
  53.         if (isset($_REQUEST['idtext']) && (int)$_REQUEST['idtext']) {
  54.             $idtext $_REQUEST['idtext'];
  55.         }
  56.         // l'id d'un auteur
  57.         if (isset($_REQUEST['idperson']) && (int)$_REQUEST['idperson']) {
  58.             $idperson $_REQUEST['idperson'];
  59.         }
  60.         // premiere lettre du titre
  61.         if (isset($_REQUEST['lettre']) && !empty($_REQUEST['idperson'])) {
  62.             $lettre $_REQUEST['lettre'];
  63.         }
  64.         // type de texte
  65.         if (isset($_REQUEST['typetxt']) && !empty($_REQUEST['typetxt'])) {
  66.             $typetxt $_REQUEST['typetxt'];
  67.         }
  68. //        // mots cles
  69.         if (isset($_REQUEST['keywords']) && $_REQUEST['keywords'] != 'titre' && !empty($_REQUEST['keywords'])) {
  70.             $keywords filter_var(trim($_REQUEST['keywords']), FILTER_SANITIZE_STRINGFILTER_FLAG_NO_ENCODE_QUOTES);
  71.             if ($this->my_is_int($keywords)) {
  72.                 $idtext = (int)$keywords;
  73.                 $keywords null;
  74.             }
  75.         }
  76.         // liste des traductions
  77.         if (isset($_REQUEST['listtraductions']) && $_REQUEST['listtraductions'] == true) {
  78.             $listtraductions true;
  79.         }
  80.         // publie ou pas
  81.         if (isset($_REQUEST['publish']) && !empty($_REQUEST['publish'])) {
  82.             $publish $_REQUEST['publish'];
  83.         } else {
  84.             $publish null;
  85.         }
  86.         // fictif ou pas
  87.         if (isset($_REQUEST['textfictif']) && !empty($_REQUEST['textfictif'])) {
  88.             $textfictif = (int)$_REQUEST['textfictif'];
  89.         } else {
  90.             $textfictif 0;
  91.         }
  92.         // aides
  93.         if (isset($_REQUEST['idaide']) && $this->my_is_int($_REQUEST['idaide'])) {
  94.             $idaide = (int)$_REQUEST['idaide'];
  95.         }
  96.         $lng 'fr'//$GLOBALS['lng'];
  97.         $query_select 'partial e.{title, date, type, idtext, publish, valid, statut, country, language, textfictif}';
  98.         $join_on ',ct.' $lng ' as country_str,ln.' $lng ' as language_str';
  99. //        // on precise les champs pour le SELECT
  100.         if (empty($idperson)) {
  101. ////            $this->selectAdd();
  102. //            $this->selectAdd('title,date,type,idtext,publish,valid,country,language,textfictif');
  103.             $query->leftJoin('e.text_author''authors');
  104. //            $query->select('e, authors');
  105.             $query->select($query_select);
  106.         }
  107. //        // recherche par ID
  108.         if (!empty($idtext)) {
  109.             $query->andWhere('e.idtext=' $idtext);
  110. //            $query .= ' AND t.idtext='.$idtext;
  111.         }
  112. //        // recherche par alphabet
  113.         if (!empty($lettre)) {
  114.             $query->andWhere('title REGEXP \'^' $this->escape($lettre) . '\' ');
  115. ////            $query .= ' AND t.title REGEXP \'^'.$this->escape($lettre).'\' ';
  116.         }
  117. //        // recherche par mots cles
  118.         if (!empty($keywords)) {
  119. //            $this->whereAdd('title LIKE \'%'.$this->escape($keywords).'%\'');
  120. //            $query .= ' AND t.title LIKE \'%'.$this->escape($keywords).'%\'';
  121.         }
  122. //        // selectionne uniquement les textes originaux
  123.         if ($typetxt == 'original') {
  124. //            $this->whereAdd('type=0');
  125. //            $query .= ' AND t.type=0';
  126.         }
  127. //        // selectionne uniquement les traductions
  128.         if ($typetxt == 'translate') {
  129.             $query->andWhere('e.type = 1');
  130. //            $query .= ' AND t.type=1';
  131.         }
  132. //        // selectionne uniquement les adaptations
  133.         if ($typetxt == 'adaptation') {
  134.             $query->andWhere('e.type=2');
  135. //            $query .= ' AND t.type=2';
  136.         }
  137. //        // selectionne les textes/traductions/adaptations en cours de rédaction
  138.         if (!empty($publish)) {
  139.             $query->andWhere('e.publish=0');
  140. //            $query .= ' AND t.publish=0';
  141.         }
  142. //
  143. //        // selectionne les textes fictifs
  144. //        $this->whereAdd('textfictif='.$textfictif);
  145. //        $query .= ' AND t.textfictif='.$textfictif;
  146. //
  147. //        // selectionne uniquement les textes publies
  148.         if (!empty($this->isPublish) || (isset($GLOBALS['publish']) && $GLOBALS['publish'] == 1)) {
  149.             $query->andWhere('publish=1');
  150.             $query .= ' AND t.publish=1';
  151.         }
  152. //        // recherche par auteur ou traducteur
  153.         if (!empty($idperson)) {
  154. //            // jointure pour recherche par auteurs
  155.             if ($typetxt == 'original') {
  156.                 $ta DB_DataObject::factory('textAuthor');
  157.                 $this->joinAdd($ta);
  158.                 $this->selectAs();
  159.                 $this->selectAs($ta'ta_%s');
  160.                 $this->whereAdd('text_author.idperson=' $idperson);
  161.             }
  162.             // jointures pour recherche par traducteurs
  163.             if ($typetxt == 'translate') {
  164.                 $tt DB_DataObject::factory('textTranslator');
  165.                 $this->joinAdd($tt);
  166.                 $this->selectAs($tt'tt_%s');
  167.                 $this->whereAdd('text_translator.idtext=' $idperson);
  168.             }
  169.         }
  170. //
  171. //        $query = 'SELECT '.$query_select.' FROM texts t, countries ct, languages ln
  172. //                  WHERE 1
  173. //                  AND ct.id=t.country
  174. //                  AND ln.id=t.language '.$query;
  175. //
  176. //        $query = null;
  177. //
  178. //        // selectionne les traductions d'un texte
  179. //        if(!empty($idtext) && isset($listtraductions)) {
  180. //            $query = 'SELECT t.title,t.date,t.type,t.idtext,t.publish,t.valid,t.country,t.language,t.textfictif
  181. //                      FROM texts t, text_traduction tt
  182. //                      WHERE t.idtext=tt.idtexttraduction
  183. //                      AND tt.idtext='.$idtext;
  184. //        }
  185. //
  186. //        // les texts avec une aide
  187. //        if(!empty($idaide)) {
  188. //            $query = 'SELECT '.$query_select.',ta.*
  189. //                      FROM texts t, text_aide ta
  190. //                      WHERE t.idtext=ta.idtext
  191. //                      AND ta.idaide='.$idaide;
  192. //        }
  193.         if ($this->getCount()) {
  194.             $query->select('COUNT(e.idtext)');
  195.             $this->setCount(false);
  196.             return $query;
  197.         }
  198.         // on lance la recherche
  199.         return $query->getQuery();
  200.     }
  201.     // }}}
  202.     //  {{{ setToArray()
  203.     /** Listes des textes dans un tableau associatif
  204.      *
  205.      * Tableau associatif notament utilisé pour lister les informations sur des textes
  206.      * Utile pour gnérer les tableaux HTML de listes de textes
  207.      *
  208.      * @access  public
  209.      * @return  array
  210.      * @see     findData()
  211.      */
  212.     public function setToArray($spec true)
  213.     {
  214.         if ($spec == true) {
  215.             $this->findData();
  216.         }
  217.         $values = array();
  218.         $color null;
  219.         $nb 0;
  220.         while ($this->fetch()) {
  221.             $this->getLinks();
  222.             $values[$nb] = $this->getInfosText();
  223.             $values[$nb]['id'] = $this->idtext;
  224.             $values[$nb]['valid'] = $this->valid;
  225.             $values[$nb]['statut'] = $this->statut;
  226.             // compter les traductions
  227.             if (isset($this->count_translations)) {
  228.                 $values[$nb]['translations_nb'] = $this->countTranslations($this->idtext);
  229.             }
  230.             // couleur de ligne alternative
  231.             $color $this->colorAlternate($color);
  232.             $values[$nb]['colorline'] = $color;
  233.             $nb++;
  234.         }
  235.         return $values;
  236.     }
  237.     // }}}
  238.     //  {{{ getInfosText()
  239.     /** Infos sur un texte
  240.      *
  241.      * Retourne un tableau associatif avec les principales
  242.      * informations sur un texte
  243.      *
  244.      * @access  public
  245.      * @param int $idtext Identifiant de la fiche texte
  246.      * @return  array
  247.      * @see     findData()
  248.      */
  249.     public function getInfosText($idtext null$params_data = array())
  250.     {
  251.         $conn $this->getEntityManager();
  252.         // infos de la table
  253.         if (!isset($this->idtext) || empty($this->idtext) || $this->idtext != $idtext) {
  254.             $this->idtext $idtext;
  255.         }
  256.         $query $this->createQueryBuilder('u')
  257.             ->select('u, idextranetuser, country, idcontact_publisher, idgenretext')
  258.             ->leftJoin('u.idextranetuser''idextranetuser')
  259.             ->leftJoin('u.idcontact_publisher''idcontact_publisher')
  260.             ->leftJoin('u.idgenretext''idgenretext')
  261.             ->leftJoin('u.idcontact_performing''idcontact_performing')
  262.             ->leftJoin('u.country''country')
  263.             ->where('u.idtext =:value')->setParameter('value'$this->idtext);
  264.         $this->datas $infos $query->getQuery()->getOneOrNullResult(Query::HYDRATE_ARRAY);
  265.         $infos['titleshort'] = $this->cutSentence($infos['title'], 40);
  266.         $infos['year'] = $infos['date'];
  267.         $infos['special_text'] = $infos['specialText'];
  268.         $infos['idgenretext_object'] = $infos['idgenretext'];
  269.         if (!empty($infos['idgenretext'])) {
  270.             $infos['idgenretext'] = $infos['idgenretext']['idgenretext'];
  271.         }
  272.         $infos['publisher_url_text'] = $infos['publisherUrlText'];
  273.         $infos['url_clean'] = $infos['urlClean'];
  274.         $infos['abstract_url'] = $infos['abstractUrl'];
  275.         $infos['abstract_author'] = $infos['abstractAuthor'];
  276.         if (isset($this->_country->fr)) {
  277.             $infos['country'] = $this->_country->fr;
  278.         } elseif (isset($this->country_str)) {
  279.             $infos['country'] = $this->country_str;
  280.         } else {
  281.             if (isset($infos['country']['id'])) {
  282.                 $infos['country'] = $infos['country']['id'];
  283.             }
  284.         }
  285.         $infos['country_src'] = $infos['language'];
  286.         $infos['language_src'] = $infos['language'];
  287.         $this->idtext $idtext_original $infos['idtext'];
  288.         switch ($infos['type']) {
  289.             /* Texte original */
  290.             case 0:
  291.                 $infos['typetxt'] = 'original';
  292.                 $infos['original'] = true;
  293.                 break;
  294.             /* Traduction */
  295.             case 1:
  296.                 $infos['typetxt'] = 'translate';
  297.                 $infos['translate'] = true;
  298.                 /* on veut l'auteur du texte original, pas de la traduction */
  299.                 $originalText $this->getOriginalsTexts($this->idtext);
  300.                 // on renvoi l'id de l'original
  301.                 $idtext_original key($originalText);
  302.                 $infos['idtextoriginal'] = $idtext_original;
  303.                 /* traducteurs */
  304.                 $infos['translators'] = $this->getTranslators($this->idtext);
  305.                 $infos['alltranslators'] = $this->noPunct($infos['translators']);
  306.                 // au dela de 1 traducteur, on dit que c'est un collectif
  307.                 $this->collectif($infos['translators'], 1);
  308.                 break;
  309.             /* Adaptation */
  310.             case 2:
  311.                 $infos['typetxt'] = 'adaptation';
  312.                 $infos['adaptation'] = true;
  313.                 // on recup les infos sur l'adaptation
  314.                 $infos['adaptation_infos'] = $this->getOriginalsTexts($this->idtext'text_adaptation''idtextadaptation');
  315.                 break;
  316.             default:
  317.                 error_log('Type de texte inconnu: ' $infos['type']);
  318.                 break;
  319.         }
  320.         // auteurs
  321.         $infos['authors'] = $this->getPersons($idtext_original'text_author');
  322.         // tous les auteurs
  323.         $infos['allauthors'] = $this->noPunct($infos['authors']);
  324.         // au dela de 1 auteur, on dit que c'est un collectif
  325.         $this->collectif($infos['authors'], 2);
  326.         // voir si il y a des aides
  327.         if (!empty($params_data['get_aides'])) {
  328.             $infos['nb_aides'] = $conn->getRepository(TextAide::class)->countAides(null$this->idtext);
  329.             if ($infos['nb_aides'] > 0) {
  330.                 $infos['aides'] = $conn->getRepository(TextAide::class)->getListTextAide(array(
  331.                     'idtext' => array($this->idtext),
  332.                     'get_texts_with_aides' => true,
  333.                     'dbg' => array('liste_aides''Liste des aides du texte')
  334.                 ));
  335.             }
  336.         }
  337.         // date de creation
  338.         $this->abstract_date $infos['abstractDate'];
  339.         if (isset($this->abstract_date) && $this->abstract_date != '0000-00-00' && $this->abstract_date != null) {
  340.             $infos['abstract_date'] = $this->getFormeDate($this->abstract_date$GLOBALS['format_date'][$GLOBALS['lng']]);
  341.             $infos['abstract_date_us'] = $this->abstract_date;
  342.         }
  343.         if ($infos['statut']) {
  344.             $infos['statut'] = $this->statut $infos['statut'];
  345.             // incomplet ?
  346.             if ($infos['statut'] == 1) {
  347.                 $infos['validation_encours'] = true;
  348.             }
  349.             if ($infos['statut'] == 0) {
  350.                 $infos['incomplet'] = true;
  351.             }
  352.             if ($infos['statut'] > 1) {
  353.                 $infos['valide'] = true;
  354.             }
  355.         }
  356.         // utilisateur
  357.         if (isset($this->idextranetuser)) {
  358.             $infos['idextranetuser'] = $this->idextranetuser;
  359.         }
  360.         // récupèrer l'illustration
  361.         if (!empty($params_data['get_illustration'])) {
  362.             if (!empty($params_data['get_illustration']['format'])) {
  363.                 $illustrations $conn->getRepository(Contents::class)->getIllustrations($infos['idtext'], 'texts''class_couv'$params_data['get_illustration']['format']);
  364.             } else {
  365.                 $illustrations $conn->getRepository(Contents::class)->getIllustrations($infos['idtext'], 'texts''class_couv');
  366.             }
  367.             if (!empty($illustrations)) {
  368.                 // illustrations
  369.                 $infos['illustrations'] = $illustrations['illustrations'];
  370.                 // vignettes
  371.                 if (!empty($illustrations['vignette_object'])) {
  372.                     $infos['vignette_object'] = $illustrations['vignette_object'];
  373.                 }
  374.             }
  375.         }
  376.         $this->loadResult($infos);
  377.         return $infos;
  378.     }
  379.     // }}}
  380.     //  {{{ getInfosObject()
  381.     /** Alias de getInfosText
  382.      *
  383.      * @access  public
  384.      * @param int $idobject identifiant
  385.      * @return  array
  386.      * @see     getInfosText()
  387.      */
  388.     public function getInfosObject($idobject null)
  389.     {
  390.         return $this->getInfosText($idobject);
  391.     }
  392.     // }}}
  393.     //  {{{ getTranslateTitle()
  394.     /** Recherche des titre traduit
  395.      *
  396.      * chercher le titre traduit du texte dans une langue donnée
  397.      *
  398.      * @access  public
  399.      * @param int $idtext Identifiant du texte
  400.      * @param string $lng Identifiant de la langue
  401.      * @param bool $all afficher toutes les infos
  402.      */
  403.     public function getTranslateTitle($idtext null$lng null$all null)
  404.     {
  405.         try {
  406.             //requête qui va chercher le titre du texte dans une langue donnée
  407.             $sql 'SELECT t.idtext, t.title, t.date, t.country, p.firstname, p.lastname
  408.                 FROM texts t, text_traduction tt, text_translator ttr, persons p
  409.                 WHERE t.idtext=tt.idtexttraduction
  410.                 AND t.idtext=ttr.idtext
  411.                 AND ttr.idperson=p.idperson
  412.                 AND t.language=\'' $this->escape($lng) . '\' AND tt.idtext=' . ((int)$idtext) . ' AND t.publish=1';
  413.             $res $this->query($sql);
  414.             if ($res->numRows() > 0) {
  415.                 while ($row $res->fetchRow()) {
  416.                     if ($all == null) { // je veux tous le renseignements
  417.                         $result['idtext'] = $row['idtext'];
  418.                         $result['title'] = $row['title'];
  419.                         $result['date'] = $row['date'];
  420.                         $result['lastname'] = $row['lastname'];
  421.                         $result['firstname'] = $row['firstname'];
  422.                         $result['country'] = $row['country'];
  423.                     } else { // je prend juste le titre traduit
  424.                         $result $row['title'];
  425.                     }
  426.                 }
  427.                 return $result;
  428.             } else { // aucune traduction pour ce texte
  429.                 if ($all == null) {
  430.                     return [];
  431.                 } else {
  432.                     return null;
  433.                 }
  434.             }
  435.         } catch (\Throwable $e) {
  436.             return null;
  437.         }
  438.     }
  439.     // }}}
  440.     //  {{{ getPersons()
  441.     /** Personnes associées à un texte
  442.      *
  443.      * Liste et les personnes associèes à un texte.
  444.      * On peux effectuer un tri par type (auteur, traducteur, éditeur...)
  445.      *
  446.      * @access  public
  447.      * @param int $idtext identifiant du texte
  448.      * @param string $type type recherché (auteur, traducteur...)
  449.      * @param string $type_contact non implémenté
  450.      * @return  array
  451.      */
  452.     public function getPersons($idtext null$type 'text_author')
  453.     {
  454.         if (empty($idtext) && isset($this->idtext)) $idtext $this->idtext;
  455.         $infos_link $this->getRelationsArray($type);
  456.         if (!empty($infos_link)) {
  457.             return $this->getLinkedObject($infos_link$idtext$infos_link['type'], 'texts');
  458.         }
  459.     }
  460.     /// }}}
  461.     // {{{ getAuthors()
  462.     /** Auteurs d'un texte
  463.      *
  464.      * Liste les auteurs d'un texte (ou du texte orginal d'une traduction)
  465.      *
  466.      * @access  public
  467.      * @param int $idtext identifiant du texte
  468.      * @return  array
  469.      */
  470.     public function getAuthors($idtext null$type null)
  471.     {
  472.         if (empty($idtext)) $idtext $this->idtext;
  473.         if (!empty($this->type)) $type $this->type;
  474.         // on recupere le type si besoin
  475.         // if (empty($this->type) && empty($type)) {
  476.             $queryBuilder $this->createQueryBuilder('t');
  477.             $queryBuilder->select('t.type')
  478.                 ->andWhere('t.idtext = :idtext')
  479.                 ->setParameter('idtext'$idtext);
  480.             $query $queryBuilder->getQuery();
  481.             $data $query->getOneOrNullResult(Query::HYDRATE_ARRAY);
  482.             $type $this->type = (int)$data['type'];
  483.             if (empty($this->idtext)) {
  484.                 $this->idtext = (int)$idtext;
  485.             }
  486.         // }
  487.         // si traduction, on récup l'id du texte original pour avoir l'auteur
  488.         if ($type == 1) {
  489.             $originalText $this->getOriginalsTexts($idtext'text_traduction''idtexttraduction');
  490.             $idtext key($originalText);
  491.         }
  492.         return $this->getPersons($idtext'text_author');
  493.     }
  494.     // }}}
  495.     //  {{{ getTranslators()
  496.     /** Traducteurs d'un texte
  497.      *
  498.      * Liste les traducteurs d'un texte
  499.      *
  500.      * @access  public
  501.      * @param int $idtext identifiant du texte
  502.      * @return  array
  503.      * @see getPersons()
  504.      */
  505.     public function getTranslators($idtext null)
  506.     {
  507.         if (empty($idtext)) $idtext $this->idtext;
  508.         return $this->getPersons($idtext'text_translator');
  509.     }
  510.     // }}}
  511.     //  {{{ getOriginalsTexts()
  512.     /** Sélection des textes originaux
  513.      *
  514.      * Textes originaux dont dépend une traduction ou une adaptation
  515.      *
  516.      * @access public
  517.      * @param string $idtextlie Identifiant de l'adaptation ou de la traduction
  518.      * @param string $table Nom de la table de liaison (text_traduction, text_adaptation...)
  519.      * @params string   $cle Nom de la clé de liaison
  520.      * @return array
  521.      */
  522.     public function getOriginalsTexts($idtextlie null$table 'text_traduction'$cle 'idtexttraduction'$params = array())
  523.     {
  524.         if (empty($idtextlie)) {
  525.             $idtextlie $this->idtext;
  526.         }
  527.         $query 'SELECT t.idtext, t.title, t.type, t.language, t.date, t.url_clean
  528.                   FROM texts t, ' $table ' tt
  529.                   WHERE t.idtext=tt.idtext
  530.                   AND tt.' $cle '=' $idtextlie '
  531.                   ORDER BY t.title';
  532.         $texts $this->getEntityManager()->getConnection()->fetchAllAssociativeIndexed($query);
  533.         if (!empty($params['get_authors']) && !empty($texts)) {
  534.             foreach ($texts as $k => $v) {
  535.                 $texts[$k]['allauthors'] = $this->getAuthors($k$v['type']);
  536.             }
  537.         }
  538.         return $texts;
  539.     }
  540.     // }}}
  541.     //  {{{ orderByDefaut()
  542.     /** Classement par défaut
  543.      *
  544.      * Défini le tri par défaut pour les requêtes de type SELECT
  545.      *
  546.      * @access public
  547.      * @return string
  548.      */
  549.     public function orderByDefaut($order null)
  550.     {
  551.         // tri par défaut
  552.         if (empty($order)) {
  553.             $order 'texts.idtext';
  554.         }
  555.         return $order;
  556.     }
  557.     // }}}
  558.     //  {{{ countSpectacles()
  559.     /** Compter le nombre de spectacle pour un texte et ses adaptations
  560.      *
  561.      *
  562.      * @access public
  563.      * @param int $idtext Identifiant du texte
  564.      * @return int
  565.      */
  566.     public function countSpectacles($idtext null$publish false$params = array())
  567.     {
  568.         $idtext = (int)$idtext;
  569.         if ($idtext <= 0) return 0;
  570.         // On prépare les résultats pour la condition de la requête
  571.         $list_idtextadaptation $this->queryCol('SELECT DISTINCT(ta.idtextadaptation) FROM text_adaptation ta WHERE ta.idtext=' $idtext);
  572.         $list_idtext $this->queryCol('SELECT t.idtext FROM texts t WHERE t.idtext=' $idtext);
  573.         $resutat_function_textes array_merge_recursive($list_idtext$list_idtextadaptation);
  574.         $sql 'SELECT COUNT(DISTINCT(s.idspectacle)) as total
  575.             FROM text_spectacle ts, spectacles s
  576.             WHERE ts.idspectacle=s.idspectacle';
  577.         // est-ce qu'on veux les publié ou pas ?
  578.         if ($publish != false) {
  579.             $sql .= ' AND s.publish=' . (int)$publish;
  580.         }
  581.         //compter aussi les adaptations
  582.         $sql .= ' AND (ts.idtext=' $idtext '
  583.                 OR ts.idtext IN (
  584.                     ' implode(','$resutat_function_textes) . '
  585.                 )';
  586.         //compter aussi les adaptations à l'étranger
  587.         if (array_key_exists('countforeignshow'$params)) {
  588.             $sql .= 'OR ts.idtext IN(
  589.                     SELECT DISTINCT(t.idtext)
  590.                             FROM
  591.                                 texts t,
  592.                                 text_traduction tt
  593.                             WHERE
  594.                             t.idtext = tt.idtexttraduction
  595.                             AND tt.idtext = ' $idtext '
  596.                 )';
  597.         }
  598.         $sql .= ')';
  599.         return $this->queryOne($sql);
  600.     }
  601.     // }}}
  602.     //  {{{ countTranslations()
  603.     /** Compter le nombre de traductions pour un texte
  604.      *
  605.      * @access public
  606.      * @param int $idtext Identifiant du texte
  607.      * @return int
  608.      */
  609.     public function countTranslations($idtext null$publish false)
  610.     {
  611.         if (empty($idtext)) {
  612.             $sql 'SELECT COUNT(DISTINCT(t.`idtext`)) as total
  613.                     FROM texts t
  614.                     WHERE t.`type`=1';
  615.         } else {
  616.             $sql 'SELECT COUNT(DISTINCT(t.`idtext`)) as total
  617.                     FROM text_traduction tt, texts t
  618.                     WHERE tt.`idtexttraduction`=t.`idtext` AND tt.`idtext`=' $idtext;
  619.         }
  620.         // est-ce qu'on veux les publié ou pas ?
  621.         if ($publish != false) {
  622.             $sql .= ' AND t.publish=' $publish;
  623.         }
  624.         return $this->queryOne($sql);
  625.     }
  626.     // }}}
  627.     //  {{{ getCountTranslations()
  628.     /** faut-il compter (dans des listes de resultats) ?
  629.      *
  630.      * @access public
  631.      * @param bool $count
  632.      * @return int
  633.      */
  634.     public function getCountTranslations($count true)
  635.     {
  636.         if ($count == true) {
  637.             $this->count_translations true;
  638.         }
  639.     }
  640.     // }}}
  641.     //  {{{ countLanguageTranslations()
  642.     /** Compter le nombre de langue de traduction pour un texte
  643.      *
  644.      * Défini le tri par défaut pour les requêtes de type SELECT
  645.      *
  646.      * @access public
  647.      * @param int $idtext Identifiant du texte
  648.      * @return int
  649.      */
  650.     public function countLanguageTranslations($idtext null)
  651.     {
  652.         $sql 'SELECT COUNT(DISTINCT(t.language))
  653.                  FROM texts t, text_traduction tt
  654.                  WHERE tt.idtext=' . ((int)$idtext) . '
  655.                  AND t.idtext=tt.idtexttraduction';
  656.         return $this->queryOne($sql);
  657.     }
  658.     // }}}
  659.     //  {{{ getListLanguageTranslations()
  660.     /** Liste des langues d'un texte
  661.      *
  662.      * @access  public
  663.      * @param int $idtext id du texte
  664.      * @return  array
  665.      */
  666.     public function getListLanguageTranslations($idtext)
  667.     {
  668.         //langue
  669.         $tr $GLOBALS['tr'];
  670.         $sql null;
  671.         // requete
  672.         $sql 'SELECT DISTINCT(t.language),t.idtext
  673.                 FROM texts t,text_traduction tt
  674.                 WHERE tt.idtext=' $idtext '
  675.                 AND t.idtext=tt.idtexttraduction GROUP BY t.language';
  676.         // execution de la requete
  677.         $this->query($sql);
  678.         while ($this->fetch()) {
  679.             $lg $this->getLink('language''languages''id');
  680.             $lang[$this->idtext]['lang'] = $lg->$GLOBALS['lng'];
  681.             $lang[$this->idtext]['idtext'] = $this->idtext;
  682.         }
  683.         // retourner les enregistrements
  684.         return $lang;
  685.     }
  686.     // }}}
  687.     //  {{{ getListSearch()
  688.     /** Liste des textes
  689.      *
  690.      * Pour les champs Ajax de relations et les recherches diverses
  691.      * permet de générer un tabelau associatif des titres des textes en
  692.      * fonction de critères de recherche alphabétique ou mots clès
  693.      *
  694.      * @access  public
  695.      * @param string $lettres Pour la recherche alphabetique
  696.      * @param string $keywords Recherche par mots cles
  697.      * @return  array
  698.      */
  699.     public function getListSearch($lettre$type null$keywords null$other$type_object null)
  700.     {
  701.         $queryBuilder $this->createQueryBuilder('t');
  702.         $queryBuilder->select('partial t.{idtext,title,type,country,language}');
  703.         // uniquement les textes originaux
  704.         if ($type != 'text_spectacle' && $type != 'new_text' && $type != 'podcast_text' && $type != 'idobject' && $type_object != 'playlist') {
  705.             $queryBuilder->andWhere('t.type=0');
  706.         }
  707.         // selection par ordre alpha
  708.         if (!empty($lettre)) {
  709. //            $queryBuilder->andWhere('LOWER(LEFT(LTRIM(t.title),1))=\''.$this->escape($lettre).'\'');
  710.             $queryBuilder->andWhere('t.title LIKE \'' $this->escape($lettre) . '%\'');
  711.         }
  712.         // recherche avec un mot cle
  713.         $list $this->splitKeywords($keywords);
  714.         if ($list) {
  715.             if (!empty($list[$this->IDSTR])) {
  716.                 // mots clés
  717.                 foreach ($list[$this->IDSTR] as $s) {
  718.                     $queryBuilder->andWhere('t.title LIKE \'%' $s '%\'');
  719.                 }
  720.             }
  721.             if (!empty($list[$this->IDNUM])) {
  722.                 // recherche par numéro d'id pour les mots clés numériques
  723.                 $queryBuilder->orWhere('idtext IN (' implode(','$list[$this->IDNUM]) . ')');
  724.             }
  725.         }
  726. //        $this->orderBy('title');
  727.         $query $queryBuilder->getQuery();
  728.         $texts $query->getResult(Query::HYDRATE_ARRAY);
  729. //        $this->find();
  730.         $r = array();
  731.         foreach ($texts as $text) {
  732.             $this->loadResult($text);
  733.             // texte et auteur (ou collectif)
  734.             $r[$this->idtext] = $this->cutSentence($this->title45) . ' (' $this->getOneAuthor() . ')';
  735.             // si c'est une traduction, ajouter le code langue
  736.             if ($this->type == 1) {
  737.                 $r[$this->idtext] .= ' (' $this->language ')';
  738.             }
  739.             // si trouvé par id, on l'affiche en fin de titre
  740.             if (!empty($list[$this->IDNUM]) && in_array($this->idtext$list[$this->IDNUM])) {
  741.                 $r[$this->idtext] .= ' - n°' $this->idtext;
  742.             }
  743.         }
  744.         $this->free();
  745.         return $r;
  746.     }
  747.     // }}}
  748.     //  {{{ getOneAuthor()
  749.     /** Retourner sous forme de string le nom de l'auteur ou 'collectif'
  750.      *
  751.      * @param int $idtext Identifiant du texte
  752.      * @return  string
  753.      */
  754.     public function getOneAuthor($idtext null)
  755.     {
  756.         $author null;
  757.         if (empty($idtext)) {
  758.             $idtext $this->idtext;
  759.         }
  760.         if ($authors $this->getAuthors($idtext)) {
  761.             if (count($authors) > 1) {
  762.                 $author 'Collectif';
  763.             } else {
  764.                 foreach ($authors as $key => $value) {
  765.                     if (!empty($value['firstname'])) {
  766.                         $author .= $value['firstname'] . ' ';
  767.                     }
  768.                     $author .= $value['lastname'];
  769.                 }
  770.             }
  771.         }
  772.         return $author;
  773.     }
  774.     // }}}
  775.     //  {{{ getObjectTitle()
  776.     /** Infos de l'item recherché
  777.      *
  778.      * Pour les champs Ajax de relations
  779.      *
  780.      * @access private
  781.      */
  782.     public function getObjectTitle($idobject null$infos_object = array(), $params = array())
  783.     {
  784.         // si on n'a pas passé l'id a la méthode, on doit-être dans une boucle
  785.         if (!$idobject) {
  786.             $idobject $this->idtext;
  787.         }
  788.         $fields = array('idtext''title''type''url_clean''valid');
  789.         // si on a les valeurs
  790.         if (!empty($infos_object)) {
  791.             foreach ($fields as $k => $v) {
  792.                 if (array_key_exists($v$infos_object)) {
  793.                     $infos[$v] = $infos_object[$v];
  794.                 }
  795.             }
  796.         } else { // si on n'a les valeurs dans une boucle
  797.             // si on n'a pas $this->title, c'est qu'il faut les infos
  798.             if (!isset($this->title)) {
  799.                 $sql 'SELECT ' implode(','$fields) . '
  800.                         FROM ' $this->__table '
  801.                         WHERE ' $this->__idtable '=' . ((int)$idobject);
  802.                 $infos $this->queryRow($sql);
  803.                 if (empty($infos)) {
  804.                     return false;
  805.                 }
  806.             } else { // sinon, dans le tableau infos
  807.                 foreach ($fields as $k => $v) {
  808.                     if (isset($this->$v) && $this->$v != '') {
  809.                         $infos[$v] = trim($this->$v);
  810.                     }
  811.                 }
  812.             }
  813.         }
  814.         // title
  815.         $title_view $infos['title'];
  816.         // ajouter les metteurs en scène en chaine si demandé
  817.         if (!array_key_exists('noauthor'$params)) {
  818.             $infos_author $this->getOneAuthor($infos['idtext']);
  819.             if (!empty($infos_author)) {
  820.                 $title_view .= ' (' $infos_author ')';
  821.                 $infos['title'] = $title_view;
  822.             }
  823.         }
  824.         // renvoyer un array plutôt que le titre (utile si on veux l'url)
  825.         if (array_key_exists('return_array'$params)) {
  826.             return $infos;
  827.         }
  828.         return $title_view;
  829.     }
  830.     // }}}
  831.     //  {{{ getGenretextList()
  832.     /** Liste des genres de texte
  833.      *
  834.      * @access  public
  835.      * @return  array
  836.      */
  837.     public function getGenretextList($plus null$visibility null$return_array false)
  838.     {
  839.         $sql_genretext 'SELECT idgenretext,genretext FROM genretexts ';
  840.         if (!empty($visibility)) {
  841.             $sql_genretext .= ' WHERE visibility IN (' $this->arrayToIn($visibility) . ') ';
  842.         }
  843.         $sql_genretext .= ' ORDER BY ordergenre';
  844.         $genre_list $this->getEntityManager()->getConnection()->fetchAllKeyValue($sql_genretext);
  845.         // objet de traduction
  846.         $tr $GLOBALS['tr'];
  847.         if (!$return_array) {
  848.             foreach ($genre_list as $k => $v) {
  849.                 $new_genre_list[$k] = $tr->trans($v $plus);
  850.             }
  851.         } else {
  852.             foreach ($genre_list as $k => $v) {
  853.                 $new_genre_list[$k]['name'] = $tr->trans($v $plus);
  854.                 $new_genre_list[$k]['code'] = str_replace('genre_'''$v);
  855.             }
  856.         }
  857.         return $new_genre_list;
  858.     }
  859.     // }}}
  860.     //  {{{ getTypeText()
  861.     /** Retrouver le type de texte
  862.      *
  863.      * @access  public
  864.      * @param int idtype ID du type de texte
  865.      * @return  string
  866.      */
  867.     public function getTypeText($idtype)
  868.     {
  869.         if (empty($typetxt)) {
  870.             if ($idtype == 1) {
  871.                 $typetxt 'translate';
  872.             } else if ($idtype == 2) {
  873.                 $typetxt 'adaptation';
  874.             } else {
  875.                 $typetxt 'original';
  876.             }
  877.         }
  878.         return $typetxt;
  879.     }
  880.     // }}}
  881.     //  {{{ getVignetteText()
  882.     /** Récupére la vignette d'un texte ou la cree si besoin
  883.      *
  884.      * @access   public
  885.      * param     int idtext identifiant du texte
  886.      * @return   string
  887.      */
  888.     public function getVignetteText($idtext null$format = array())
  889.     {
  890.         if (empty($idtext)) {
  891.             $idtext $this->idtext;
  892.         }
  893.         // par default : image normal 100px x 100px qualite 75
  894.         if (!empty($format)) {
  895.             $set_format $format;
  896.         } else {
  897.             $set_format = array('width' => $_ENV['VIGN_TEXT_WIDTH'], 'height' => $_ENV['VIGN_TEXT_HEIGHT'], 'direction' => 'thumb');
  898.         }
  899.         // generation par la classe Images
  900.         if (!isset($this->images)) {
  901.             $this->images Images::getInstance($this->getEntityManager());
  902.         }
  903.         $this->images->setVignetteFormat($set_format);
  904.         return $this->images->getVignetteObject($idtext'texts''class_couv');
  905.     }
  906.     // }}}
  907.     // {{{ getInfosTextRow()
  908.     /** Retrouner un tableau standard dans les listes
  909.      *
  910.      *
  911.      * @param bool $allauthors afficher les auteurs
  912.      * @param bool $vignette trouver les vignettes
  913.      * @param bool $genre le genre
  914.      * @param bool $tabpublisher publisher sous forme de tableau
  915.      * @access public
  916.      * @return array
  917.      */
  918.     public function getInfosTextRow($allauthors true$vignette true$genre false$tabpublisher true$params = array())
  919.     {
  920.         $month = array(
  921.             => 'Janvier',
  922.             => 'Février',
  923.             => 'Mars',
  924.             => 'Avril',
  925.             => 'Mai',
  926.             => 'Juin',
  927.             => 'Juillet',
  928.             => 'Août',
  929.             => 'Septembre',
  930.             10 => 'Octobre',
  931.             11 => 'Novembre',
  932.             12 => 'Decembre',
  933.         );
  934.         $txt = array();
  935.         $idtext $this->idtext;
  936.         // id du texte, titre, url, auteur du texte
  937.         $txt['idtext'] = $idtext;
  938.         $txt['title'] = $this->title;
  939.         $txt['url_clean'] = $this->url_clean;
  940.         if (isset($this->date)) {
  941.             $txt['date'] = $this->date;
  942.         }
  943.         $txt['textorder'] = $this->textorder;
  944.         // date d'écriture
  945.         if (isset($this->datewrite)) {
  946.             $txt['datewrite'] = $this->datewrite;
  947.         }
  948.         // text fictif
  949.         if (isset($this->textfictif)) {
  950.             $txt['textfictif'] = $this->textfictif;
  951.         }
  952.         if (isset($this->isbn)) {
  953.             $txt['isbn'] = $this->isbn;
  954.         }
  955.         if (isset($this->ean)) {
  956.             $txt['ean'] = $this->ean;
  957.         }
  958.         if (isset($this->nbpages)) {
  959.             $txt['nbpages'] = $this->nbpages;
  960.         }
  961.         if (isset($this->publication_year)) {
  962.             $txt['publication_year'] = $this->publication_year;
  963.             $publication_month_caractere[] = $publication_date[] = $txt['publication_year'];
  964.         }
  965.         if (isset($this->publication_month)) {
  966.             if (strlen($this->publication_month) == 1) {
  967.                 $txt['publication_month'] = '0' $this->publication_month;
  968.             } else {
  969.                 $txt['publication_month'] = $this->publication_month;
  970.             }
  971.             $publication_date[] = $txt['publication_month'];
  972.             $txt['publication_month_caractere'] = $month[$this->publication_month];
  973.         }
  974.         // les auteurs du texte
  975.         if ($allauthors) {
  976.             $txt['allauthors'] = $this->noPunct($this->getAuthors($idtext));
  977.             $this->collectif($txt['allauthors'], 03);
  978.         }
  979.         // si traduction, aussi le traducteur
  980.         if (isset($this->type) && $this->type == 1) {
  981.             $txt['alltranslators'] = $this->noPunct($this->getTranslators($idtext));
  982.         }
  983.         // date de publication complète
  984.         if (!empty($publication_date)) {
  985.             $txt['publication_date'] = join('-'$publication_date);
  986.         }
  987.         // date d'ajout
  988.         if (isset($this->dateinsert)) {
  989.             $txt['dateinsert'] = $this->dateinsert;
  990.             $txt['dateinsert_lng'] = $this->getFormeDate($this->dateinsert$GLOBALS['format_date'][$GLOBALS['lng']]);
  991.             $txt['dateinsert_hour_lng'] = $this->getFormeDate($this->dateinsert'H:i');
  992.         }
  993.         // l'editeur
  994.         if (isset($this->url_clean_publisher) && $this->url_clean_publisher != '') {
  995.             if (!empty($params['api'])) {
  996.                 $txt['publisher'][$this->idcontact] = array(
  997.                     'organisation' => $this->organisation,
  998.                     'url_clean' => $this->url_clean_publisher,
  999.                 );
  1000.             } elseif ($tabpublisher) {
  1001.                 $txt['publisher']['organisation'] = $this->organisation;
  1002.                 $txt['publisher']['url_clean'] = $this->url_clean_publisher;
  1003.             } else {
  1004.                 $txt['publisher'] = $this->organisation;
  1005.                 $txt['url_clean_publisher'] = $this->url_clean_publisher;
  1006.             }
  1007.         }
  1008.         // vignette de base
  1009.         if ($vignette) {
  1010.             if (is_array($vignette)) {
  1011.                 $format $vignette;
  1012.             } else {
  1013.                 $format = array();
  1014.             }
  1015.             $txt['vignette'] = $this->getVignetteText($idtext$format);
  1016.             $format['blur'] = true;
  1017.             $txt['vignette_flou'] = $this->getVignetteText($idtext$format);
  1018.         }
  1019.         // pour une traduction, il faut aussi le texte orginal
  1020.         if (isset($this->type) && $this->type == 1) {
  1021.             $txt['original_texts'] = $this->getOriginalsTexts($idtext);
  1022.         }
  1023.         // genre de texte (theatre si pas précisé)
  1024.         if ($genre) {
  1025.             if (isset($this->idgenretext)) {
  1026.                 $txt['idgenretext'] = $this->idgenretext;
  1027.             } else {
  1028.                 $txt['idgenretext'] = 1;
  1029.             }
  1030.             // traduction du genre de text
  1031.             if (isset($this->genretext)) {
  1032.                 $txt['genretext'] = $GLOBALS['tr']->trans($this->genretext);
  1033.             }
  1034.         }
  1035.         // si c'est une traduction, id du texte original
  1036.         if (isset($this->idtextoriginal)) {
  1037.             $txt['idtextoriginal'] = $this->idtextoriginal;
  1038.         }
  1039.         // langue
  1040.         if (isset($this->language)) {
  1041.             $txt['language'] = $this->getNameLanguage($this->language);
  1042.         }
  1043.         // pays
  1044.         if (isset($this->country)) {
  1045.             $txt['country'] = $this->getNameCountry($this->country);
  1046.         }
  1047.         // statut et validation
  1048.         if (isset($this->valid)) {
  1049.             $txt['valid'] = $this->valid;
  1050.         }
  1051.         if (isset($this->publish)) {
  1052.             $txt['publish'] = $this->publish;
  1053.         }
  1054.         if (isset($this->statut)) {
  1055.             $txt['statut'] = $this->statut;
  1056.         }
  1057.         if (!empty($params['stylemore'])) {
  1058.             $txt['stylemore'] = $params['stylemore'];
  1059.         } else {
  1060.             $txt['stylemore'] = array('imagep' => 'width:85px;''desctxt' => 'width:170px;');
  1061.         }
  1062.         return $txt;
  1063.     }
  1064.     // }}}
  1065.     //  {{{ getRelationsArray()
  1066.     /** Tableau des relations
  1067.      *
  1068.      * @access  public
  1069.      * @param string|int $type le type de champ
  1070.      */
  1071.     public function getRelationsArray($type null)
  1072.     {
  1073.         // tout ça est dans la table "contacts"
  1074.         $types_idcontact = array(
  1075.             'publisher',
  1076.             'idcontact_publisher',
  1077.             'idcontact_translation',
  1078.             'idcontact_performing',
  1079.             'source',
  1080.         );
  1081.         if (!empty($type) && in_array($type$types_idcontact)) {
  1082.             $precise_type $type;
  1083.             $type 'idcontact';
  1084.         } else {
  1085.             $precise_type null;
  1086.         }
  1087.         // author est avec la relation text_author
  1088.         if (!empty($type) && $type == 'author') {
  1089.             $type 'text_author';
  1090.         }
  1091.         $array_types = array(
  1092.             'text_trailer' => array(// documents multimedia associés
  1093.                 'type_join' => 'method',
  1094.                 'method' => 'getMultimediaList',
  1095.             ),
  1096.             // contacts idcontact
  1097.             'idcontact' => array(// contacts associés ?
  1098.                 'type_join' => 'simple',
  1099.                 'dest_table' => 'contacts',
  1100.                 'fields' => array('idcontact''organisation''lastname''firstname''type''url_clean''valid'),
  1101.                 'join_field_src' => $precise_type,
  1102.             ),
  1103.             'text_classification' => array(// classifications associées
  1104.                 'field_input' => 'idclassification',
  1105.                 'type_join' => 'multiple',
  1106.                 'dest_table' => 'classifications',
  1107.                 'join_table' => 'text_classification',
  1108.                 'fields' => array('idclassification''classification''type'),
  1109.             ),
  1110.             'text_translator' => array(// traducteurs
  1111.                 'type_join' => 'multiple',
  1112.                 'dest_table' => 'persons',
  1113.                 'join_field_src' => 'idtext',
  1114.                 'join_field_dest' => 'idperson',
  1115.                 'join_table' => 'text_translator',
  1116.                 'fields' => array('idperson''lastname''firstname''url_clean''valid'),
  1117.                 'sql_more' => ' ORDER BY j2.classement ASC',
  1118.             ),
  1119.             'text_author' => array(// auteurs
  1120.                 'type_join' => 'multiple',
  1121.                 'dest_table' => 'persons',
  1122.                 'join_field_src' => 'idtext',
  1123.                 'join_field_dest' => 'idperson',
  1124.                 'join_table' => 'text_author',
  1125.                 'fields' => array('idperson''lastname''firstname''url_clean''valid'),
  1126.                 'sql_more' => ' ORDER BY j2.classement ASC',
  1127.             ),
  1128.             'text_traduction' => array(// texts originaux liés à la traduction
  1129.                 'type_join' => 'multiple',
  1130.                 'dest_table' => 'texts',
  1131.                 'join_field_src' => 'idtexttraduction',
  1132.                 'join_field_dest' => 'idtext',
  1133.                 'join_table' => 'text_traduction',
  1134.                 'fields' => array('idtext''title''type''url_clean''valid'),
  1135.                 'title_params' => array('noauthor' => true), // sans l'auteur
  1136.             ),
  1137.             'text_adaptation' => array(// text originaux liés à l'adaptation
  1138.                 'type_join' => 'multiple',
  1139.                 'dest_table' => 'texts',
  1140.                 'join_field_src' => 'idtextadaptation',
  1141.                 'join_field_dest' => 'idtext',
  1142.                 'join_table' => 'text_adaptation',
  1143.                 'fields' => array('idtext''title''type''url_clean''valid'),
  1144.                 'title_params' => array('noauthor' => true), // sans l'auteur
  1145.             ),
  1146.             'text_person' => array(// persons liées à un texte
  1147.                 'type_join' => 'multiple',
  1148.                 'dest_table' => 'persons',
  1149.                 'join_table' => 'text_person',
  1150.                 'join_field_dest' => 'idperson',
  1151.                 'field_link' => 'idrole'//TODO
  1152.                 'fields' => array('idperson''lastname''firstname''url_clean''valid'),
  1153.             ),
  1154.             'text_multimedia' => array(// classifications associées
  1155.                 'type_join' => 'multiple',
  1156.                 'dest_table' => 'multimedias',
  1157.                 'join_table' => 'object_multimedia',
  1158.                 'join_table_object' => 'texts',
  1159.                 //'join_table_constraint' => 'object_multimedia.object=\'texts\' AND object_multimedia.idobject=?',
  1160.                 'fields' => array('idmultimedia''sujet_titre''url_clean'),
  1161.             ),
  1162.             // idextranetuser idtext
  1163.             'idextranetuser' => array(// utilisateur associé
  1164.                 'type_join' => 'simple',
  1165.                 'dest_table' => 'extranetusers',
  1166.                 'join_field_src' => 'idextranetuser'// jointure
  1167.                 'fields' => array('idextranetuser''login''email'),
  1168.                 'description' => 'Utilisateur associé au texte',
  1169.                 'silent_delete_relation' => true,
  1170.             ),
  1171.         );
  1172.         if (!empty($array_types[$type])) {
  1173.             $array_types[$type]['type'] = $type;
  1174.             return $array_types[$type];
  1175.         } else {
  1176.             return $array_types;
  1177.         }
  1178.     }
  1179.     // }}}
  1180.     //  {{{ getLinkedObject()
  1181.     /** Particularité pour Texts
  1182.      *
  1183.      * @access  public
  1184.      * @see     Theatre::getLinkedObject()
  1185.      */
  1186.     public function getLinkedObject($infos_link$idobject$type$src)
  1187.     {
  1188.         $itemslist $this->getLinkedObjectTrait($infos_link$idobject$type$src);
  1189.         foreach ($itemslist as $k => $v) {
  1190.             if (!empty($v['lastname']) && $v['lastname'] == 'Collectif') {
  1191.                 $itemslist[$k]['collectif'] = true;
  1192.             }
  1193.         }
  1194.         return $itemslist;
  1195.     }
  1196.     // }}}
  1197.     // {{{ collectif()
  1198.     /** Modifie le tableau pour les collectifs
  1199.      *
  1200.      *
  1201.      * @param array  le tableau des auteurs (ou traducteurs)
  1202.      * @param int $nb nombre d'auteurs ou de traducteurs
  1203.      * @param int $type 0=auteurs 1=traducteurs
  1204.      * @access protected
  1205.      * @return array
  1206.      */
  1207.     protected function collectif(&$arr$type 0$nb_supp 1)
  1208.     {
  1209.         static $types = array(
  1210.             => 'auteurs',
  1211.             => 'traducteurs'
  1212.         );
  1213.         $nb count($arr);
  1214.         if ($nb <= $nb_supp || !isset($types[$type])) return;
  1215.         $arr = array(=> array(
  1216.             'lastname' => '(' $nb ' ' $types[$type] . ')',
  1217.             'firstname' => 'Collectif',
  1218.             'collectif' => true)
  1219.         );
  1220.     }
  1221.     // }}}
  1222.     // {{{ countAssociateTexts()
  1223.     /** Compter le nb de textes associés à un objet
  1224.      *
  1225.      *
  1226.      * @param string $object Type d'objet
  1227.      * @param int $idobject Identifiant
  1228.      * @param int $idclassification Classification
  1229.      * @access public
  1230.      * @return array
  1231.      */
  1232.     public function countAssociateTexts($object$idobject$idclassification)
  1233.     {
  1234.         $infos_link $this->getRelationsArray('text_person');
  1235.         if (!empty($infos_link)) {
  1236.             return $this->getLinkedObject($infos_link$idobject$infos_link['type'], 'texts');
  1237.         }
  1238.     }
  1239.     // }}}
  1240.     //  {{{ getSQLTexts()
  1241.     /** Générer la requete standard pour un text
  1242.      *
  1243.      * $params = array(
  1244.      *  'select' => champs en plus pour le select,
  1245.      *  'from' => champs en plus pour le from,
  1246.      *  'where' => paramètres en plus le where,
  1247.      *  'order' => classement des résultats,
  1248.      *  'limit' => limiter le nb de résultats array(debut,fin), (all pour pas de limit)
  1249.      * )
  1250.      * $special = array(
  1251.      *  'select_by_text_or_adaptation' => text et adaptation,
  1252.      *  'prochains' => true = date dans le future, un entier = fait un between
  1253.      *  'anciens' =>
  1254.      *  'join' => jointure gauche sur contacts et schedules
  1255.      * )
  1256.      *
  1257.      *
  1258.      * @access   public
  1259.      * @param array $params Les paramètres pour la requete
  1260.      * @param array $special Les paramètres supplémentaires
  1261.      * @param bool $debug afficher la requête TODO
  1262.      * @return   string
  1263.      */
  1264.     public function getSQLTexts($params = array(), $special = array(), $debug false)
  1265.     {
  1266.         // tables et champs
  1267.         $tables_list = array(
  1268.             'texts' => array(
  1269.                 /* @TODO Suppression de 'date' ticket #171 est-ce que d'autres pages vont bug suite à ça ? */
  1270.                 'fields' => array('title''url_clean''publication_year''publication_month''isbn''textfictif''dateinsert''textorder''type''publish''statut''valid'),
  1271.             ),
  1272.             'contacts' => array(
  1273.                 'fields' => array('idcontact''url_clean as url_clean_publisher''organisation'),
  1274.             ),
  1275.         );
  1276.         // définition de l'alias
  1277.         $al 1;
  1278.         foreach ($tables_list as $k => $v) {
  1279.             $tables_list[$k]['table_alias'] = $k ' T' $al;
  1280.             foreach ($v['fields'] as $f) {
  1281.                 // si le champ contient ' as '
  1282.                 if (strpos($f' as ') !== false) {
  1283.                     $ff explode(' as '$f);
  1284.                     $select_fields_array[] = 'T' $al '.`' $ff[0] . '` as `' $ff[1] . '`';
  1285.                 } else {
  1286.                     $select_fields_array[] = 'T' $al '.`' $f '`';
  1287.                 }
  1288.             }
  1289.             $al++;
  1290.         }
  1291.         // select de base
  1292.         $sql_select 'SELECT DISTINCT(T1.`idtext`), ' join(','$select_fields_array) . ',
  1293.                         CONCAT(T1.`publication_year`, T1.`publication_month`) AS publication_date,
  1294.                         CAST(CONCAT(T1.`publication_year`, T1.`publication_month`) AS DATE) AS publication_date_full ';
  1295.         // select en plus
  1296.         if (array_key_exists('select'$params)) {
  1297.             $sql_select .= ',' $params['select'];
  1298.         }
  1299.         // compte seulement
  1300.         if (array_key_exists('count_only'$special)) {
  1301.             $sql_select 'SELECT COUNT(DISTINCT(T1.`idtext`)) as total ';
  1302.         }
  1303.         // from avec jointure entre texts/contacts
  1304.         if (array_key_exists('join'$special)) {
  1305.             $sql_from ' FROM texts T1
  1306.                                 LEFT JOIN contacts T2 ON T2.`idcontact`=T1.`idcontact_publisher` ';
  1307.         } else {
  1308.             foreach ($tables_list as $k => $v) {
  1309.                 $sql_from_tables[] = $v['table_alias'];
  1310.             }
  1311.             $sql_from ' FROM ' join(','$sql_from_tables);
  1312.         }
  1313.         // selectionde table en plus
  1314.         if (array_key_exists('from'$params)) {
  1315.             if (is_array($params['from'])) {
  1316.                 foreach ($params['from'] as $k => $v) {
  1317.                     $sql_from .= ',' $v ' T' $al;
  1318.                     // join avec la table principale ?
  1319.                     if (!empty($k) && $k == 'join') {
  1320.                         $params['where'] = ' T1.idtext=T' $al '.idtext';
  1321.                     }
  1322.                 }
  1323.                 $al++;
  1324.             } else {
  1325.                 $sql_from .= ',' $params['from'];
  1326.             }
  1327.         }
  1328.         // where standard
  1329.         $sql_where ' WHERE 1 ';
  1330.         // avec couv uniquement
  1331.         if (array_key_exists('avec_couverture'$special)) {
  1332.             $sql_from .= ' ,object_file of, files f, file_classification fc ';
  1333.             $sql_where .= ' AND of.idfile=f.idfile
  1334.                             AND of.idobject=T1.idtext
  1335.                             AND fc.idfile=f.idfile
  1336.                             AND fc.idclassification=20
  1337.                             AND of.object=\'texts\' ';
  1338.         }
  1339.         // avec un contenu associé en particulier
  1340.         if (!empty($special['idclassification'])) {
  1341.             $sql_from .= ' ,object_content oc2, contents c2, content_classification cc2 ';
  1342.             $sql_where .= ' AND oc2.idcontent=c2.idcontent
  1343.                             AND cc2.idcontent=c2.idcontent
  1344.                             AND oc2.idobject=T1.idtext
  1345.                             AND cc2.idclassification IN (' join(','$special['idclassification']) . ')
  1346.                             AND oc2.object=\'texts\' ';
  1347.         }
  1348.         // par classification
  1349.         if (array_key_exists('by_classification'$special)) {
  1350.             if (!is_array($special['by_classification'])) {
  1351.                 $sql_from .= ' ,text_classification tcl,classifications cl2';
  1352.                 $sql_where .= ' AND tcl.idtext=s.idtext
  1353.                                 AND tcl.idclassification=cl2.idclassification';
  1354.                 if ($this->my_is_int($special['by_classification'])) {
  1355.                     $sql_where .= ' AND cl2.idclassification=' . ((int)$special['by_classification']) . ' ';
  1356.                 } else {
  1357.                     $sql_where .= ' AND cl2.classification=\'' $this->escape($special['by_classification']) . '\' ';
  1358.                 }
  1359.             } else {
  1360.                 $sql_from .= ' ,text_classification tcl,classifications cl2';
  1361.                 $sql_where .= ' AND tcl.`idtext`=T1.`idtext`
  1362.                                 AND tcl.`idclassification`=cl2.`idclassification`';
  1363.                 $sql_where .= ' AND cl2.`idclassification` IN (' $this->arrayToIn($special['by_classification']) . ') ';
  1364.             }
  1365.         }
  1366.         $having_more '';
  1367.         // pour les playlists
  1368.         if (!empty($special['playlists'])) {
  1369.             if (!empty($special['playlists']['text'])) {
  1370.                 $sql_from .= ' ,`playlists` ';
  1371.                 $sql_where .= ' AND `playlists`.`idtext`=T1.`idtext` ';
  1372.             }
  1373.             if (!empty($special['playlists']['idclassifications'])) {
  1374.                 $sql_from .= ' ,`playlist_classification` ';
  1375.                 $sql_where .= ' AND `playlist_classification`.`idplaylist`=`playlists`.`idplaylist` ';
  1376.                 $sql_where .= ' AND `playlist_classification`.idclassification IN (' $this->arrayToIn($special['playlists']['idclassifications']) . ') ';
  1377.             }
  1378.             if (!isset($special['playlists']['publish'])) {
  1379.                 $sql_where .= ' AND `playlists`.`publish`=1 ';
  1380.             }
  1381.         }
  1382.         // pour les podcasts
  1383.         if (!empty($special['podcasts'])) {
  1384.             $sql_from .= ' ,`podcasts`,`podcast_text` ';
  1385.             $sql_select .= ' , podcasts.idpodcast ';
  1386.             if (!empty($special['podcasts']['type_podcast'])) {
  1387.                 //franceculture
  1388.                 if ($special['podcasts']['type_podcast'] == 'franceculture') {
  1389.                     $sql_where .= ' AND `podcasts`.`code_franceinter` IS NOT NULL ';
  1390.                 } //culturebox
  1391.                 else {
  1392.                     $sql_where .= ' AND `podcasts`.`code_ft` IS NOT NULL ';
  1393.                 }
  1394.             }
  1395.             $sql_where .= ' AND `podcast_text`.`idtext`= T1.`idtext` ';
  1396.             $sql_where .= ' AND `podcasts`.`idpodcast`=`podcast_text`.`idpodcast` ';
  1397.             if (!isset($special['podcasts']['publish'])) {
  1398.                 $sql_where .= ' AND `podcasts`.`publish`=1 ';
  1399.             }
  1400.         }
  1401.         // par aide => le type d'aide = idaide
  1402.         if (array_key_exists('aides'$special)) {
  1403.             // jionture avec text_aide et aides
  1404.             $sql_from .= ' ,text_aide tai, aides ai, aidecontacts aic';
  1405.             $sql_where .= ' AND tai.`idtext`=T1.`idtext`
  1406.                             AND tai.`idaide`=ai.`idaide`
  1407.                             AND ai.`idaidecontact`=aic.`idaidecontact` ';
  1408.             // recherche par l'aide'
  1409.             if (!empty($special['aides']['idaide'])) {
  1410.                 $sql_where .= ' AND tai.`idaide`=' . ((int)$special['aides']['idaide']) . ' ';
  1411.             }
  1412.             // recherche par la catégorie d'aide
  1413.             if (!empty($special['aides']['idaidecontact_or_type_aide']) && !empty($special['aides']['idaidecontact']) && !empty($special['aides']['type_aide'])) {
  1414.                 $sql_where .= ' AND ( aic.`idaidecontact`=' . ((int)$special['aides']['idaidecontact']) . ' OR ';
  1415.                 if (is_array($special['aides']['type_aide'])) {
  1416.                     $sql_where .= ' ai.`type_aide`IN (' implode(','$special['aides']['type_aide']) . ' ))';
  1417.                 } else {
  1418.                     $sql_where .= ' ai.`type_aide`=' . ((int)$special['aides']['type_aide']) . ' )';
  1419.                 }
  1420.             } else {
  1421.                 if (!empty($special['aides']['idaidecontact'])) {
  1422.                     $sql_where .= ' AND aic.`idaidecontact`=' . ((int)$special['aides']['idaidecontact']) . ' ';
  1423.                 }
  1424.                 // recherche par la catégorie d'aide
  1425.                 if (!empty($special['aides']['type_aide'])) {
  1426.                     if (is_array($special['aides']['type_aide'])) {
  1427.                         $sql_where .= ' AND ai.`type_aide`IN (' implode(','$special['aides']['type_aide']) . ' ) ';
  1428.                     } else {
  1429.                         $sql_where .= ' AND ai.`type_aide`=' . ((int)$special['aides']['type_aide']) . ' ';
  1430.                     }
  1431.                 }
  1432.             }
  1433.             // recherche par le contact
  1434.             if (!empty($special['aides']['idcontact'])) {
  1435.                 $sql_where .= ' AND tai.`idcontact`=' . ((int)$special['aides']['idcontact']) . ' ';
  1436.             }
  1437.             // rechercher l'année de l'aide
  1438.             if (!empty($special['aides']['year'])) {
  1439.                 $sql_where .= ' AND YEAR(tai.`date_start`)=\'' . ((int)$special['aides']['year']) . '\' ';
  1440.             }
  1441.             // par période d'aide
  1442.             if (!empty($special['aides']['period'])) {
  1443.                 if (!empty($special['aides']['period']['start'])) {
  1444.                     $sql_where .= ' AND (tai.`date_start` BETWEEN \'' $special['aides']['period']['start'] . '\' AND \'' $special['aides']['period']['end'] . '\') ';
  1445.                 }
  1446.             }
  1447.             if (!empty($special['aides']['get_by_nombres_aides'])) {
  1448.                 if (!empty($special['aides']['get_by_nombres_aides_val'])) {
  1449.                     $having_more .= ' HAVING COUNT(DISTINCT tai.idaide) = ' . (int)$special['aides']['get_by_nombres_aides_val'] . '';
  1450.                 } else {
  1451.                     $having_more .= ' HAVING COUNT(DISTINCT tai.idaide) > 1';
  1452.                 }
  1453.             }
  1454.         }
  1455.         // recherche par traducteur
  1456.         if (array_key_exists('type'$special) && $special['type'] == 'translation') {
  1457.             $sql_from .= ' text_translator tt, persons p';
  1458.             $sql_where .= ' AND tt.idtext=t.idtext AND p.idperson=tt.idperson AND T1.type=1';
  1459.         }
  1460.         // recherche par auteur
  1461.         if (array_key_exists('authors'$special)) {
  1462.             $sql_from .= ' ,text_author ta, persons p';
  1463.             $sql_where .= ' AND ta.`idtext`=T1.`idtext`
  1464.                             AND p.`idperson`=ta.`idperson` ';
  1465.             if ((isset($special['authors'][0]) && isset($special['authors'][1]))
  1466.                 && !is_array($special['authors'][0]) && is_array($special['authors'][1])) {
  1467.                 $sql_where .= ' AND ta.`idperson` ' $special['authors'][0] . ' (' join(','$special['authors'][1]) . ') ';
  1468.             } else {
  1469.                 if (!empty($special['authors']['letter'])) {
  1470.                     $sql_where .= ' AND LOWER(LEFT(LTRIM(p.`lastname`),1))=\'' $this->escape($special['authors']['letter']) . '\' ';
  1471.                 } else {
  1472.                     $sql_where .= ' AND ta.`idperson` IN (' join(','$special['authors']) . ') ';
  1473.                 }
  1474.             }
  1475.         }
  1476.         // uniquement si pas de jointure
  1477.         if (!array_key_exists('join'$special)) {
  1478.             $sql_where .= ' AND T2.idcontact=T1.idcontact_publisher';
  1479.         }
  1480.         // genre de texte
  1481.         if (!empty($special['genretext'])) {
  1482.             $sql_where .= ' AND T1.idgenretext IN (' $this->arrayToIn($special['genretext']) . ') ';
  1483.         }
  1484.         // paramètres en plus
  1485.         if (array_key_exists('where'$params)) {
  1486.             $sql_where .= $params['where'];
  1487.         }
  1488.         // publie
  1489.         /*if(!array_key_exists('publish', $params)) {
  1490.             $sql_where .= ' AND publish=1';
  1491.         }*/
  1492.         // par utilisateur
  1493.         if (!empty($special['idextranetuser'])) {
  1494.             $sql_where .= ' AND T1.idextranetuser=' . (int)$special['idextranetuser'] . ' ';
  1495.         }
  1496.         // type de texte
  1497.         // recherche alpha
  1498.         if (array_key_exists('alpha'$special)) {
  1499.             if (is_array($special['alpha'])) {
  1500.                 foreach ($special['alpha'] as $k => $v) {
  1501.                     $sql_where .= ' AND ' $k ' REGEXP \'^' $v '\' ';
  1502.                 }
  1503.             } else {
  1504.                 $sql_where .= ' AND T1.lastname REGEXP \'^' $special['alpha'] . '\' ';
  1505.             }
  1506.         }
  1507.         // recherche des textes
  1508.         if (!empty($special['idtext'])) {
  1509.             if (is_array($special['idtext'])) {
  1510.                 if (isset($special['idtext'][0]) && isset($special['idtext'][1]) && (!is_array($special['idtext'][0]) && is_array($special['idtext'][1]))) {
  1511.                     $sql_where .= ' AND T1.`idtext` ' $special['idtext'][0] . ' (' join(','$special['idtext'][1]) . ') ';
  1512.                 } else {
  1513.                     $sql_where .= ' AND T1.`idtext` IN (' join(','$special['idtext']) . ') ';
  1514.                 }
  1515.             } else {
  1516.                 $sql_where .= ' AND T1.`idtext` IN (' $special['idtext'] . ') ';
  1517.             }
  1518.         }
  1519.         // par période de publication
  1520.         if (!empty($special['periode'])) {
  1521.             if (!empty($special['periode']['from'])) {
  1522.                 $now = new DateTime(date('Y-m-d'));
  1523.                 $now->modify($special['periode']['from']);
  1524.                 $sql_where .= ' AND CAST(CONCAT(T1.`publication_year`,\'-\',T1.`publication_month`,\'-00\') AS DATE) BETWEEN \'' $now->format('Y-m') . '-00\' AND \'' date('Y-m') . '-00\' ';
  1525.             } elseif (is_array($special['periode'])) {
  1526.                 $sql_where .= ' AND CAST(CONCAT(T1.`publication_year`,\'-\',T1.`publication_month`,\'-00\') AS DATE) BETWEEN \'' $special['periode']['datestart'] . '\' AND \'' $special['periode']['dateend'] . '\' ';
  1527.             }
  1528.         }
  1529.         if (!empty($special['deja_paru'])) {
  1530.             $sql_where .= ' AND CAST(CONCAT(T1.`publication_year`,\'-\',T1.`publication_month`,\'-00\') AS DATE)<=\'' date('Y-m') . '-00\' ';
  1531.         }
  1532.         // par année de publication
  1533.         if (!empty($special['year'])) {
  1534.             $sql_where .= ' AND T1.`publication_year`=' . (int)$special['year'] . ' ';
  1535.         }
  1536.         // groupement par défaut
  1537.         if (!isset($special['no_group'])) {
  1538.             if (!array_key_exists('groupby'$params)) {
  1539.                 $groupby ' GROUP BY T1.idtext ';
  1540.             } else {
  1541.                 $groupby ' GROUP BY ' $params['groupby'];
  1542.             }
  1543.         } else {
  1544.             $groupby '';
  1545.         }
  1546.         // classement par défaut
  1547.         if (!array_key_exists('order'$params)) {
  1548.             // si ancien, classement DESC
  1549.             if (array_key_exists('anciens'$special)) {
  1550.                 $classement 'DESC';
  1551.             } else {
  1552.                 $classement 'ASC';
  1553.             }
  1554.             if (array_key_exists('classement'$params)) {
  1555.                 $classement $params['classement'];
  1556.             }
  1557.             //$order = ' ORDER BY T1.publication_year '.$classement;
  1558.             $order ' ORDER BY CAST(CONCAT(T1.`publication_year`,\'-\',T1.`publication_month`,\'-00\') AS DATE) ' $classement;
  1559.         } else {
  1560.             $order ' ORDER BY ' $params['order'];
  1561.         }
  1562.         // classement aléatoire
  1563.         if (array_key_exists('random'$special)) {
  1564.             $order ' ORDER BY RAND() ' $special['random'];
  1565.         }
  1566.         if (array_key_exists('no_order'$special)) {
  1567.             $order ' ';
  1568.         }
  1569.         // limite par défaut
  1570.         if (!array_key_exists('limit'$params)) {
  1571.             $limit ' LIMIT 0,10';
  1572.         } else {
  1573.             if ($params['limit'] != 'all') {
  1574.                 $limit ' LIMIT ' $params['limit'][0] . ',' $params['limit'][1];
  1575.             } else {
  1576.                 $limit ' ';
  1577.             }
  1578.         }
  1579.         $sql_global $sql_select $sql_from $sql_where $groupby $having_more $order $limit;
  1580.         return $sql_global;
  1581.     }
  1582.     // }}}
  1583.     //  {{{ countListTexts()
  1584.     /** Compter la liste des texts
  1585.      *
  1586.      * @access   public
  1587.      * @param array $params_sql paramètre pour la requete SQL
  1588.      * @param bool $debug mode débugage
  1589.      * @return   int
  1590.      */
  1591.     public function countListTexts($params_sql null$debug false)
  1592.     {
  1593.         // si pas de tableau
  1594.         if (!isset($params_sql['special'])) {
  1595.             $params_sql['special'] = array();
  1596.         }
  1597.         if (!isset($params_sql['params'])) {
  1598.             $params_sql['params'] = array();
  1599.         }
  1600.         // si pas de limite => tout
  1601.         if (empty($params_sql['params']['limit'])) {
  1602.             $params_sql['params']['limit'] = 'all';
  1603.         }
  1604.         $params_sql['special']['count_only'] = true;
  1605.         $params_sql['special']['no_group'] = true;
  1606.         // construction de la requête avec le passage de paramètres
  1607.         return $this->queryOne($this->getSQLTexts($params_sql['params'], $params_sql['special'], $debug));
  1608.     }
  1609.     // }}}
  1610.     //  {{{ getListTexts()
  1611.     /** Récupére la liste des texts
  1612.      *
  1613.      * Récupére les texts de manière standard
  1614.      *
  1615.      * @access   public
  1616.      * @param array $params_sql paramètre pour la requete SQL
  1617.      * @param array $format de la vignette si pas standard
  1618.      * @param bool $debug mode débugage
  1619.      * @return   array
  1620.      */
  1621.     public function getListTexts($params_sql = array(), $params = array(), $debug false)
  1622.     {
  1623.         // si pas de tableau
  1624.         if (!isset($params_sql['special'])) {
  1625.             $params_sql['special'] = array();
  1626.         }
  1627.         if (!isset($params_sql['params'])) {
  1628.             $params_sql['params'] = array();
  1629.         }
  1630.         // construction de la requête avec le passage de paramètres
  1631.         $sql $this->getSQLTexts($params_sql['params'], $params_sql['special'], $debug);
  1632.         $params_row = array();
  1633.         // style more ?
  1634.         if (!empty($params['stylemore'])) {
  1635.             $params_row['stylemore'] = $params['stylemore'];
  1636.         } else {
  1637.             $params_row['stylemore'] = array('imagep' => 'width:80px;''desctxt' => 'width:200px;');
  1638.         }
  1639.         // format de la vignette
  1640.         if (!empty($params['vignette_format'])) {
  1641.             $vignette_format $params['vignette_format'];
  1642.         } else {
  1643.             $vignette_format = array('height' => $_ENV['VIGN_TEXT_HEIGHT'], 'width' => $_ENV['VIGN_TEXT_WIDTH'], 'direction' => 'thumb');
  1644.         }
  1645.         // paramètre de debug
  1646.         $dbg = (empty($params_sql['dbg'])) ? array() : $dbg $params_sql['dbg'];
  1647.         // executer la requete
  1648.         $this->query($sql$dbg);
  1649.         $txt = array();
  1650.         // debug
  1651.         $start_boucle microtime(true);
  1652.         if (!isset($params_sql['api'])) {
  1653.             $params_row['api'] = true;
  1654.         }
  1655.         // mettre en forme chaque reponse
  1656.         while ($this->fetch()) {
  1657.             $text $this->getInfosTextRow($this->idtext$vignette_formatfalsetrue$params_row);
  1658.             $text['publisher_first'] = true;
  1659.             if (!empty($params['publisher_first_inverse'])) {
  1660.                 $text['publisher_first_inverse'] = true;
  1661.             }
  1662.             $txt[$this->idtext] = $text;
  1663.             if (!empty($txt['translators'])) {
  1664.                 ;
  1665.                 exit;
  1666.             }
  1667.         }
  1668.         // debug de la boucle
  1669.         if ($this->isTraceMode('list_object')) {
  1670.             $this->setTraceInfos(array(
  1671.                 'execution_time_boucle' => (microtime(true) - $start_boucle),
  1672.                 'dbg' => $dbg,
  1673.             ));
  1674.         }
  1675.         // libère
  1676.         $this->free();
  1677.         return $txt;
  1678.     }
  1679.     // }}}
  1680.     //  {{{ getTextsPersons()
  1681.     /** Trouver tous les texts d'une ou plusieurs personnes
  1682.      *
  1683.      * @access   public
  1684.      * @param string $type_text = type de texte
  1685.      * @return   array
  1686.      */
  1687.     public function getTextsPersons($idperson$typetext 'all'$publish 'all'$join false)
  1688.     {
  1689.         // publié ou pas ou tus
  1690.         if ($this->my_is_int($publish)) {
  1691.             $sql_publish ' AND t.`publish`=1 AND t.`valid`=1 ';
  1692.         } else {
  1693.             $sql_publish ' ';
  1694.         }
  1695.         if (is_array($idperson)) {
  1696.             $idpersons join(','$idperson);
  1697.         } else {
  1698.             $idpersons $idperson;
  1699.         }
  1700.         // trouver les textes orginaux de cette personne
  1701.         if ($typetext == 'all' || $typetext == 'original') {
  1702.             $sql_author 'SELECT t.`idtext`
  1703.                            FROM text_author ta
  1704.                            JOIN texts t ON ta.`idtext`=t.`idtext`
  1705.                            WHERE ta.`idperson` IN (' $idpersons ')' $sql_publish;
  1706.             $author $this->queryAll($sql_author);
  1707.         }
  1708.         // trouver les adaptations des textes de cette personne
  1709.         if ($typetext == 'all' || $typetext == 'adaptation') {
  1710.             $sql_adaptation 'SELECT tad.`idtextadaptation`
  1711.                                FROM text_adaptation tad
  1712.                                JOIN texts t ON t.`idtext`=tad.`idtext`
  1713.                                JOIN text_author ta ON t.`idtext`=ta.`idtext`
  1714.                                WHERE ta.`idperson` IN (' $idpersons ')' $sql_publish;
  1715.             $adaptation $this->queryAll($sql_adaptation);
  1716.         }
  1717.         // trouver les traductions par cette personne
  1718.         if ($typetext == 'all' || $typetext == 'translator') {
  1719.             $sql_translator 'SELECT t.`idtext`
  1720.                                FROM text_translator tt
  1721.                                JOIN texts t ON tt.`idtext`=t.`idtext`
  1722.                                WHERE
  1723.                                tt.`idperson` IN (' $idpersons ')' $sql_publish;
  1724.             $translator $this->queryAll($sql_translator);
  1725.         }
  1726.         // trouver les traductions des textes de cette personne
  1727.         if ($typetext == 'all' || $typetext == 'translation') {
  1728.             $sql_translation 'SELECT tt.`idtexttraduction`
  1729.                                 FROM text_traduction tt
  1730.                                 JOIN text_author ta ON tt.`idtext`=ta.`idtext`
  1731.                                 JOIN texts t ON tt.`idtext`=t.`idtext`
  1732.                                 WHERE ta.`idperson` IN (' $idpersons ')' $sql_publish;
  1733.             $translation $this->queryAll($sql_translation);
  1734.         }
  1735.         $idtexts = array();
  1736.         if (!empty($author)) {
  1737.             foreach ($author as $k => $v) {
  1738.                 $idtexts[] = $v['idtext'];
  1739.             }
  1740.         }
  1741.         if (!empty($adaptation)) {
  1742.             foreach ($adaptation as $k => $v) {
  1743.                 $idtexts[] = $v['idtextadaptation'];
  1744.             }
  1745.         }
  1746.         if (!empty($translator)) {
  1747.             foreach ($translator as $k => $v) {
  1748.                 $idtexts[] = $v['idtext'];
  1749.             }
  1750.         }
  1751.         if (!empty($translation)) {
  1752.             foreach ($translation as $k => $v) {
  1753.                 $idtexts[] = $v['idtexttraduction'];
  1754.             }
  1755.         }
  1756.         if ($join) {
  1757.             return join(','$idtexts);
  1758.         }
  1759.         return $idtexts;
  1760.     }
  1761.     // }}}
  1762.     //  {{{ countTexts()
  1763.     /** Compter le nombre total de textes
  1764.      *
  1765.      * @access public
  1766.      * @params int $type 0 ou 1 original ou traduction
  1767.      * @params int $idcontact_publisher Identifiant d'un éditeur
  1768.      * @return int
  1769.      */
  1770.     public function countTexts($type 0$idcontact_publisher null$language null)
  1771.     {
  1772.         $sql 'SELECT COUNT(DISTINCT(`idtext`))
  1773.                  FROM texts WHERE 1 ';
  1774.         if ($type != 'all') {
  1775.             $sql .= ' AND `type`=' $type;
  1776.         }
  1777.         if (!empty($idcontact_publisher)) {
  1778.             if ($idcontact_publisher == 'all') {
  1779.                 $sql .= ' AND `idcontact_publisher` IS NOT NULL ';
  1780.             } else {
  1781.                 $sql .= ' AND `idcontact_publisher`=' . (int)$idcontact_publisher;
  1782.             }
  1783.         }
  1784.         if (!empty($language)) {
  1785.             $sql .= ' AND `language`=' $this->quote($language);
  1786.         }
  1787.         return $this->queryOne($sql);
  1788.     }
  1789.     // }}}
  1790.     //  {{{ getApiFields()
  1791.     /** champs à renvoyer par l'API
  1792.      *
  1793.      * @access  public
  1794.      * @param array tableau de données
  1795.      */
  1796.     protected function getApiFields()
  1797.     {
  1798.         return array(
  1799.             'object' => 'url_clean',
  1800.             'title' => 'title',
  1801.             'url_clean' => 'permanent_url#(.*)#' $_ENV['URL_THNET'] . '/textes/${1}/'// url complète
  1802.             'type' => 'type',
  1803.             'isbn' => 'isbn',
  1804.             'allauthors->authors' => array(
  1805.                 'lastname' => 'lastname',
  1806.                 'firstname' => 'firstname',
  1807.                 'url_clean' => 'permanent_url#(.*)#' $_ENV['URL_THNET'] . '/biographies/${1}/',
  1808.             ),
  1809.             'alltranslators->translators' => array(
  1810.                 'object' => 'url_clean',
  1811.                 'lastname' => 'lastname',
  1812.                 'firstname' => 'firstname',
  1813.                 'url_clean' => 'permanent_url#(.*)#' $_ENV['URL_THNET'] . '/biographies/${1}/',
  1814.             ),
  1815.             'original' => array(
  1816.                 'object' => 'url_clean',
  1817.                 'title' => 'title',
  1818.                 'url_clean' => 'permanent_url#(.*)#' $_ENV['URL_THNET'] . '/spectacles/${1}/'// url complète
  1819.                 'allauthors->authors' => array(
  1820.                     'lastname' => 'lastname',
  1821.                     'firstname' => 'firstname',
  1822.                     'url_clean' => 'permanent_url#(.*)#' $_ENV['URL_THNET'] . '/biographies/${1}/',
  1823.                 ),
  1824.             ),
  1825.             'publisher->publishers' => array(
  1826.                 'object' => 'url_clean',
  1827.                 'organisation' => 'name',
  1828.                 'url_clean' => 'permanent_url#(.*)#' $_ENV['URL_THNET'] . '/contacts/${1}/',
  1829.             ),
  1830.             'vignette' => 'cover',
  1831.             'dateinsert' => 'insert_date',
  1832.         );
  1833.     }
  1834.     // }}}
  1835.     //  {{{ getTextsFromSpectacles()
  1836.     /** récupèrer les textes à partir d'une liste de spectacle
  1837.      *
  1838.      * @access  public
  1839.      * @param array $list_spectacles Liste des spectacles
  1840.      */
  1841.     public function getTextsFromSpectacles($list_spectacles$params_sql = array(), $params_display = array())
  1842.     {
  1843.         $conn $this->getEntityManager();
  1844.         // retrouver des textes
  1845.         foreach ($list_spectacles as $k => $v) {
  1846.             if (!empty($v['idtext'])) {
  1847.                 $idtexts[$v['idtext']] = $v['idtext'];
  1848.             }
  1849.         }
  1850.         // rechercher les textes
  1851.         if (!empty($idtexts)) {
  1852.             if (empty($params_display)) {
  1853.                 $params_display = array(
  1854.                     'stylemore' => array('imagep' => 'width:75px;''desctxt' => 'width:190px;'),
  1855.                     'vignette_format' => array('width' => 90'height' => 65'direction' => 'thumb')
  1856.                 );
  1857.             }
  1858.             if (empty($params_sql['params'])) {
  1859.                 $params_sql['params'] = array(
  1860.                     'limit' => 'all',
  1861.                     'order' => ' FIELD(T1.idtext, ' implode(','$idtexts) . ')'
  1862.                 );
  1863.             }
  1864.             if (empty($params_sql['special'])) {
  1865.                 $params_sql['special'] = array(
  1866.                     'idtext' => array('IN'$idtexts),
  1867.                     'join' => true,
  1868.                 );
  1869.             }
  1870.             if (!empty($params_sql['limit'])) {
  1871.                 $params_sql['params']['limit'] = $params_sql['limit'];
  1872.                 unset($params_sql['limit']);
  1873.             }
  1874.             $params_sql['dbg'] = array('texts_affiche_' uniqid(), 'Textes des spectacles à l\'affiche');
  1875.             $list_texts $this->getListTexts($params_sql$params_display);
  1876.             if (!empty($list_texts) && !empty($params_display['hide_publishing_date'])) {
  1877.                 foreach ($list_texts as $k => $v) {
  1878.                     $list_texts[$k]['publication_year'] = null;
  1879.                 }
  1880.             }
  1881.             // associer texts et spectacles
  1882.             $i 0;
  1883.             foreach ($list_spectacles as $k => $v) {
  1884.                 if (empty($v['collage']) && !empty($list_texts[$v['idtext']])) {
  1885.                     if (empty($list_texts_listes[$v['idtext']])) {
  1886.                         $list_texts_listes[$v['idtext']] = $list_texts[$v['idtext']];
  1887.                     }
  1888.                     if (!empty($list_texts_listes[$v['idtext']]) && array_key_exists($v['idtext'], $idtexts)) {
  1889.                         // gros dirty hack pour un texte qui a plusieurs spectacles
  1890.                         if (!empty($list_texts_listes[$v['idtext']]['spectacle'][1])) {
  1891.                             $id uniqid();
  1892.                             $list_texts_listes[$id] = $list_texts[$v['idtext']];
  1893.                             $list_texts_listes[$id]['spectacle'][1] = $v;
  1894.                             if (!empty($params_sql['get_aides'])) {
  1895.                                 $params_sql['get_aides']['special']['idtexts'] = array($v['idtext']);
  1896.                                 $params_sql['get_aides']['dbg'] = array('aide_text_' $v['idtext'], 'Aide pour le texte ' $v['idtext']);
  1897.                                 $list_texts_listes[$id]['aides'] = $conn->getRepository(Aides::class)->getListAides($params_sql['get_aides']);
  1898.                             }
  1899.                         } else {
  1900.                             $list_texts_listes[$v['idtext']]['spectacle'][1] = $v// limite 1 spectacle
  1901.                             // trouver les aides du texte et éventuellement pour le contact courant
  1902.                             if (!empty($params_sql['get_aides'])) {
  1903.                                 $params_sql['get_aides']['special']['idtexts'] = array($v['idtext']);
  1904.                                 $params_sql['get_aides']['dbg'] = array('aide_text_' $v['idtext'], 'Aide pour le texte ' $v['idtext']);
  1905.                                 $list_texts_listes[$v['idtext']]['aides'] = $conn->getRepository(Aides::class)->getListAides($params_sql['get_aides']);
  1906.                             }
  1907.                         }
  1908.                     }
  1909.                 }
  1910.             }
  1911.             return $list_texts_listes;
  1912.         }
  1913.     }
  1914.     // }}}
  1915.     // {{{ makeJsonLD()
  1916.     /** Génére le code en js+ld pour les moteurs de recherche
  1917.      *
  1918.      *
  1919.      * @access public
  1920.      * @return string
  1921.      */
  1922.     public function makeJsonLD($infos)
  1923.     {
  1924.         $tableau = array(
  1925.             "@type" => "Book",
  1926.             'bookFormat' => 'Paperback',
  1927.             'inLanguage' => $infos['language'],
  1928.             'name' => $infos['title'],
  1929. //            'numberOfPages' => $infos['nbpages'],
  1930.             'url' => $_ENV['URL_THNET'] . 'textes/' $infos['url_clean'],
  1931.             'workExample' => array(
  1932.                 "@type" => "Book",
  1933. //                'datePublished' => $infos['publication_year'].'-'.$infos['publication_month'],
  1934. //                'isbn' => $infos['isbn'],
  1935.             )
  1936.         );
  1937.         //L'illustration du livre
  1938.         if (!empty($infos['illustrations'])) {
  1939.             $tableau['image'] = $infos['illustrations'][0]['url_file_path'];
  1940.         } else if (!empty($infos['vignette_object'])) {
  1941.             $tableau['image'] = $infos['vignette_object'];
  1942.         }
  1943.         //Ajout de l'éditeur
  1944.         if (!empty($infos['publisher']['organisation'])) {
  1945.             $tableau['workExample']['publisher'] = $infos['publisher']['organisation'];
  1946.         }
  1947.         foreach ($infos['authors'] as $idperson => $person) {
  1948.             $tableau['author'][] = array(
  1949.                 "@type" => "Person",
  1950.                 "familyName" => $person['lastname'],
  1951.                 "givenName" => $person['firstname'],
  1952.                 "name" => $person['view_name']
  1953.             );
  1954.         }
  1955.         $jsonld '
  1956.         <script type="application/ld+json">
  1957.         {
  1958.         "@context": "http://schema.org",
  1959.         "@type": "WebPage",
  1960.         "mainEntity": ' json_encode($tableau) . '
  1961.         }</script>';
  1962.         return $jsonld;
  1963.     }
  1964.     // }}}
  1965. }