vendor/theatre/core/src/Repository/KeywordsRepository.php line 322

Open in your IDE?
  1. <?php
  2. namespace TheatreCore\Repository;
  3. use TheatreCore\Entity\Keywords;
  4. use TheatreCore\Traits\TheatreTrait;
  5. use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
  6. use Doctrine\Persistence\ManagerRegistry;
  7. /**
  8.  * KeywodsRepository
  9.  *
  10.  * This class was generated by the Doctrine ORM. Add your own custom
  11.  * repository methods below.
  12.  */
  13. class KeywordsRepository extends ServiceEntityRepository
  14. {
  15.     use TheatreTrait;
  16.     private $em;
  17.     public $__table;
  18.     public $__table_object;
  19.     public $__idtable;
  20.     public function __construct(ManagerRegistry $registry)
  21.     {
  22.         parent::__construct($registryKeywords::class);
  23.         $this->__table $this->getClassMetadata()->getTableName();
  24.         $this->__table_object $this->getClassMetadata()->name;
  25.         $this->__idtable $this->getClassMetadata()->getSingleIdentifierFieldName();
  26.     }
  27.     //  {{{ findData()
  28.     /** Recherche d'keyword
  29.      *
  30.      * Permet de rechercher des keywords selon différents critères
  31.      *
  32.      * @access  public
  33.      * @see     Theatre::find()
  34.      */
  35.     public function findData($idclassification null)
  36.     {
  37.         // parametres
  38.         if (isset($_REQUEST['keywords']) && $_REQUEST['keywords'] != 'nom') {
  39.             $keywords filter_var(trim($_REQUEST['keywords']));
  40.         }
  41.         if (isset($_REQUEST['idkeyword']) && my_is_int($_REQUEST['idkeyword'])) {
  42.             $idkeyword = (int)$_REQUEST['idkeyword'];
  43.         }
  44.         $query $this->createQueryBuilder('e');
  45.         if ($this->getCount()) {
  46.             $query->select('COUNT(e.idkeyword)');
  47.             $this->setCount(false);
  48.             return $query;
  49.         }
  50.         // query perso
  51. //        $query = 'SELECT * FROM '.$this->__table.'
  52. //                    WHERE  1';
  53. //
  54. //        //recherche stricte par id
  55. //        if(!empty($idkeyword)) {
  56. //            $query .= ' AND cl.idkeyword='.(int)$idkeyword;
  57. //        } else {
  58. //            // mots cles
  59. //            if (!empty($keywords)) {
  60. //                $query .= ' AND title LIKE \'%'.$this->escape($keywords).'%\' ';
  61. //            }
  62. //        }
  63.         // on lance la recherche
  64.         return $query->getQuery();
  65.     }
  66.     // }}}
  67.     //  {{{ setToArray()
  68.     /** Liste des keywords dans un tableau associatif
  69.      *
  70.      * Tableau associatif notament utilisé pour lister les informations sur des keywords
  71.      * Utile pour générer les tableaux HTML de listes de keywords
  72.      *
  73.      * @access  public
  74.      * @return  array
  75.      * @see     findData()
  76.      */
  77.     public function setToArray($spec true)
  78.     {
  79.         if ($spec == true) {
  80.             $this->findData();
  81.         }
  82.         $values = array();
  83.         $color null;
  84.         $nb 0;
  85.         while ($this->fetch()) {
  86.             $values[$nb] = $this->getInfosKeyword();
  87.             $values[$nb]['id'] = $this->idkeyword;
  88.             // couleur de ligne alternative
  89.             $color $this->colorAlternate($color);
  90.             $values[$nb]['colorline'] = $color;
  91.             $nb++;
  92.         }
  93.         return $values;
  94.     }
  95.     // }}}
  96.     //  {{{ getInfosKeyword()
  97.     /** Informations sur une keyword
  98.      *
  99.      * @access public
  100.      * @param int $idkeyword Identifiant de l'keyword
  101.      * @return array
  102.      */
  103.     public function getInfosKeyword($idkeyword null$params = array())
  104.     {
  105.         $infos = array();
  106.         ////////////// infos de la table
  107.         if (empty($this->idkeyword)) {
  108.             $data $this->get($idkeyword);
  109.             $this->loadResult($data);
  110.         }
  111.         $infos += array(
  112.             'idkeyword' => $this->idkeyword,
  113.             'title' => $this->title,
  114.             'url_clean' => $this->url_clean,
  115.             'dateupdate' => $this->dateupdate,
  116.             'dateinsert' => $this->dateinsert,
  117.             'publish' => $this->publish,
  118.         );
  119.         $infos['nameview'] = $this->title;
  120.         return $infos;
  121.     }
  122.     // }}}
  123.     //  {{{ getObjectTitle()
  124.     /** Infos de l'item recherché
  125.      *
  126.      *
  127.      * @access public
  128.      * @param int $idobject Identifiant de l'item
  129.      * @param array $infos_object Informations pour construire le titre
  130.      * @param array $params Paramétres supplémentaires
  131.      * @return string|array
  132.      */
  133.     public function getObjectTitle($idobject null$infos_object = array(), $params = array())
  134.     {
  135.         if (!$idobject && isset($this->idkeyword)) $idobject $this->idkeyword;
  136.         // champs
  137.         $fields = array('idkeyword''title''url_clean');
  138.         if (!empty($infos_object)) {
  139.             foreach ($fields as $k => $v) {
  140.                 if (array_key_exists($v$infos_object)) {
  141.                     $infos[$v] = $infos_object[$v];
  142.                 } else {
  143.                     $infos[$v] = '';
  144.                 }
  145.             }
  146.         } else {
  147.             //charger les infos que si necessaire
  148.             if (empty($this->title)) {
  149.                 $sql 'SELECT ' implode(','$fields) . 
  150.                         FROM ' $this->__table 
  151.                         WHERE ' $this->__idtable '=' $idobject;
  152.                 $infos $this->queryRow($sql);
  153.             } else {
  154.                 foreach ($fields as $k => $v) {
  155.                     if (isset($this->$v) && $this->$v != '') {
  156.                         $infos[$v] = trim($this->$v);
  157.                     } else {
  158.                         $infos[$v] = '';
  159.                     }
  160.                 }
  161.             }
  162.         }
  163.         // renvoyer un array plutôt que le titre (utile si on veux l'url)
  164.         if (array_key_exists('return_array'$params)) {
  165.             return $infos;
  166.         }
  167.         return $infos['title'];
  168.     }
  169.     // }}}
  170.     //  {{{ getListSearch()
  171.     /** Liste des keywords
  172.      *
  173.      * Pour les champs Ajax de relations et les recherches diverses
  174.      *
  175.      * @access  public
  176.      * @param string $lettres Pour la recherche alphabetique
  177.      * @param string $type Pour le type recherche (editeurs, revues...)
  178.      * @param string $keywords Recherche par mots cles
  179.      * @return  array
  180.      */
  181.     public function getListSearch($lettre$type null$keywords null)
  182.     {
  183.         $sql 'SELECT k.idkeyword, k.title
  184.                  FROM ' $this->__table ' k 
  185.                  WHERE 1 ';
  186.         // selection par ordre alpha
  187.         if (!empty($lettre) && $lettre != 'tous') {
  188.             $sql_where[] = array('LOWER(LEFT(LTRIM(title),1))=\'' $this->escape($lettre) . '\'');
  189.         }
  190.         // recherche avec un mot cle
  191.         $list $this->splitKeywords($keywords);
  192.         if ($list) {
  193.             if (!empty($list[$this->IDSTR])) {
  194.                 // mots clés
  195.                 foreach ($list[$this->IDSTR] as $s) {
  196.                     $sql_more_name[] = 'title LIKE \'%' $s '%\'';
  197.                 }
  198.                 $sql_where[] = array('(' join(' OR '$sql_more_name) . ')');
  199.             }
  200.             if (!empty($list[$this->IDNUM])) {
  201.                 // recherche par numéro d'id pour les mots clés numériques
  202.                 $sql_where[] = array('idkeyword IN (' implode(','$list[$this->IDNUM]) . ')''OR');
  203.             }
  204.         }
  205.         if (!empty($sql_where)) {
  206.             foreach ($sql_where as $k => $v) {
  207.                 if (!empty($v[1])) {
  208.                     $sql .= ' ' $v[1] . ' ' $v[0];
  209.                 } else {
  210.                     $sql .= ' AND ' $v[0];
  211.                 }
  212.             }
  213.         }
  214.         $sql .= ' ORDER BY title';
  215.         $this->query($sql);
  216.         $r = array();
  217.         while ($this->fetch()) {
  218.             $r[$this->idkeyword] = $this->title;
  219.             // si trouvé par id, on l'affiche en fin de titre
  220.             if (!empty($list[$this->IDNUM]) && in_array($this->idkeyword$list[$this->IDNUM])) {
  221.                 $r[$this->idkeyword] .= ' - n°' $this->idkeyword;
  222.             }
  223.         }
  224.         $this->free();
  225.         return $r;
  226.     }
  227.     // }}}
  228.     //  {{{ getListKeywords()
  229.     /** Retourne des listes des keywords
  230.      *
  231.      * Retourne des listes de keywords au format "standard""
  232.      *
  233.      * @access   public
  234.      * @param array $params_sql paramètre pour la requete SQL
  235.      * @param array $format_vignette de la vignette si pas standard
  236.      * @param array $params_display paramètre pour l'affichage
  237.      * @return   array
  238.      */
  239.     public function getListKeywords($params_sql null$format_vignette = array(), $params_display = array())
  240.     {
  241.         // si pas de tableau
  242.         if (!isset($params_sql['special'])) {
  243.             $params_sql['special'] = array();
  244.         }
  245.         if (!isset($params_sql['params'])) {
  246.             $params_sql['params'] = array();
  247.         }
  248.         // construction de la requête avec le passage de paramètres
  249.         $sql $this->getSQLKeywords($params_sql);
  250.         // paramètre de debug
  251.         $dbg = (empty($params_sql['dbg'])) ? array() : $dbg $params_sql['dbg'];
  252.         // executer la requete
  253.         $this->query($sql$dbg);
  254.         $videos = array();
  255.         // donnée entières ?
  256.         if (empty($params_display['alldata'])) {
  257.             $params_display['alldata'] = false;
  258.         }
  259.         // debug
  260.         $start_boucle microtime(true);
  261.         $keywords = array();
  262.         // on boucle
  263.         while ($this->fetch()) {
  264.             $idkeyword $this->idkeyword;
  265.             if (!empty($params_sql['fields'])) {
  266.                 foreach ($params_sql['fields'] as $f) {
  267.                     $keywords[$idkeyword][$f] = $this->$f;
  268.                 }
  269.             } else {
  270.                 $keywords[$idkeyword] = $this->getInfosKeyword($idkeyword);
  271.             }
  272.         }
  273.         // debug de la boucle
  274.         if ($this->isTraceMode('list_object')) {
  275.             $this->setTraceInfos(array(
  276.                 'execution_time_boucle' => microtime(true) - $start_boucle,
  277.                 'nb_occurence' => count($keywords),
  278.                 'dbg' => $dbg,
  279.             ));
  280.         }
  281.         $this->free();
  282.         return $keywords;
  283.     }
  284.     // }}}
  285.     //  {{{ countListKeywords()
  286.     /** Compter la liste des keywords
  287.      *
  288.      * @access   public
  289.      * @param array $params_sql paramètre pour la requete SQL
  290.      * @param bool $debug mode débugage
  291.      * @return   int
  292.      */
  293.     public function countListKeywords($params_sql null$debug false)
  294.     {
  295.         // si pas de limite => tout
  296.         if (empty($params_sql['limit'])) {
  297.             $params_sql['limit'] = array('all');
  298.         }
  299.         $params_sql['special']['count_only'] = true;
  300.         // construction de la requête avec le passage de paramètres
  301.         return $this->queryOne($this->getSQLKeywords($params_sql$debug));
  302.     }
  303.     // }}}
  304.     //  {{{ getSQLKeywords()
  305.     /** Générer la requete standard pour des keywords
  306.      *
  307.      * @access   public
  308.      * @param array $aueru Les paramètres pour la requete
  309.      * @param bool $debug afficher la requête
  310.      * @return   string
  311.      */
  312.     public function getSQLKeywords($query = array(), $debug false)
  313.     {
  314.         // on prepare les tableaux
  315.         foreach (array('select''from''where''order''group''limit') as $t) {
  316.             if (!empty($query[$t])) {
  317.                 if (!is_array($query[$t])) {
  318.                     $query[$t][] = $query[$t];
  319.                 } else {
  320.                     $query[$t] = $query[$t];
  321.                 }
  322.             } else {
  323.                 $query[$t] = array();
  324.             }
  325.         }
  326.         // champs par défaut
  327.         $this->addSQLParams('select'$query, array(
  328.             array('keywords' => '*')
  329.         ));
  330.         // publié ou pas
  331.         if (empty($query['publish']) && $_ENV['CHECK_IF_ONLINE']) {
  332.             $this->addSQLParams('where'$query, array(
  333.                 array('keywords''publish'1)
  334.             ));
  335.         } elseif (!empty($query['publish'])) {
  336.             $this->addSQLParams('where'$query, array(
  337.                 array('keywords''publish'$query['publish'])
  338.             ));
  339.         }
  340.         // liaison avec multimedia_keyword
  341.         if (!empty($query['special']['idmultimedia'])) {
  342.             $this->addSQLParams('from'$query, array(
  343.                 'multimedia_keyword',
  344.             ));
  345.             // jointure entre les 3 tables
  346.             $this->addSQLParams('join'$query, array(
  347.                 'keywords.`idkeyword`' => 'multimedia_keyword.`idkeyword`',
  348.             ));
  349.             $this->addSQLParams('where'$query, array(
  350.                 array('multimedia_keyword''idmultimedia'$query['special']['idmultimedia']),
  351.             ));
  352.         }
  353.         return $this->getSQLObject($query);
  354.     }
  355.     // }}}
  356. }