vendor/theatre/core/src/Repository/ClassificationsRepository.php line 408

Open in your IDE?
  1. <?php
  2. namespace TheatreCore\Repository;
  3. use Symfony\Contracts\Translation\TranslatorInterface;
  4. use TheatreCore\Entity\Classifications;
  5. use TheatreCore\Traits\TheatreTrait;
  6. use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
  7. use Doctrine\Persistence\ManagerRegistry;
  8. /**
  9.  * ClassificationsRepository
  10.  *
  11.  * This class was generated by the Doctrine ORM. Add your own custom
  12.  * repository methods below.
  13.  */
  14. class ClassificationsRepository extends ServiceEntityRepository
  15. {
  16.     use TheatreTrait{
  17.         getRelationsArray as protected getRelationsArrayTrait;
  18.     }
  19.     private $em;
  20.     public $__table;
  21.     public $__table_object;
  22.     public $__idtable;
  23.     private $_classification;
  24.     public function __construct(ManagerRegistry $registryTranslatorInterface $translator)
  25.     {
  26.         parent::__construct($registryClassifications::class);
  27.         $this->__table $this->getClassMetadata()->getTableName();
  28.         $this->__table_object $this->getClassMetadata()->name;
  29.         $this->__idtable $this->getClassMetadata()->getSingleIdentifierFieldName();
  30.         $this->translator $translator;
  31.     }
  32.     // pour stocker les identifiants de classification
  33.     protected $_idlist null;
  34.     const IDNUM 0// identifiant numérique (28)
  35.     const IDSTR 1// identifiant textuel  ('class_truc')
  36.     // {{{ getName()
  37.     /** Retourne le nom traduit pour la classification donnée (class_truc)
  38.      *
  39.      *
  40.      * @param  string $classification identifiant de la classification (numérique ou textuel)
  41.      * @access public
  42.      * @return string  le label traduit correspondant (langterms)
  43.      */
  44.     public function getName($classification)
  45.     {
  46.         if($this->my_is_int($classification)) {
  47.             $sql 'SELECT classification FROM '.$this->__table.' WHERE idclassification='.((int)$classification);
  48.             $res $this->queryOne($sql);
  49.             $classification $res;
  50.         }
  51. //        return $GLOBALS['tr']->trans($classification);
  52.         return $classification;
  53.         
  54.     }
  55.     // }}}
  56.     //  {{{ getClassificationList()
  57.     /** Récupére la liste des classifications
  58.      *
  59.      *
  60.      * @access   public
  61.      * @return   array
  62.      * @param    string $type files ou contents
  63.      * @param    string $object texts,persons,contacts,spectacles...
  64.      * @param    int $idobject identifiant de l'objet
  65.      * @param    int $idclassification_parent identifiant de la classification parente
  66.      *
  67.      */
  68.     public function getClassificationList($type=null,$object=null,$idobject=null,$is_public=array(0,1),$display_public=false)
  69.     {
  70.         $sql 'SELECT idclassification,classification,public_name FROM '.$this->__table.' WHERE 1 ';
  71.         if(!empty($type)) {
  72.             $sql .= 'AND type="'.$type.'" ';
  73.         }
  74.         if(!empty($object)) {
  75.             $sql .= 'AND '.$object.'=1 ';
  76.         }
  77.         if(empty($idobject) || ($idobject!=3)) {
  78.             $sql .= 'AND lagarce!=1 ';
  79.         }
  80.         if(!empty($is_public)) {
  81.             $sql .= 'AND is_public IN ('.implode(','$is_public).') ';
  82.         }
  83.         $res $this->query($sql);
  84.         $classifications = array();
  85.         while($row $this->fetchRow()) { //$res->fetchRow()
  86.             if($display_public==='get_value') {
  87.                 $classifications[$row['idclassification']] = $row['idclassification'];
  88.             } else {
  89.                 if($display_public===false) {
  90.                     $classifications[$row['idclassification']] = $this->getName($row['classification']);
  91.                 } else {
  92.                     $classifications[$row['idclassification']] = $row['public_name'];
  93.                 }
  94.             }
  95.         }
  96.         $this->free(); //$res->free()
  97.         return $classifications;
  98.     }
  99.     // }}}
  100.     //  {{{ findData()
  101.     /** Recherche de classifications
  102.      *
  103.      * Permet de rechercher des classificationes selon différents critères
  104.      *
  105.      * @access  public
  106.      * @see     Theatre::find()
  107.      */
  108.     public function findData($idclassification=null)
  109.     {
  110.         // parametres
  111.         if(isset($_REQUEST['keywords']) && $_REQUEST['keywords']!='nom') {
  112.             $keywords filter_var(trim($_REQUEST['keywords']));
  113.         }
  114.         if(isset($_REQUEST['idclassification']) && is_numeric($_REQUEST['idclassification'])) {
  115.             $idclassification = (int)$_REQUEST['idclassification'];
  116.         }
  117.         // query perso
  118. //        $query = 'SELECT cl.*,lg.fr FROM '.$this->__table.' cl, langterms lg
  119. //                  WHERE  cl.classification=lg.id ';
  120.         $query $this->createQueryBuilder('e');
  121.         $query->select('e');
  122.         //recherche stricte par id
  123.         if($idclassification) {
  124.             $query->andWhere('e.idclassification='.(int)$idclassification);
  125.         } else {
  126.             // mots cles
  127.             if (!empty($keywords)) {
  128.                 $query->andWhere('e.classification LIKE \'%'.$this->escape($keywords).'%\' '); //OR e.langterms.fr LIKE \'%'.$this->escape($keywords).'%\')
  129.             }
  130.         }
  131.         if($this->getCount()){
  132.             $query->select('COUNT(e.idclassification)');
  133.             $this->setCount(false);
  134.             return $query;
  135.         }
  136.         // on lance la recherche
  137.         return $query->getQuery();
  138.     }
  139.     // }}}
  140.     //  {{{ setToArray()
  141.     /** Liste des classifications dans un tableau associatif
  142.      *
  143.      * Tableau associatif notament utilisé pour lister les informations sur des classifications
  144.      * Utile pour générer les tableaux HTML de listes de classifications
  145.      *
  146.      * @access  public
  147.      * @return  array
  148.      * @see     findData()
  149.      */
  150.     public function setToArray($spec=true)
  151.     {
  152.         if($spec==true) {
  153.             $this->findData();
  154.         }
  155.         $values = array();
  156.         $color null;
  157.         $nb 0;
  158.         while($this->fetch()) {
  159.             $values[$nb] = $this->getInfosClassification();
  160.             $values[$nb]['id'] = $this->idclassification;
  161.             // couleur de ligne alternative
  162.             $color $this->colorAlternate($color);
  163.             $values[$nb]['colorline'] = $color;
  164.             $nb++;
  165.         }
  166.         return $values;
  167.     }
  168.     // }}}
  169.     //  {{{ getInfosClassification()
  170.     /** Infos sur une classification
  171.      *
  172.      *
  173.      * @access  public
  174.      * @return  array
  175.      * @param   int     $idclassification
  176.      */
  177.     public function getInfosClassification($idclassification=null)
  178.     {
  179.         $infos = array();
  180.         ////////////// infos de la table
  181.         if(empty($this->idclassification)) {
  182.             $this->get($idclassification);
  183.             $infos $this->objToArray();
  184.         }
  185.         $infos += array(
  186.             'idclassification' => $this->idclassification,
  187.             'classification' => $this->classification,
  188.             'type' => $this->type,
  189.             'texts' => $this->texts,
  190.             'spectacles' => $this->spectacles,
  191.             'persons' => $this->persons,
  192.             'contacts' => $this->contacts,
  193.             'contents' => $this->contents,
  194.             'files' => $this->files,
  195.             'multimedias' => $this->multimedias,
  196.             'lagarce' => $this->lagarce,
  197.             'idgroupclassification' => $this->idgroupclassification,
  198.             'nom' => $this->getName($this->classification),
  199.         );
  200.         return $infos;
  201.     }
  202.     // }}}
  203.     // {{{ orderByDefaut()
  204.     /** Classement par défaut
  205.      *
  206.      * Défini le tri par défaut pour les requêtes de type SELECT
  207.      *
  208.      * @access public
  209.      * @return string
  210.      */
  211.     public function orderByDefaut($order=null)
  212.     {
  213.         // tri par défaut
  214.         if(empty($order)) {
  215.             $order 'classification';
  216.         }
  217.         return $order;
  218.     }
  219.     // }}}
  220.     //  {{{ getTypePageByClassification()
  221.     /** Une page pour une classification !
  222.      *
  223.      * @access   public
  224.      * @return   array
  225.      * @param    int $classification identifiant texte de la classification
  226.      * @param    string $object type d'objet
  227.      *
  228.      */
  229.     public function getTypePageByClassification($classification,$object)
  230.     {
  231.         $module $GLOBALS['module'];
  232.         $sql_from 'SELECT page FROM classification_module cm ';
  233.         $sql_where 'WHERE cm.module=\''.$this->escape($module).'\' ';
  234.         // entier uu string
  235.         if($this->my_is_int($classification)) {
  236.             $sql_where .= ' AND cm.idclassification=='.(int)$classification;
  237.         } else {
  238.             $sql_from .= ', classifications cl ';
  239.             $sql_where .= ' AND cl.idclassification=cm.idclassification AND cl.classification=\''.$classification.'\' ';
  240.         }
  241.         $sql $sql_from.$sql_where;
  242.         if($page $this->queryOne($sql) && !empty($page)) {
  243.             return $page;
  244.         }
  245.         return 'unknown_page_type';
  246.     }
  247.     // }}}
  248.     // {{{ classificationsToList()
  249.     /** Sépare les identifiants numériques et textuels, retourne un tableau contenant l'ensemble (deux sous-tableaux),
  250.      *  et stocke le tout dans la propriété _idlist.
  251.      *
  252.      *
  253.      * @access public
  254.      * @return array
  255.      */
  256.     public function classificationsToList($classification)
  257.     {
  258.         $this->_idlist = array();
  259.         if (!empty($classification)) {
  260.             if (!is_array($classification)) {
  261.                 $classification = array($classification);
  262.             }
  263.             foreach($classification as $v) {
  264.                 if ($this->my_is_int($v)) {
  265.                     $this->_idlist[$this->IDNUM][] = (int)$v;
  266.                 } else {
  267.                     $this->_idlist[$this->IDSTR][] = '\''.$this->escape($v).'\'';
  268.                 }
  269.             }
  270.         }
  271.         return $this->_idlist;
  272.     }
  273.     // }}}
  274.     // {{{ listClassificationsWhere()
  275.     /** Construit une clause where à partir d'une liste d'id de classifications
  276.      *
  277.      *
  278.      * @param  mixed $list  tableau ou rien pour utiliser la propriété _idlist
  279.      * @access protected
  280.      * @return string  la partie de la requête correspondante
  281.      */
  282.     public function listClassificationsWhere($list=null)
  283.     {
  284.         if (is_null($list)) $list $this->_idlist;
  285.         if (empty($list)) return '1';
  286.         if (!empty($list[$this->IDSTR])) {
  287.             $s '(cl.classification IN ('.implode(','$list[$this->IDSTR]).'))';
  288.         } else {
  289.             $s '';
  290.         }
  291.         if (!empty($list[$this->IDNUM])) {
  292.             $i '(cl.idclassification IN ('.implode(',',$list[$this->IDNUM]).'))';
  293.         } else {
  294.             $i '';
  295.         }
  296.         if ($s && $i) {
  297.             $w $s.' OR '.$i;
  298.         } else {
  299.             $w $s.$i;
  300.             if (empty($w)) return '1';
  301.         }
  302.         return '('.$w.')';
  303.     }
  304.     // }}}
  305.     // {{{ getType()
  306.     /** Retourne le(s) type(s) des classifications dans _idlist
  307.      *
  308.      *
  309.      * @access protected
  310.      * @return array
  311.      */
  312.     protected function getType($classification=null$object=null)
  313.     {
  314.         if(is_null($this->_classification) || (isset($this->_classification) && $this->_classification != $classification)){
  315.             $this->classification $classification;
  316. //            $this->classificationsToList($classification)
  317.             $this->_idlist null;
  318.         }
  319.         if (is_null($this->_idlist)) $this->classificationsToList($classification);
  320.         $sql 'SELECT DISTINCT(cl.type) FROM '.$this->__table.' cl WHERE '.$this->listClassificationsWhere();
  321.         if (!empty($object)) {
  322.             $sql .= ' AND '.$this->escape($object).'=1';
  323.         }
  324.         $res $this->queryCol($sql);
  325.         return $res;
  326.     }
  327.     // }}}
  328.     //  {{{ getListSearch()
  329.     /** Liste des classifications
  330.      *
  331.      * Pour les champs Ajax de relations et les recherches diverses
  332.      *
  333.      * @access  public
  334.      * @return  array
  335.      * @param   string $lettres     Pour la recherche alphabetique
  336.      * @param   string $type        Pour le type recherche (editeurs, revues...)
  337.      * @param   string $keywords    Recherche par mots cles
  338.      * @param   bool   $classic     Si on recherche par l'action = true, sinon c'est depuis un block input symfony (à développer)
  339.      */
  340.     public function getListSearch($lettre=null,$type=null,$keywords=null,$only=null,$type_object=null,$classic=false)
  341.     {
  342.         $sql 'SELECT cl.classification, cl.idclassification, lg.fr, cl.type
  343.                 FROM '.$this->__table.' cl, langterms lg
  344.                 WHERE lg.id=cl.classification ';
  345.         if(strpos($type,'_classification') !== false) {
  346.             $type_tab explode('_',$type);
  347.             $type_src $type_tab[0].'s';
  348.         }
  349.         if(!empty($type_src)) {
  350.             $sql .= ' AND cl.type=\''.$type_src.'\' ';
  351.         }
  352.         if (!empty($type_object)) {
  353.             $sql .= ' AND cl.'.$type_object.'=1';
  354.         }
  355.         // selection par ordre alpha
  356.         if (!empty($lettre) && $lettre!='tous') {
  357.             $sql .= ' AND LOWER(LEFT(LTRIM(lg.fr),1))=\''.$this->escape($lettre).'\' ';
  358.         }
  359.         // recherche avec un mot cle
  360.         $list $this->splitKeywords($keywords);
  361.         if ($list) {
  362.             $subsql '';
  363.             if (!empty($list[$this->IDSTR])) {
  364.                 // mots clés
  365.                 $ssubsql '';
  366.                 foreach($list[$this->IDSTR] as $s) {
  367.                     if ($ssubsql) {
  368.                         $ssubsql .= ' AND ';
  369.                     }
  370.                     $ssubsql .= '(lg.fr LIKE \'%'.$s.'%\'';
  371.                     if (preg_match('/^[a-z0-9_]+$/'$s)) {
  372.                         if (preg_match('/^class_/'$s)) $ssubsql.= ' OR cl.classification LIKE \''.$s.'%\'';
  373.                         else $ssubsql.= ' OR cl.classification LIKE \'class_%'.$s.'%\'';
  374.                     }
  375.                     $ssubsql .= ')';
  376.                 }
  377.                 $subsql .= '('.$ssubsql.') ';
  378.             }
  379.             if (!empty($list[$this->IDNUM])) {
  380.                 // recherche par numéro d'id pour les mots clés numériques
  381.                 if ($subsql$subsql .= ' OR ';
  382.                 $subsql .= 'idclassification IN ('.implode(','$list[$this->IDNUM]).')';
  383.             }
  384.             if ($subsql) {
  385.                 $sql .= ' AND ('.$subsql.')';
  386.             }
  387.         }
  388.         $sql .= ' ORDER BY lg.fr';
  389.         $result $this->queryAll($sql);
  390.         $r = array();
  391.         foreach($result as $k=>$v) {
  392.             $r[$v['idclassification']] = $v['fr'];
  393.             // si trouvé par id, on l'affiche en fin de titre
  394.             if (!empty($list[$this->IDNUM]) && in_array($v['idclassification'], $list[$this->IDNUM])) {
  395.                 $r[$v['idclassification']] .= ' ('.$v['idclassification'].')';
  396.             }
  397.         }
  398.         return $r;
  399.     }
  400.     // }}}
  401.     //  {{{ getObjectTitle()
  402.     /** Infos de l'item recherché
  403.      *
  404.      * Affichage standard du titre de l'objet
  405.      *
  406.      * @access public
  407.      * @return string
  408.      * @param  int $idobject Identifiant de l'item
  409.      * @param  array $infos_object Informations pour construire le titre
  410.      * @param  array $params Paramétres supplémentaires
  411.      */
  412.     public function getObjectTitle($idobject=null,$infos_object=array(),$params=array())
  413.     {
  414.         // identifiant
  415.         if(!$idobject) { $idobject $this->idclassification; }
  416.         // champs
  417.         $params['fields'] = array('classification');
  418.         // appel la méthode standard
  419.         $infos_object $this->getObjectTitleSimple($idobject,$infos_object,$params);
  420.         return $this->getName($infos_object['classification']);
  421.     }
  422.     // }}}
  423.     // {{{ getPossibleObjects()
  424.     /** Retourne la liste des types d'objets possibles pour une classification
  425.      *
  426.      *
  427.      * @access public
  428.      * @return array
  429.      */
  430.     public function getPossibleObjects() {
  431.         return array(
  432.             'texts'      => 'Textes',
  433.             'spectacles' => 'Spectacles',
  434.             'persons'    => 'Personnes',
  435.             'contacts'   => 'Contacts',
  436.             'contents'   => 'Contenus',
  437.             'files'      => 'Fichiers',
  438.             'multimedias'=> 'Multimedias',
  439.             'dvds'    => 'DVD',
  440.             'playlists'    => 'Playlists',
  441.             'lagarce'    => 'Lagarce',
  442.         );
  443.     }
  444.     // }}}
  445.     //  {{{ getAssociate()
  446.     /** méthode générique pour obtenir ou compter les contenus/fichiers associes par type
  447.      *
  448.      * @access   public
  449.      * @param    int        $idobject id de l'objet lié
  450.      * @param    string     $objet  le type d'objet (personnes, spectacles...)
  451.      * @param    string|int|array $classification classification recherchee
  452.      * @param    mixed      $fields  si vide, compte seulement, sinon obtient les champs listés
  453.      * @param    array      $extra  paramètres optionnels:
  454.      *          where       clause where additionnelle
  455.      *          order       clause de tri
  456.      *          tables      tables supplémentaires (doit commencer par une virgule)
  457.      *          row         retourne seulement une ligne
  458.      *          mode        'content' par défaut, ou 'file', si classification est précisé, inutile
  459.      *          group       id d'un groupe de classification
  460.      * @return   int|array  le compte (champ total/queryOne), une ligne (array simple/queryRow), ou tous les résultats (array complexe/queryAll)
  461.      */
  462.     public function getAssociate($idobject,$object,$classification$fields=false$extra=array())
  463.     {
  464.         if (empty($object) || empty($idobject)) return false;
  465.         if(!empty($extra['force_mode'])) {
  466.             $mode $extra['force_mode'];
  467.         } else {
  468.             if (empty($classification)) {
  469.                 if (empty($extra['mode'])) {
  470.                     $extra['mode'] = 'content';
  471.                 }
  472.                 $mode $extra['mode'];
  473.             } else {
  474.                 // on recupère les types pour ces classifications (files/contents)
  475.                 $types $this->getType($classification$object);
  476.                 if (count($types) != 1) return false// classifications ayant des types différents !
  477.                 $mode substr($types[0], 0, -1); // on garde le type sans le s final
  478.             }
  479.         }
  480.         // construction noms des tables et champs
  481.         $x $mode[0]; // première lettre, c ou f
  482.         $xtable $mode.'s'// contents c ou files f
  483.         $xid $x.'.id'.$mode// c.idcontent ou f.idfile
  484.         $xc $x.'c'// cc ou fc
  485.         $xctable $mode.'_classification'// content_classification cc ou file_classification fc
  486.         $xcid $xc.'.id'.$mode;
  487.         $ox 'o'.$x// oc ou of
  488.         $oxtable 'object_'.$mode// object_content ou object_file
  489.         $oxid $ox.'.id'.$mode// oc.idcontent ou of.idfile
  490.         if(is_null($this->_classification) || (isset($this->_classification) && $this->_classification != $classification)) {
  491.             $this->classification $classification;
  492.             $this->_idlist null;
  493.         }
  494.         // string ou int pour classification
  495.         if (is_null($this->_idlist)) $this->classificationsToList($classification);
  496.         if (empty($fields)) {
  497.             // si fields est vide, on veut seulement compter
  498.             $sql_fields =  'COUNT(DISTINCT('.$oxid.')) as total';
  499.         } else {
  500.             $sql_fields $fields;
  501.         }
  502.         // SELECT
  503.         $sql 'SELECT '.$sql_fields.'
  504.                 FROM '.$oxtable.' '.$ox.',
  505.                      '.$xtable.' '.$x.',
  506.                      '.$xctable.' '.$xc.',
  507.                      '.$this->__table.' cl';
  508.         // infos fichiers complémentaires
  509.         if ($mode=='file') {
  510.             $sql .= ',typesfiles tf';
  511.         }
  512.         // tables additionnelles ?
  513.         if (!empty($extra['tables'])) {
  514.             $sql .= $extra['tables'];
  515.         }
  516.         // WHERE
  517.         $sql .='
  518.                    WHERE '.$oxid.'='.$xid.'
  519.                    AND '.$xid.'='.$xcid.'
  520.                    AND '.$ox.'.idobject=\''.((int)$idobject).'\'
  521.                    AND '.$ox.'.object=\''.$object.'\'
  522.                    AND cl.idclassification='.$xc.'.idclassification';
  523.         // langue ?
  524.         if(!empty($extra['language'])) {
  525.             $sql .= ' AND '.$x.'.language=\''.$this->escape($extra['language']).'\' ';
  526.         }
  527.         // status ?
  528.         if($this->publish_status<2) {
  529.             $sql .= ' AND '.$x.'.publish='.(int)$this->publish_status;
  530.         }
  531.         // status complet
  532.         if (isset($extra['publish_valid'])) {
  533.             $sql .= ' AND '.$x.'.publish=1 AND '.$x.'.valid=1 ';
  534.         }
  535.         // classifications
  536.         $sql .= ' AND '.$this->listClassificationsWhere();
  537.         // groupe de classifications
  538.         if (isset($extra['group'])) {
  539.             $sql .= ' AND cl.idgroupclassification='.((int)$extra['group']);
  540.         }
  541.         // editable
  542.         if (!empty($extra['is_editable'])) {
  543.             $sql .= ' AND '.$x.'.is_editable='.((int)$extra['is_editable']);
  544.         }
  545.         // valid ?
  546.         if (isset($extra['valid'])) {
  547.             $sql .= ' AND '.$x.'.valid='.((int)$extra['valid']);
  548.         }
  549.         if (isset($extra['publish'])) {
  550.             $sql .= ' AND '.$x.'.publish='.((int)$extra['publish']);
  551.         }
  552.         // un élément en particulier
  553.         if (!empty($extra['idfile'])) {
  554.             $sql .= ' AND '.$x.'.idfile='.((int)$extra['idfile']);
  555.         }
  556.         // un utilisateur en particulier
  557.         if (!empty($extra['idextranetuser'])) {
  558.             $sql .= ' AND '.$x.'.idextranetuser='.((int)$extra['idextranetuser']);
  559.         }
  560.         // where additionnel ?
  561.         if (!empty($extra['where'])) {
  562.             $sql .= ' '.$extra['where'];
  563.         }
  564.         // Spécifique au mode content
  565.         if ($mode=='content') {
  566.             // si media, recuperer uniquement ceux qui ont un contenu multimedia
  567.             if(!empty($extra['media'])) {
  568.                 $sql .= ' AND '.$x.'.display_media=1';
  569.             }
  570.         }
  571.         // Spécifique au mode file
  572.         if ($mode=='file') {
  573.             // type de fichier
  574.             $sql .= ' AND '.$x.'.idtype=tf.idtype';
  575.         }
  576.         // Simple comptage
  577.         if (empty($fields)) {
  578.             // on compte seulement, tri inutile
  579.             if (!empty($extra['limit'])) {
  580.                 $sql .= ' LIMIT '.$extra['limit'];
  581.             }
  582.             $res $this->queryOne($sql);
  583.             return (int)$res;
  584.         }
  585.         if(!empty($extra['group_content'])) {
  586.             $sql .= ' GROUP BY c.idcontent ';
  587.         }
  588.         // ORDER BY
  589.         $sql .= ' ORDER BY ';
  590.         if (!empty($extra['order'])) {
  591.             $sql .= $extra['order'];
  592.         } else {
  593.             $sql .= $x.'.`range`,'.$xid;
  594.         }
  595.         // LIMIT
  596.         if (!empty($extra['limit'])) {
  597.             $sql .= ' LIMIT '.$extra['limit'];
  598.         }
  599.         if(!empty($extra['debug_sql_associate'])) {
  600.             setDebug($sql);
  601.         }
  602.         if (empty($extra['row'])) {
  603.             $res $this->queryAll($sql);
  604.         } else {
  605.             $res $this->queryRow($sql);
  606.         }
  607.         return $res;
  608.     }
  609.     // }}}
  610.     //  {{{ getAssociateSimple()
  611.     /** méthode générique pour obtenir ou compter les contenus/fichiers associes par type => mais en passant par une relation classique
  612.      *
  613.      * @see  getAssociate
  614.      */
  615.     public function getAssociateSimple($idobject,$object,$classification$fields=false$extra=array())
  616.     {
  617.         // pas d'idobjet ou pas d'object
  618.         if (empty($object) || empty($idobject)) return false;
  619.         // object et idobject
  620.         $object_link substr($object0, -1); // sans le s final
  621.         $idobject_link 'id'.$object_link;
  622.         if (empty($classification)) {
  623.             if (empty($extra['mode'])) {
  624.                 $extra['mode'] = 'content';
  625.             }
  626.             $mode $extra['mode'];
  627.         } else {
  628.             // on recupère les types pour ces classifications (files/contents)
  629.             $types $this->getType($classification$object);
  630.             if (count($types) != 1) return false// classifications ayant des types différents !
  631.             $mode substr($types[0], 0, -1); // on garde le type sans le s final
  632.         }
  633.         // construction noms des tables et champs
  634.         // table files ou contents
  635.         $x $mode[0]; // première lettre, c ou f
  636.         $xtable $mode.'s'// contents c ou files f
  637.         $xid $x.'.id'.$mode// c.idcontent ou f.idfile
  638.         // table de classification si besoin
  639.         //if(!empty($classification)) {
  640.         $cl $x.'c'// cc ou fc
  641.         $cl_table $mode.'_classification'// content_classification cc ou file_classification fc
  642.         $cl_id $cl.'.id'.$mode;
  643.         //}
  644.         $lt 'j1'// alias
  645.         $link_table $object_link.'_'.$mode// nom de l'object sans s (exemple contents => content_file/content_content ou contacts => content_contact/content_file)
  646.         $link_table_id $lt.'.'.$idobject_link// id de la table de liaison
  647.         // string ou int pour classification
  648.         if (is_null($this->_idlist)) $this->classificationsToList($classification);
  649.         if (empty($fields)) {
  650.             // si fields est vide, on veut seulement compter
  651.             $sql_fields =  'COUNT(DISTINCT('.$link_table_id.')) as total';
  652.         } else {
  653.             $sql_fields $fields;
  654.         }
  655.         // SELECT
  656.         $sql 'SELECT '.$sql_fields.' ';
  657.         // FROM
  658.         $sql .= ' FROM '.$link_table.' '.$lt.', '.$xtable.' '.$x.' ';
  659.         //  besoin des classifications ?
  660.         //if(!empty($classification)) {
  661.         $sql .= ' ,'.$cl_table.' '.$cl.', '.$this->__table.' cl ';
  662.         //}
  663.         // infos fichiers complémentaires
  664.         if ($mode=='file') {
  665.             $sql .= ',typesfiles tf';
  666.         }
  667.         // tables additionnelles ?
  668.         if (!empty($extra['tables'])) {
  669.             $sql .= $extra['tables'];
  670.         }
  671.         // WHERE
  672.         $sql .= ' WHERE '.$link_table_id.'='.$xid.' AND '.$link_table_id.'=\''.((int)$idobject).'\' ';
  673.         // besoin des classifications ?
  674.         //if(!empty($classification)) {
  675.         $sql .= ' AND cl.idclassification='.$cl.'.idclassification AND '.$xid.'='.$cl_id.' ';
  676.         //}
  677.         // langue du contents ou du files ?
  678.         if(!empty($extra['language'])) {
  679.             $sql .= ' AND '.$x.'.language=\''.$this->escape($extra['language']).'\' ';
  680.         }
  681.         // classifications
  682.         //if(!empty($classification)) {
  683.         $sql .= ' AND '.$this->listClassificationsWhere();
  684.         //}
  685.         // groupe de classifications
  686.         if (isset($extra['group'])) {
  687.             $sql .= ' AND cl.idgroupclassification='.((int)$extra['group']);
  688.         }
  689.         // where additionnel ?
  690.         if (!empty($extra['where'])) {
  691.             $sql .= ' '.$extra['where'];
  692.         }
  693.         // Spécifique au mode content
  694.         if ($mode=='content') {
  695.             // si media, recuperer uniquement ceux qui ont un contenu multimedia
  696.             if(!empty($extra['media'])) {
  697.                 $sql .= ' AND '.$x.'.display_media=1';
  698.             }
  699.         }
  700.         // Spécifique au mode file
  701.         if ($mode=='file') {
  702.             // type de fichier
  703.             $sql .= ' AND '.$x.'.idtype=tf.idtype';
  704.         }
  705.         // Simple comptage
  706.         if (empty($fields)) {
  707.             // on compte seulement, tri inutile
  708.             if (!empty($extra['limit'])) {
  709.                 $sql .= ' LIMIT '.$extra['limit'];
  710.             }
  711.             $res $this->queryOne($sql);
  712.             return (int)$res;
  713.         }
  714.         // ORDER BY
  715.         $sql .= ' ORDER BY ';
  716.         if (!empty($extra['order'])) {
  717.             $sql .= $extra['order'];
  718.         } else {
  719.             $sql .= $x.'.`range`,'.$xid;
  720.         }
  721.         // LIMIT
  722.         if (!empty($extra['limit'])) {
  723.             $sql .= ' LIMIT '.$extra['limit'];
  724.         }
  725.         //print_r($sql);
  726.         if (empty($extra['row'])) {
  727.             $res $this->queryAll($sql);
  728.         } else {
  729.             $res $this->queryRow($sql);
  730.         }
  731.         return $res;
  732.     }
  733.     // }}}
  734.     // {{{ getClassificationsInGroup()
  735.     /** Retourne la liste des id des classifications pour le groupe donné
  736.      *
  737.      *
  738.      * @param  int $idgroupclassification
  739.      * @access public
  740.      * @return array
  741.      */
  742.     public function getClassificationsInGroup($idgroupclassification,$object=null,$idobject=null)
  743.     {
  744.         $sql 'SELECT idclassification, classification
  745.                 FROM '.$this->__table.'
  746.                 WHERE idgroupclassification='.((int)$idgroupclassification).' ORDER BY `range`';
  747.         // trouver les classifications liées à un groupe
  748.         if(!empty($object) && !empty($idobject)) {
  749.             $sql 'SELECT cl.classification, cl.idclassification
  750.                     FROM '.$this->__table.' cl, content_classification cc, object_content oc
  751.                     WHERE oc.idcontent=cc.idcontent
  752.                     AND cl.idclassification=cc.idclassification
  753.                     AND cl.idgroupclassification='.((int)$idgroupclassification).'
  754.                     AND oc.object=\''.$this->escape($object).'\'
  755.                     AND oc.idobject='.(int)$idobject.'
  756.                     GROUP BY cl.classification ORDER BY cl.`range`';
  757.         }
  758.         $res $this->queryAll($sql);
  759.         return $res;
  760.     }
  761.     // }}}
  762.     // {{{ getObjectClassification()
  763.     /** Récupére la liste des classifications pour un objet
  764.      *
  765.      * @access   public
  766.      * @return   array
  767.      * @param    string $type files ou contents
  768.      * @param    string $object texts,persons,contacts,spectacles...
  769.      * @param    int $idobject identifiant de l'objet
  770.      * @param    int $idclassification_parent identifiant de la classification parente
  771.      *
  772.      */
  773.     public function getObjectClassification($object,$idobject,$infos_link)
  774.     {
  775.         if(empty($object)) $object $this->__table;
  776.         return $this->getLinkedObject($infos_link,$idobject,$infos_link['type'],$object);
  777.     }
  778.     // }}}
  779.     //  {{{ getRelationsArray()
  780.     /** Décrit les relations de l'objet
  781.      *
  782.      * @access  public
  783.      * @param string|int $type si on souhaite retourner uniquement un type precis
  784.      * @see     Theatre::getLinkedObject()
  785.      */
  786.     public function getRelationsArray($type)
  787.     {
  788.         // récupérer les relations communes
  789.         $array_types $this->getRelationsArrayTrait('all');
  790.         $array_types += array(
  791.             // classification_module idclassification/module
  792.             'classification_module' => array(// modules associés
  793.                 'type_join' => 'multiple',
  794.                 'dest_table' => 'modules',
  795.                 'join_table' => 'classification_module',
  796.                 'fields' => array('module','description','publish'),
  797.                 'description' => 'Module(s) associé(s) à cette classification',
  798.                 'silent_delete_relation' => true,
  799.             ),
  800.         );
  801.         // retourne uniquement un type précis
  802.         if($type=='all') {
  803.             return $array_types;
  804.         }
  805.         if(!empty($array_types[$type])) {
  806.             $array_types[$type]['type'] = $type;
  807.             return $array_types[$type];
  808.         } else {
  809.             return null;
  810.         }
  811.     }
  812.     // }}}
  813.     public function getAlphaRelation($type)
  814.     {
  815.         /*if($type=='content_classification') {
  816.         }
  817.         // Alphabet
  818.         $sql_letters = 'SELECT DISTINCT(UPPER(LEFT(t.title,1))) AS letter
  819.                         FROM '.$this->__table.' cl, '.$other_obj->__table.' ot
  820.                         WHERE cl.idclassification = m.idmultimedia
  821.                         AND s.idspectacle = ts.idspectacle
  822.                         AND ts.idtext = t.idtext
  823.                         AND om.idobject = s.idspectacle
  824.                         AND om.idobject = ts.idspectacle
  825.                         AND m.audio_video = 2
  826.                         AND m.publish = 1
  827.                         AND m.type IN ( 4, 7 )
  828.                         AND om.object = \'spectacles\'
  829.                         GROUP BY t.idtext
  830.                         ORDER BY letter';
  831.         $valid_letters = $this->queryCol($sql_letters);*/
  832.     }
  833.     //  {{{ countByClassification()
  834.     /** Compter le nombre d'élément d'une classifgication
  835.      *
  836.      */
  837.     public function countByClassification($idclassification,$publish_valid=false)
  838.     {
  839.         $sql 'SELECT COUNT(DISTINCT(ct.`idcontent`))
  840.                 FROM content_classification cc, contents ct
  841.                 WHERE ct.`idcontent`=cc.`idcontent`
  842.                 AND cc.`idclassification`='.(int)$idclassification;
  843.         // uniquement les en lignes et validés
  844.         if($publish_valid) {
  845.             if(is_array($publish_valid)) {
  846.                 if(isset($publish_valid['valid']) && $publish_valid['valid']!=2) {
  847.                     $sql .= ' AND ct.`valid`='.(int)$publish_valid['valid'];
  848.                 }
  849.                 if(isset($publish_valid['publish']) && $publish_valid['publish']!=2) {
  850.                     $sql .= ' AND ct.`publish`='.(int)$publish_valid['publish'];
  851.                 }
  852.             } else {
  853.                 $sql .= ' AND ct.`publish`=1 AND ct.`valid`=1 ';
  854.             }
  855.         }
  856.         $res $this->queryOne($sql);
  857.         return (int)$res;
  858.     }
  859.     // }}}
  860.     // {{{ getObjectClassifications()
  861.     /** Récupére la liste des classifications pour un objet
  862.      *
  863.      * @access   public
  864.      * @return   array
  865.      * @param    string $object texts,persons,contacts,spectacles...
  866.      * @param    int $idobject identifiant de l'objet
  867.      * @param    int $idgroupclassification uniquement un type de classification
  868.      * @param    bool $order classement
  869.      *
  870.      */
  871.     public function getObjectClassifications($object,$idobject,$idgroupclassification=null,$order=null)
  872.     {
  873.         $sql 'SELECT cl.* FROM classifications cl 
  874.                 JOIN '.substr($object0, -1).'_classification oc ON oc.`idclassification`=cl.`idclassification`
  875.                 WHERE oc.`id'.substr($object0, -1).'`='.(int)$idobject;
  876.         // le groupe ?
  877.         if(!empty($idgroupclassification)) {
  878.             $sql .= ' AND cl.`idgroupclassification`='.(int)$idgroupclassification;
  879.         }
  880.         // classement ?
  881.         if(!empty($order)) {
  882.             $sql .= ' ORDER BY cl.`range`';
  883.         }
  884.         
  885.         $results $this->queryAll($sql);
  886.         if($results) {
  887.             return $results;
  888.         }
  889.     }
  890.     // }}}
  891. }