vendor/theatre/core/src/Repository/PlaylistsRepository.php line 899

Open in your IDE?
  1. <?php
  2. namespace TheatreCore\Repository;
  3. use TheatreCore\Entity\Classifications;
  4. use TheatreCore\Entity\Multimedias;
  5. use TheatreCore\Entity\Playlists;
  6. use TheatreCore\Traits\TheatreTrait;
  7. use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
  8. use Doctrine\Persistence\ManagerRegistry;
  9. /**
  10.  * PlaylistsRepository
  11.  *
  12.  * This class was generated by the Doctrine ORM. Add your own custom
  13.  * repository methods below.
  14.  */
  15. class PlaylistsRepository extends ServiceEntityRepository
  16. {
  17.     public $array_types = array('idperson''idspectacle''idcontact''idtext''playlist_multimedia''playlistClassification');
  18.     use TheatreTrait {
  19.         getRelationsArray as protected getRelationsArrayTrait;
  20.         getItemsList as protected getItemsListTrait;
  21.     }
  22.     private $em;
  23.     public $__table;
  24.     public $__table_object;
  25.     public $__idtable;
  26.     public function __construct(ManagerRegistry $registry)
  27.     {
  28.         parent::__construct($registryPlaylists::class);
  29.         $this->__table $this->getClassMetadata()->getTableName();
  30.         $this->__table_object $this->getClassMetadata()->name;
  31.         $this->__idtable $this->getClassMetadata()->getSingleIdentifierFieldName();
  32. //        $this->__table = 'persons';
  33. //        $this->__table_object = '\\App\\Entity\\Persons';
  34.     }
  35.     //  {{{ findData()
  36.     /** Recherche des playlists
  37.      *
  38.      * Permet de rechercher des playlists en fonction de certains critères :
  39.      * la première lettre, un bout du nom, le type de multimedia, si il est en ligne ou pas
  40.      *
  41.      * @access  public
  42.      * @see     Theatre::find()
  43.      */
  44.     public function findData($publish null$keywords null$idobject null$object null)
  45.     {
  46.         // requete perso
  47.         $query $this->createQueryBuilder('e');
  48.         if ($this->getCount()) {
  49.             $query->select('COUNT(e.idplaylist)');
  50.             $this->setCount(false);
  51.             return $query;
  52.         }
  53.         // parametre
  54.         if (isset($_REQUEST['idplaylist']) && !empty($_REQUEST['idplaylist'])) {
  55.             $idplaylist $_REQUEST['idplaylist'];
  56.         }
  57.         if (isset($_REQUEST['keywords']) && $_REQUEST['keywords'] != 'nom' && !empty($_REQUEST['keywords'])) {
  58.             $keywords $_REQUEST['keywords'];
  59.         }
  60.         if (isset($_REQUEST['publish']) && !empty($_REQUEST['publish'])) {
  61.             $publish $_REQUEST['publish'];
  62.         }
  63.         if (isset($_REQUEST['idclassification']) && !empty($_REQUEST['idclassification'])) {
  64.             $idclassification = (int)$_REQUEST['idclassification'];
  65.         }
  66.         //recherche stricte par id
  67.         if (!empty($idplaylist)) {
  68. //            $this->whereAdd($this->__table.'.'.$this->__idtable.'='.((int)$idplaylist));
  69.             $query->andWhere('e.idplaylist = :idplaylist')->setParameter(':idplaylist'$idplaylist);
  70.         }
  71.         // mots cles
  72.         if (!empty($keywords)) {
  73. //            $this->whereAdd($this->__table.'.title LIKE \'%'.$this->escape($keywords).'%\'');
  74.             $query->andWhere('e.title LIKE \'%:title%\'')->setParameter(':title'$keywords);
  75.         }
  76.         // selectionne les fiches hors ligne
  77.         if (!empty($publish) && $publish == 'no') {
  78.             $this->whereAdd($this->__table '.publish=0');
  79.             $query->andWhere('e.publish=0');
  80.         }
  81.         // selectionne les playlists auteur par lui même
  82.         if (!empty($idclassification)) {
  83.             dump('à refaire la recherche par classification');
  84. //            $this->whereAdd($this->__table.'.idplaylist IN (SELECT idplaylist FROM playlist_classification WHERE idclassification='.$idclassification.')');
  85.         }
  86.         // on lance la recherche
  87.         return $query->getQuery();
  88.     }
  89.     // }}}
  90.     //  {{{ setToArray()
  91.     /** Liste des multimedias dans un tableau associatif
  92.      *
  93.      * Tableau associatif notament utilisé pour lister les informations sur les multimedias
  94.      * Utile pour générer les tableaux HTML de listes de multimedias
  95.      *
  96.      * @access  public
  97.      * @return  array
  98.      * @see     findData()
  99.      */
  100.     public function setToArray($spec true)
  101.     {
  102.         if ($spec == true) {
  103.             $this->findData();
  104.         }
  105.         $values = array();
  106.         $color null;
  107.         $nb 0;
  108.         while ($this->fetch()) {
  109.             // valeurs de l'enregistrement
  110.             $values[$nb] = $this->getInfosPlaylist();
  111.             // couleur de ligne alternative
  112.             $color $this->colorAlternate($color);
  113.             $values[$nb]['colorline'] = $color;
  114.             $values[$nb]['id'] = $this->idplaylist;
  115.             $nb++;
  116.         }
  117.         return $values;
  118.     }
  119.     // }}}
  120.     //  {{{ orderByDefaut()
  121.     /** Classement par défaut
  122.      *
  123.      * Défini le tri par défaut pour les requêtes de type SELECT
  124.      *
  125.      * @access public
  126.      * @return string
  127.      */
  128.     public function orderByDefaut($order null)
  129.     {
  130.         // tri par défaut
  131.         if (empty($order)) {
  132.             $order 'idplaylist';
  133.         }
  134.         return $order;
  135.     }
  136.     // }}}
  137.     //  {{{ getInfosPlaylist()
  138.     /** Informations sur un playlist
  139.      *
  140.      * @access public
  141.      * @param int $idplaylist numero de la fiche playlist
  142.      * @return array  les infos sous forme de tableau
  143.      */
  144.     public function getInfosPlaylist($idplaylist null$params_data = array(), $params_display = array())
  145.     {
  146.         $infos = array();
  147.         $con $this->getEntityManager();
  148.         ////////////// infos de la table
  149.         if (!isset($this->idplaylist) || empty($this->idplaylist) || $this->idplaylist != $idplaylist) {
  150.             if (!empty($idplaylist)) {
  151. //                $x;
  152. //                if(!$this->get($idplaylist)) {
  153. //                    return array();
  154. //                } else {
  155. //                    $infos = $this->objToArray();
  156. //                }
  157.                 $query $con->getRepository(Playlists::class)
  158.                     ->createQueryBuilder('e')
  159.                     ->select('e')
  160.                     ->andWhere('e.idplaylist = :idplaylist')
  161.                     ->setParameter('idplaylist'$idplaylist)
  162.                     ->getQuery();
  163.                 $infos $this->objToArray($query);
  164.                 $this->loadResult($infos);
  165.                 if (empty($infos)) {
  166.                     return [];
  167.                 }
  168.             }
  169.         } else {
  170.             $idplaylist $this->idplaylist;
  171. //            $x->setParameter('$idplaylist', $idplaylist);
  172.             $query $con->getRepository(Playlists::class)
  173.                 ->createQueryBuilder('e')
  174.                 ->select('e')
  175.                 ->andWhere('e.idplaylist = :idplaylist')
  176.                 ->setParameter('idplaylist'$idplaylist)
  177.                 ->getQuery();
  178.             $infos $this->objToArray($query);
  179.             $this->loadResult($infos);
  180.             if (empty($infos)) {
  181.                 return [];
  182.             }
  183.         }
  184.         $format_vignette = array();
  185.         if (!empty($params_data['format_vignette'])) {
  186.             $format_vignette $params_data['format_vignette'];
  187.         }
  188.         $params_display array_merge(array('alldata' => true), $params_display);
  189.         $infos['nameview'] = $this->title ?? null;
  190.         if (!empty($params_data['all'])) {
  191.             // les relations
  192.             foreach ($this->array_types as $t) {
  193.                 $x $this->getRelationsArray($t);
  194.                 $infos[$t] = $this->noPunct($this->getLinkedObject($this->getRelationsArray($t), $idplaylist$t'playlists'));
  195.             }
  196.             // récupèrer le détail des éléments multimedias associés
  197.             if (!empty($params_data['multimedias']) && !empty($infos['playlist_multimedia'])) {
  198.                 $multimedias $con->getRepository(Multimedias::class);
  199.                 foreach ($infos['playlist_multimedia'] as $m) {
  200.                     $ids_multimedia[] = $m['idmultimedia'];
  201.                 }
  202.                 $params_multimedias = array(
  203.                     'where' => array(array('multimedias''idmultimedia'$ids_multimedia)),
  204.                     'order' => array(array('multimedias''idmultimedia'$ids_multimedia)), // classement par le IN via FIELD
  205.                     'dbg' => array('rech''Vidéos liées au playlist'),
  206.                 );
  207.                 if (!empty($params_display['limitmultimedias'])) {
  208.                     $params_multimedias['limit'] = $params_display['limitmultimedias'];
  209.                 }
  210.                 $infos['multimedias'] = $multimedias->getListMultimedias($params_multimedias$format_vignette$params_display);
  211.                 // compter
  212.                 $infos['nb_multimedias'] = count($ids_multimedia);
  213.                 // prendre la première vignette
  214.                 foreach ($infos['multimedias'] as $k => $v) {
  215.                     $infos['vignette'] = $v['vignette'];
  216.                     $infos['vignette_flou'] = $v['vignette_flou'];
  217.                 }
  218.             }
  219.             // récupèrer les classifications
  220.             $infos['classifications'] = $con->getRepository(Classifications::class)->getObjectClassification('playlists'$idplaylist$this->getRelationsArray('playlist_classification'));
  221.         }
  222.         if (!empty($infos['description'])) {
  223.             $infos['description_html'] = $this->wikiTransform($infos['description']);
  224.         }
  225.         return $infos;
  226.     }
  227.     // }}}
  228.     //  {{{ getItemsList()
  229.     /** Liste des items pour les champs relationnels
  230.      *
  231.      * Retourne un tableau associatif contenant la liste des items d'une relation
  232.      *
  233.      * @access  public
  234.      * @param string $type Ce qu'on recherche
  235.      * @param string $idtext L'id de l'objet
  236.      * @return  array
  237.      */
  238.     public function getItemsList($idplaylist$type)
  239.     {
  240.         if (in_array($type$this->array_types)) {
  241.             return $this->getLinkedObject($this->getRelationsArray($type), $idplaylist$type'playlists');
  242.         } else {
  243.             return 'Aucune fonction de recherche pour le type <strong>' $type '</strong> dans la méthode !';
  244.         }
  245.     }
  246.     // }}}
  247.     //  {{{ getRelationsArray()
  248.     /** Tableau des relations
  249.      *
  250.      * @access  public
  251.      * @param string|int $type le type de champ
  252.      */
  253.     public function getRelationsArray($type null)
  254.     {
  255.         // récupérer les relations communes
  256.         $array_types $this->getRelationsArrayTrait('all');
  257.         $array_types += array(
  258.             'idspectacle' => array(
  259.                 'type_join' => 'simple',
  260.                 'dest_table' => 'spectacles',
  261.                 'join_field_src' => 'idspectacle',
  262.                 'dest_table_field' => 'idspectacle',
  263.                 'fields' => array('idspectacle''title''url_clean'),
  264.                 'hide_relation' => true,
  265.                 'silent_delete_relation' => true,
  266.                 'description' => 'Spectacle associé à cette playlist',
  267.             ),
  268.             'idperson' => array(
  269.                 'type_join' => 'simple',
  270.                 'dest_table' => 'persons',
  271.                 'join_field_src' => 'idperson',
  272.                 'dest_table_field' => 'idperson',
  273.                 'fields' => array('idperson''lastname''firstname''url_clean'),
  274.                 'silent_delete_relation' => true,
  275.                 'description' => 'Personne associée à cette playlist',
  276.             ),
  277.             'idcontact' => array(
  278.                 'type_join' => 'simple',
  279.                 'dest_table' => 'contacts',
  280.                 'join_field_src' => 'idcontact',
  281.                 'dest_table_field' => 'idcontact',
  282.                 'fields' => array('idcontact''organisation''url_clean'),
  283.                 'silent_delete_relation' => true,
  284.                 'description' => 'Contact associé à cette playlist',
  285.             ),
  286.             'idtext' => array(
  287.                 'type_join' => 'simple',
  288.                 'dest_table' => 'texts',
  289.                 'join_field_src' => 'idtext',
  290.                 'dest_table_field' => 'idtext',
  291.                 'fields' => array('idtext''title''url_clean'),
  292.                 'silent_delete_relation' => true,
  293.                 'description' => 'Texte associé à cette playlist',
  294.             ),
  295.             'playlist_multimedia' => array(
  296.                 'type_join' => 'multiple',
  297.                 'dest_table' => 'multimedias',
  298.                 'fields' => array('idmultimedia''sujet_titre''url_clean''status''price'),
  299.                 'join_table' => 'playlist_multimedia',
  300.                 'hide_relation' => true,
  301.                 'silent_delete_relation' => true,
  302.                 'sql_more' => ' ORDER BY j2.`orderplaylist` ',
  303.                 'description' => 'Multimédia(s) associé(s) à cette playlist',
  304.             ),
  305.             'playlist_classification' => array(
  306.                 'type_join' => 'multiple',
  307.                 'dest_table' => 'classifications',
  308.                 'fields' => array('idclassification''classification''type''idgroupclassification'),
  309.                 'join_table' => 'playlist_classification',
  310.                 'hide_relation' => true,
  311.                 'silent_delete_relation' => true,
  312.                 'description' => 'Classification(s) associée(s) à cette playlist',
  313.             ),
  314.         );
  315.         if (!empty($array_types[$type])) {
  316.             $array_types[$type]['type'] = $type;
  317.             return $array_types[$type];
  318.         } else {
  319.             return $array_types;
  320.         }
  321.     }
  322.     // }}}
  323.     //  {{{ getSQLPlaylists()
  324.     /** Générer la requete standard pour des playlists
  325.      *
  326.      *
  327.      * @access   public
  328.      * @param array $params Les paramètres pour la requete
  329.      * @param array $special Les paramètres supplémentaires
  330.      * @param bool $debug afficher la requête TODO
  331.      * @return   string
  332.      */
  333.     public function getSQLPlaylists($query = array(), $debug false)
  334.     {
  335.         // on prepare les tableaux
  336.         foreach (array('select''from''where''order''group''limit') as $t) {
  337.             if (!empty($query[$t])) {
  338.                 if (!is_array($query[$t])) {
  339.                     $query[$t][] = $query[$t];
  340.                 } else {
  341.                     $query[$t] = $query[$t];
  342.                 }
  343.             } else {
  344.                 $query[$t] = array();
  345.             }
  346.         }
  347.         // champs par défaut
  348.         $this->addSQLParams('select'$query, array(
  349.             array('playlists' => '*')
  350.         ));
  351.         // publié ou pas
  352.         if (empty($query['publish']) && $_ENV['CHECK_IF_ONLINE']) {
  353.             $this->addSQLParams('where'$query, array(
  354.                 array('playlists''publish'1)
  355.             ));
  356.         } elseif (!empty($query['publish'])) {
  357.             $this->addSQLParams('where'$query, array(
  358.                 array('playlists''publish'$query['publish'])
  359.             ));
  360.         }
  361.         // recherche par liaison via playlist_multimedia
  362.         if (!empty($query['special']['idmultimedias'])) {
  363.             $this->addSQLParams('from'$query, array(
  364.                 'playlist_multimedia',
  365.             ));
  366.             // jointure entre les 3 tables
  367.             $this->addSQLParams('join'$query, array(
  368.                 'playlists.`idplaylist`' => 'playlist_multimedia.`idplaylist`',
  369.             ));
  370.             $this->addSQLParams('where'$query, array(
  371.                 array('playlist_multimedia''idmultimedia'$query['special']['idmultimedias']),
  372.             ));
  373.             $this->addSQLParams('order'$query, array(
  374.                 array('playlist_multimedia''orderplaylist'),
  375.             ));
  376.         }
  377.         // recherche par liaison via playlist_person
  378.         if (!empty($query['special']['idpersons'])) {
  379.             $this->addSQLParams('where'$query, array(
  380.                 array('playlists''idperson'$query['special']['idpersons']),
  381.             ));
  382.             $this->addSQLParams('order'$query, array(
  383.                 array('playlists''idperson'$query['special']['idpersons']),
  384.             ));
  385.         }
  386.         // jointure avec persons
  387.         if (!empty($query['special']['persons'])) {
  388.             $this->addSQLParams('from'$query, array(
  389.                 'persons',
  390.             ));
  391.             $this->addSQLParams('join'$query, array(
  392.                 'playlists.`idperson`' => 'persons.`idperson`',
  393.             ));
  394.             $this->addSQLParams('order'$query, array('persons.`lastname`'));
  395.             $this->addSQLParams('direction'$query'ASC');
  396.             if (!empty($query['special']['persons']['group'])) {
  397.                 $this->addSQLParams('group'$query$query['special']['persons']['group']);
  398.             }
  399.             if (!empty($query['special']['persons']['idperson'])) {
  400.                 $this->addSQLParams('where'$query, array(
  401.                     array('persons''idperson'$query['special']['persons']['idperson']),
  402.                 ));
  403.             }
  404.         }
  405.         // recherche par liaison via playlist_text
  406.         if (!empty($query['special']['idtext'])) {
  407.             $this->addSQLParams('where'$query, array(
  408.                 array('playlists''idtext'$query['special']['idtext']),
  409.             ));
  410.         }
  411.         // jointure avec text_aide et aide
  412.         if (!empty($query['special']['aides'])) {
  413.             $this->addSQLParams('from'$query, array(
  414.                 'aides',
  415.             ));
  416.             if (!empty($query['special']['aides']['text_aide'])) {
  417.                 $this->addSQLParams('from'$query, array(
  418.                     'text_aide',
  419.                 ));
  420.                 $this->addSQLParams('join'$query, array(
  421.                     'playlists.`idtext`' => 'text_aide.`idtext`',
  422.                 ));
  423.                 $this->addSQLParams('join'$query, array(
  424.                     'text_aide.`idaide`' => 'aides.`idaide`',
  425.                 ));
  426.             }
  427.             if (!empty($query['special']['aides']['idaidecontact'])) {
  428.                 $this->addSQLParams('where'$query, array(
  429.                     array('aides''idaidecontact'$query['special']['aides']['idaidecontact']),
  430.                 ));
  431.             }
  432.         }
  433.         // recherche par classification
  434.         if (!empty($query['special']['idclassifications'])) {
  435.             $this->addSQLParams('from'$query, array(
  436.                 'playlist_classification',
  437.             ));
  438.             // jointure entre les 3 tables
  439.             $this->addSQLParams('join'$query, array(
  440.                 'playlists.`idplaylist`' => 'playlist_classification.`idplaylist`',
  441.             ));
  442.             $this->addSQLParams('where'$query, array(
  443.                 array('playlist_classification''idclassification'$query['special']['idclassifications']),
  444.             ));
  445.         }
  446.         return $this->getSQLObject($query);
  447.     }
  448.     // }}}
  449.     //  {{{ countListPlaylists()
  450.     /** Compter la liste des playlists
  451.      *
  452.      * @access   public
  453.      * @param array $params_sql paramètre pour la requete SQL
  454.      * @param bool $debug mode débugage
  455.      * @return   int
  456.      */
  457.     public function countListPlaylists($params_sql null$debug false)
  458.     {
  459.         // si pas de tableau
  460.         if (!isset($params_sql['special'])) {
  461.             $params_sql['special'] = array();
  462.         }
  463.         if (!isset($params_sql['params'])) {
  464.             $params_sql['params'] = array();
  465.         }
  466.         // si pas de limite => tout
  467.         if (empty($params_sql['params']['limit'])) {
  468.             $params_sql['limit'] = array('all');
  469.         }
  470.         $params_sql['count_only'] = true;
  471.         // construction de la requête avec le passage de paramètres
  472.         return $this->queryOne($this->getSQLPlaylists($params_sql$debug));
  473.     }
  474.     // }}}
  475.     //  {{{ getListPlaylists()
  476.     /** Retourne des listes de playlists
  477.      *
  478.      * Retourne des listes de playlist au format "standard""
  479.      *
  480.      * @access   public
  481.      * @param array $params_sql paramètre pour la requete SQL
  482.      * @param array $format_vignette de la vignette si pas standard
  483.      * @param array $params_display paramètre pour l'affichage
  484.      * @return   array
  485.      */
  486.     public function getListPlaylists($params_sql null$format_vignette = array(), $params_display = array())
  487.     {
  488.         // si pas de tableau
  489.         if (!isset($params_sql['special'])) {
  490.             $params_sql['special'] = array();
  491.         }
  492.         if (!isset($params_sql['params'])) {
  493.             $params_sql['params'] = array();
  494.         }
  495.         // construction de la requête avec le passage de paramètres
  496.         $sql $this->getSQLPlaylists($params_sql);
  497.         // paramètre de debug
  498.         $dbg = (empty($params_sql['dbg'])) ? array() : $dbg $params_sql['dbg'];
  499.         // executer la requete
  500.         $this->query($sql$dbg);
  501.         $videos = array();
  502.         // donnée entières ?
  503.         if (empty($params_display['alldata'])) {
  504.             $params_display['alldata'] = false;
  505.         }
  506.         // debug
  507.         $start_boucle microtime(true);
  508.         $playlists = array();
  509.         $datas $this->query($sql);
  510.         // on boucle
  511.         foreach ($datas as $data) {
  512.             $this->loadResult($data);
  513.             if (!empty($params_sql['count_only'])) {
  514.                 return $this->total;
  515.             }
  516.             $idplaylist $this->idplaylist;
  517.             if (!empty($params_sql['fields'])) {
  518.                 foreach ($params_sql['fields'] as $f) {
  519.                     $playlists[$idplaylist][$f] = $this->$f;
  520.                 }
  521.             } else {
  522.                 $playlists[$idplaylist] = $this->getInfosPlaylist($idplaylist, array('all' => true'multimedias' => true), array('vignette_format' => $format_vignette));
  523.             }
  524.         }
  525.         if (!empty($params_display['other_url_clean'])) {
  526.             if (!empty($playlists)) {
  527.                 foreach ($playlists as $k => $v) {
  528.                     // le lien vers le contenu directement
  529.                     if (!empty($v['idtext'])) {
  530.                         foreach ($v['idtext'] as $t) {
  531.                             $playlists[$k]['other_url_clean'] = '/textes/' $t['url_clean'] . '/playlist/id/' $v['urlClean'];
  532.                         }
  533.                     }
  534.                 }
  535.             }
  536.         }
  537.         // debug de la boucle
  538.         if ($this->isTraceMode('list_object')) {
  539.             $this->setTraceInfos(array(
  540.                 'execution_time_boucle' => microtime(true) - $start_boucle,
  541.                 'nb_occurence' => count($playlists),
  542.                 'dbg' => $dbg,
  543.             ));
  544.         }
  545.         $this->free();
  546.         return $playlists;
  547.     }
  548.     // }}}
  549.     //  {{{ getObjectTitle()
  550.     /** Infos de l'item recherché
  551.      *
  552.      * Affichage standard du titre de l'objet
  553.      *
  554.      * @access public
  555.      * @param int $idobject Identifiant de l'item
  556.      * @param array $infos_object Informations pour construire le titre
  557.      * @param array $params Paramétres supplémentaires
  558.      * @return string
  559.      */
  560.     public function getObjectTitle($idobject null$infos_object = array(), $params = array())
  561.     {
  562.         $title '';
  563.         if (!$idobject) {
  564.             $idobject $this->idplaylist;
  565.         }
  566.         // champs
  567.         $fields = array('idplaylist''title''url_clean');
  568.         if (!empty($infos_object)) {
  569.             foreach ($fields as $k => $v) {
  570.                 if (array_key_exists($v$infos_object)) {
  571.                     $$v $infos_object[$v];
  572.                 }
  573.             }
  574.         } else {
  575.             //charger les infos que si necessaire
  576.             if (empty($this->title)) {
  577.                 $this->selectAdd();
  578.                 $this->selectAdd(implode(','$fields));
  579.                 $this->get($idobject);
  580.             }
  581.             foreach ($fields as $k => $v) {
  582.                 if (isset($this->$v) && $this->$v != '') {
  583.                     $$v trim($this->$v);
  584.                 }
  585.             }
  586.         }
  587.         return $title;
  588.     }
  589.     // }}}
  590.     //  {{{ getListSearch()
  591.     /** Liste des playlists
  592.      *
  593.      * Pour les champs Ajax de relations et les recherches diverses
  594.      *
  595.      * @access  public
  596.      * @param string $lettres Pour la recherche alphabetique
  597.      * @param string $type Pour le type recherche (editeurs, revues...)
  598.      * @param string $keywords Recherche par mots cles
  599.      * @return  array
  600.      */
  601.     public function getListSearch($lettre$type null$keywords null)
  602.     {
  603.         $sql 'SELECT ' $this->__idtable ', title
  604.                  FROM ' $this->__table '
  605.                  WHERE 1 ';
  606.         // selection par ordre alpha
  607.         if (!empty($lettre) && $lettre != 'tous') {
  608.             $sql_where[] = array('LOWER(LEFT(LTRIM(title),1))=\'' $this->escape($lettre) . '\'');
  609.         }
  610.         // recherche avec un mot cle
  611.         $list $this->splitKeywords($keywords);
  612.         if ($list) {
  613.             if (!empty($list[$this->IDSTR])) {
  614.                 // mots clés
  615.                 foreach ($list[$this->IDSTR] as $s) {
  616.                     $sql_more_name[] = 'title LIKE \'%' $s '%\'';
  617.                 }
  618.                 $sql_where[] = array('(' join(' OR '$sql_more_name) . ')');
  619.             }
  620.             if (!empty($list[$this->IDNUM])) {
  621.                 // recherche par numéro d'id pour les mots clés numériques
  622.                 $sql_where[] = array('idplaylist IN (' implode(','$list[$this->IDNUM]) . ')''OR');
  623.             }
  624.         }
  625.         foreach ($sql_where as $k => $v) {
  626.             if (!empty($v[1])) {
  627.                 $sql .= ' ' $v[1] . ' ' $v[0];
  628.             } else {
  629.                 $sql .= ' AND ' $v[0];
  630.             }
  631.         }
  632.         $sql .= ' ORDER BY title';
  633.         $this->query($sql);
  634.         $r = array();
  635.         while ($this->fetch()) {
  636.             $r[$this->idplaylist] = $this->title;
  637.             // si trouvé par id, on l'affiche en fin de titre
  638.             if (!empty($list[$this->IDNUM]) && in_array($this->idplaylist$list[$this->IDNUM])) {
  639.                 $r[$this->idplaylist] .= ' - n°' $this->idplaylist;
  640.             }
  641.         }
  642.         $this->free();
  643.         return $r;
  644.     }
  645.     // }}}
  646.     //  {{{ countPlaylists()
  647.     /** Nombre de Playlist
  648.      *
  649.      * Compter le nb de playlists
  650.      *
  651.      * @access  public
  652.      * @return  int
  653.      */
  654.     public function countPlaylists($object null$idobject null$classification null)
  655.     {
  656.         if (!empty($object) && !empty($idobject)) {
  657.             $object substr($object0, -1);
  658.             $sql_count '
  659.                 SELECT COUNT(DISTINCT(p.`' $this->__idtable '`)) as total
  660.                 FROM ' $this->__table ' p
  661.                     LEFT JOIN playlist_classification pc ON pc.`idplaylist`=p.`idplaylist`
  662.                     LEFT JOIN classifications c ON pc.`idclassification`=c.`idclassification`
  663.                 WHERE p.`publish`=1
  664.                 AND p.`id' $object '` IN (' $this->arrayToIn($idobject) . ') ';
  665.         } else {
  666.             $sql_count '
  667.                 SELECT COUNT(DISTINCT(p.`' $this->__idtable '`)) as total
  668.                 FROM ' $this->__table ' p
  669.                     LEFT JOIN playlist_classification pc ON pc.`idplaylist`=p.`idplaylist`
  670.                     LEFT JOIN classifications c ON pc.`idclassification`=c.`idclassification`
  671.                 WHERE p.`publish`=1';
  672.         }
  673.         if (!empty($classification)) {
  674.             if ($this->my_is_int($classification)) {
  675.                 $sql_count .= ' AND c.`idclassification`=' . (int)$classification;
  676.             } else {
  677.                 if (is_array($classification)) {
  678.                     $sql_count .= ' AND c.`classification` IN (\'' implode('\',\''$classification) . '\')';
  679.                 } else {
  680.                     $sql_count .= ' AND c.`classification`=\'' $this->escape($classification) . '\'';
  681.                 }
  682.             }
  683.         }
  684.         $total $this->queryOne($sql_count);
  685.         if ($total) {
  686.             return $total;
  687.         } else {
  688.             return null;
  689.         }
  690.     }
  691.     // }}}
  692.     //  {{{ getByClassification()
  693.     /** Nombre de Playlist
  694.      *
  695.      * Compter le nb de playlists
  696.      *
  697.      * @access  public
  698.      * @return  int
  699.      */
  700.     public function getByClassification($object$idobject$classification null)
  701.     {
  702.         if (!empty($object) && !empty($idobject)) {
  703.             $object substr($object0, -1);
  704.             $sql_count '
  705.                 SELECT p.`idplaylist`
  706.                 FROM ' $this->__table ' p
  707.                     LEFT JOIN playlist_classification pc ON pc.`idplaylist`=p.`idplaylist`
  708.                     LEFT JOIN classifications c ON pc.`idclassification`=c.`idclassification`
  709.                 WHERE p.`publish`=1
  710.                 AND p.`id' $object '`=' . (int)$idobject;
  711.         } else {
  712.             $sql_count '
  713.                 SELECT p.`idplaylist`
  714.                 FROM ' $this->__table ' p
  715.                     LEFT JOIN playlist_classification pc ON pc.`idplaylist`=p.`idplaylist`
  716.                     LEFT JOIN classifications c ON pc.`idclassification`=c.`idclassification`
  717.                 WHERE p.`publish`=1';
  718.         }
  719.         if (!empty($classification)) {
  720.             if ($this->my_is_int($classification)) {
  721.                 $sql_count .= ' AND c.`idclassification`=' . (int)$classification;
  722.             } else {
  723.                 if (is_array($classification)) {
  724.                     $sql_count .= ' AND c.`classification` IN (\'' implode('\',\''$classification) . '\')';
  725.                 } else {
  726.                     $sql_count .= ' AND c.`classification`=\'' $this->escape($classification) . '\'';
  727.                 }
  728.             }
  729.         }
  730.         $sql_count .= ' LIMIT 0,1';
  731.         $idplaylist $this->queryOne($sql_count);
  732.         if ($idplaylist) {
  733.             return $this->getInfosPlaylist($idplaylist, array('all' => true));
  734.         } else {
  735.             return null;
  736.         }
  737.     }
  738.     // }}}
  739.     //  {{{ getSpectaclesAnneesSaisons()
  740.     /** Récupèrer les années saisons où il y a des spectacles
  741.      *
  742.      * Récupérer les années et saisons où il y a des spectacles à l'affiche associés ipar le texte à une playlist avec une classification
  743.      *
  744.      * @access  public
  745.      * @return  array
  746.      */
  747.     public function getSpectaclesAnneesSaisons($idclassifications = array())
  748.     {
  749.         $sql_annees 'SELECT sc.`date`, YEAR(sc.`date`) as annee
  750.                         FROM `schedules` sc
  751.                         JOIN `spectacles` s ON sc.`idspectacle`=s.`idspectacle`
  752.                         JOIN `text_spectacle` ts ON ts.`idspectacle`=s.`idspectacle`
  753.                         JOIN `playlists` p ON p.`idtext`=ts.`idtext`
  754.                         JOIN `playlist_classification` pc ON pc.`idplaylist`=p.`idplaylist`
  755.                         WHERE 1
  756.                         AND s.`textfictif`=0 AND s.`publish`=1 AND s.`valid`=1
  757.                         AND p.`publish`=1
  758.                         AND pc.`idclassification` IN (' $this->arrayToIn($idclassifications) . ')
  759.                         AND sc.`date` > \'1999-12-31\'
  760.                         ORDER BY sc.`date` ';
  761.         $listdates $this->queryAll($sql_annees);
  762.         return $listdates;
  763.     }
  764.     // }}}
  765.     //  {{{ getAutors()
  766.     /** Récupèrer les auteurs qui ont un texte par l'auteur
  767.      *
  768.      * @access  public
  769.      * @return  array
  770.      */
  771.     public function getAuthors()
  772.     {
  773.         $fields = array(
  774.             'idperson',
  775.             'lastname',
  776.             'firstname',
  777.             'url_clean',
  778.         );
  779.         foreach ($fields as $k => $v) {
  780.             $select[] = '`persons`.`' $v '`';
  781.         }
  782.         $sql_persons 'SELECT ' implode(', '$select) . '
  783.                         FROM `persons` , `playlist_classification` , `playlists`
  784.                         WHERE 1 AND playlists.`publish`=1
  785.                         AND playlist_classification.`idclassification` IN (144) AND playlists.`idperson`=persons.`idperson`
  786.                         AND playlists.`idplaylist`=playlist_classification.`idplaylist`
  787.                         GROUP BY `persons`.`idperson`
  788.                         ORDER BY `persons`.`lastname` ';
  789.         $listpersons $this->queryAll($sql_persons);
  790.         if (!empty($listpersons)) {
  791.             foreach ($listpersons as $k => $v) {
  792.                 $listpersons[$k]['lastname'] = mb_strtoupper($v['lastname'], 'UTF8');
  793.             }
  794.         }
  795.         return $listpersons;
  796.     }
  797.     // }}}
  798. }