<?php
namespace TheatreCore\Repository;
use Symfony\Contracts\Translation\TranslatorInterface;
use TheatreCore\Entity\Classifications;
use TheatreCore\Traits\TheatreTrait;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* ClassificationsRepository
*
* This class was generated by the Doctrine ORM. Add your own custom
* repository methods below.
*/
class ClassificationsRepository extends ServiceEntityRepository
{
use TheatreTrait{
getRelationsArray as protected getRelationsArrayTrait;
}
private $em;
public $__table;
public $__table_object;
public $__idtable;
private $_classification;
public function __construct(ManagerRegistry $registry, TranslatorInterface $translator)
{
parent::__construct($registry, Classifications::class);
$this->__table = $this->getClassMetadata()->getTableName();
$this->__table_object = $this->getClassMetadata()->name;
$this->__idtable = $this->getClassMetadata()->getSingleIdentifierFieldName();
$this->translator = $translator;
}
// pour stocker les identifiants de classification
protected $_idlist = null;
const IDNUM = 0; // identifiant numérique (28)
const IDSTR = 1; // identifiant textuel ('class_truc')
// {{{ getName()
/** Retourne le nom traduit pour la classification donnée (class_truc)
*
*
* @param string $classification identifiant de la classification (numérique ou textuel)
* @access public
* @return string le label traduit correspondant (langterms)
*/
public function getName($classification)
{
if($this->my_is_int($classification)) {
$sql = 'SELECT classification FROM '.$this->__table.' WHERE idclassification='.((int)$classification);
$res = $this->queryOne($sql);
$classification = $res;
}
// return $GLOBALS['tr']->trans($classification);
return $classification;
}
// }}}
// {{{ getClassificationList()
/** Récupére la liste des classifications
*
*
* @access public
* @return array
* @param string $type files ou contents
* @param string $object texts,persons,contacts,spectacles...
* @param int $idobject identifiant de l'objet
* @param int $idclassification_parent identifiant de la classification parente
*
*/
public function getClassificationList($type=null,$object=null,$idobject=null,$is_public=array(0,1),$display_public=false)
{
$sql = 'SELECT idclassification,classification,public_name FROM '.$this->__table.' WHERE 1 ';
if(!empty($type)) {
$sql .= 'AND type="'.$type.'" ';
}
if(!empty($object)) {
$sql .= 'AND '.$object.'=1 ';
}
if(empty($idobject) || ($idobject!=3)) {
$sql .= 'AND lagarce!=1 ';
}
if(!empty($is_public)) {
$sql .= 'AND is_public IN ('.implode(',', $is_public).') ';
}
$res = $this->query($sql);
$classifications = array();
while($row = $this->fetchRow()) { //$res->fetchRow()
if($display_public==='get_value') {
$classifications[$row['idclassification']] = $row['idclassification'];
} else {
if($display_public===false) {
$classifications[$row['idclassification']] = $this->getName($row['classification']);
} else {
$classifications[$row['idclassification']] = $row['public_name'];
}
}
}
$this->free(); //$res->free()
return $classifications;
}
// }}}
// {{{ findData()
/** Recherche de classifications
*
* Permet de rechercher des classificationes selon différents critères
*
* @access public
* @see Theatre::find()
*/
public function findData($idclassification=null)
{
// parametres
if(isset($_REQUEST['keywords']) && $_REQUEST['keywords']!='nom') {
$keywords = filter_var(trim($_REQUEST['keywords']));
}
if(isset($_REQUEST['idclassification']) && is_numeric($_REQUEST['idclassification'])) {
$idclassification = (int)$_REQUEST['idclassification'];
}
// query perso
// $query = 'SELECT cl.*,lg.fr FROM '.$this->__table.' cl, langterms lg
// WHERE cl.classification=lg.id ';
$query = $this->createQueryBuilder('e');
$query->select('e');
//recherche stricte par id
if($idclassification) {
$query->andWhere('e.idclassification='.(int)$idclassification);
} else {
// mots cles
if (!empty($keywords)) {
$query->andWhere('e.classification LIKE \'%'.$this->escape($keywords).'%\' '); //OR e.langterms.fr LIKE \'%'.$this->escape($keywords).'%\')
}
}
if($this->getCount()){
$query->select('COUNT(e.idclassification)');
$this->setCount(false);
return $query;
}
// on lance la recherche
return $query->getQuery();
}
// }}}
// {{{ setToArray()
/** Liste des classifications dans un tableau associatif
*
* Tableau associatif notament utilisé pour lister les informations sur des classifications
* Utile pour générer les tableaux HTML de listes de classifications
*
* @access public
* @return array
* @see findData()
*/
public function setToArray($spec=true)
{
if($spec==true) {
$this->findData();
}
$values = array();
$color = null;
$nb = 0;
while($this->fetch()) {
$values[$nb] = $this->getInfosClassification();
$values[$nb]['id'] = $this->idclassification;
// couleur de ligne alternative
$color = $this->colorAlternate($color);
$values[$nb]['colorline'] = $color;
$nb++;
}
return $values;
}
// }}}
// {{{ getInfosClassification()
/** Infos sur une classification
*
*
* @access public
* @return array
* @param int $idclassification
*/
public function getInfosClassification($idclassification=null)
{
$infos = array();
////////////// infos de la table
if(empty($this->idclassification)) {
$this->get($idclassification);
$infos = $this->objToArray();
}
$infos += array(
'idclassification' => $this->idclassification,
'classification' => $this->classification,
'type' => $this->type,
'texts' => $this->texts,
'spectacles' => $this->spectacles,
'persons' => $this->persons,
'contacts' => $this->contacts,
'contents' => $this->contents,
'files' => $this->files,
'multimedias' => $this->multimedias,
'lagarce' => $this->lagarce,
'idgroupclassification' => $this->idgroupclassification,
'nom' => $this->getName($this->classification),
);
return $infos;
}
// }}}
// {{{ orderByDefaut()
/** Classement par défaut
*
* Défini le tri par défaut pour les requêtes de type SELECT
*
* @access public
* @return string
*/
public function orderByDefaut($order=null)
{
// tri par défaut
if(empty($order)) {
$order = 'classification';
}
return $order;
}
// }}}
// {{{ getTypePageByClassification()
/** Une page pour une classification !
*
* @access public
* @return array
* @param int $classification identifiant texte de la classification
* @param string $object type d'objet
*
*/
public function getTypePageByClassification($classification,$object)
{
$module = $GLOBALS['module'];
$sql_from = 'SELECT page FROM classification_module cm ';
$sql_where = 'WHERE cm.module=\''.$this->escape($module).'\' ';
// entier uu string
if($this->my_is_int($classification)) {
$sql_where .= ' AND cm.idclassification=='.(int)$classification;
} else {
$sql_from .= ', classifications cl ';
$sql_where .= ' AND cl.idclassification=cm.idclassification AND cl.classification=\''.$classification.'\' ';
}
$sql = $sql_from.$sql_where;
if($page = $this->queryOne($sql) && !empty($page)) {
return $page;
}
return 'unknown_page_type';
}
// }}}
// {{{ classificationsToList()
/** Sépare les identifiants numériques et textuels, retourne un tableau contenant l'ensemble (deux sous-tableaux),
* et stocke le tout dans la propriété _idlist.
*
*
* @access public
* @return array
*/
public function classificationsToList($classification)
{
$this->_idlist = array();
if (!empty($classification)) {
if (!is_array($classification)) {
$classification = array($classification);
}
foreach($classification as $v) {
if ($this->my_is_int($v)) {
$this->_idlist[$this->IDNUM][] = (int)$v;
} else {
$this->_idlist[$this->IDSTR][] = '\''.$this->escape($v).'\'';
}
}
}
return $this->_idlist;
}
// }}}
// {{{ listClassificationsWhere()
/** Construit une clause where à partir d'une liste d'id de classifications
*
*
* @param mixed $list tableau ou rien pour utiliser la propriété _idlist
* @access protected
* @return string la partie de la requête correspondante
*/
public function listClassificationsWhere($list=null)
{
if (is_null($list)) $list = $this->_idlist;
if (empty($list)) return '1';
if (!empty($list[$this->IDSTR])) {
$s = '(cl.classification IN ('.implode(',', $list[$this->IDSTR]).'))';
} else {
$s = '';
}
if (!empty($list[$this->IDNUM])) {
$i = '(cl.idclassification IN ('.implode(',',$list[$this->IDNUM]).'))';
} else {
$i = '';
}
if ($s && $i) {
$w = $s.' OR '.$i;
} else {
$w = $s.$i;
if (empty($w)) return '1';
}
return '('.$w.')';
}
// }}}
// {{{ getType()
/** Retourne le(s) type(s) des classifications dans _idlist
*
*
* @access protected
* @return array
*/
protected function getType($classification=null, $object=null)
{
if(is_null($this->_classification) || (isset($this->_classification) && $this->_classification != $classification)){
$this->classification = $classification;
// $this->classificationsToList($classification)
$this->_idlist = null;
}
if (is_null($this->_idlist)) $this->classificationsToList($classification);
$sql = 'SELECT DISTINCT(cl.type) FROM '.$this->__table.' cl WHERE '.$this->listClassificationsWhere();
if (!empty($object)) {
$sql .= ' AND '.$this->escape($object).'=1';
}
$res = $this->queryCol($sql);
return $res;
}
// }}}
// {{{ getListSearch()
/** Liste des classifications
*
* Pour les champs Ajax de relations et les recherches diverses
*
* @access public
* @return array
* @param string $lettres Pour la recherche alphabetique
* @param string $type Pour le type recherche (editeurs, revues...)
* @param string $keywords Recherche par mots cles
* @param bool $classic Si on recherche par l'action = true, sinon c'est depuis un block input symfony (à développer)
*/
public function getListSearch($lettre=null,$type=null,$keywords=null,$only=null,$type_object=null,$classic=false)
{
$sql = 'SELECT cl.classification, cl.idclassification, lg.fr, cl.type
FROM '.$this->__table.' cl, langterms lg
WHERE lg.id=cl.classification ';
if(strpos($type,'_classification') !== false) {
$type_tab = explode('_',$type);
$type_src = $type_tab[0].'s';
}
if(!empty($type_src)) {
$sql .= ' AND cl.type=\''.$type_src.'\' ';
}
if (!empty($type_object)) {
$sql .= ' AND cl.'.$type_object.'=1';
}
// selection par ordre alpha
if (!empty($lettre) && $lettre!='tous') {
$sql .= ' AND LOWER(LEFT(LTRIM(lg.fr),1))=\''.$this->escape($lettre).'\' ';
}
// recherche avec un mot cle
$list = $this->splitKeywords($keywords);
if ($list) {
$subsql = '';
if (!empty($list[$this->IDSTR])) {
// mots clés
$ssubsql = '';
foreach($list[$this->IDSTR] as $s) {
if ($ssubsql) {
$ssubsql .= ' AND ';
}
$ssubsql .= '(lg.fr LIKE \'%'.$s.'%\'';
if (preg_match('/^[a-z0-9_]+$/', $s)) {
if (preg_match('/^class_/', $s)) $ssubsql.= ' OR cl.classification LIKE \''.$s.'%\'';
else $ssubsql.= ' OR cl.classification LIKE \'class_%'.$s.'%\'';
}
$ssubsql .= ')';
}
$subsql .= '('.$ssubsql.') ';
}
if (!empty($list[$this->IDNUM])) {
// recherche par numéro d'id pour les mots clés numériques
if ($subsql) $subsql .= ' OR ';
$subsql .= 'idclassification IN ('.implode(',', $list[$this->IDNUM]).')';
}
if ($subsql) {
$sql .= ' AND ('.$subsql.')';
}
}
$sql .= ' ORDER BY lg.fr';
$result = $this->queryAll($sql);
$r = array();
foreach($result as $k=>$v) {
$r[$v['idclassification']] = $v['fr'];
// si trouvé par id, on l'affiche en fin de titre
if (!empty($list[$this->IDNUM]) && in_array($v['idclassification'], $list[$this->IDNUM])) {
$r[$v['idclassification']] .= ' ('.$v['idclassification'].')';
}
}
return $r;
}
// }}}
// {{{ getObjectTitle()
/** Infos de l'item recherché
*
* Affichage standard du titre de l'objet
*
* @access public
* @return string
* @param int $idobject Identifiant de l'item
* @param array $infos_object Informations pour construire le titre
* @param array $params Paramétres supplémentaires
*/
public function getObjectTitle($idobject=null,$infos_object=array(),$params=array())
{
// identifiant
if(!$idobject) { $idobject = $this->idclassification; }
// champs
$params['fields'] = array('classification');
// appel la méthode standard
$infos_object = $this->getObjectTitleSimple($idobject,$infos_object,$params);
return $this->getName($infos_object['classification']);
}
// }}}
// {{{ getPossibleObjects()
/** Retourne la liste des types d'objets possibles pour une classification
*
*
* @access public
* @return array
*/
public function getPossibleObjects() {
return array(
'texts' => 'Textes',
'spectacles' => 'Spectacles',
'persons' => 'Personnes',
'contacts' => 'Contacts',
'contents' => 'Contenus',
'files' => 'Fichiers',
'multimedias'=> 'Multimedias',
'dvds' => 'DVD',
'playlists' => 'Playlists',
'lagarce' => 'Lagarce',
);
}
// }}}
// {{{ getAssociate()
/** méthode générique pour obtenir ou compter les contenus/fichiers associes par type
*
* @access public
* @param int $idobject id de l'objet lié
* @param string $objet le type d'objet (personnes, spectacles...)
* @param string|int|array $classification classification recherchee
* @param mixed $fields si vide, compte seulement, sinon obtient les champs listés
* @param array $extra paramètres optionnels:
* where clause where additionnelle
* order clause de tri
* tables tables supplémentaires (doit commencer par une virgule)
* row retourne seulement une ligne
* mode 'content' par défaut, ou 'file', si classification est précisé, inutile
* group id d'un groupe de classification
* @return int|array le compte (champ total/queryOne), une ligne (array simple/queryRow), ou tous les résultats (array complexe/queryAll)
*/
public function getAssociate($idobject,$object,$classification, $fields=false, $extra=array())
{
if (empty($object) || empty($idobject)) return false;
if(!empty($extra['force_mode'])) {
$mode = $extra['force_mode'];
} else {
if (empty($classification)) {
if (empty($extra['mode'])) {
$extra['mode'] = 'content';
}
$mode = $extra['mode'];
} else {
// on recupère les types pour ces classifications (files/contents)
$types = $this->getType($classification, $object);
if (count($types) != 1) return false; // classifications ayant des types différents !
$mode = substr($types[0], 0, -1); // on garde le type sans le s final
}
}
// construction noms des tables et champs
$x = $mode[0]; // première lettre, c ou f
$xtable = $mode.'s'; // contents c ou files f
$xid = $x.'.id'.$mode; // c.idcontent ou f.idfile
$xc = $x.'c'; // cc ou fc
$xctable = $mode.'_classification'; // content_classification cc ou file_classification fc
$xcid = $xc.'.id'.$mode;
$ox = 'o'.$x; // oc ou of
$oxtable = 'object_'.$mode; // object_content ou object_file
$oxid = $ox.'.id'.$mode; // oc.idcontent ou of.idfile
if(is_null($this->_classification) || (isset($this->_classification) && $this->_classification != $classification)) {
$this->classification = $classification;
$this->_idlist = null;
}
// string ou int pour classification
if (is_null($this->_idlist)) $this->classificationsToList($classification);
if (empty($fields)) {
// si fields est vide, on veut seulement compter
$sql_fields = 'COUNT(DISTINCT('.$oxid.')) as total';
} else {
$sql_fields = $fields;
}
// SELECT
$sql = 'SELECT '.$sql_fields.'
FROM '.$oxtable.' '.$ox.',
'.$xtable.' '.$x.',
'.$xctable.' '.$xc.',
'.$this->__table.' cl';
// infos fichiers complémentaires
if ($mode=='file') {
$sql .= ',typesfiles tf';
}
// tables additionnelles ?
if (!empty($extra['tables'])) {
$sql .= $extra['tables'];
}
// WHERE
$sql .='
WHERE '.$oxid.'='.$xid.'
AND '.$xid.'='.$xcid.'
AND '.$ox.'.idobject=\''.((int)$idobject).'\'
AND '.$ox.'.object=\''.$object.'\'
AND cl.idclassification='.$xc.'.idclassification';
// langue ?
if(!empty($extra['language'])) {
$sql .= ' AND '.$x.'.language=\''.$this->escape($extra['language']).'\' ';
}
// status ?
if($this->publish_status<2) {
$sql .= ' AND '.$x.'.publish='.(int)$this->publish_status;
}
// status complet
if (isset($extra['publish_valid'])) {
$sql .= ' AND '.$x.'.publish=1 AND '.$x.'.valid=1 ';
}
// classifications
$sql .= ' AND '.$this->listClassificationsWhere();
// groupe de classifications
if (isset($extra['group'])) {
$sql .= ' AND cl.idgroupclassification='.((int)$extra['group']);
}
// editable
if (!empty($extra['is_editable'])) {
$sql .= ' AND '.$x.'.is_editable='.((int)$extra['is_editable']);
}
// valid ?
if (isset($extra['valid'])) {
$sql .= ' AND '.$x.'.valid='.((int)$extra['valid']);
}
if (isset($extra['publish'])) {
$sql .= ' AND '.$x.'.publish='.((int)$extra['publish']);
}
// un élément en particulier
if (!empty($extra['idfile'])) {
$sql .= ' AND '.$x.'.idfile='.((int)$extra['idfile']);
}
// un utilisateur en particulier
if (!empty($extra['idextranetuser'])) {
$sql .= ' AND '.$x.'.idextranetuser='.((int)$extra['idextranetuser']);
}
// where additionnel ?
if (!empty($extra['where'])) {
$sql .= ' '.$extra['where'];
}
// Spécifique au mode content
if ($mode=='content') {
// si media, recuperer uniquement ceux qui ont un contenu multimedia
if(!empty($extra['media'])) {
$sql .= ' AND '.$x.'.display_media=1';
}
}
// Spécifique au mode file
if ($mode=='file') {
// type de fichier
$sql .= ' AND '.$x.'.idtype=tf.idtype';
}
// Simple comptage
if (empty($fields)) {
// on compte seulement, tri inutile
if (!empty($extra['limit'])) {
$sql .= ' LIMIT '.$extra['limit'];
}
$res = $this->queryOne($sql);
return (int)$res;
}
if(!empty($extra['group_content'])) {
$sql .= ' GROUP BY c.idcontent ';
}
// ORDER BY
$sql .= ' ORDER BY ';
if (!empty($extra['order'])) {
$sql .= $extra['order'];
} else {
$sql .= $x.'.`range`,'.$xid;
}
// LIMIT
if (!empty($extra['limit'])) {
$sql .= ' LIMIT '.$extra['limit'];
}
if(!empty($extra['debug_sql_associate'])) {
setDebug($sql);
}
if (empty($extra['row'])) {
$res = $this->queryAll($sql);
} else {
$res = $this->queryRow($sql);
}
return $res;
}
// }}}
// {{{ getAssociateSimple()
/** méthode générique pour obtenir ou compter les contenus/fichiers associes par type => mais en passant par une relation classique
*
* @see getAssociate
*/
public function getAssociateSimple($idobject,$object,$classification, $fields=false, $extra=array())
{
// pas d'idobjet ou pas d'object
if (empty($object) || empty($idobject)) return false;
// object et idobject
$object_link = substr($object, 0, -1); // sans le s final
$idobject_link = 'id'.$object_link;
if (empty($classification)) {
if (empty($extra['mode'])) {
$extra['mode'] = 'content';
}
$mode = $extra['mode'];
} else {
// on recupère les types pour ces classifications (files/contents)
$types = $this->getType($classification, $object);
if (count($types) != 1) return false; // classifications ayant des types différents !
$mode = substr($types[0], 0, -1); // on garde le type sans le s final
}
// construction noms des tables et champs
// table files ou contents
$x = $mode[0]; // première lettre, c ou f
$xtable = $mode.'s'; // contents c ou files f
$xid = $x.'.id'.$mode; // c.idcontent ou f.idfile
// table de classification si besoin
//if(!empty($classification)) {
$cl = $x.'c'; // cc ou fc
$cl_table = $mode.'_classification'; // content_classification cc ou file_classification fc
$cl_id = $cl.'.id'.$mode;
//}
$lt = 'j1'; // alias
$link_table = $object_link.'_'.$mode; // nom de l'object sans s (exemple contents => content_file/content_content ou contacts => content_contact/content_file)
$link_table_id = $lt.'.'.$idobject_link; // id de la table de liaison
// string ou int pour classification
if (is_null($this->_idlist)) $this->classificationsToList($classification);
if (empty($fields)) {
// si fields est vide, on veut seulement compter
$sql_fields = 'COUNT(DISTINCT('.$link_table_id.')) as total';
} else {
$sql_fields = $fields;
}
// SELECT
$sql = 'SELECT '.$sql_fields.' ';
// FROM
$sql .= ' FROM '.$link_table.' '.$lt.', '.$xtable.' '.$x.' ';
// besoin des classifications ?
//if(!empty($classification)) {
$sql .= ' ,'.$cl_table.' '.$cl.', '.$this->__table.' cl ';
//}
// infos fichiers complémentaires
if ($mode=='file') {
$sql .= ',typesfiles tf';
}
// tables additionnelles ?
if (!empty($extra['tables'])) {
$sql .= $extra['tables'];
}
// WHERE
$sql .= ' WHERE '.$link_table_id.'='.$xid.' AND '.$link_table_id.'=\''.((int)$idobject).'\' ';
// besoin des classifications ?
//if(!empty($classification)) {
$sql .= ' AND cl.idclassification='.$cl.'.idclassification AND '.$xid.'='.$cl_id.' ';
//}
// langue du contents ou du files ?
if(!empty($extra['language'])) {
$sql .= ' AND '.$x.'.language=\''.$this->escape($extra['language']).'\' ';
}
// classifications
//if(!empty($classification)) {
$sql .= ' AND '.$this->listClassificationsWhere();
//}
// groupe de classifications
if (isset($extra['group'])) {
$sql .= ' AND cl.idgroupclassification='.((int)$extra['group']);
}
// where additionnel ?
if (!empty($extra['where'])) {
$sql .= ' '.$extra['where'];
}
// Spécifique au mode content
if ($mode=='content') {
// si media, recuperer uniquement ceux qui ont un contenu multimedia
if(!empty($extra['media'])) {
$sql .= ' AND '.$x.'.display_media=1';
}
}
// Spécifique au mode file
if ($mode=='file') {
// type de fichier
$sql .= ' AND '.$x.'.idtype=tf.idtype';
}
// Simple comptage
if (empty($fields)) {
// on compte seulement, tri inutile
if (!empty($extra['limit'])) {
$sql .= ' LIMIT '.$extra['limit'];
}
$res = $this->queryOne($sql);
return (int)$res;
}
// ORDER BY
$sql .= ' ORDER BY ';
if (!empty($extra['order'])) {
$sql .= $extra['order'];
} else {
$sql .= $x.'.`range`,'.$xid;
}
// LIMIT
if (!empty($extra['limit'])) {
$sql .= ' LIMIT '.$extra['limit'];
}
//print_r($sql);
if (empty($extra['row'])) {
$res = $this->queryAll($sql);
} else {
$res = $this->queryRow($sql);
}
return $res;
}
// }}}
// {{{ getClassificationsInGroup()
/** Retourne la liste des id des classifications pour le groupe donné
*
*
* @param int $idgroupclassification
* @access public
* @return array
*/
public function getClassificationsInGroup($idgroupclassification,$object=null,$idobject=null)
{
$sql = 'SELECT idclassification, classification
FROM '.$this->__table.'
WHERE idgroupclassification='.((int)$idgroupclassification).' ORDER BY `range`';
// trouver les classifications liées à un groupe
if(!empty($object) && !empty($idobject)) {
$sql = 'SELECT cl.classification, cl.idclassification
FROM '.$this->__table.' cl, content_classification cc, object_content oc
WHERE oc.idcontent=cc.idcontent
AND cl.idclassification=cc.idclassification
AND cl.idgroupclassification='.((int)$idgroupclassification).'
AND oc.object=\''.$this->escape($object).'\'
AND oc.idobject='.(int)$idobject.'
GROUP BY cl.classification ORDER BY cl.`range`';
}
$res = $this->queryAll($sql);
return $res;
}
// }}}
// {{{ getObjectClassification()
/** Récupére la liste des classifications pour un objet
*
* @access public
* @return array
* @param string $type files ou contents
* @param string $object texts,persons,contacts,spectacles...
* @param int $idobject identifiant de l'objet
* @param int $idclassification_parent identifiant de la classification parente
*
*/
public function getObjectClassification($object,$idobject,$infos_link)
{
if(empty($object)) $object = $this->__table;
return $this->getLinkedObject($infos_link,$idobject,$infos_link['type'],$object);
}
// }}}
// {{{ getRelationsArray()
/** Décrit les relations de l'objet
*
* @access public
* @param string|int $type si on souhaite retourner uniquement un type precis
* @see Theatre::getLinkedObject()
*/
public function getRelationsArray($type)
{
// récupérer les relations communes
$array_types = $this->getRelationsArrayTrait('all');
$array_types += array(
// classification_module idclassification/module
'classification_module' => array(// modules associés
'type_join' => 'multiple',
'dest_table' => 'modules',
'join_table' => 'classification_module',
'fields' => array('module','description','publish'),
'description' => 'Module(s) associé(s) à cette classification',
'silent_delete_relation' => true,
),
);
// retourne uniquement un type précis
if($type=='all') {
return $array_types;
}
if(!empty($array_types[$type])) {
$array_types[$type]['type'] = $type;
return $array_types[$type];
} else {
return null;
}
}
// }}}
public function getAlphaRelation($type)
{
/*if($type=='content_classification') {
}
// Alphabet
$sql_letters = 'SELECT DISTINCT(UPPER(LEFT(t.title,1))) AS letter
FROM '.$this->__table.' cl, '.$other_obj->__table.' ot
WHERE cl.idclassification = m.idmultimedia
AND s.idspectacle = ts.idspectacle
AND ts.idtext = t.idtext
AND om.idobject = s.idspectacle
AND om.idobject = ts.idspectacle
AND m.audio_video = 2
AND m.publish = 1
AND m.type IN ( 4, 7 )
AND om.object = \'spectacles\'
GROUP BY t.idtext
ORDER BY letter';
$valid_letters = $this->queryCol($sql_letters);*/
}
// {{{ countByClassification()
/** Compter le nombre d'élément d'une classifgication
*
*/
public function countByClassification($idclassification,$publish_valid=false)
{
$sql = 'SELECT COUNT(DISTINCT(ct.`idcontent`))
FROM content_classification cc, contents ct
WHERE ct.`idcontent`=cc.`idcontent`
AND cc.`idclassification`='.(int)$idclassification;
// uniquement les en lignes et validés
if($publish_valid) {
if(is_array($publish_valid)) {
if(isset($publish_valid['valid']) && $publish_valid['valid']!=2) {
$sql .= ' AND ct.`valid`='.(int)$publish_valid['valid'];
}
if(isset($publish_valid['publish']) && $publish_valid['publish']!=2) {
$sql .= ' AND ct.`publish`='.(int)$publish_valid['publish'];
}
} else {
$sql .= ' AND ct.`publish`=1 AND ct.`valid`=1 ';
}
}
$res = $this->queryOne($sql);
return (int)$res;
}
// }}}
// {{{ getObjectClassifications()
/** Récupére la liste des classifications pour un objet
*
* @access public
* @return array
* @param string $object texts,persons,contacts,spectacles...
* @param int $idobject identifiant de l'objet
* @param int $idgroupclassification uniquement un type de classification
* @param bool $order classement
*
*/
public function getObjectClassifications($object,$idobject,$idgroupclassification=null,$order=null)
{
$sql = 'SELECT cl.* FROM classifications cl
JOIN '.substr($object, 0, -1).'_classification oc ON oc.`idclassification`=cl.`idclassification`
WHERE oc.`id'.substr($object, 0, -1).'`='.(int)$idobject;
// le groupe ?
if(!empty($idgroupclassification)) {
$sql .= ' AND cl.`idgroupclassification`='.(int)$idgroupclassification;
}
// classement ?
if(!empty($order)) {
$sql .= ' ORDER BY cl.`range`';
}
$results = $this->queryAll($sql);
if($results) {
return $results;
}
}
// }}}
}