<?php
namespace TheatreCore\Repository;
use Symfony\Contracts\Translation\TranslatorInterface;
use TheatreCore\Classes\Images\Images;
use TheatreCore\Entity\Bigregions;
use TheatreCore\Entity\ContactAide;
use TheatreCore\Entity\Contacts;
use TheatreCore\Entity\Spectacles;
use TheatreCore\Traits\TheatreTrait;
use TheatreCore\Entity\Directories;
use TheatreCore\Entity\Extranetusers;
use TheatreCore\Entity\Files;
use TheatreCore\Entity\Typesstructures;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
use Doctrine\ORM\Query;
use Theatre_Extranetusers;
use DateTime;
/**
* ContactsRepository
*
* This class was generated by the Doctrine ORM. Add your own custom
* repository methods below.
*/
class ContactsRepository extends ServiceEntityRepository
{
use TheatreTrait {
getRelationsArray as protected getRelationsArrayTrait;
}
private $em;
public $__table;
public $__table_object;
public $__idtable;
public function __construct(ManagerRegistry $registry, TranslatorInterface $translator, Images $images)
{
parent::__construct($registry, Contacts::class);
$this->__table = $this->getClassMetadata()->getTableName();
$this->__table_object = $this->getClassMetadata()->name;
$this->__idtable = $this->getClassMetadata()->getSingleIdentifierFieldName();
$this->translator = $translator;
$this->images = $images;
}
// {{{ findData()
/** Recherche des contacts
*
* Permet de rechercher des contacts en fonction de certains critères :
* la première lettre, un bout du nom, le type de contact, si il est en ligne ou pas
*
* @access public
* @see Theatre::find()
*/
public function findData($lettre = null, $idtypestructure = null, $publish = null, $keywords = null)
{
// requete perso
$query = null;
$query = $this->createQueryBuilder('c');
// parametre
if (!empty($_REQUEST['idcontact']) && my_is_int($_REQUEST['idcontact'])) {
$idcontact = (int)$_REQUEST['idcontact'];
}
if (isset($_REQUEST['lettre']) && !empty($_REQUEST['lettre'])) {
$lettre = filter_var($_REQUEST['lettre']);
}
if (isset($_REQUEST['keywords']) && $_REQUEST['keywords'] != 'nom') {
$keywords = filter_var(trim($_REQUEST['keywords']), FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES);
if ($this->my_is_int($keywords)) {
$idcontact = (int)$keywords;
$keywords = null;
}
}
if (!empty($_REQUEST['idtypestructure']) && strlen($_REQUEST['idtypestructure']) < 5) {
$idtypestructure = $_REQUEST['idtypestructure'];
}
if (isset($_REQUEST['publish']) && !empty($_REQUEST['publish'])) {
$publish = filter_var($_REQUEST['publish']);
}
if (isset($_REQUEST['city']) && $_REQUEST['city'] != 'ville' && !empty($_REQUEST['city'])) {
$city = filter_var(trim($_REQUEST['city']));
}
if (isset($_REQUEST['is_ecole'])) {
$is_ecole = true;
}
//
// // on précise les champs pour le SELECT
// $query = 'SELECT c.idcontact,c.type,c.lastname,c.firstname,c.organisation,c.email1,c.country,c.city,c.publish,c.valid,c.dateupdate
// FROM contacts c WHERE 1 ';
//
//recherche stricte par id
if (!empty($idcontact)) {
$query->andWhere('c.idcontact=' . ((int)$idcontact));
}
// // premiere lettre
if (!empty($lettre)) {
$query->andWhere('(c.lastname REGEXP \'^' . $this->escape($lettre) . '\' OR c.organisation REGEXP \'^' . $this->escape($lettre) . '\') ');
}
// mots cles
if (!empty($keywords)) {
$query->andWhere('(c.lastname LIKE \'%' . $this->escape($keywords) . '%\' OR c.organisation LIKE \'%' . $this->escape($keywords) . '%\') ');
}
// selectionne par type de structure
if (!empty($idtypestructure)) {
$query->andWhere('c.idtypestructure=\'' . $this->escape($idtypestructure) . '\' ');
}
// selectionne les fiches hors ligne
if (!empty($publish) && $publish == 'no') {
$publish = 0;
$query->andWhere('c.publish=' . ((int)$publish));
}
// ville
if (!empty($city)) {
$query->andWhere('c.city LIKE \'%' . $this->escape($city) . '%\'');
}
// // ecoles
if (!empty($is_ecole)) {
$conn = $this->getEntityManager()->getConnection();
$queryIN = $conn->executeQuery('SELECT idcontact FROM person_ecole')->fetchAll(\PDO::FETCH_COLUMN | \PDO::FETCH_ASSOC);
$query->andWhere(' c.idcontact IN (' . implode(',', $queryIN) . ') ');
}
//
// if(isset($_REQUEST['idaide']) && my_is_int($_REQUEST['idaide'])) {
// $query .= ' AND c.`idcontact` IN (
// SELECT idcontact FROM contact_aide
// WHERE idaide='.(int)$_REQUEST['idaide'].'
// ) ';
// }
//
// // que les contacts publiés ou non et pas les anciens/supprimés
// $query .= ' AND c.publish<2';
if ($this->getCount()) {
$query->select('COUNT(c.idcontact)');
$this->setCount(false);
return $query;
}
// on lance la recherche
return $query->getQuery();
}
// }}}
// {{{ setToArray()
/** liste des structures partenaires => CDN, classification 113
*
* @access public
* @return array
*/
public function getStructuresPartenaires($idtypestructure = null, $prospection = null)
{
$conn = $this->getEntityManager()->getConnection();
$sql = 'SELECT *, c.`idcontact` as idcontact FROM contacts c
LEFT JOIN contact_classification cc ON cc.`idcontact`=c.`idcontact`
WHERE 1 ';
if (is_null($idtypestructure) && !empty($idtypestructure)) {
$sql .= ' AND c.`idtypestructure`=\'' . filter_var($idtypestructure, FILTER_SANITIZE_STRING) . '\' ';
} else {
//$sql .= ' AND c.`idtypestructure` IN (\'CDN\') OR cc.`idclassification`=113 ';
$sql .= ' AND cc.`idclassification`=113 ';
}
// voir les partenaires en cours de prospection
if (!is_null($prospection)) {
$sql = 'SELECT *, c.`idcontact` as idcontact FROM contacts c
LEFT JOIN contact_classification cc ON cc.`idcontact`=c.`idcontact`
WHERE 1 ';
$sql .= ' AND c.`idtypestructure` IN (\'CDN\') AND c.`idcontact` NOT IN (
SELECT idcontact FROM contact_classification WHERE idclassification=113
) OR cc.`idclassification`=124 ';
}
$sql .= 'GROUP BY c.`idcontact` ';
$stmt = $conn->prepare($sql);
$stmt->execute();
return $stmt->fetchAll();
}
// {{{ setToArray()
/** Liste des contacts dans un tableau associatif
*
* Tableau associatif notament utilisé pour lister les informations sur des contacts
* Utile pour générer les tableaux HTML de listes de contacts
*
* @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->getInfosContact(null, array('get_extranetusers' => true));
$values[$nb]['id'] = $this->idcontact;
// couleur de ligne alternative
$color = $this->colorAlternate($color);
$values[$nb]['colorline'] = $color;
$nb++;
}
return $values;
}
// }}}
// {{{ getInfosContact()-
/** Informations sur un contact
*
* @access public
* @param int $idcontact Identifiant du contact
* @return array
*/
public function getInfosContact($idcontact = null, $params = array())
{
$infos = array();
$con = $this->getEntityManager();
////////////// infos de la table
if (empty($this->idcontact) || $idcontact != $this->idcontact) {
if (!empty($params['get_idtypestructure_TODO'])) {
$sql = 'SELECT *
FROM ' . $this->__table . ', typesstructures
WHERE typesstructures.idtypestructure=' . $this->__table . '.idtypestructure
AND ';
if (!my_is_int($idcontact)) {
$sql .= $this->__table . '.url_clean=' . $this->escape($idcontact);
} else {
$sql .= $this->__table . '.' . $this->__idtable . '=' . (int)$idcontact;
}
//$this->queryRow($sql, null, MDB2_FETCHMODE_OBJECT);
} else {
$query = $this->createQueryBuilder('u')
->select('u, cc')
->leftJoin('u.country', 'cc');
if (!$this->my_is_int($idcontact)) {
$query->where('u.urlClean = :value')->setParameter('value', $idcontact['urlClean']);
} else {
$query->where('u.' . $this->__idtable . ' =:value')->setParameter('value', $idcontact);
}
$infos = $query->getQuery()->getOneOrNullResult(Query::HYDRATE_ARRAY);
$this->loadResult($infos);
}
}
if (empty($infos['organisation']) && empty($infos['lastname']) && !isset($this->idcontact)) {
return array();
}
$infos += array(
'idcontact' => $this->idcontact,
'idtypestructure' => $this->idtypestructure,
'link_on_video' => $this->linkOnVideo,
'city' => $this->city,
'nom_suite' => $this->nomSuite,
'email' => $this->email1,
'phone1' => $this->phone1,
'url' => $this->url,
'type_view' => $this->typeView,
'stats_access' => $this->statsAccess,
'is_festival' => $this->isFestival,
'is_partenaire' => $this->isPartenaire,
'valid' => $this->valid,
'publish' => $this->publish,
'dateupdate' => $this->dateupdate,
'url_clean' => $this->urlClean,
'address1' => $this->address1,
'idmultimedia' => $this->idmultimedia,
'zip' => $this->zip,
);
if (!empty($this->country['id'])) {
$infos['country'] = $this->getNameCountry($this->country['id']);
$infos['country_code'] = $this->country['id'];
}
// affichage de l'organisation et/ou du nom
$infos_object = array(
'lastname' => $this->lastname,
'firstname' => $this->firstname,
'organisation' => $this->organisation,
'title' => $this->organisation,
'fullname' => $this->organisation,
'type' => $this->type,
);
$infos += $infos_object;
// type de structure
if (array_key_exists('get_idtypestructure', $params) && !empty($infos['idtypestructure'])) {
$typesstructures = $con->getRepository(Typesstructures::class);
$infos['typestructure'] = $typesstructures->getInfosTypeStructure($infos['idtypestructure']);
$infos['typestructure_string'] = $infos['typestructure'];
}
// retrouver les comptes mon théâtre associés
if (array_key_exists('get_extranetusers', $params)) {
$infos['extranetusers'] = $con->getRepository(Extranetusers::class)->getObjectExtranetusers('contact', $infos['idcontact']);
$infos['nb_extranetusers'] = count($infos['extranetusers']);
}
// retrouver les fiches annuaires associées
if (array_key_exists('get_directories', $params)) {
$infos['directories'] = $con->getRepository(Directories::class)->getDirectoriesByObject('contact', $infos['idcontact']);
$infos['nb_directories'] = count($infos['directories']);
}
// tester si il y a un bandeau custom
if (array_key_exists('get_bandeau', $params)) {
$files = $con->getRepository(Files::class);
$files->setPublishStatus(1);
if (!empty($params['get_bandeau'])) {
$bandeau = $files->getObjectFiles($infos['idcontact'], 'contacts', 100);
$infos['bandeau'] = URL_DIRECTORYUPLOAD . $this->getThumbnail($bandeau[0]['file'], $params['get_bandeau']['size'], $params['get_bandeau']['direction']);
} else {
$bandeau = $files->getObjectFiles($infos['idcontact'], 'contacts', 100);
$infos['bandeau'] = $bandeau[0]['file'];
}
}
// retrouver les personnes associées
if (array_key_exists('get_persons', $params)) {
$infos['persons'] = $this->getAssociatePersons($infos['idcontact']);
$infos['nb_persons'] = count($infos['persons']);
}
// retrouver les personnes associées
if (array_key_exists('get_boss', $params)) {
$infos['boss_all'] = $this->getCurrentBoss($infos['idcontact'], true);
if (!empty($infos['boss_all'])) {
foreach ($infos['boss_all'] as $k => $v) {
$infos['boss'] = $v;
break;
}
}
}
// retrouver le logo/avatar
if (array_key_exists('get_profile_picture', $params)) {
$infos['profile_picture'] = $this->getVignetteContact($infos['idcontact'], array(), 'class_pp');
if (strpos($infos['profile_picture'], 'normal-def.jpg') !== false) {
$infos['profile_picture'] = $_ENV['URL_THNET'] . '/images/menu/interface/no_contact-100x100.png';
}
}
// voir si il y a des aides
if (!empty($params['get_aides'])) {
$infos['nb_aides'] = $this->getEntityManager()->getRepository(ContactAide::class)->countAides(null, $infos['idcontact']);
if ($infos['nb_aides'] > 0) {
$infos['aides'] = $this->getEntityManager()->getRepository(Contacts::class)->getListContactAide(array(
'idcontact' => array($infos['idcontact']),
'get_contacts_with_aides' => true,
'dbg' => array('liste_aides', 'Liste des aides de la structure')
));
$infos['nb_aides'] = count($infos['aides']);
}
}
$infos['nameview'] = $this->getObjectTitle($this->idcontact, $infos_object);
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 = 'organisation';
}
return $order;
}
// }}}
// {{{ getListSearch()
/** Liste de contacts
*
* Pour les champs Ajax de relations et les recherches diverses
*
* @access public
* @param string $lettres Pour la recherche alphabetique
* @param string $type Pour le type recherche (editeurs, revues...)
* @param string $keywords Recherche par mots cles
* @return array
*/
public function getListSearch($lettre = null, $type = null, $keywords = null, $only = null, $strict = false)
{
$sql = 'SELECT `idcontact`, `type`, `organisation`, `firstname`, `lastname`, `city`
FROM ' . $this->__table . '
WHERE ';
// selection par ordre alpha
if (!empty($lettre)) {
$sql_where[] = 'LOWER(LEFT(LTRIM(organisation),1))=\'' . $this->escape($lettre) . '\'';
}
// recherche avec un mot cle
if (!empty($keywords) && $strict) {
$sql_where[] = '`organisation` LIKE \'%' . $keywords . '%\'';
} else {
$list = $this->splitKeywords($keywords);
if ($list) {
// recherche avec les mots clés
if (!empty($list[$this->IDSTR])) {
//$sql_where[] = '`organisation` LIKE \''.$this->escape('%'.$keywords.'%').'\'';
foreach ($list[$this->IDSTR] as $s) {
// si on veut supprimer les pronoms et autres trucs du genre
//if(strlen($s)>3) {
$sql_more_name[] = '`organisation` LIKE \'%' . $s . '%\'';
//}
// essai avec soundhex
//$sql_more_name[] = '`organisation` LIKE \'%'.$s.'%\' OR SOUNDEX(`organisation`)=SOUNDEX(\''.$s.'\')';
}
//$sql_where[] = 'SOUNDEX(`organisation`)=SOUNDEX(\''.$this->escape($keywords).'\') OR ('.join(' OR ', $sql_more_name).')';
//$sql_where[] = '('.join(' OR ', $sql_more_name).') OR SOUNDEX(`organisation`)=SOUNDEX(\''.$this->escape($keywords).'\')';
if (!empty($sql_more_name)) {
$sql_where[] = '(' . join(' AND ', $sql_more_name) . ')';
}
}
// recherche par numéro d'id pour les mots clés numériques
if (!empty($list[$this->IDNUM])) {
$sql_where[] = '`idcontact` IN (' . implode(',', $list[$this->IDNUM]) . ')';
}
}
}
$sql .= join(' OR ', $sql_where);
// on recherche par type
/*if($type=='idcontact_publisher') {
$sql .= ' AND idcontact IN (SELECT DISTINCT(idcontact_publisher) FROM texts) ';
}*/
//echo $sql;
$sql .= ' ORDER BY organisation';
$this->query($sql);
$r = array();
while ($this->fetch()) {
// le titre
$r[$this->idcontact] = $this->getObjectTitle($this->idcontact);
// optionnellement, la ville
if ($this->city != '') {
$r[$this->idcontact] .= ' - ' . $this->city;
}
// si trouvé par id, on l'affiche en fin de titre
if (!empty($list[$this->IDNUM]) && in_array($this->idcontact, $list[$this->IDNUM])) {
$r[$this->idcontact] .= ' - n°' . $this->idcontact;
}
}
$this->free();
return $r;
}
// }}}
// {{{ getObjectTitle()
/** Infos de l'item recherché
*
* Affichage standard du titre de l'objet
*
* @access public
* @param int $idobject Identifiant de l'item
* @param array $infos_object Informations pour construire le titre
* @param array $params Paramétres supplémentaires
* @return string
*/
public function getObjectTitle($idobject = null, $infos_object = array(), $params = array())
{
if (!$idobject) {
$idobject = $this->idcontact;
}
// champs
$fields = array('type', 'organisation', 'firstname', 'lastname', 'url_clean', 'valid');
if (empty($infos_object)) {
//charger les infos que si necessaire
if (empty($this->organisation) && empty($this->lastname)) {
// $this->selectAdd();
// $this->selectAdd(join($fields, ','));
$infos_object = $this->get($idobject);
}
if (empty($infos_object)) {
foreach ($fields as $k => $v) {
if (empty($this->$v)) {
$infos_object[$v] = '';
} else {
$infos_object[$v] = trim($this->$v);
}
}
}
} else {
foreach ($fields as $k => $v) {
if (empty($infos_object[$v])) {
$infos_object[$v] = '';
} else {
$infos_object[$v] = trim($infos_object[$v]);
}
}
}
// id
$infos_object['idcontact'] = $idobject;
// nom en majuscules suivi par le prénom
$name = '';
if (!array_key_exists('url_clean', $params)) {
if ($infos_object['lastname']) {
$name .= mb_strtoupper($infos_object['lastname']);
}
if ($infos_object['firstname']) {
if ($name) $name .= ' ';
$name .= $infos_object['firstname'];
}
} else { // on souhaite un affichage nom/prenom
if ($infos_object['firstname']) {
$name .= $infos_object['lastname'];
}
if ($infos_object['lastname']) {
if ($name) $name .= ' ';
$name .= $infos_object['lastname'];
}
}
//si c'est une personne (type=0), nom, prenom et organisation entre parenthese si elle existe
$return = '';
if ($infos_object['type'] == 0) {
// on ajoute le nom
$return .= $name;
if ($infos_object['organisation']) {
if ($name) {
// nom _et_ organisation
$return .= ' (' . $infos_object['organisation'] . ')';
} else {
// organisation seulement
$return .= $infos_object['organisation'];
}
}
} elseif ($infos_object['type'] == 1) {//organisation
if ($infos_object['organisation']) {
// on ajoute l'organisation
$return .= $infos_object['organisation'];
}
if ($name && !array_key_exists('noname', $params)) {
if ($return) {
// organisation _et_ nom
$return .= ' (' . $name . ')';
} else {
// nom seulement
$return .= $name;
}
}
}
if (!empty($infos_object['organisation'])) {
$infos_object['title'] = $infos_object['organisation'];
}
if (!$return) $return = '???'; // vide, bug?...
// renvoyer un array plutôt que le titre (utile si on veux l'url)
if (array_key_exists('return_array', $params)) {
return $infos_object;
}
//retour
return $return;
}
// }}}
// {{{ countObjects()
/** Compter le nombre d'objet lié à un contact
*
*
* @param string $object Type
* @param string $associate_field Champ associé
* @param string $idcontact id du contact
* @access public
* @return int
*/
public function countObjects($object, $associate_field, $idcontact = null)
{
if (!$idcontact && isset($this->idcontact)) {
$idcontact = $this->idcontact;
}
if (!$idcontact) {
return false;
}
// ajout du 's'
$sql = 'SELECT COUNT(DISTINCT(id' . $object . ')) as total
FROM ' . $object . 's
WHERE ' . $associate_field . '=' . ((int)$idcontact);
$nbCount = $this->queryOne($sql);
return $nbCount;
}
// }}}
// {{{ getContactsByClassification()
/** Retourne la liste des contacts par tag(s)
*
*
* @param string|array $tagnames
* @param string $classification_name
* @access public
* @return array
*/
public function getContactsByClassification($classification_name = null, $order_by = null, $limit = null, $idgroupclassification = null, $area = null)
{
// requete classique si pas idclassification
$sql = 'SELECT ct.idcontact,ct.url_clean, ct.link_on_video, ct.url, ct.organisation, ct.idtypestructure, f.file, tf.titre AS extension
FROM ' . $this->__table . ' ct, object_file of, files f, classifications cl, file_classification fc, typesfiles tf
WHERE 1
AND of.idobject=ct.' . $this->__idtable . '
AND f.idfile=of.idfile
AND f.publish=1
AND f.idtype=tf.idtype
AND f.idfile=fc.idfile
AND cl.idclassification=fc.idclassification
AND of.object=\'contacts\' ';
// recherche par classifications
if (!empty($classification_name)) {
// recherche simple par idclassification
if (is_array($classification_name) || $this->my_is_int($classification_name)) {
$sql = 'SELECT ct.idcontact,ct.url_clean, ct.url, ct.organisation, ct.idtypestructure, cc.idclassification, cl.classification
FROM ' . $this->__table . ' ct
JOIN contact_classification cc ON cc.idcontact=ct.idcontact
JOIN classifications cl ON cl.idclassification=cc.idclassification
WHERE ct.publish=1 ';
if (is_array($classification_name)) {
$sql .= ' AND cc.idclassification IN (' . join(',', $classification_name) . ') ';
} else {
$sql .= ' AND cc.idclassification=' . (int)$classification_name;
}
} else {
$sql .= ' AND cl.classification=\'' . $this->escape($classification_name) . '\'';
}
}
// recherche par idgroupclassification
if (!empty($idgroupclassification)) {
$sql .= ' AND cl.idgroupclassification=\'' . $this->escape($idgroupclassification) . '\'';
}
// recherche par regions
if (!empty($area)) {
$bigregions = $this->getEntityManager()->getRepository(Bigregions::class);
$sql .= ' AND ' . $bigregions->getZipCode($area, 'ct') . ' ';
}
if (empty($order_by)) {
$sql .= ' ORDER BY ct.idcontact';
} else {
$sql .= ' ORDER BY ' . $order_by;
}
if (!empty($limit)) {
$sql .= ' LIMIT ' . $limit;
}
$res = $this->queryAll($sql);
return $res;
}
// }}}
// {{{ setRelationContact()
/** Enregistrement dans les table relationnelle
*
* Permet l'enregistrement multiple de valeur dans les tables
* de relation
*
* @access public
* @param string $table Nom de la table de relation
* @param string $key Clé dans le tableau
* @param string $col Colonne
* @param array $array_values Valeur à enregistrer
* @param int $id Id de l'enregistrement principal
* @return bool
*/
public function setRelationContact($table_liaison, $fields, $array_values, $allRights = true)
{
if ($allRights) {
$rights = array('update' => 1);
}
// on vérifie les droits
if ($this->isCheckRights() || !$allRights) {
$extranetusers = Theatre_Extranetusers::factory('extranetusers');
$rights = $extranetusers->getRights();
}
if (isset($rights) && $rights['update'] == 1) {
$where = null;
// construire
$i = 0;
foreach ($fields as $k => $v) {
// le premier champ et les champs après 1 construisent le WHERE du delete
if ($i != 1) {
if (is_null($v)) {
$where .= ' AND ' . $k . ' IS NULL';
} else {
$where .= ' AND ' . $k . '=\'' . $v . '\'';
}
}
$insert_fields[] = $k;
$interro_fields[] = '?';
$i++;
}
if (empty($where)) {
throw new \Exception('Il n\'y a pas de clause WHERE pour relationSelect');
}
// on supprime puis on insère (replace ne marche pas)
$sql_delete = 'DELETE FROM ' . $table_liaison . ' WHERE 1 ' . $where;
$prep = $this->_em->getConnection()->prepare($sql_delete);
$prep->execute();
// si le tableau est vide on sort
if (empty($array_values)) {
return true;
}
// on prepare
$sql_prepare = 'INSERT INTO ' . $table_liaison . ' (' . implode(',', $insert_fields) . ') VALUES ( ' . implode(',', $interro_fields) . ')';
$prep = $this->_em->getConnection()->prepare($sql_prepare);
// le premier index de 'fields' correspond à la clé
reset($fields);
$idt = current($fields);
$i = 0;
foreach ($array_values as $k => $v) {
$prep_values[$i] = array($idt, $v);
// si le nombre de champ déclaré est sup à 2
if (count($fields) > 2) {
$j = 0;
foreach ($fields as $kb => $vb) {
if ($j > 1) {
$prep_values[$i][] = $vb;
}
$j++;
}
}
$i++;
}
foreach ($prep_values as $value) {
$res = $prep->execute($value);
}
if (!empty($res)) {
return true;
} else {
throw new \Exception($res->getDebugInfo());
}
} else {
throw new \Exception($GLOBALS['tr']->trans('no_right') . ' setRelationSelect');
}
}
// }}}
// {{{ 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)
{
// où trouve t'on ce contact ?
if ($type == 'direct_relation') {
$relation_fields = array(array(
'table' => 'bookmark_extranetuser',
'where_object' => true,
), array(
'table' => 'comments',
'where_object' => true,
), array(
'table' => 'contact_classification',
), array(
'table' => 'contact_contactassocie',
), array(
'table' => 'contact_contactassocie',
'field' => 'idcontactassocie',
), array(
'table' => 'contact_extranetuser',
), array(
'table' => 'contact_person',
), array(
'table' => 'contact_extranetuser',
), array(
'table' => 'contents',
), array(
'table' => 'content_contact',
), array(
'table' => 'new_contact',
), array(
'table' => 'newschedules',
), array(
'table' => 'object_content',
'where_object' => true,
), array(
'table' => 'object_file',
'where_object' => true,
), array(
'table' => 'object_multimedia',
'where_object' => true,
), array(
'table' => 'schedules',
), array(
'table' => 'spectacles',
'field' => 'idcontact_creation',
), array(
'table' => 'spectacles',
'field' => 'idcontact_production',
), array(
'table' => 'spectacle_contact',
), array(
'table' => 'reflexions',
'field' => 'idcontact_signature',
), array(
'table' => 'faqgroups',
'where_object' => true,
), array(
'table' => 'quizgroups',
'where_object' => true,
), array(
'table' => 'stats',
'where_object' => true,
), array(
'table' => 'statscumul',
'where_object' => true,
), array(
'table' => 'texts',
'field' => 'idcontact_publisher',
), array(
'table' => 'texts',
'field' => 'idcontact_translation',
), array(
'table' => 'multimedias',
'field' => 'idcontact_producteur',
), array(
'table' => 'texts',
'field' => 'idcontact_performing',
), array(
'table' => 'user_action',
'where_object' => true,
)
);
return $relation_fields;
}
// récupérer les relations communes
$array_types = $this->getRelationsArrayTrait('all');
// quelques trucs spécifiques
if ($type == 'contact_festivals') {
$sql_idtypestructure = '=\'FT\'';
$type = 'contact_contactassocie';
} elseif ($type == 'contact_anciennestructure') {
$sql_idtypestructure = 'IS NULL';
$type = 'contact_contactassocie';
} else {
$sql_idtypestructure = null;
}
$array_types += array(
// contact_contactassocie idcontactassocie/idcontact/idstructure
'contact_contactassocie' => array(// contacts associés
'type_join' => 'multiple',
'dest_table' => 'contacts',
'join_table' => 'contact_contactassocie',
'join_field_src' => 'idcontactassocie',
'fields' => array('idcontact', 'organisation', 'lastname', 'firstname', 'type'),
'where' => ' AND j2.idtypestructure ' . $sql_idtypestructure, // j2 = alias dans Items_list::getItemListResult
'description' => 'Contact associé à d\'autre(s) contact(s)',
),
// contact_classification idcontact/idclassification
'contact_classification' => array(// classifications associées
'type_join' => 'multiple',
'dest_table' => 'classifications',
'join_table' => 'contact_classification',
'fields' => array('idclassification', 'classification', 'type'),
'description' => 'Classification(s) associée(s) à ce contact',
'silent_delete_relation' => true,
),
// content_contact idcontact/idcontact/idrole
'content_contact' => array(// contact associé à des contenus (journal, journaliste...)
'type_join' => 'multiple',
'dest_table' => 'contents',
'join_table' => 'content_contact',
'fields' => array('idcontent', 'title', 'text'),
'description' => 'Contenu(s) associé(s) au contact',
),
// contact_person idcontact/idperson/idrole
'contact_person' => array(// contact associé à des personnes (direction d'une structure...)
'type_join' => 'multiple',
'dest_table' => 'persons',
'join_table' => 'contact_person',
'fields' => array('idperson', 'lastname', 'firstname', 'url_clean'),
'fields_join_table' => array('idoffice', 'date_start', 'date_end'),
'description' => 'Personne(s) associée(s) au contact',
),
// contact_extranetuser idcontact/idextranetuser
'contact_extranetuser' => array(// contact associé à des utilisateurs (administrateur d'une fiche de structure...)
'type_join' => 'multiple',
'dest_table' => 'extranetusers',
'join_field_dest' => 'contact_idextranetuser',
'join_table' => 'contact_extranetuser',
'fields' => array('idextranetuser', 'login', 'firstname', 'lastname'),
'description' => 'Utilisateur(s) associée(s) au contact',
),
// contents publisher
'content_publisher' => array(// contact associé à un contenu comme producteur du contenu
'type_join' => 'multiple',
'dest_table' => 'contents',
'join_table' => 'content_publisher',
'fields' => array('idcontent', 'title', 'text'),
),
// contents idcontact_journalist
'content_idcontact_journalist' => array(// contact associé à un contenu comme journaliste
'type_join' => 'simple',
'dest_table' => 'contents',
'dest_table_field' => 'idcontact_journalist',
'fields' => array('idcontent', 'title', 'text'),
'description' => 'Contenu(s) associé(s) au contact comme journaliste',
),
// multimedias idcontact_journalist
'multimedia_idcontact_producteur' => array(// contact associé à un contenu comme journaliste
'type_join' => 'simple',
'dest_table' => 'multimedias',
'dest_table_field' => 'idcontact_producteur',
'fields' => array('idmultimedia', 'sujet_titre', 'url_clean'),
'description' => 'Mulimédia(s) associé(s) au contact comme producteur',
),
// contents idcontact_newspaper
'content_idcontact_newspaper' => array(// contact associé à un contenu comme journal
'type_join' => 'simple',
'dest_table' => 'contents',
'dest_table_field' => 'idcontact_newspaper',
'fields' => array('idcontent', 'title', 'text'),
'description' => 'Contenu(s) associé(s) au contact comme journal',
),
// reflexions idcontact_signature
'content_idcontact_signature' => array(// contact associé à une réfléxion
'type_join' => 'simple',
'dest_table' => 'reflexions',
'dest_table_field' => 'idcontact_signature',
'fields' => array('idreflexion', 'title', 'module'),
'description' => 'Contenu(s) associé(s) à une piste de réflexion comme signature',
),
// contact associé à un calendrier
'schedule_idcontact' => array(// contact associé à une réfléxion
'type_join' => 'simple',
'dest_table' => 'schedules',
'dest_table_field' => 'idcontact',
'fields' => array('idschedule', 'idspectacle', 'note'),
'description' => 'Contact(s) associé(s) à une date dans un calendrier',
'only_message' => true,
'silent_delete_relation' => true,
),
// spectacles idcontact_creation/idcontact_production
'spectacle_production' => array(// contacts associés à des spectacles
'type_join' => 'simple',
'dest_table' => 'spectacles',
'dest_table_field' => 'idcontact_production',
'fields' => array('idspectacle', 'title', 'url_clean'),
'description' => 'Spectacle(s) dont le contact est producteur',
),
// spectacles idcontact_creation/idcontact_production
'spectacle_creation' => array(// contacts associés à des spectacles
'type_join' => 'simple',
'dest_table' => 'spectacles',
'dest_table_field' => 'idcontact_creation',
'fields' => array('idspectacle', 'title', 'url_clean'),
'description' => 'Spectacle(s) dont le contact est le lieu de création',
),
// spectacle_contact idspectacle/idcontact/idrole
'spectacle_contact' => array(// contacts associés à des spectacles
'type_join' => 'multiple',
'dest_table' => 'spectacles',
'join_table' => 'spectacle_contact',
'fields' => array('idspectacle', 'title', 'url_clean'),
'description' => 'Spectacle(s) lié(s) à ce contact',
),
// texts idcontact_publisher/idcontact_translation/idcontact_performing
'text_idcontact_publisher' => array(// contacts associés à une fiche texte comme publisher
'type_join' => 'simple',
'dest_table' => 'texts',
'dest_table_field' => 'idcontact_publisher',
'fields' => array('idtext', 'title', 'url_clean'),
'description' => 'Texte(s) ou traduction(s) dont le contact est l\'éditeur',
),
// texts idcontact_publisher/idcontact_translation/idcontact_performing
'text_idcontact_translation' => array(// contacts associés à une fiche texte comme autorisation de traduction
'type_join' => 'simple',
'dest_table' => 'texts',
'dest_table_field' => 'idcontact_translation',
'fields' => array('idtext', 'title', 'url_clean'),
'description' => 'Texte(s) ou traduction(s) dont le contact est l\'autorisation de traduction',
),
// texts idcontact_publisher/idcontact_translation/idcontact_performing
'text_idcontact_performing' => array(// contacts associés à une fiche texte comme autorisation de représentation
'type_join' => 'simple',
'dest_table' => 'texts',
'dest_table_field' => 'idcontact_performing',
'fields' => array('idtext', 'title', 'url_clean'),
'description' => 'Texte(s) ou traduction(s) dont le contact est l\'autorisation de représentation',
),
// multimedias idmultimedia
'idmultimedia' => array(// video de tête
'type_join' => 'simple',
'dest_table' => 'multimedias',
'join_field_src' => 'idmultimedia',
'dest_table_field' => 'idmultimedia',
'fields' => array('idmultimedia', 'sujet_titre', 'url_clean'),
'description' => 'Contenu multimedias associé au contact',
),
);
// 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;
}
}
// }}}
// {{{ getContactSpectacles()
/** Trouve les spectacles associés à un contact
*
* @access public
* @param string|int $type si on souhaite retourner uniquement un type precis
* @see Theatre::getLinkedObject()
*/
public function getContactSpectacles($idcontact, $get_array = true)
{
// id du contact
$idcontact = (int)$idcontact;
/* trouver les spectacles dont le contact à pu être
- producteur / coprod / prod delegue
- compagnie / lieu de création
- lieu de représentation */
$sql = '
SELECT DISTINCT(spectacles.idspectacle) FROM spectacles
LEFT JOIN schedules ON schedules.idspectacle=spectacles.idspectacle
LEFT JOIN spectacle_contact ON spectacle_contact.idspectacle=spectacles.idspectacle
WHERE
schedules.idcontact=' . $idcontact . '
OR (spectacle_contact.idcontact=' . $idcontact . ' AND spectacle_contact.idrole IN (17,18,19))
OR spectacles.idcontact_production=' . $idcontact . '
OR spectacles.idcontact_creation=' . $idcontact;
// avec une jointure sur multimedias
$sql = '
SELECT DISTINCT(spectacles.idspectacle), object_multimedia.idmultimedia FROM spectacles
LEFT JOIN schedules ON schedules.idspectacle=spectacles.idspectacle
LEFT JOIN spectacle_contact ON spectacle_contact.idspectacle=spectacles.idspectacle
INNER JOIN object_multimedia ON spectacles.idspectacle=object_multimedia.idobject
WHERE
object_multimedia.object=\'spectacles\'
AND (
schedules.idcontact=' . $idcontact . '
OR (spectacle_contact.idcontact=' . $idcontact . ' AND spectacle_contact.idrole IN (17,18,19))
OR spectacles.idcontact_production=' . $idcontact . '
OR spectacles.idcontact_creation=' . $idcontact . '
)';
if ($this->isTraceMode('get_sql_object')) {
$this->setTraceInfos(array(
'sql_query' => $sql,
'dbg' => array('spectacles_contact_' . uniqid(), 'Spectacles associés à un contact'),
));
}
$list_spectacles = $this->queryAll($sql);
if (!empty($list_spectacles)) {
/*foreach($list_spectacles as $k=>$v) {
$list_spectacles_array[] = $v['idspectacle'];
}*/
if ($get_array) {
return $list_spectacles;
} else {
return join(',', $list_spectacles);
}
}
return false;
}
// }}}
// {{{ getInfosObject()
/** Alias de getInfosContact
*
* @access public
* @param int $idobject identifiant
* @return array
* @see getInfosContact()
*/
public function getInfosObject($idobject = null)
{
return $this->getInfosContact($idobject);
}
// }}}
// {{{ getAssociatePersons()
/** Personnes aossociées au contact
*
* @access public
* @param int $idcontact identifiant du contact
* @param int $idoffice role (exemple : direction)
* @param bool $actual_only uniquement les actuels (contrainte sur la date)
* @return array
*/
public function getAssociatePersons($idcontact, $idoffice = null, $actual_only = null)
{
// infos sur la liaison
$infos_link = $this->getRelationsArray('contact_person');
// select egalement l'idrole
if ($idoffice) {
$infos_link['where'] = ' AND j2.idoffice=' . $idoffice;
}
// qui n'a pas fini son mandat
if ($actual_only) {
$infos_link['where'] .= ' AND (j2.date_end IS NULL OR j2.date_end>=\'' . date('Y-m-d') . '\')';
}
// avec ou sans virgule avec le noPunct
if (!empty($infos_link)) {
return $this->noPunct($this->getLinkedObject($infos_link, $idcontact, $infos_link['type'], 'contacts'));
}
}
// }}}
// {{{ getSQLContacts()
/** Générer la requete standard pour des vidéos
*
*
* @access public
* @param array $query Les paramètres pour la requete
* @param bool $debug afficher la requête
* @return string
*/
public function getSQLContacts($query = array(), $debug = false)
{
// on prepare les tableaux
foreach (array('select', 'from', 'where', 'order', 'group', 'limit') as $t) {
if (!empty($query[$t])) {
if (!is_array($query[$t])) {
$query[$t][] = $query[$t];
} else {
$query[$t] = $query[$t];
}
} else {
$query[$t] = array();
}
}
// champs par défaut
$this->addSQLParams('select', $query, array(
array('contacts' => '*')
));
// publié ou pas
if (empty($query['publish']) && $_ENV['CHECK_IF_ONLINE']) {
$this->addSQLParams('where', $query, array(
array('contacts', 'publish', 1)
));
} elseif (!empty($query['publish'])) {
$this->addSQLParams('where', $query, array(
array('contacts', 'publish', $query['publish'])
));
}
// recherche par type de structure
if (!empty($query['idtypestructure'])) {
$this->addSQLParams('where', $query, array(
array('contacts', 'idtypestructure', $query['idtypestructure'], 'AND'),
));
}
// recherche par contacts
if (!empty($query['idcontact'])) {
$this->addSQLParams('where', $query, array(
array('contacts', 'idcontact', $query['idcontact'], 'AND'),
));
}
// recherche par classification
if (!empty($query['classification']) || !empty($query['idclassification'])) {
if (!empty($query['idclassification']['NOT'])) {
// TODO
} else {
$this->addSQLParams('from', $query, array(
'contact_classification',
'classifications',
));
// jointure entre les 3 tables
$this->addSQLParams('join', $query, array(
'contacts.`idcontact`' => 'contact_classification.`idcontact`',
'contact_classification.`idclassification`' => 'classifications.`idclassification`',
));
// recherche
if (!empty($query['classification']) && is_array($query['classification'])) {
if (!empty($query['classification']['NOT'])) {
$condition_classification = 'NOT IN';
$query['classification'] = $query['classification']['NOT'];
} else {
$condition_classification = 'IN';
}
$this->addSQLParams('where', $query, array(
array('classifications', 'classification', $query['classification'], 'AND', $condition_classification),
));
}
if (!empty($query['idclassification']) && is_array($query['idclassification'])) {
if (!empty($query['idclassification']['NOT'])) {
$condition_classification = 'NOT IN';
$query['idclassification'] = $query['idclassification']['NOT'];
} else {
$condition_classification = 'IN';
}
$this->addSQLParams('where', $query, array(
array('classifications', 'idclassification', $query['idclassification'], 'AND', $condition_classification),
));
}
}
}
return $this->getSQLObject($query);
}
// }}}
// {{{ getListContacts()
/** Retourne des listes de contacts
*
* Retourne des listes de contact au format "standard""
*
* @access public
* @param array $params_sql paramètre pour la requete SQL
* @param array $format de la vignette si pas standard
* @param bool $debug mode débugage
* @return array
*/
public function getListContacts($params_sql = array(), $format_vignette = array(), $params = array())
{
// tout dans params_sql
if (!empty($params_sql['special'])) {
foreach ($params_sql['special'] as $k => $v) {
if (empty($params_sql[$k])) {
$params_sql[$k] = $v;
}
}
}
// construction de la requête avec le passage de paramètres
$sql = $this->getSQLContacts($params_sql);
// paramètre de debug
$dbg = (empty($params_sql['dbg'])) ? array() : $dbg = $params_sql['dbg'];
// executer la requete
$datas = $this->queryAll($sql, $dbg);
$contacts = array();
// debug
$start_boucle = microtime(true);
// on boucle
foreach ($datas as $data) {
$idcontact = $data['idcontact'];
if (!empty($params_sql['fields'])) {
foreach ($params_sql['fields'] as $f) {
$contacts[$idcontact][$f] = $data[$f];
}
} else {
$contacts[$idcontact] = $this->getInfosContact($idcontact, $params);
}
}
// debug de la boucle
if ($this->isTraceMode('list_object')) {
$this->setTraceInfos(array(
'execution_time_boucle' => microtime(true) - $start_boucle,
'nb_occurence' => count($contacts),
'dbg' => $dbg,
));
}
$this->free();
return $contacts;
}
// }}}
// {{{ getVignetteContact()
/** Récupère la vignette d'un contact ou la cree si besoin
*
* @access public
* param int idcontact identifiant du contact
* param array format $format de la vignette
* @return string
*/
public function getVignetteContact($idcontact = null, $format = array(), $classification = 'class_pp')
{
// id du spectacle
if (empty($idcontact)) {
$idcontact = $this->idcontact;
}
$idcontact = (int)$idcontact;
// par default : image arrondie crop 100px x 100px qualite 75
if (!empty($format)) {
$set_format = $format;
} else {
if ($classification == 'class_pp') {
$set_format = array('width' => 100, 'height' => 100, 'direction' => 'crop');
} else {
$set_format = array('width' => 100, 'height' => 100, 'direction' => 'crop');
}
}
// generation par la classe Images
$this->images->setVignetteFormat($set_format);
return $this->images->getVignetteObject($idcontact, 'contacts', $classification, null, $this->publish_status);
}
// }}}
// {{{ getSpectaclesIn()
/** Récupérer les ids des spectacles dans le lieu
*
* @params int $idcontact Identifiant
* @return array
*/
public function getSpectaclesIn($idcontact, $count_only = false, $idclassification = null)
{
$params_sql = array(
'from' => 'schedules, spectacles ',
'where' => 'schedules.idspectacle=spectacles.idspectacle
AND spectacles.publish=1
AND (schedules.idcontact=' . $idcontact . ' OR schedules.idcontact_festival=' . $idcontact . ')',
);
return $this->getSpectaclesCommon($idcontact, $params_sql, $count_only, $idclassification);
}
// }}}
// {{{ getSpectaclesProd()
/** Récupérer les ids des spectacles coproduits par le lieu
*
* @params int $idcontact Identifiant
* @params bool $count_only Compter seulement
* @params int|array $idclassification Classification(s)
* @return array
*/
public function getSpectaclesProd($idcontact, $count_only = false, $idclassification = null, $roles = null)
{
$params_sql = array(
'from' => 'spectacles INNER JOIN spectacle_contact ON spectacle_contact.`idspectacle`=spectacles.`idspectacle` ',
);
if (is_array($idcontact)) {
$params_sql['where'] = ' spectacles.`publish`=1 AND (spectacle_contact.`idcontact` IN (' . implode(',', $idcontact) . ') OR spectacles.`idcontact_production` IN (' . implode(',', $idcontact) . '))';
} else {
$params_sql['where'] = ' spectacles.`publish`=1 AND (spectacle_contact.`idcontact`=' . $idcontact . ' OR spectacles.`idcontact_production`=' . $idcontact . ')';
}
if (!is_null($roles)) {
if (is_array($roles)) {
$params_sql['where'] .= ' AND spectacle_contact.`idrole` IN (' . implode(',', $roles) . ')';
} else {
$params_sql['where'] .= ' AND spectacle_contact.`idrole` = ' . $roles . '';
}
} else {
$params_sql['where'] .= ' AND spectacle_contact.`idrole` IN (17,18,19)';
}
return $this->getSpectaclesCommon($idcontact, $params_sql, $count_only, $idclassification);
}
// }}}
// {{{ getSpectaclesSoutien()
/** Récupérer les ids des spectacles avec le soutien de
*
* @params int $idclassification_soutien Type de classification
* @params int|array $idclassification Classification(s)
* @return array
*/
public function getSpectaclesSoutien($idclassification_soutien, $idclassification = null, $idcontact = null, $count_only = null)
{
// les spectacles avec le soutien du JTN
$params_sql = array(
'from' => ' spectacles INNER JOIN spectacle_classification ON spectacle_classification.idspectacle=spectacles.idspectacle',
'where' => ' spectacles.publish=1 AND spectacle_classification.idclassification=' . $idclassification_soutien,
);
return $this->getSpectaclesCommon($idcontact, $params_sql, $count_only, $idclassification);
}
// }}}
// {{{ getSpectaclesAide()
/** Récupérer les ids des spectacles avec une aide pour cette structure
*
* @params int $idclassification_soutien Type de classification
* @params int|array $idclassification Classification(s)
* @return array
*/
public function getSpectaclesAide($idcontact, $count_only = null, $type_aide = array())
{
// les spectacles avec une aide associée à ce contact
$sql_where = ' spectacles.`publish`=1 AND aides.`idcontact`=' . $idcontact;
// pour des types d'aide en particulier
if (!empty($type_aide)) {
$sql_where .= ' AND aides.type_aide IN (' . $this->arrayToIn($type_aide) . ') ';
}
$params_sql = array(
'from' => 'spectacles INNER JOIN spectacle_aide ON spectacle_aide.`idspectacle`=spectacles.`idspectacle`
INNER JOIN aides ON aides.`idaide`=spectacle_aide.`idaide` ',
'where' => $sql_where,
);
return $this->getSpectaclesCommon($idcontact, $params_sql, $count_only);
}
// }}}
// {{{ getSpectaclesPublisher()
/** Récupérer les ids des spectacles d'une maison d'édition
*
* @params int $idcontact Identifiant
* @params bool $count_only Compter seulement
* @params int|array $idclassification Classification(s)
* @return array
*/
public function getSpectaclesPublisher($idcontact, $count_only = false, $idclassification = null)
{
$params_sql = array(
'from' => 'spectacles
INNER JOIN text_spectacle ON text_spectacle.idspectacle=spectacles.idspectacle
INNER JOIN texts ON texts.idtext=text_spectacle.idtext',
'where' => 'spectacles.publish=1 AND texts.idcontact_publisher=' . $idcontact,
);
return $this->getSpectaclesCommon($idcontact, $params_sql, $count_only, $idclassification);
}
// }}}
// {{{ getSpectaclesCommon()
/** Récupérer les ids des spectacles
*
* @params int $idcontact Identifiant
* @params bool $count_only Compter seulement
* @params int|array $idclassification Classification(s)
* @return array
*/
public function getSpectaclesCommon($idcontact, $params_sql, $count_only = false, $idclassification = null)
{
// les spectacles coproduits ou lieu de crée ou compagnie
$sql_select = 'SELECT DISTINCT(spectacles.`idspectacle`) ';
if (!empty($count_only)) {
$sql_select = 'SELECT COUNT(DISTINCT(spectacles.`idspectacle`)) as total ';
}
$sql_from = ' FROM ' . $params_sql['from'];
$sql_where = ' WHERE ' . $params_sql['where'];
// uniquement s'ils ont une classification particulière
if (!empty($idclassification)) {
// caster pour avoir un array
if (!is_array($idclassification)) {
$idclassification = (array)$idclassification;
}
if (strpos($params_sql['from'], 'spectacle_contact') === false) {
$sql_from .= ' JOIN spectacle_contact ON spectacle_contact.`idspectacle`=spectacles.`idspectacle` ';
}
$sql_from .= ' JOIN object_content ON spectacle_contact.`idspectacle`=object_content.`idobject`
JOIN contents ON contents.`idcontent`=object_content.`idcontent`
JOIN content_classification ON contents.`idcontent`=content_classification.`idcontent` ';
// uniquement les contenus publiés
$sql_where .= '
AND contents.`publish`=1
AND contents.`valid`=1
AND object_content.`object`=\'spectacles\'
AND content_classification.`idclassification` IN (' . join(',', $idclassification) . ') ';
}
// construction de la requête
$sql = $sql_select . $sql_from . $sql_where;
if (!empty($count_only)) {
return $this->queryOne($sql);
}
$ids_spectacle = $this->queryCol($sql);
return $ids_spectacle;
}
// }}}
// {{{ countAllSpectacles()
/** compter tous les spectacles d'un contact
*
* @return array
*/
public function countAllSpectacles($idcontact, $idclassification = null)
{
return $this->getSpectaclesProd($idcontact, true, $idclassification) + $this->getSpectaclesIn($idcontact, true, $idclassification);
}
// }}}
// {{{ countContacts()
/** compter tous les contacts
*
* @return int
*/
public function countContacts()
{
return $this->queryOne('SELECT COUNT(DISTINCT(idcontact)) FROM contacts');
}
// }}}
// {{{ countSpectaclesIn()
/** compter le nombre de spectacle d'un contact pour une saison
*
* @return int
*/
public function countSpectaclesIn($idcontacts = array(), $special = array())
{
$param_sql = array(
'limit' => 'all',
);
$param_special = array(
'count_only' => true,
);
if (!empty($idcontacts)) {
if (!is_array($idcontacts)) {
$idcontacts = (array)$idcontacts;
}
$param_special['idcontacts'] = array('IN', $idcontacts);
}
if (array_key_exists('saison', $special)) {
$param_special['saison'] = $special['saison'];
}
if (!empty($special['idtypestructure'])) {
$param_special['idtypestructure'] = $special['idtypestructure'];
}
$query = $this->getEntityManager()->getRepository(Spectacles::class)->getSQLSpectacles($param_sql, $param_special);
return $query->getSingleResult(Query::HYDRATE_SCALAR)['total'];
}
// }}}
// {{{ getBoss()
/** Retrouver le directeur actuel
*
* @param int $idcontact Identifiant du contact
* @return int
*/
public function getCurrentBoss($idcontact, $multiple = false)
{
// trouver le directeur actuel de la structure
$boss = $this->getAssociatePersons($idcontact, 1, false);
foreach ($boss as $k => $v) {
$date_current = new Datetime(date('Y-m-d H:i:s'));
$date_current = $date_current->format('Y-m-d');
if ($v['date_start'] != '0000-00-00 00:00:00') {
$date_start = new Datetime($v['date_start']);
$date_start = $date_start->format('Y-m-d');
if ($date_start > $date_current) {
unset($boss[$k]);
}
}
if ($v['date_end'] != '0000-00-00 00:00:00') {
$date_end = new Datetime($v['date_end']);
$date_end = $date_end->format('Y-m-d');
if ($date_end < $date_current) {
unset($boss[$k]);
}
}
}
// un seul
if (!$multiple) {
foreach ($boss as $b) {
return $b;
}
} else {
return $boss;
}
}
// }}}
}