vendor/theatre/core/src/Repository/ContentsRepository.php line 563

Open in your IDE?
  1. <?php
  2. namespace TheatreCore\Repository;
  3. use TheatreCore\Classes\Images\Images;
  4. use TheatreCore\Entity\Classifications;
  5. use TheatreCore\Entity\Contents;
  6. use TheatreCore\Entity\Files;
  7. use TheatreCore\Entity\ObjectContent;
  8. use TheatreCore\Traits\TheatreTrait;
  9. use TheatreCore\Entity\Spectacles;
  10. use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
  11. use Doctrine\Persistence\ManagerRegistry;
  12. use Symfony\Contracts\Translation\TranslatorInterface;
  13. use Theatre_Extranetusers;
  14. /**
  15.  * ContentsRepository
  16.  *
  17.  * This class was generated by the Doctrine ORM. Add your own custom
  18.  * repository methods below.
  19.  */
  20. class ContentsRepository extends ServiceEntityRepository
  21. {
  22.     use TheatreTrait {
  23.         getItemsList as protected getItemsListTrait;
  24.     }
  25.     private $em;
  26.     public $__table;
  27.     public $__table_object;
  28.     public $__idtable;
  29.     private $translator;
  30.     public function __construct(ManagerRegistry $registryTranslatorInterface $translatorImages $images)
  31.     {
  32.         parent::__construct($registryContents::class);
  33.         $this->__table $this->getClassMetadata()->getTableName();
  34.         $this->__table_object $this->getClassMetadata()->name;
  35.         $this->__idtable $this->getClassMetadata()->getSingleIdentifierFieldName();
  36.         $this->setFields $this->getClassMetadata()->getColumnNames();
  37.         $this->translator $translator;
  38.         $this->images $images;
  39. //        $this->__table = 'persons';
  40. //        $this->__table_object = '\\App\\Entity\\Persons';
  41.     }
  42.     //  {{{ getInfosContent()
  43.     /** Informations sur un contenu associe
  44.      *
  45.      * @access public
  46.      * @param int $idcontent identifiant du contenus associé
  47.      * @return array
  48.      */
  49.     public function getInfosContent($idcontent null$params = array())
  50.     {
  51.         $infos = array();
  52.         // selectionne aussi la classification
  53.         $sql 'SELECT c.*, cl.classification, c.`range` as `range`, e.idextranetuser, e.login
  54.                 FROM ' $this->__table ' c
  55.                     LEFT JOIN extranetusers e ON c.idextranetuser=e.idextranetuser, classifications cl, content_classification cc
  56.                 WHERE cc.idcontent=c.idcontent AND cc.idclassification=cl.idclassification
  57.                 AND c.idcontent=' . ((int)$idcontent);
  58.         // restreindre à un extranetuser
  59.         /*if(!empty($params['idextranetuser'])) {
  60.         }*/
  61.         $infos $this->queryRow($sql);
  62.         if (!empty($infos)) {
  63.             // est-ce qu'on converti le wiki en HTML ?
  64.             if (!empty($params['wiki_convert'])) {
  65.                 $infos['text'] = $this->wikiTransform($infos['text'], $infos['markdown']);
  66.                 $infos['deck'] = $this->wikiTransform($infos['deck'], $infos['markdown']);
  67.             }
  68.             // est-ce qu'on récup aussi les fichiers
  69.             if (!empty($params['get_files'])) {
  70.                 $datafile $this->getAssociateFileContent($idcontent);
  71.                 if (!empty($datafile)) {
  72.                     $infos['files'] = $datafile;
  73.                 }
  74.             }
  75.             // selectionne éalement le journaliste associé et le journal et les contacts associes
  76.             foreach (array('idcontact_journalist''idcontact_newspaper') as $f) {
  77.                 if (!empty($infos[$f])) {
  78.                     $infos[$f] = $this->getLinkedContact($infos['idcontent'], $f);
  79.                 }
  80.             }
  81.             // contact signature
  82.             $infos['idcontact'] = $this->getLinkedContact($infos['idcontent'], 'idcontact');
  83.             $infos['idperson'] = $this->getLinkedPerson($infos['idcontent'], 'content_person');
  84.             // selectionne aussi la/les classification(s)
  85.             $classifications_list $this->getClassifications($idcontent);
  86.             if (!empty($classifications_list)) {
  87.                 $infos['classifications'] = $classifications_list;
  88.                 $infos['classification_code'] = $infos['classification'];
  89.                 $infos['classification'] = $this->translator->trans($infos['classification']);
  90.             }
  91.             // récupèrer les infos sur l'extranetuser
  92.             if (!empty($infos['login'])) {
  93.                 $infos['extranetuser'] = array(
  94.                     'login' => $infos['login'],
  95.                     'idextranetuser' => $infos['idextranetuser'],
  96.                 );
  97.             }
  98.         }
  99.         // langue
  100.         if (!empty($infos['language'])) {
  101.             $infos['language_string'] = $this->getNameLanguage($infos['language']);
  102.         }
  103.         return $infos;
  104.     }
  105.     // }}}
  106.     //  {{{ getInfosObject()
  107.     /** Alias de getInfosContent
  108.      *
  109.      * @access  public
  110.      * @param int $idobject identifiant
  111.      * @return  array
  112.      * @see     getInfosObject()
  113.      */
  114.     public function getInfosObject($idobject null)
  115.     {
  116.         return $this->getInfosContent($idobject);
  117.     }
  118.     // }}}
  119.     //  {{{ addContent()
  120.     /** Ajoute un contenu et l'associe si besoin
  121.      *
  122.      *
  123.      * @access   public
  124.      * @param string $objet le type d'objet à insérer (personnes, spectacles...)
  125.      * @param string $idobject (id de l'utilisateur pour le nom de son répertoire)
  126.      * @param string $idcontent (id du contenu à modifier si on est en mode modification)
  127.      * @param string $sort classement
  128.      */
  129.     public function addContent($object$idobject$idcontent null$sort 0$classifications = array(), $return_value false$group_idclassification null$values null)
  130.     {
  131.         /**
  132.          * En modification, on doit verifier que le contenu ne soit pas deja utilise
  133.          * si il est utilise, on doit juste supprimer la relation
  134.          */
  135.         $em $this->getEntityManager();
  136.         $content null;
  137.         if (!is_null($idcontent)) {
  138.             $content $em->getRepository(Contents::class)->find($idcontent);
  139.         }
  140.         if ($content) {
  141.             if ($x $em->getRepository(ObjectContent::class)->findBy(['idcontent' => $content])) {
  142.                 // si associe a quelque chose d'autre
  143. //            if($this->isUseObjectContent($idcontent)) {
  144. //                $id = null;
  145.                 // supression de la relation dans object_content
  146.                 $this->deleteDataRelation('object_content''idcontent'$idcontent'idobject'$idobject'object'$object);
  147.                 // creation d'un nouveau contenu
  148.                 $newidcontent $this->setData($idcontenttrue);
  149.             } else {
  150.                 // modification simple
  151.                 if ($return_value) {
  152.                     $this->setData($idcontent);
  153.                     return $idcontent;
  154.                 } else {
  155.                     // mettre à jour le classement/groupement dans object_content si nécessaire
  156.                     $object_content $this->getEntityManager()->getRepository(ObjectContent::class);
  157.                     // ajout dans object_content
  158.                     $object_content->setUpdateFields(array(
  159.                         'idclassification' => $group_idclassification
  160.                     ));
  161.                     $object_content->setData(nullfalsetrue'idobject=' $idobject ' AND idcontent=' $idcontent ' AND object=\'' $object '\' ');
  162.                     return $this->setData($idcontent);
  163.                 }
  164.             }
  165.         } else { // creation
  166.             $newidcontent $this->setData($idcontenttrue);
  167.         }
  168.         // ajout dans object_content si nouveau contenu
  169.         if (isset($newidcontent)) {
  170.             $idcontent $newidcontent;
  171.             $content_created $this->find($idcontent);
  172.             //objet dans la table object_content
  173.             $object_content = new ObjectContent();
  174.             // ajout dans object_content
  175.             $object_content->setIdobject($idobject);
  176.             $object_content->setObject($object);
  177.             $object_content->setIdcontent($content_created);
  178.             $object_content->setRange($sort);
  179.             $object_content->setIdclassification($group_idclassification);
  180.             // ajout dans object_content
  181.             try {
  182.                 $em->persist($object_content);
  183.                 $em->flush();
  184.             } catch (Exception $e) {
  185.                 $em->getConnection()->rollBack();
  186.                 throw $e;
  187.             }
  188.         }
  189.         // ajouter aussi les classifications ?
  190.         if (!empty($classifications)) {
  191.             foreach ($classifications as $class) {
  192.                 $class_tab[$idcontent] = $class;
  193.             }
  194.             try {
  195.                 $this->setRelationSelect('content_classification''idclassification''idcontent'$class_tab$idcontent);
  196.             } catch (\Exception $e) {
  197.                 return $e->getError();
  198.             }
  199.         }
  200.         //retourner l'idcontent du contenu
  201.         return $idcontent;
  202.     }
  203.     // }}}
  204.     //  {{{ setRelationSelectObject()
  205.     /** Enregistrement dans les table relationnelle avec object
  206.      *
  207.      * Permet l'enregistrement multiple de valeur dans les tables
  208.      * de relation avec object
  209.      *
  210.      * @access   public
  211.      * @param string $table Nom de la table de relation
  212.      * @param string $key Clé dans le tableau
  213.      * @param string $col Colonne
  214.      * @param array $array_values Valeur à enregistrer
  215.      * @param int $id Id de l'enregistrement principal
  216.      * @param string $object Nom de l'objet
  217.      * @return   bool
  218.      */
  219.     public function setRelationSelectObject($table$key$col$array_values$id$object$allRights true$group_idclassification null)
  220.     {
  221. //        $this->setOption('quote_identifier', false);
  222.         $em $this->getEntityManager()->getConnection();
  223.         if ($allRights) {
  224.             $rights = array('update' => 1);
  225.         }
  226.         if ($this->isCheckRights() || !$allRights) {
  227.             $extranetusers Theatre_Extranetusers::factory('extranetusers');
  228.             $rights $extranetusers->getRights();
  229.         }
  230.         if (isset($rights) && $rights['update'] == 1) {
  231.             // on supprime puis on insère (replace ne marche pas)
  232.             $sql_del 'DELETE FROM ' $table ' WHERE ' $key '=\'' $id '\' AND object=\'' $this->escape($object) . '\'';
  233.             $this->logDeletion('[Contents::setRelationSelectObject] Supprime de relations ' $sql_del);
  234.             $em->exec($sql_del);
  235.             // si array_values est vide, c'est qu'on veux supprimer ?
  236.             if (empty($array_values)) {
  237.                 return true;
  238.             }
  239.             // on prepare
  240.             if (!empty($group_idclassification)) {
  241.                 $sql 'INSERT INTO ' $table ' (' $key ', object, ' $col ', idclassification) VALUES (?, ?, ?, ?)';
  242.             } else {
  243.                 $sql 'INSERT INTO ' $table ' (' $key ', object, ' $col ') VALUES (?, ?, ?)';
  244.             }
  245.             $prep $em->prepare($sql);
  246.             foreach ($array_values as $key => $value) {
  247.                 if (!empty($group_idclassification)) {
  248.                     $prep_values[] = array($id$object$value$group_idclassification);
  249.                 } else {
  250.                     $prep_values[] = array($id$object$value);
  251.                 }
  252.             }
  253.             foreach ($prep_values as $value) {
  254.                 $res $prep->execute($value);
  255.             }
  256.         } else {
  257.             throw new \Exception($this->translator->trans('no_right') . 'setRelationSelectObject');
  258.         }
  259.     }
  260.     // }}}
  261.     //  {{{ deleteContent()
  262.     /** Supprimer un contenu
  263.      *
  264.      * On verifie que le contenu est utilise et on supprime
  265.      * la liaison et le contenu si plus utilise
  266.      *
  267.      * @access   public
  268.      * @param string $id id du contentu à supprimer
  269.      * @param string $object type de fichier à supprimer (ex : persons, contacts...)
  270.      * @param string $idobject id de la personne qui possède le fichier
  271.      */
  272.     public function deleteContent($id$object$idobject)
  273.     {
  274.         //le contenu n'est pas utilisé, on peut le supprimer
  275.         if (!$this->isUseContent($id)) {
  276.             return $this->deleteData($id);
  277.         }
  278.         //dans touts les cas, supprimer l'enregistrement dans la relation object_file
  279.         return $this->deleteDataRelation('object_content''idcontent'$id'idobject'$idobject'object'$object);
  280.     }
  281.     // }}}
  282.     //  {{{ isUseContent()
  283.     /** Vérifier si un contenu est utilisé par un autre objet
  284.      *
  285.      *
  286.      * @access   public
  287.      * @param string $id id du contenu à vérifier
  288.      */
  289.     public function isUseContent($idcontent)
  290.     {
  291.         $sql 'SELECT COUNT(DISTINCT(idobject)) AS total
  292.                 FROM object_content
  293.                 WHERE object_content.idcontent=' . (int)$idcontent;
  294.         $total $this->queryOne($sql);
  295.         //on a au moins 2 enregistrements liés
  296.         return ($total 1);
  297.     }
  298.     // }}}
  299.     //  {{{ countAssociateContent()
  300.     /** compter les contenus associes par type
  301.      *
  302.      * @access   public
  303.      * @param string|int|array $classification classification recherchee
  304.      * @param int $idobject id de l'objet lié
  305.      * @param string $objet le type d'objet (personnes, spectacles...)
  306.      * @return   array
  307.      * @see Theatre_Classifications::getAssociate())
  308.      */
  309.     public function countAssociateContent($object$idobject$classification$extra = array())
  310.     {
  311.         // string ou int pour classification
  312.         $con $this->getEntityManager();
  313.         $classifications $con->getRepository(Classifications::class);
  314.         if (!empty($extra['publish_status'])) {
  315.             $classifications->setPublishStatus($extra['publish_status']);
  316.         } else {
  317.             $classifications->setPublishStatus($this->publish_status);
  318.         }
  319.         return $classifications->getAssociate($idobject$object$classificationfalse$extra);
  320.     }
  321.     // }}}
  322.     //  {{{ getAssociateContents()
  323.     /** Retourner les contenus lies a un objet
  324.      *
  325.      * Retourne un tableau associatif des contenus associes
  326.      * a un objet
  327.      *
  328.      * @access   public
  329.      * @param string $idobject id de l'objet lié
  330.      * @param string $objet le type d'objet (personnes, spectacles...)
  331.      * @param int|string|array $classification classification(s)
  332.      * @param string $params parametre (no_by_lang => 'pas de classement par langue', 'get_files' => demander également les fichiers)
  333.      * @see Theatre_Classifications::getAssociate())
  334.      */
  335.     public function getAssociateContents($idobject$object$classification null$params = array())
  336.     {
  337.         if (!empty($params['group_content'])) {
  338.             $fields 'DISTINCT(c.idcontent)';
  339.         } else {
  340.             $fields 'c.idcontent';
  341.         }
  342.         $fields .= ', c.idextranetuser, c.publish, c.title, c.language, oc.object, oc.idobject, l.fr';
  343.         // récupèrer aussi les texts
  344.         if (!empty($params['get_texts'])) {
  345.             $fields .= ', c.text, c.deck,c.dateinsert';
  346.         }
  347.         //if(!empty($classification)) {
  348.         $fields .= ', cl.classification';
  349.         //}
  350.         $extra = array(
  351.             'tables' => ',languages l',
  352.             'where' => 'AND c.language=l.id',
  353.             'order' => 'c.language,cc.idclassification,c.dateinsert',
  354.         );
  355.         // on exclut certains con
  356.         if (!empty($params['exclude_contents'])) {
  357.             $extra['where'] .= ' AND c.idcontent NOT IN(' implode(','$params['exclude_contents']) . ')';
  358.         }
  359.         if (!empty($params['group_content'])) {
  360.             $extra['group_content'] = true;
  361.         }
  362.         $classifications $this->getEntityManager()->getRepository(Classifications::class);
  363.         $classifications->setPublishStatus($this->publish_status);
  364.         $tabcontent $classifications->getAssociate($idobject$object$classification$fields$extra);
  365.         // si il y a des resultat
  366.         if (!empty($tabcontent)) {
  367.             // objet traduction
  368.             $tr $this->translator;
  369.             // classement par langue
  370.             if (empty($params['no_by_lang'])) {
  371.                 // liste des langues
  372.                 $sql_lng 'SELECT c.language
  373.                                FROM object_content oc, contents c
  374.                                WHERE oc.idcontent=c.idcontent
  375.                                AND oc.idobject=\'' $idobject '\'
  376.                                AND oc.object=\'' $object '\'
  377.                                GROUP BY c.language ORDER BY c.language';
  378.                 $languages $this->queryAll($sql_lng);
  379.                 // valeurs
  380.                 foreach ($languages as $k => $v) {
  381.                     foreach ($tabcontent as $key => $value) {
  382.                         if ($tabcontent[$key]['language'] == $v['language']) {
  383.                             // si text
  384.                             if (!empty($value['text'])) {
  385.                                 $tabcontent[$key]['text'] = $this->wikiTransform($value['text'], $value['markdown']);
  386.                             }
  387.                             $tabcontent[$key]['classification'] = $tr->trans($value['classification']);
  388.                             $tabcontent[$key]['key_classification'] = $value['classification'];
  389.                             $tabcontent[$key]['language_term'] = $tabcontent[$key]['fr'];
  390.                             if ($idobject == && $value['classification'] == 'class_journal') {
  391.                                 $tabcontent[$key]['is_collapse'] = 'display: none;';
  392.                             }
  393.                             // est-ce qu'on récup aussi les fichiers
  394.                             if (!empty($params['get_files']) && array_key_exists('idcontent'$value)) {
  395.                                 $tabcontent[$key]['files'] = $this->getAssociateFileContent($value['idcontent']);
  396.                             }
  397.                             if (!empty($params['api'])) {
  398.                                 $tabcontent[$key] = $this->getApiTab($tabcontent[$key]);
  399.                             }
  400.                             $tabbylang[$v['language']][] = $tabcontent[$key];
  401.                         }
  402.                     }
  403.                 }
  404.                 return $tabbylang;
  405.             } else {
  406.                 foreach ($tabcontent as $key => $value) {
  407.                     $tabcontent[$key]['classification'] = $tr->trans($value['classification']);
  408.                     $tabcontent[$key]['key_classification'] = $value['classification'];
  409.                     // est-ce qu'on récup aussi les fichiers
  410.                     if (!empty($params['get_files']) && array_key_exists('idcontent'$value)) {
  411.                         $tabcontent[$key]['files'] = $this->getAssociateFileContent($value['idcontent']);
  412.                     }
  413.                 }
  414.                 return $tabcontent;
  415.             }
  416.         } else {
  417.             return null;
  418.         }
  419.     }
  420.     // }}}
  421.     //  {{{ getAssociateContent()
  422.     /** Recuperer un contenu associe
  423.      *
  424.      * Recuperer les infos sur un seul contenu associe
  425.      *
  426.      * @access   public
  427.      * @param int $idobject id de l'objet lié
  428.      * @param string $objet le type d'objet (personnes, spectacles...)
  429.      * @param string|int|array $classification classification recherchee
  430.      * @param array $params_content options supplémentaires (media=>true|false, check_lng=>true|false, wiki_convert=>true|false,get_files=>true|false)
  431.      * @return   array
  432.      * @see Theatre_Classifications::getAssociate())
  433.      */
  434.     public function getAssociateContent($idobject$object$classification$params_content = array())
  435.     {
  436.         $params_content['row'] = true;
  437.         // string ou int pour classification
  438.         $conn $this->getEntityManager();
  439.         $classifications $conn->getRepository(Classifications::class);
  440.         $classifications->setPublishStatus($this->publish_status);
  441.         $data $classifications->getAssociate($idobject$object$classification'*'$params_content);
  442.         if (!empty($data)) {
  443.             // les classifications
  444.             $classifications_list $classifications->getObjectClassification($this->__table$data['idcontent'], $this->getRelationsArray('content_classification'));
  445.             $data['classifications'] = $classifications_list;
  446.             // est-ce qu'on converti le wiki en HTML ?
  447.             if (!empty($params_content['wiki_convert']) && !empty($data['text'])) {
  448.                 $data['text'] = $this->wikiTransform($data['text'], $data['markdown']);
  449.             }
  450.             // est-ce qu'on récup aussi les fichiers
  451.             if (!empty($params_content['get_files'])) {
  452.                 if (array_key_exists('idcontent'$data)) {
  453.                     $datafile $this->getAssociateFileContent($data['idcontent']);
  454.                     if (!empty($datafile)) {
  455.                         $data['files'] = $datafile;
  456.                     }
  457.                 }
  458.             }
  459.             if (!empty($data['dateinsert'])) {
  460.                 $data['dateinsert_lng'] = $this->getFormeDate($data['dateinsert'], "%A %d %B %Y"true);
  461.                 $data['dateinsert_lng_withtout_day'] = $this->getFormeDate($data['dateinsert'], "%d %B %Y"true);
  462.             }
  463.             if (!empty($data['dateupdate'])) {
  464.                 $data['dateupdate_lng'] = $this->getFormeDate($data['dateupdate'], "%A %d %B %Y"true);
  465.                 $data['dateupdate_lng_without_day'] = $this->getFormeDate($data['dateupdate'], "%d %B %Y"true);
  466.             }
  467.             //retourner le contenu
  468.             return $data;
  469.         }
  470.         return null;
  471.     }
  472.     // }}}
  473.     //  {{{ getMultimediaContents()
  474.     /** Recuperer les contenus associes qui ont un doc multimedia
  475.      *
  476.      *
  477.      * @access   public
  478.      * @param int $idobject id de l'objet lié
  479.      * @param string $objet le type d'objet (personnes, spectacles...)
  480.      * @param int|string|array $classification classification(s) (par défaut: toutes)
  481.      * @return   array
  482.      * @see Theatre_Classifications::getAssociate())
  483.      */
  484.     public function getMultimediaContents($idobject$object$classification null)
  485.     {
  486.         $fields 'c.idcontent, c.title, om.idmultimedia, cl.classification, cc.idclassification';
  487.         $extra = array(
  488.             'tables' => ',object_multimedia om',
  489.             'where' => 'AND c.idcontent=om.idobject AND om.object=\'contents\'',
  490.         );
  491.         $classifications $this->getEntityManager()->getRepository(Classifications::class);
  492.         $classifications->setPublishStatus($this->publish_status);
  493.         $tabcontent $classifications->getAssociate($idobject$object$classification$fields$extra);
  494.         //retourner les contenus
  495.         if (!empty($tabcontent)) {
  496.             foreach ($tabcontent as $k => $v) {
  497.                 $tabcontent[$k]['classification'] = $this->translator->trans($v['classification']);
  498.             }
  499.             return $tabcontent;
  500.         }
  501.         return null;
  502.     }
  503.     // }}}
  504.     //  {{{ getMoreAssociateContent()
  505.     /** Recuperer des contenus associes
  506.      *
  507.      *
  508.      * @access   public
  509.      * @param int $idobject id de l'objet lié
  510.      * @param string $objet le type d'objet (personnes, spectacles...)
  511.      * @param int|string|array $classification classification recherchee
  512.      * @return   array
  513.      * @see Theatre_Classifications::getAssociate())
  514.      */
  515.     public function getMoreAssociateContent($idobject$object$classification$media false$extra = array())
  516.     {
  517.         $fields '*';
  518.         $extra['media'] = $media;
  519.         $conn $this->getEntityManager();
  520.         $classifications $conn->getRepository(Classifications::class);
  521.         $classifications->setPublishStatus($this->publish_status);
  522.         $tabcontent $classifications->getAssociate($idobject$object$classification$fields$extra);
  523.         //retourner les contenus
  524.         if (!empty($tabcontent)) {
  525.             return $tabcontent;
  526.         }
  527.         return null;
  528.     }
  529.     // }}}
  530.     //  {{{ getAssociateFileContent()
  531.     /** Recuperer les fichiers associes a un contenu
  532.      *
  533.      *
  534.      * @access   public
  535.      * @param int $idobject id de l'objet lié
  536.      * @param string $object type d'objet
  537.      * @param string|int|array $classification classification recherchee
  538.      * @return   array
  539.      * @see Theatre_Classifications::getAssociate())
  540.      */
  541.     public function getAssociateFileContent($idobject$object 'contents'$classification null)
  542.     {
  543.         $conn $this->getEntityManager();
  544.         $files $conn->getRepository(Files::class);
  545.         $files->setPublishStatus($this->publish_status);
  546.         $infos_files $files->getObjectFiles($idobject$object$classification);
  547.         return $infos_files;
  548.     }
  549.     // }}}
  550.     //  {{{ getObjectTitle()
  551.     /** Infos sur l'item recherche
  552.      *
  553.      * Affichage 'standard' du titre de l'item
  554.      *
  555.      * @access  public
  556.      * @param int $idobject Identifiant de l'item
  557.      * @param array $infos_object Informations pour construire le titre
  558.      * @param array $params Paramétres supplémentaires
  559.      * @return  string
  560.      */
  561.     public function getObjectTitle($idobject null$infos_object = array(), $params = array())
  562.     {
  563.         $title '';
  564.         if (!$idobject) {
  565.             $idobject $this->idcontent;
  566.         }
  567.         // champs
  568.         $fields = array('idcontent''title''idclassification');
  569.         if (!empty($infos_object)) {
  570.             foreach ($fields as $k => $v) {
  571.                 if (array_key_exists($v$infos_object)) {
  572.                     $$v $infos_object[$v];
  573.                 } else {
  574.                     $$v '';
  575.                 }
  576.             }
  577.         } else {
  578.             //charger les infos que si necessaire
  579.             if (empty($this->idclassification)) {
  580.                 $sql 'SELECT c.idcontent,c.title,cc.idclassification
  581.                         FROM contents c, content_classification cc
  582.                         WHERE cc.idcontent=c.idcontent AND c.idcontent=' . (int)$idobject;
  583.                 $data $this->queryRow($sql);
  584.             }
  585.             foreach ($fields as $k => $v) {
  586.                 if (!empty($data[$v])) {
  587.                     $$v trim($data[$v]);
  588.                 } else {
  589.                     $$v '';
  590.                 }
  591.             }
  592.         }
  593.         if (empty($idclassification)) {
  594.             //error_log('Classification non trouvée'."\n".debug_string_backtrace());
  595.             return $title;
  596.         }
  597.         $query 'SELECT cl.classification FROM classifications cl WHERE cl.idclassification=' . (int)$idclassification;
  598.         $classification $this->queryOne($query);
  599.         $classification $this->translator->trans($classification);
  600.         return $title ' / ' $classification;
  601.     }
  602.     // }}}
  603.     //  {{{ getIllustrations()
  604.     /** Récupère les illustrations
  605.      *
  606.      * Affiche pour les spectacles, couverture pour les textes
  607.      *
  608.      * @access  public
  609.      * @param int $idobject id de l'objet lié
  610.      * @param string $object type d'objet
  611.      * @param string|int|array $classification classification recherchee
  612.      * @return   array
  613.      * @see getAssociateFileContent()
  614.      */
  615.     public function getIllustrations($idobject$object$classification$format = array())
  616.     {
  617.         // recuperer la couv
  618.         $illustrations $this->getAssociateFileContent($idobject$object$classification);
  619.         $tab_illustrations = array();
  620.         if (!empty($illustrations)) {
  621.             // vignettes des illustrations
  622.             foreach ($illustrations as $k => $illustration) {
  623.                 $illustrations[$k]['vignette'] = $this->getThumbnail($illustrations[$k]['file'], 255'L');
  624.                 $illustrations[$k]['vignette_flou'] = $this->getThumbnail($illustrations[$k]['file'], 255'L', ['blur' => true]);
  625.             }
  626.             $tab_illustrations['illustrations'] = $illustrations;
  627.             // insctancier l'objet lié et trouver la méthode getVignetteObject
  628.             $obj $this->getEntityManager()->getRepository('TheatreCore\Entity\\' ucfirst($object));
  629.             $methode 'getVignette' ucfirst(substr($object0, -1));
  630.             if (method_exists($obj$methode)) {
  631.                 $vignette $obj->$methode($idobject$format);
  632.                 if (!preg_match('/-def\.jpg$/'$vignette)) {
  633.                     $tab_illustrations['vignette_object'] = $vignette;
  634.                 }
  635.             }
  636.         }
  637.         return $tab_illustrations;
  638.     }
  639.     // }}}
  640.     //  {{{ getListSearch()
  641.     /** Liste des contenus associés
  642.      *
  643.      * Pour les champs Ajax de relations et les recherches diverses
  644.      *
  645.      * @access  public
  646.      * @param string $lettres Pour la recherche alphabetique
  647.      * @param string $type Pour le type recherche (editeurs, revues...)
  648.      * @param string $keywords Recherche par mots cles
  649.      * @return  array
  650.      */
  651.     public function getListSearch($lettre null$type null$keywords null$only null)
  652.     {
  653.         $qb $this->createQueryBuilder('c');
  654.         $qb->select('c')
  655.             ->orderBy('c.dateArticle''ASC');
  656.         return $qb;
  657.         // titre, classification
  658.         $sql 'SELECT c.idcontent, c.title, cl.classification
  659.                 FROM contents c, classifications cl, content_classification cc
  660.                 WHERE cc.idclassification=cl.idclassification AND c.idcontent=cc.idcontent';
  661.         // par lettre
  662.         if (!empty($lettre)) {
  663.             $sql .= ' AND LOWER(LEFT(LTRIM(c.title),1))=\'' $this->escape($lettre) . '\'';
  664.         }
  665.         // recherche avec un mot cle
  666.         $list $this->splitKeywords($keywords);
  667.         if ($list) {
  668.             $subsql '';
  669.             if (!empty($list[$this->IDSTR])) {
  670.                 // mots clés
  671.                 foreach ($list[$this->IDSTR] as $s) {
  672.                     if ($subsql$subsql .= ' AND ';
  673.                     $subsql .= 'c.title LIKE \'%' $s '%\'';
  674.                 }
  675.             }
  676.             if (!empty($list[$this->IDNUM])) {
  677.                 // recherche par numéro d'id pour les mots clés numériques
  678.                 if ($subsql$subsql .= ' OR ';
  679.                 $subsql .= 'c.idcontent IN (' implode(','$list[$this->IDNUM]) . ')';
  680.             }
  681.             if ($subsql$sql .= ' AND (' $subsql ')';
  682.         }
  683.         $this->query($sql);
  684.         $r = array();
  685.         while ($this->fetch()) {
  686.             $r[$this->idcontent] = $this->title ' (' $this->translator->trans($this->classification) . ')';
  687.             // si trouvé par id, on l'affiche en fin de titre
  688.             if (!empty($list[$this->IDNUM]) && in_array($this->idcontent$list[$this->IDNUM])) {
  689.                 $r[$this->idcontent] .= ' - n°' $this->idcontent;
  690.             }
  691.         }
  692.         $this->free();
  693.         return $r;
  694.     }
  695.     // }}}
  696.     //  {{{ getRelationsArray()
  697.     /** Tableau des relations
  698.      *
  699.      * @access  public
  700.      * @param string|int $type le type de champ
  701.      */
  702.     public function getRelationsArray($type null)
  703.     {
  704.         $array_types = array(
  705.             'multimedia_content' => array(// documents multimedia associés
  706.                 'type_join' => 'method',
  707.                 'method' => 'getMultimediaList',
  708.                 /*'type_join' => 'multiple',
  709.                 'dest_table' => 'multimedias',
  710.                 'join_table' => 'multimedia_content',
  711.                 'fields' => array('idmultimedia','sujet_titre','url_clean'),*/
  712.             ),
  713.             'object_multimedia' => array(// documents multimedia associés
  714.                 'type_join' => 'multiple',
  715.                 'dest_table' => 'multimedias',
  716.                 'join_table' => 'object_multimedia',
  717.                 'fields' => array('idmultimedia''sujet_titre''url_clean'),
  718.             ),
  719.             'idcontact_newspaper' => array(// journal associé
  720.                 'type_join' => 'simple',
  721.                 'dest_table' => 'contacts',
  722.                 'join_field_src' => 'idcontact_newspaper',
  723.                 'fields' => array('idcontact''organisation''url''type'),
  724.             ),
  725.             'idcontact_journalist' => array(// journaliste associé
  726.                 'type_join' => 'simple',
  727.                 'dest_table' => 'contacts',
  728.                 'join_field_src' => 'idcontact_journalist',
  729.                 'fields' => array('idcontact''organisation''lastname''firstname''type'),
  730.             ),
  731.             'idcontact' => array(// contact associé
  732.                 'type_join' => 'multiple',
  733.                 'dest_table' => 'contacts',
  734.                 'join_table' => 'content_contact',
  735. //                'join_field_src' => 'idcontact',
  736. //                'join_field_dest' => 'contact_idcontact',
  737.                 'fields' => array('idcontact''organisation''url''type''city'),
  738.             ),
  739.             'content_contact' => array(// contacts associés
  740.                 'type_join' => 'multiple',
  741.                 'dest_table' => 'contacts',
  742.                 'join_table' => 'content_contact',
  743.                 'fields' => array('idcontact''organisation''lastname''firstname''type'),
  744.             ),
  745.             'content_person' => array(// persons associés
  746.                 'type_join' => 'multiple',
  747.                 'dest_table' => 'persons',
  748.                 'join_table' => 'content_person',
  749.                 'fields' => array('idperson''lastname''firstname'),
  750.             ),
  751.             'content_classification' => array(// classifications associées
  752.                 'type_join' => 'multiple',
  753.                 'dest_table' => 'classifications',
  754.                 'join_table' => 'content_classification',
  755.                 'fields' => array('idclassification''classification''type''idgroupclassification'),
  756.             ),
  757.             'content_publisher' => array(// classifications associées
  758.                 'type_join' => 'multiple',
  759.                 'dest_table' => 'contacts',
  760.                 'join_table' => 'content_publisher',
  761.                 'join_field_dest' => 'idcontact',
  762.                 'fields' => array('idcontact''organisation''lastname''firstname''type'),
  763.             ),
  764.             'content_content' => array(// contenus associés
  765.                 'type_join' => 'multiple',
  766.                 'dest_table' => 'contents',
  767.                 'join_table' => 'object_content',
  768.                 'fields' => array('idcontent''title''dateinsert'),
  769.             ),
  770.             'content_template' => array(// classifications associées
  771.                 'type_join' => 'multiple',
  772.                 'dest_table' => 'templates',
  773.                 'join_table' => 'content_template',
  774.                 'fields' => array('idtemplate''description''fichier'),
  775.             ),
  776.             /*'object_content' => array(// classifications associées
  777.                 'type_join' => 'multiple',
  778.                 'dest_table' => 'content',
  779.                 'join_table' => 'object_content',
  780.                 'fields' => array('idcontent','title','subtitle'),
  781.             ),*/
  782.         );
  783.         if (!empty($array_types[$type])) {
  784.             $array_types[$type]['type'] = $type;
  785.             return $array_types[$type];
  786.         } else {
  787.             return $array_types;
  788.         }
  789.     }
  790.     // }}}
  791.     //  {{{ getLinkedPerson()
  792.     /** Tableau des relations pour les biographies
  793.      *
  794.      * @access  public
  795.      * @param string|int $type le type de champ
  796.      */
  797.     public function getLinkedPerson($idcontent$type$type_value null$infos_link = array())
  798.     {
  799.         $conn $this->getEntityManager();
  800.         if (empty($infos_link)) {
  801.             $infos_link $this->getRelationsArray($type);
  802.         }
  803.         $infos_linked_obj $this->getLinkedObject($infos_link$idcontent$type'contents');
  804.         return $infos_linked_obj;
  805.     }
  806.     // }}}
  807.     //  {{{ getLinkedContact()
  808.     /** Tableau des relations
  809.      *
  810.      * @access  public
  811.      * @param string|int $type le type de champ
  812.      */
  813.     public function getLinkedContact($idcontent$type$type_value null$infos_link = array())
  814.     {
  815.         $conn $this->getEntityManager();
  816.         if (empty($infos_link)) {
  817.             $infos_link $this->getRelationsArray($type);
  818.         }
  819.         $infos_linked_obj $this->getLinkedObject($infos_link$idcontent$type'contents');
  820.         foreach ($infos_linked_obj as $k => $v) {
  821.             // on veux également le logo
  822.             $files $conn->getRepository(Files::class);
  823.             $logos $files->getObjectFiles($v['idcontact'], 'contacts''class_logo_normal');
  824.             if (empty($logos)) {
  825.                 $logos $files->getObjectFiles($v['idcontact'], 'contacts''class_logo_accueil');
  826.             }
  827.             if (!empty($logos)) {
  828.                 $logos[0]['vignette'] = $this->getThumbnail($logos[0]['file'], 100'thumb');
  829.                 $logos[0]['vignette_flou'] = $this->getThumbnail($logos[0]['file'], 100'thumb', ['blur' => true]);
  830.                 $logos[0]['vignette_moyenne'] = $this->getThumbnail($logos[0]['file'], 200'thumb');
  831.                 $logos[0]['vignette_moyenne_flou'] = $this->getThumbnail($logos[0]['file'], 200'thumb', ['blur' => true]);
  832.                 $infos_linked_obj[$k]['logo'] = $logos[0];
  833.             }
  834.         }
  835.         return $infos_linked_obj;
  836.     }
  837.     // }}}
  838.     //  {{{ getAssociateObjects()
  839.     /** Liste des objets associés au contenus par type à partir de l'id du contenu
  840.      *
  841.      * @access  public
  842.      * @param string|int $type le type de champ
  843.      */
  844.     public function getAssociateObjects($idcontent$object)
  845.     {
  846.         $sql 'SELECT * FROM object_content WHERE 1 ';
  847.         // préciser le type d'objet
  848.         if (!empty($object)) {
  849.             $sql .= ' AND object=\'' $object '\' ';
  850.         }
  851.         // préciser le contenu
  852.         if (!empty($idcontent)) {
  853.             if (is_array($idcontent)) {
  854.                 $sql .= ' AND idcontent IN (' join(','$idcontent) . ') ';
  855.             } else {
  856.                 $sql .= ' AND idcontent=' . ((int)$idcontent) . ' ';
  857.             }
  858.         }
  859.         return $this->queryAll($sql);
  860.     }
  861.     // }}}
  862.     //  {{{ getListContents()
  863.     /** Liste des contenus associés
  864.      *
  865.      * @access  public
  866.      * @param string|int $type le type de champ
  867.      */
  868.     public function getListContents($params_sql null$params_display = array(), $debug false)
  869.     {
  870.         $count_query false;
  871.         $sql_select 'SELECT DISTINCT(ct.`idcontent`),ct.`title` ';
  872.         // en plus
  873.         if (!empty($params_sql['sql']['select'])) {
  874.             $sql_select .= ',' $params_sql['sql']['select'];
  875.         }
  876.         $sql_from ' FROM contents ct ';
  877.         $sql_where ' WHERE 1 ';
  878.         if (!empty($params_sql['special']['in'])) {
  879.             if (is_array($params_sql['special']['in'])) {
  880.                 $sql_where .= ' AND ct.idcontent IN (' join(','$params_sql['special']['in']) . ') ';
  881.             } else {
  882.                 $sql_where .= ' AND ct.idcontent IN (' $params_sql['special']['in'] . ') ';
  883.             }
  884.         }
  885.         // recherche par classifications
  886.         if (!empty($params_sql['special']['by_classification'])) {
  887.             $sql_from .= ' JOIN content_classification ccl ON ct.idcontent=ccl.idcontent ';
  888.             $sql_where .= ' AND ccl.idclassification IN (' join(','$params_sql['special']['by_classification']) . ') ';
  889.         }
  890.         // on veut l'uilisateur
  891.         if (!empty($params_sql['special']['get_extranetuser'])) {
  892.             $sql_select .= ',e.login,e.idextranetuser';
  893.             $sql_from .= ' JOIN extranetusers e ON ct.idextranetuser=e.idextranetuser ';
  894.         }
  895.         // recherche par spectacles
  896.         if (!empty($params_sql['special']['idspectacle'])) {
  897.             if (!is_array($params_sql['special']['idspectacle'])) {
  898.                 $params_sql['special']['idspectacle'] = (array)$params_sql['special']['idspectacle'];
  899.             }
  900.             $sql_from .= ' JOIN object_content oc ON ct.`idcontent`=oc.`idcontent` ';
  901.             $sql_where .= ' AND oc.`object`=\'spectacles\' AND oc.`idobject` IN (' join(','$params_sql['special']['idspectacle']) . ') ';
  902.         }
  903.         // on ligne ou pas ?
  904.         if (!empty($params_sql['special']['get_extranetuser'])) {
  905.             if (isset($params_sql['special']['publish']) && $params_sql['special']['publish'] != 2) {
  906.                 $sql_where .= ' AND ct.publish=' . (int)$params_sql['special']['publish'];
  907.             }
  908.             if (isset($params_sql['special']['valid']) && $params_sql['special']['valid'] != 2) {
  909.                 $sql_where .= ' AND ct.valid=' . (int)$params_sql['special']['valid'];
  910.             }
  911.         }
  912.         // recherche par spectacle/contact
  913.         if (!empty($params_sql['special']['get_critiques_idcontact'])) {
  914.             if (!empty($params_sql['special']['get_critiques_idcontact_count'])) {
  915.                 $count_query true;
  916.                 $sql_select 'SELECT COUNT(DISTINCT(ct.`idcontent`)) AS total ';
  917.             } else {
  918.                 $sql_select 'SELECT DISTINCT(ct.`idcontent`), ct.title as title, ct.*, e.`login`, e.`idextranetuser` ';
  919.             }
  920.             $sql_from ' FROM contents ct
  921.                 JOIN content_classification cc ON ct.`idcontent`=cc.`idcontent`
  922.                 JOIN object_content oc ON ct.`idcontent`=oc.`idcontent`
  923.                 JOIN spectacles s ON oc.`idobject`=s.`idspectacle`
  924.                 JOIN schedules sc ON s.`idspectacle`=sc.`idspectacle`
  925.                 JOIN extranetusers e ON ct.`idextranetuser`=e.`idextranetuser` ';
  926.             $sql_where ' WHERE s.`publish`=1 AND s.`valid`=1
  927.                     AND ct.`publish`=1 AND ct.`valid`=1
  928.                     AND cc.`idclassification`=101 ';
  929.             if (!empty($params_sql['special']['get_critiques_idcontact_idspectacle'])) {
  930.                 $sql_where .= '
  931.                         AND (
  932.                             sc.`idspectacle` IN (' $this->arrayToIn($params_sql['special']['get_critiques_idcontact_idspectacle']) . ')
  933.                             OR (
  934.                                 sc.`idcontact`=' $params_sql['special']['get_critiques_idcontact'] . '
  935.                                 OR sc.`idcontact_festival`=' $params_sql['special']['get_critiques_idcontact'] . '
  936.                             )
  937.                         )';
  938.             } else {
  939.                 $sql_where ' WHERE s.`publish`=1 AND s.`valid`=1
  940.                         AND ct.`publish`=1 AND ct.`valid`=1
  941.                         AND cc.`idclassification`=101
  942.                         AND (sc.`idcontact`=' $params_sql['special']['get_critiques_idcontact'] . '
  943.                         OR sc.`idcontact_festival`=' $params_sql['special']['get_critiques_idcontact'] . ') ';
  944.             }
  945.             // en plus
  946.             if (!empty($params_sql['sql']['where'])) {
  947.                 $sql_where .= $params_sql['sql']['where'];
  948.             }
  949.             // classement des critiques anté
  950.             $sql_order ' ORDER BY ct.`date_article` DESC';
  951.         }
  952.         if (!empty($params_sql['special']['get_critiques_publisher'])) {
  953.             if (!empty($params_sql['special']['get_critiques_publisher_count'])) {
  954.                 $count_query true;
  955.                 $sql_select 'SELECT COUNT(DISTINCT(ct.`idcontent`)) AS total ';
  956.             } else {
  957.                 $sql_select 'SELECT DISTINCT(ct.`idcontent`), ct.title as title, ct.*, e.`login`, e.`idextranetuser` ';
  958.             }
  959.             $sql_from ' FROM contents ct
  960.                 JOIN content_classification cc ON ct.`idcontent`=cc.`idcontent`
  961.                 JOIN object_content oc ON ct.`idcontent`=oc.`idcontent`
  962.                 JOIN spectacles s ON oc.`idobject`=s.`idspectacle`
  963.                 JOIN text_spectacle ts ON s.`idspectacle` = ts.idspectacle
  964.                 JOIN texts t ON ts.idtext = t.idtext
  965.                 JOIN schedules sc ON s.`idspectacle`=sc.`idspectacle`
  966.                 JOIN extranetusers e ON ct.`idextranetuser`=e.`idextranetuser` ';
  967.             $sql_where ' WHERE s.`publish`=1 AND s.`valid`=1
  968.                     AND ct.`publish`=1 AND ct.`valid`=1
  969.                     AND cc.`idclassification`=101 ';
  970.             $sql_where ' WHERE s.`publish`=1 AND s.`valid`=1
  971.                     AND ct.`publish`=1 AND ct.`valid`=1
  972.                     AND cc.`idclassification`=101
  973.                     AND t.`idcontact_publisher`=' $params_sql['special']['get_critiques_publisher'] . ' ';
  974.             // en plus
  975.             if (!empty($params_sql['sql']['where'])) {
  976.                 $sql_where .= $params_sql['sql']['where'];
  977.             }
  978.             // classement des critiques anté
  979.             $sql_order ' ORDER BY ct.`date_article` DESC';
  980.         }
  981.         // recherche dernières critques
  982.         if (!empty($params_sql['special']['get_critiques'])) {
  983.             $sql_select 'SELECT DISTINCT(ct.`idcontent`), ct.title as title, ct.*, e.`login`, e.`idextranetuser` ';
  984.             $sql_from ' FROM contents ct
  985.                 JOIN content_classification cc ON ct.`idcontent`=cc.`idcontent`
  986.                 JOIN object_content oc ON ct.`idcontent`=oc.`idcontent`
  987.                 JOIN spectacles s ON oc.`idobject`=s.`idspectacle`
  988.                 JOIN schedules sc ON s.`idspectacle`=sc.`idspectacle`
  989.                 JOIN extranetusers e ON ct.`idextranetuser`=e.`idextranetuser` ';
  990.             $sql_where ' WHERE s.`publish`=1 AND s.`valid`=1
  991.                 AND ct.`publish`=1 AND ct.`valid`=1
  992.                 AND cc.`idclassification`=101';
  993.             // en plus
  994.             if (!empty($params_sql['sql']['where'])) {
  995.                 $sql_where .= $params_sql['sql']['where'];
  996.             }
  997.             // classement des critiques anté
  998.             $sql_order ' ORDER BY ct.`date_article` DESC';
  999.         }
  1000.         if (!empty($params_sql['special']['prochains'])) {
  1001.             $dateend strftime('%Y-%m-%d'strtotime(date('Y-m-d')) + $params_sql['special']['prochains'] * 24 3600);
  1002.             $sql_where .= ' AND (sc.date BETWEEN \'' date('Y-m-d') . '\' AND \'' $dateend '\') ';
  1003.         }
  1004.         // recherche par spectacle/person/text
  1005.         if (!empty($params_sql['special']['get_critiques_idperson'])) {
  1006.             if (!empty($params_sql['special']['get_critiques_idperson']['count'])) {
  1007.                 $count_query true;
  1008.                 $sql_select 'SELECT COUNT(DISTINCT(ct.`idcontent`)) AS total ';
  1009.             } else {
  1010.                 $sql_select 'SELECT DISTINCT(ct.`idcontent`), ct.title as title, ct.*, e.`login`, e.`idextranetuser` ';
  1011.             }
  1012.             $sql_from ' FROM contents ct
  1013.                 JOIN content_classification cc ON ct.`idcontent`=cc.`idcontent`
  1014.                 JOIN object_content oc ON ct.`idcontent`=oc.`idcontent`
  1015.                 JOIN spectacles s ON oc.`idobject`=s.`idspectacle`
  1016.                 JOIN schedules sc ON s.`idspectacle`=sc.`idspectacle`
  1017.                 LEFT JOIN spectacle_person sp ON s.`idspectacle`=sp.`idspectacle`
  1018.                 LEFT JOIN text_spectacle ts ON s.`idspectacle`=ts.`idspectacle`
  1019.                 JOIN extranetusers e ON ct.`idextranetuser`=e.`idextranetuser` ';
  1020.             $sql_where ' WHERE s.`publish`=1 AND s.`valid`=1
  1021.                 AND ct.`publish`=1 AND ct.`valid`=1
  1022.                 AND cc.`idclassification`=101
  1023.                 AND
  1024.                     (
  1025.                     sp.`idperson`=' $params_sql['special']['get_critiques_idperson']['idperson'];
  1026.             if (!empty($params_sql['special']['get_critiques_idperson']['idtexts_person'])) {
  1027.                 $sql_where .= ' OR ts.`idtext` IN (' $params_sql['special']['get_critiques_idperson']['idtexts_person'] . ')';
  1028.             }
  1029.             $sql_where .= ')';
  1030.             // en plus
  1031.             if (!empty($params_sql['sql']['where'])) {
  1032.                 $sql_where .= $params_sql['sql']['where'];
  1033.             }
  1034.         }
  1035.         // classement
  1036.         if (empty($params_sql['sql']['order']) && empty($sql_order)) {
  1037.             $sql_order ' ORDER BY ct.dateinsert DESC';
  1038.         } elseif (!empty($params_sql['sql']['order'])) {
  1039.             $sql_order ' ORDER BY ' $params_sql['sql']['order'];
  1040.         }
  1041.         // en plus
  1042.         $sql_groupby '';
  1043.         if (!empty($params_sql['sql']['groupby'])) {
  1044.             $sql_groupby .= ' GROUP BY ' $params_sql['sql']['groupby'];
  1045.         }
  1046.         // limite
  1047.         if (empty($params_sql['sql']['limit'])) {
  1048.             $limit ' LIMIT 0,10';
  1049.         } else {
  1050.             if ($params_sql['sql']['limit'] != 'all') {
  1051.                 if (is_array($params_sql['sql']['limit'])) {
  1052.                     $limit ' LIMIT ' $params_sql['sql']['limit'][0] . ',' $params_sql['sql']['limit'][1];
  1053.                 } else {
  1054.                     if (strpos($params_sql['sql']['limit'], 'LIMIT') !== false) {
  1055.                         $limit ' ' $params_sql['sql']['limit'];
  1056.                     } else {
  1057.                         $limit ' LIMIT ' $params_sql['sql']['limit'];
  1058.                     }
  1059.                 }
  1060.             } else {
  1061.                 $limit ' ';
  1062.             }
  1063.         }
  1064.         $sql $sql_select $sql_from $sql_where $sql_groupby $sql_order $limit;
  1065.         // paramètre de debug
  1066.         $dbg = (empty($params_sql['dbg'])) ? array() : $dbg $params_sql['dbg'];
  1067.         if ($count_query) {
  1068.             return $this->queryOne($sql$dbg);
  1069.         } else {
  1070.             $this->query($sql$dbg);
  1071.             $ct = array();
  1072.             // debug
  1073.             $start_boucle microtime(true);
  1074.             // mettre en forme chaque reponse
  1075.             while ($this->fetch()) {
  1076.                 $idcontent $this->idcontent;
  1077.                 $cont $this->getInfosContentRow($params_display, array('param_sql' => $params_sql));
  1078.                 $ct[$idcontent] = $cont;
  1079.             }
  1080.             // libère
  1081.             $this->free();
  1082.             // debug de la boucle
  1083.             if ($this->isTraceMode('list_object')) {
  1084.                 $this->setTraceInfos(array(
  1085.                     'execution_time_boucle' => (microtime(true) - $start_boucle),
  1086.                     'dbg' => $dbg,
  1087.                 ));
  1088.             }
  1089.             return $ct;
  1090.         }
  1091.     }
  1092.     // }}}
  1093.     //  {{{ getInfosContentRow()
  1094.     /** Infos standard sur un contenu
  1095.      *
  1096.      * Cette méthode peut-être utilisée dans les boucle while/fetch et récupère
  1097.      * la plus part des infos utiles dans les listes de résultats
  1098.      *
  1099.      * @access   public
  1100.      * @param array $format_vignette Format des vignettes
  1101.      * @return   array
  1102.      */
  1103.     public function getInfosContentRow($params_display null$params_more = array())
  1104.     {
  1105.         $cont = array();
  1106.         $idcontent $this->idcontent;
  1107.         $cont['idcontent'] = $idcontent;
  1108.         $cont['title'] = $this->title;
  1109.         if (array_key_exists('shorten_title'$params_display) && $params_display['shorten_title']) {
  1110.             $cont['shorten_title'] = substr($this->title050);
  1111.             if (strlen($this->title) >= 50) {
  1112.                 $cont['shorten_title'] = $cont['shorten_title'] . " ...";
  1113.             }
  1114.         }
  1115.         // récup aussi les classifications
  1116.         if (!empty($params_display['get_classifications'])) {
  1117.             $classifications $this->getEntityManager()->getRepository(Classifications::class);
  1118.             $classifications_list $classifications->getObjectClassification($this->__table$idcontent$this->getRelationsArray('content_classification'));
  1119.             $cont['classifications'] = $classifications_list;
  1120.         }
  1121.         // pour les critiques
  1122.         if (!empty($params_display['get_critiques'])) {
  1123.             $params_display['fields'] = array(
  1124.                 'title',
  1125.                 'deck',
  1126.                 'idextranetuser',
  1127.                 'login',
  1128.                 'dateinsert',
  1129.                 'date_article',
  1130.                 'writer',
  1131.                 'writer_group',
  1132.                 'writer_group_url',
  1133.                 'link'
  1134.             );
  1135.             $params_display['get_infos_spectacle'] = array(
  1136.                 'vignette' => [
  1137.                     'width' => $_ENV['VIGN_SPECTACLE_WIDTH'],
  1138.                     'height' => $_ENV['VIGN_SPECTACLE_HEIGHT'],
  1139.                     'direction' => 'crop'
  1140.                 ],
  1141.                 'stylemore' => [
  1142.                     'imagep' => 'width:70px;',
  1143.                     'descsp' => 'width:300px;'
  1144.                 ],
  1145.             );
  1146.             // recuperer les fichiers associes a ce contenu
  1147.             $datafile $this->getAssociateFileContent($cont['idcontent']);
  1148.             if (!empty($datafile)) {
  1149.                 foreach ($datafile as $k => $v) {
  1150.                     if (!empty($v['is_image'])) {
  1151.                         // dimension des vignettes
  1152.                         $thumb_size = (!empty($params_display['get_critiques_vignette_large'])) ? 350 250;
  1153.                         //vignettes des critiques
  1154.                         $cont['vignette'] = $this->getThumbnail(
  1155.                             $v['file'],
  1156.                             $thumb_size,
  1157.                             'thumb'
  1158.                         );
  1159.                         //vignettes flous des critiques
  1160.                         $cont['vignette_flou'] = $this->getThumbnail(
  1161.                             $v['file'],
  1162.                             $thumb_size,
  1163.                             'thumb',
  1164.                             [
  1165.                                 'blur' => true,
  1166.                             ]
  1167.                         );
  1168.                     }
  1169.                 }
  1170.             }
  1171.         }
  1172.         if (!empty($params_display['fields'])) {
  1173.             foreach ($params_display['fields'] as $f => $v) {
  1174.                 if (isset($this->$v)) {
  1175.                     $cont[$v] = $this->$v;
  1176.                 }
  1177.             }
  1178.         }
  1179.         if (!empty($cont['dateinsert'])) {
  1180.             $cont['dateinsert_lng'] = $this->getFormeDate($cont['dateinsert'], "%A %d %B %Y"true);
  1181.         }
  1182.         if (!empty($cont['date_article'])) {
  1183.             $cont['date_article_lng'] = $this->getFormeDate($cont['date_article'], "%A %d %B %Y"true);
  1184.             $cont['date_article_lng_simple'] = $this->getFormeDate($cont['date_article'], "%a %d %b %Y"true);
  1185.         }
  1186.         // trouver les infos sur le spectacle associé
  1187.         if (!empty($params_display['get_infos_spectacle']) && !empty($this->idspectacle)) {
  1188.             $conn $this->getEntityManager();
  1189.             $spectacles $conn->getRepository(Spectacles::class);
  1190.             $cont['spectacles'] = $spectacles->getListSpectacles(array(
  1191.                 'params' => array(
  1192.                     'where' => ' AND s.idspectacle=' $this->idspectacle
  1193.                 ),
  1194.                 'dbg' => array('spec' $this->idspectacle'Spectacle ' $this->idspectacle),
  1195.             ), $params_display['get_infos_spectacle']);
  1196.             // une seule url de spectacle
  1197.             if (!empty($cont['spectacles'])) {
  1198.                 foreach ($cont['spectacles'] as $s) {
  1199.                     $cont['spectacle']['url_clean'] = $s['url_clean'];
  1200.                 }
  1201.             }
  1202.         }
  1203.         return $cont;
  1204.     }
  1205.     // }}}
  1206.     //  {{{ getClassifications()
  1207.     /** récup les classifications d'un fichier
  1208.      *
  1209.      * @access   public
  1210.      * @param int $idcontent id du contenu
  1211.      * @return   array
  1212.      */
  1213.     public function getClassifications($idcontent)
  1214.     {
  1215.         $conn $this->getEntityManager();
  1216.         $classifications $conn->getRepository(Classifications::class);
  1217.         return $classifications->getObjectClassification($this->__table$idcontent$this->getRelationsArray('content_classification'));
  1218.     }
  1219.     // }}}
  1220.     // }}}
  1221.     //  {{{ getItemsList()
  1222.     /** récup les classifications d'un fichier
  1223.      *
  1224.      * @access   public
  1225.      * @param int $idcontent id du contenu
  1226.      * @return   array
  1227.      */
  1228.     public function getItemsList($idobject null$type$src null)
  1229.     {
  1230.         // trouver les groupe de menu
  1231.         if ($type == 'group_idclassification') {
  1232.             $sql 'SELECT * FROM object_content oc
  1233.                     JOIN classifications cl ON oc.`idclassification`=cl.`idclassification`
  1234.                     WHERE oc.`object`=\'' $src '\'
  1235.                     AND oc.`idcontent`=' $idobject;
  1236.             $results $this->queryAll($sql);
  1237.             $itemslist = array();
  1238.             if (!empty($results)) {
  1239.                 foreach ($results as $r) {
  1240.                     $itemslist[$r['idclassification']]['id'] = $r['idclassification'];
  1241.                     $itemslist[$r['idclassification']]['view_name'] = $GLOBALS['context']['tr']->trans($r['classification']);
  1242.                 }
  1243.             }
  1244.             return $itemslist;
  1245.         }
  1246.         return $this->getItemsListTrait($idobject$type$src);
  1247.     }
  1248.     // }}}
  1249.     //  {{{ getApiFields()
  1250.     /** champs à renvoyer par l'API
  1251.      *
  1252.      * @access  public
  1253.      * @param array tableau de données
  1254.      */
  1255.     protected function getApiFields()
  1256.     {
  1257.         return array(
  1258.             'title' => 'title',
  1259.             'text' => 'text'// url complète
  1260.             'dateinsert' => 'insert_date',
  1261.         );
  1262.     }
  1263.     // }}}
  1264.     //  {{{ countContents()
  1265.     /** statistiques contenus
  1266.      *
  1267.      * @access  public
  1268.      */
  1269.     public function countContents($params = array())
  1270.     {
  1271.         // pour les spectacles d'une période
  1272.         if (!empty($params['periode'])) {
  1273.             $sql 'SELECT COUNT(DISTINCT(c.`idcontent`))
  1274.                     FROM contents c
  1275.                         JOIN object_content oc ON c.`idcontent`=oc.`idcontent`
  1276.                         JOIN schedules sc ON sc.`idspectacle`=oc.`idobject`
  1277.                         JOIN content_classification cc ON c.`idcontent`=cc.`idcontent`
  1278.                         JOIN classifications cl ON cc.`idclassification`=cl.`idclassification`
  1279.                     WHERE oc.`object`=\'spectacles\'
  1280.                     AND sc.`date` BETWEEN \'' $params['periode']['datestart'] . '\' AND \'' $params['periode']['dateend'] . '\' ';
  1281.         } else {
  1282.             $sql 'SELECT COUNT(DISTINCT(c.`idcontent`))
  1283.                      FROM contents c ';
  1284.             $sql .= ' JOIN content_classification cc ON c.`idcontent`=cc.`idcontent`
  1285.                       JOIN classifications cl ON cc.`idclassification`=cl.`idclassification` ';
  1286.             $sql .= ' WHERE 1 ';
  1287.         }
  1288.         $sql .= ' AND cl.`type`=\'contents\' ';
  1289.         if (!empty($params['classifications']) || !empty($params['idclassifications'])) {
  1290.             if (!empty($params['classifications'])) {
  1291.                 $sql .= ' AND cl.`classification` IN (' $this->arrayToIn($params['classifications']) . ') ';
  1292.             }
  1293.             if (!empty($params['idclassifications'])) {
  1294.                 $sql .= ' AND cc.`idclassification` IN (' $this->arrayToIn($params['idclassifications']) . ') ';
  1295.             }
  1296.         }
  1297.         $result $this->queryOne($sql);
  1298.         return $result;
  1299.     }
  1300.     // }}}
  1301.     //  {{{ countSpectaclesWithContentsFromTexts()
  1302.     /** si il n'y a pas de contenus-pedagogiques sur un texte, vérifier que les mises en scène liées non pas elle un contenu
  1303.      *
  1304.      * @access  public
  1305.      */
  1306.     public function countSpectaclesWithContentsFromTexts($idtext$idclassification)
  1307.     {
  1308.         $sql 'SELECT COUNT(s.`idspectacle`) FROM spectacles s
  1309.                 JOIN text_spectacle ts  ON ts.`idspectacle`=s.`idspectacle`
  1310.                 JOIN object_content oc  ON oc.`idobject`=s.`idspectacle`
  1311.                 JOIN contents c ON c.`idcontent`=oc.`idcontent`
  1312.                 JOIN content_classification cc ON cc.`idcontent`=c.`idcontent`
  1313.                 WHERE c.publish=1
  1314.                 AND oc.object=\'spectacles\'
  1315.                 AND cc.idclassification=' $idclassification '
  1316.                 AND ts.idtext IN (' $idtext ')
  1317.                 AND s.`publish`=1 AND s.`valid`=1';
  1318.         return $this->queryOne($sql);
  1319.     }
  1320.     // }}}
  1321. }