<?php
namespace TheatreCore\Repository;
use Doctrine\ORM\Query;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use TheatreCore\Classes\Date\DateTime;
use TheatreCore\Classes\Images\Images;
use TheatreCore\Entity\Bigregions;
use TheatreCore\Entity\Classifications;
use TheatreCore\Entity\Files;
use TheatreCore\Entity\ObjectFile;
use TheatreCore\Entity\Spectacles;
use TheatreCore\Entity\Typesfiles;
use TheatreCore\Traits\TheatreTrait;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
use Symfony\Contracts\Translation\TranslatorInterface;
use App\Service\Functions;
/**
* FilesRepository
*
* This class was generated by the Doctrine ORM. Add your own custom
* repository methods below.
*/
class FilesRepository extends ServiceEntityRepository
{
use TheatreTrait {
getItemsList as protected getItemsListTrait;
}
public const UMASK = 0002;
public const FILE_MODE = 0664;
public const DIR_MODE = 0775;
private $em;
public $__table;
public $__table_object;
public $__idtable;
private $bagInterface;
public function __construct(ManagerRegistry $registry, TranslatorInterface $tr, Images $images, Functions $func, ParameterBagInterface $bagInterface)
{
parent::__construct($registry, Files::class);
$this->__table = $this->getClassMetadata()->getTableName();
$this->__table_object = $this->getClassMetadata()->name;
$this->__idtable = $this->getClassMetadata()->getSingleIdentifierFieldName();
$this->bagInterface = $bagInterface;
$this->translator = $tr;
$this->images = $images;
$this->func = $func;
}
// {{{ findData()
/** Recherche des fichiers
*
* Permet de rechercher des fichiers en fonction de certains critères :
* la première lettre, un bout du nom, le type de multimedia, si il est en ligne ou pas
*
* @access public
* @see Theatre::find()
*/
public function findData($publish = null, $keywords = null, $idobject = null, $object = null)
{
$con = $this->getEntityManager();
$query = $con->getRepository(Files::class)->createQueryBuilder('e');
$query->join('e.idclassification', 'cl');
$query->select('e');
// $query = '
// SELECT DISTINCT(f.idfile),f.*,tf.*
// FROM files f
// JOIN object_file of ON of.`idfile`=f.`idfile`
// JOIN file_classification fc ON f.`idfile`=fc.`idfile`
// JOIN classifications cl ON cl.`idclassification`=fc.`idclassification`
// JOIN typesfiles tf ON tf.`idtype`=f.`idtype`
// WHERE 1 ';
// parametre
if (isset($_REQUEST['idbooklet']) && !empty($_REQUEST['idbooklet'])) {
$idbooklet = $_REQUEST['idbooklet'];
}
if (isset($_REQUEST['idtypestructure']) && !empty($_REQUEST['idtypestructure']) && strlen($_REQUEST['idtypestructure']) < 5) {
$idtypestructure = $_REQUEST['idtypestructure'];
}
if (isset($_REQUEST['idclassification']) && !empty($_REQUEST['idclassification']) && my_is_int($_REQUEST['idclassification'])) {
$idclassification = $_REQUEST['idclassification'];
}
if (isset($_REQUEST['saison']) && !empty($_REQUEST['saison']) && strlen($_REQUEST['saison']) == 9) {
$saison = explode('-', $_REQUEST['saison']);
$date_start = $saison[0] . '-09-01';
$date_end = $saison[1] . '-08-31';
}
if (isset($_REQUEST['keywords']) && $_REQUEST['keywords'] != 'nom' && !empty($_REQUEST['keywords'])) {
$keywords = $_REQUEST['keywords'];
}
if (isset($_REQUEST['publish']) && !empty($_REQUEST['publish'])) {
$publish = $_REQUEST['publish'];
}
if (isset($_REQUEST['valid']) && !empty($_REQUEST['valid'])) {
$valid = $_REQUEST['valid'];
}
//recherche stricte par id
if (!empty($idfile)) {
// $query .= 'AND f.`idfile`='.(int)$idbooklet;
$query->andWhere('f.`idfile`=' . (int)$idbooklet);
}
//
// // mots cles
if (!empty($keywords)) {
// $query .= ' AND f.`title` LIKE \'%'.$this->escape($keywords).'%\'';
$query->andWhere(' f.`title` LIKE \'%' . $this->escape($keywords) . '%\'');
}
//
// // saison
if (!empty($date_start) && !empty($date_end)) {
// $query .= ' AND f.`date_start`=\''.$date_start.'\' AND f.`date_end`=\''.$date_end.'\' ';
$query->andWhere(' f.`datestart`=\'' . $date_start . '\' AND f.`dateend`=\'' . $date_end . '\' ');
}
// saison
if (!empty($idclassification)) {
// $query .= ' AND fc.`idclassification`='.$idclassification.' ';
$query->andWhere(' fc.`idclassification`=' . $idclassification . ' ');
}
// selectionne les fiches hors ligne
if (!empty($publish) && $publish == 'no') {
// $query .= ' AND f.`publish`=0';
$query->andWhere(' f.`publish`=0');
}
// selectionne les fiches non validé
if (!empty($valid) && $valid == 'no') {
// $query .= ' AND f.`valid`=0';
$query->andWhere('f.`valid`=0');
}
// selectionne les fiches non validé proposé avec une classification publique
if (isset($_REQUEST['to_publish'])) {
// $query .= ' AND f.`publish`=0 AND cl.`is_public`=1';
$query->andWhere('e.publish=0 AND cl.isPublic=1');
}
if (isset($_REQUEST['to_valid'])) {
// $query .= ' AND f.`valid`=0 AND cl.`is_public`=1';
$query->andWhere('e.valid=0 AND cl.isPublic=1');
}
if ($this->getCount()) {
$query->select('COUNT(e.idfile)');
$this->setCount(false);
return $query;
}
// on lance la recherche
$this->specialQuery($query);
}
// }}}
// {{{ setToArray()
/** Liste des multimedias dans un tableau associatif
*
* Tableau associatif notament utilisé pour lister les informations sur les multimedias
* Utile pour générer les tableaux HTML de listes de multimedias
*
* @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()) {
// valeurs de l'enregistrement
$values[$nb] = $this->getInfosFile($this->idfile);
// couleur de ligne alternative
$color = $this->colorAlternate($color);
$values[$nb]['colorline'] = $color;
$values[$nb]['id'] = $this->idfile;
$nb++;
}
return $values;
}
// }}}
// {{{ 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 = 'dateinsert';
}
return $order;
}
// }}}
// {{{ getInfosFile()
/** Infos sur un fichier
*
* @access public
* @param int $idfile id de l'objet
* @return array
*/
public function getInfosFile($idfile = null, $params_data = array(), $params_display = array())
{
$infos = array();
////////////// infos de la table
if (!isset($this->idfile) || empty($this->idfile)) {
if (!empty($idfile)) {
$sql = 'SELECT f.*, tf.titre, tf.extension, tf.mime_type, tf.inclus
FROM ' . $this->__table . ' f, typesfiles tf
WHERE f.idtype=tf.idtype AND f.idfile=' . (int)$idfile;
$infos = $this->queryRow($sql);
if (empty($infos)) {
return array();
}
}
} else if (!empty($this->datas[$this->currentRow])) {
$infos = $this->datas[$this->currentRow];
} else {
$idfile = $this->idfile;
$infos = $this->objToArray();
$query = $this->createQueryBuilder('e')
->leftJoin('e.idtype', 'it')
->select('e')
->addSelect('partial it.{idtype,extension}')
->andWhere('e.idfile = :file')->setParameter(':file', $this->idfile)
->getQuery();
$infos = $query->getResult();
$infos = $query->getSingleResult(Query::HYDRATE_ARRAY);
}
// selectionne aussi la/les classification(s)
$classifications_list = $this->getClassifications($idfile);
if (!empty($classifications_list)) {
$infos['classifications'] = $classifications_list;
}
// ajouter le chemin complet
if (!empty($infos)) {
if (!empty($infos['idtype']['extension'])) {
$extension = $infos['idtype']['extension'];
} else {
$extension = $infos['extension'];
}
$infos['filepath'] = $_ENV['URL_DIRECTORYUPLOAD'] . strtolower($extension) . '/' . $infos['file'];
}
// générer la vignette PDF
if (!empty($infos['idfile'])) {
$images = $this->images;
if (!empty($infos['idtype']['extension'])) {
$extension = $infos['idtype']['extension'];
} else {
$extension = $infos['extension'];
}
$infos['vignette'] = $_ENV['URL_DIRECTORYUPLOAD'] . $extension . '/' . $images->pdf2thumbnail($infos['file'], $_ENV['PATH_DIRECTORYUPLOAD'] . $extension . '/');
$infos['pdf'] = $_ENV['URL_DIRECTORYUPLOAD'] . $extension . '/' . $infos['file'];
}
// le nom de la structure
if (!empty($infos['organisation'])) {
$infos['contacts']['organisation'] = $infos['organisation'];
$infos['nameview'] = $infos['organisation'] . ' / ' . $infos['title'];
}
// suite
foreach (array('url_clean', 'nom_suite', 'city') as $f) {
if (!empty($infos[$f])) {
$infos['contacts'][$f] = $infos[$f];
}
}
// valid ?
if (!empty($infos['valid']) && $infos['valid'] == 1) {
$infos['valid'] = true;
}
// la saison
if (!empty($infos['date_start']) && !empty($infos['date_end'])) {
$infos['dateStart'] = new \DateTime($infos['date_start']);
$infos['dateEnd'] = new \DateTime($infos['date_end']);
}
if (!empty($infos['dateStart']) && !empty($infos['dateEnd'])) {
$date_start_array = $infos['dateStart']->format('Y');
$date_end_array = $infos['dateEnd']->format('Y');
// $date_start_array = explode('-', $infos['dateStart']);
// $date_end_array = explode('-', $infos['dateEnd']);
$infos['saison'] = $date_start_array . '-' . $date_end_array;
// saison en cours ?
if ($infos['saison'] == DateTime::getLastSaison()) {
$infos['current_saison'] = true;
}
}
//retourner le contenu
return $infos;
}
// }}}
// {{{ uploadObjectFile()
/** Copier en upload et dans la base de données un fichier
*
*
* @access public
* @param string $file objet $_FILES[]
* @param string|array $file_classification le nom/classification du fichier à copier sans extension (ex : biofile)
* @param string $objet le type d'objet à insérer (personnes, spectacles...)
* @param string $idobject id de l'utilisateur pour le nom de son répertoire
* @param array $filedata toutes les données associées au fichier : titre, description...
* @param string $idfile (id du fichier à modifier si on est en mode modification)
* @param object $finfo instance d'un objet FileInfo (optionnel)
* @return int|bool false si erreur, id du fichier si ok
*/
public function uploadObjectFile($file, $file_classification, $object, $idobject, $filedata, $idfile = null, $finfo = null, $extra = array())
{
$conn = $this->getEntityManager();
if ($this->my_is_int($file_classification)) {
$file_classification = array($file_classification);
}
if (empty($file_classification)) return false;
// champs en option
$fields = array(
'title',
'idextranetuser',
'range',
'description',
'copyright',
'language',
'idcontent',
'idfile_original',
'watermark',
'date_start',
'date_end',
'publishing_date',
'is_editable',
'publish',
'valid'
);
$date = new \DateTime();
// pour la saison
if (!empty($filedata['saison'])) {
// transformer la saison en date_start / date_end
$saison_array = explode('-', $filedata['saison']);
// $filedata['date_start'] = $saison_array[0].'-09-01';
// $filedata['date_end'] = $saison_array[1].'-08-31';
}
if (!empty($filedata['publishing_date']) && !$filedata['publishing_date'] instanceof \DateTime && strpos('/', $filedata['publishing_date']) !== false) {
$publishing_date = explode('/', $filedata['publishing_date']);
$filedata['publishing_date'] = $date->setDate($publishing_date[2], $publishing_date[1], $publishing_date[0]);
}
//répertoire des fichiers (répertoire d'upload)
$directoryupload = $_ENV['PATH_DIRECTORYUPLOAD'];
//objet dans la table OBJECT_FILE
$obj_objectfile = $conn->getRepository(ObjectFile::class);
//on a chargé un nouveau fichier que ce soit en modification ou en insertion
if (is_array($file)
|| (is_object($file) && $file->isSubmitted() && !empty($file->getData()))) {
static $list_types_mime = null;
if (is_null($list_types_mime)) {
// récupére les infos id,mime,extension
$sql_mime = 'SELECT mime_type,idtype,extension FROM typesfiles WHERE upload=\'oui\'';
$list_types_mime = $this->queryAll($sql_mime, array(), null, true);
if (empty($list_types_mime)) {
throw new \Exception('chargement impossible des Types Mimes autorisés');
}
}
// voir si c'est un fichier uploade ou juste un fichier sur le serveur
if (is_object($file) && $file->isSubmitted()) {
//récupérer le type mime du fichier uploadé
$typemime = $file->getData();
//$typemime = $typemime['type'];
$typemime = $this->func->finfo_file_simple($finfo, $typemime->getPathName());
$is_objectfile = true;
} else {
// recuperer le type mime du fichier sur le serveur
$typemime = $this->func->finfo_file_simple($finfo, $file['file']);
$is_simplefile = true;
}
$inListTypeMime = false;
$inListTypeMimeInfo = [];
foreach($list_types_mime as $key => $element) {
if(in_array($typemime, $element)) {
$inListTypeMime = true;
$inListTypeMimeInfo = $element;
break;
}
}
// récupére l'id du type MIME et l'extension qui correspondent
if ($inListTypeMime == true) {
$idtypefile = $inListTypeMimeInfo['idtype'];
$extension = $inListTypeMimeInfo['extension'];
} else {
return false;
}
// chgt umask
$oldumask = umask();
if (self::UMASK) {
umask(self::UMASK);
}
//répertoire des données (repertoire d'upload + extension)
$directoryupload .= $extension;
// vérifier si le dossier existe, sinon le créer
if (!file_exists($directoryupload)) {
mkdir($directoryupload, self::DIR_MODE, true);
}
//// uploader le fichier ou le copier
// nom unique et chemin du nouveau fichier
do {
$nomfichier = uniqid('f-' . substr(md5($object . $idobject), 0, 3) . '-') . '.' . $extension;
$newfile = $directoryupload . '/' . $nomfichier;
} while (file_exists($newfile));
if (isset($is_objectfile)) {
$file = $file->getData();
$uploadok = $file->move($directoryupload, $nomfichier);
} else {
$uploadok = copy($file['file'], $newfile);
}
//mettre les bons droits (lecture) pour ce fichier
if ($uploadok) {
chmod($newfile, self::FILE_MODE);
}
//erreur lors de l'upload du fichier
if (empty($uploadok)) {
throw new \Exception('erreur lors de la mise-en-ligne du fichier');
}
// champ ImageDescription ?
/*$exif = exif_read_data($newfile);
print_r($exif);
exit;*/
// on souhaite un copyright ?
$extension_img = array('jpg', 'png', 'gif');
if (!empty($filedata['watermark']) && !empty($filedata['copyright']) && in_array($extension, $extension_img)) {
$images = $this->images;
$images->setWatermark($newfile, null, array('text' => $filedata['copyright']));
}
// supprimer l'ancien fichier et la relation en enlevant le fichier en dur dans le cas d'une modification !
if (!empty($idfile)) {
$this->deleteFile($idfile, $object, $idobject, true);
}
// commencer la transaction
$error = null;
$conn->beginTransaction();
$new_file = new Files();
//mise en forme des données
$idType = $conn->getRepository(Typesfiles::class)->find($idtypefile);
$new_file->setIdtype($idType);
$new_file->setFile($nomfichier);
$new_file->setDateStart(new \DateTime('now'));
// test les champs
foreach ($fields as $f) {
if (!empty($filedata[$f])) {
$field = implode('', array_map(function ($m) {
return ucfirst($m);
}, explode('_', $f)));
$new_file->{'set' . ucfirst($field)}($filedata[$f]);
}
}
$conn->persist($new_file);
$conn->flush();
$conn->commit();
$idfileinsere = $new_file->getIdfile();
//on insère un nouveau document dans la table file que ce soit une modif ou un insert !
try {
$idfileinsere = $new_file->getIdfile();
} catch (\Exception $e) {
$error = $e->getError();
if ($this->in_transaction) {
$this->rollback();
}
}
// ajout des classifications
if (empty($error)) {
try {
$this->setRelationSelect('file_classification', 'idclassification', 'idfile', $file_classification, $idfileinsere);
} catch (\Exception $e) {
$error = $e->getError();
if ($this->in_transaction) { // annuler la transaction
$this->rollback();
}
}
}
if (empty($error)) {
//mise en forme des données
$conn->beginTransaction();
$objectFile = new ObjectFile();
$objectFile->setIdobject($idobject);
$objectFile->setObject($object);
$objectFile->setIdfile($new_file);
// on ajoute la liaison avec l'objet
try {
$conn->persist($objectFile);
$conn->flush();
} catch (\Exception $e) {
$error = $e->getError();
if ($this->in_transaction) {
$this->rollback();
}
}
if (empty($error)) {
// if ($this->in_transaction) {
$conn->commit();
// }
}
}
if (empty($error)) {
// est-ce qu'on a des liaisons en plus ?
if (!empty($extra['more_linked_object'])) {
foreach ($extra['more_linked_object'] as $k => $v) {
//mise en forme des données
$values = array(
'idobject' => $k,
'object' => $v,
'idfile' => $idfileinsere
);
// champ a mettre a jour
$obj_objectfile->setUpdateFields($values);
// on ajoute la liaison avec l'objet
try {
$idobjectfile = $obj_objectfile->setData(null, true);
} catch (\Exception $e) {
$error = $e->getError();
if ($this->in_transaction) {
$this->rollback();
}
}
if (empty($error)) {
if ($this->in_transaction) {
$this->commit();
}
}
}
}
}
if (!empty($error)) {
// en cas d'erreur lors de l'insertion en bdd, on supprime le fichier uploadé
@unlink($newfile);
}
// restauration umask
umask($oldumask);
} else { //on a pas chargé de nouveau fichier, on fait juste une modification des datas
//si on a un $idfile c'est que l'on est en modification
if (!empty($idfile)) {
// il faut récupérer les infos de l'ancien fichier
$taboldfile = $this->queryRow('SELECT * FROM files WHERE files.idfile=' . (int)$idfile);
// commencer la transaction
$error = null;
// tableau pour insertion dans la table files
$values = array(
'idtype' => $taboldfile['idtype'],
'file' => $taboldfile['file'],
'dateupdate' => $this->func->now()
);
// test les champs
foreach ($fields as $f) {
if (!empty($filedata[$f])) {
$values[$f] = $filedata[$f];
}
}
if (!empty($values['idextranetuser'])) {
$values['idextranetuser'] = $values['idextranetuser']->getIdextranetuser();
}
if (!empty($values['date_start'])) {
$values['date_start'] = $values['date_start']->format('Y-m-d');
}
if (!empty($values['date_end'])) {
$values['date_end'] = $values['date_end']->format('Y-m-d');
}
if (!empty($values['publishing_date'])) {
$values['publishing_date'] = $values['publishing_date']->format('Y-m-d');
}
// publie ou pas
if (!empty($filedata['publish'])) {
$values['publish'] = $filedata['publish'];
} else {
$values['publish'] = 0;
}
// validé ou pas
if (!empty($filedata['valid'])) {
$values['valid'] = $filedata['valid'];
} else {
$values['valid'] = 0;
}
// champ a mettre a jour
$this->setUpdateFields($values);
// on update
try {
$res = $this->setData($idfile, true);
} catch (\Exception $e) {
$error = $e->getError();
// if ($this->in_transaction) {
// $this->rollback();
// }
}
// ajout des classifications
if (empty($error)) {
try {
$this->setRelationSelect('file_classification', 'idclassification', 'idfile', $file_classification, $idfile);
} catch (\Exception $e) {
$error = $e->getError();
// if($this->in_transaction) { // annuler la transaction
// $this->rollback();
// }
}
}
if (empty($error)) {
// if ($this->in_transaction) {
// $this->commit();
// }
}
// est-ce qu'on a des liaisons en plus ?
if (!empty($extra['more_linked_object'])) {
// supprimer les anciens et ajouter les nouveaux
$sql = 'DELETE
FROM object_file
WHERE idfile=' . $idfile . '
AND idobject!=' . $idobject . '
AND object!=\'' . $object . '\' ';
$this->exec($sql);
foreach ($extra['more_linked_object'] as $k => $v) {
//mise en forme des données
$values = array(
'idobject' => $k,
'object' => $v,
'idfile' => $idfile
);
// champ a mettre a jour
$obj_objectfile->setUpdateFields($values);
// on ajoute la liaison avec l'objet
try {
$idobjectfile = $obj_objectfile->setData(null, true);
} catch (\Exception $e) {
$error = $e->getError();
if ($this->in_transaction) {
$this->rollback();
}
}
if (empty($error)) {
if ($this->in_transaction) {
$this->commit();
}
}
}
}
$idfileinsere = $idfile;
}
}
// retourner l'idobject du fichier créé dans la table file
return $idfileinsere;
}
// }}}
// {{{ isUseObjectFile()
/** Vérifier si un fichier est utilisé par un autre contenu
*
*
* @access public
* @param int $idfile id du fichier à vérifier
* @return bool
*/
public function isUseObjectFile($idfile)
{
// on compte le nb d'utilisation
$total = $this->queryOne('SELECT COUNT(DISTINCT(idobject)) AS total FROM object_file WHERE object_file.idfile=' . $idfile);
//on a au moins 2 enregistrements liés
if ($total > 1) {
return true;
}
return false;
}
// }}}
// {{{ deleteFile()
/** Supprimer un fichier sur le serveur
*
*
* @access public
* @param string $id id du fichier à supprimer
* @param string $object type de fichier à supprimer (ex : persons, contacts...)
* @param string $idobject id de la personne qui possède le fichier
*/
public function deleteFile($id, $object, $idobject, $delfile)
{
//repertoire de l'utilisateur (répertoire d'upload + object + id personne)
$directoryupload = $_ENV['PATH_DIRECTORYUPLOAD'];
//le fichier n'est pas utilisé, on peut le supprimer
if (!$this->isUseObjectFile($id)) {
//récupérer les infos du fichier
// $this->selectAdd();
// $this->selectAdd('idtype,file');
$data = $this->find($id);
$type = $data->getIdtype()->getExtension();
//répertoire
if (is_object($type)) {
$filedelete = $directoryupload . $type->extension . '/' . $data->getFile();
} else {
$filedelete = null;
}
//supprimer le fichier sur le disque
if (file_exists($filedelete) && $delfile) {
// supprimer le fichier principal
@unlink($filedelete);
// supprimer aussi les vignettes
$this->deleteVignettes($id, $object, $idobject);
}
//supprimer l'enregistrement en lui même (table file)
$this->deleteData($id);
}
//dans touts les cas, supprimer l'enregistrement dans la relation object_file
$this->deleteDataRelation('object_file', 'idfile', $id, 'idobject', $idobject, 'object', $object);
}
// }}}
// {{{ deleteSimpleFile()
/** Supprimer un fichier simple sur le serveur
*
*
* @access public
* @param string $id id du fichier à supprimer
*/
public function deleteSimpleFile($idfile)
{
//repertoire de l'utilisateur (répertoire d'upload + object + id personne)
$directoryupload = PATH_DIRECTORYUPLOAD;
$infos = $this->getInfosFile($idfile);
//répertoire
$filedelete = $directoryupload . $infos['extension'] . '/' . $infos['file'];
// si c'est un pdf,
if ($infos['extension'] == 'pdf') {
$files = glob($filedelete . '-*.jpg');
if (!empty($files) && is_array($files)) {
foreach ($files as $f) {
@unlink($f);
}
}
}
//supprimer le fichier sur le disque
if (file_exists($filedelete)) {
// supprimer le fichier principal
@unlink($filedelete);
// supprimer aussi les vignettes
$this->deleteVignettes($idfile);
//supprimer l'enregistrement en lui même (table file)
$this->deleteData($idfile);
}
return true;
}
// }}}
// {{{ countObjectFiles()
/** Compter les fichiers lies a un objet
*
*
* @access public
* @param string $idobject id de l'objet lié
* @param string $object le type d'objet (personnes, spectacles...)
* @param string|int|array $idclassification le rechercher par type de classification
* @return array
* @see Theatre_Classifications::getAssociate())
*/
public function countObjectFiles($idobject, $object = 'contents', $idclassification = null, $extra = array())
{
$extra['count_only'] = true;
return $this->getObjectFiles($idobject, $object, $idclassification, $extra);
}
// }}}
// {{{ getObjectFiles()
/** Retourner les fichiers lies a un objet
*
*
* @access public
* @param string $idobject id de l'objet lié
* @param string $object le type d'objet (personnes, spectacles...)
* @param string|int|array $idclassification le rechercher par type de classification
* @return array
* @see Theatre_Classifications::getAssociate())
*/
public function getObjectFiles($idobject, $object = 'contents', $idclassification = null, $extra = array())
{
if (isset($extra['count_only']) && $extra['count_only']) {
$fields = array();
} else {
$fields = '*';
}
$extra['mode'] = 'file';
if (!empty($classification) && ($classification == 21 || $classification == 'class_affiche_spec')) {
// une seule affiche par spectacle !
$extra['limit'] = '1';
}
$classifications = $this->getEntityManager()->getRepository(Classifications::class);
$classifications->setPublishStatus($this->publish_status);
$tabfile = $classifications->getAssociate($idobject, $object, $idclassification, $fields, $extra);
if (!empty($extra['count_only'])) {
return $tabfile;
}
//retourner les données du fichier sous forme de tableau
if (!empty($tabfile)) {
$images = $this->images;
$new_tabfile = array();
$images_extensions = array('jpg', 'png', 'gif');
foreach ($tabfile as $k => $v) {
if (empty($v['idfile'])) {
dump('revoir cette ligne là 938');
break;
}
$idfile = $v['idfile'];
// grouper par idfile
foreach ($new_tabfile as $kf => $f) {
if ($f['idfile'] == $idfile) {
$new_tabfile[$kf]['classification_array'] = array(
$new_tabfile[$kf]['classification'],
$classifications->getObjectTitle($v['idclassification']),
);
$stop = true;
}
}
if (!empty($stop)) {
break;
}
$new_tabfile[$k] = $v;
$new_tabfile[$k]['classification'] = $classifications->getObjectTitle($v['idclassification']);
$new_tabfile[$k]['logo'] = strtolower($v['extension']) . '.png';
$new_tabfile[$k]['publishing_date'] = $v['publishing_date'];
if (!empty($v['date_start']) && $v['date_start'] != '0000-00-00 00:00:00' && !empty($v['date_end']) && $v['date_end'] != '0000-00-00 00:00:00') {
$date_start_array = explode('-', $v['date_start']);
$date_end_array = explode('-', $v['date_end']);
$new_tabfile[$k]['saison'] = $date_start_array[0] . '-' . $date_end_array[0];
// saison en cours ?
if ($new_tabfile[$k]['saison'] == DateTime::getLastSaison()) {
$new_tabfile[$k]['current_saison'] = true;
}
}
if (!empty($v['publishing_date']) && $v['publishing_date'] != '0000-00-00') {
$new_tabfile[$k]['publishing_date_str'] = $this->getFormeDate($v['publishing_date'], '%d/%m/%Y', true);
$new_tabfile[$k]['publishing_date_str_full'] = $this->getFormeDate($v['publishing_date'], '%d %B %Y', true);
}
$new_tabfile[$k]['dateinsert_str'] = $this->getFormeDate($v['dateinsert'], '%d/%m/%Y', true);
$new_tabfile[$k]['dateinsert_str_full'] = $this->getFormeDate($v['dateinsert'], '%d %B %Y', true);
// on veut également savoir si ce doc est associé à d'autres choses (par exemple : spectacles)
if (!empty($extra['get_objects'])) {
$new_tabfile[$k]['objects'] = $this->getObjects($v['idfile'], array('idobject' => $idobject));
}
if (!empty($extra['get_others'])) {
$sql = 'SELECT *
FROM object_file
WHERE idfile=' . $v['idfile'] . '
AND idobject!=' . $idobject;
$others = $this->queryAll($sql);
if (!empty($others)) {
$others_tab = array();
foreach ($others as $other) {
if ($other['object'] != $object) {
$others_tab[$other['object']][$other['idobject']] = $other['idobject'];
}
}
}
if (!empty($others_tab['spectacles'])) {
$params_sql_spectacle = array(
'special' => array(
'idspectacle' => $others_tab['spectacles'],
'publish' => 'all',
'join' => true, // jointure gauche avec schedules
'plus_proche' => true,
),
'params' => array(
'order' => 's.dateinsert DESC',
'limit' => array(0, 100),
'where' => ' AND statut!=4',
),
'dbg' => array('spectacles_list', 'Liste des spectacles'),
);
// affichage
$params_display = array(
'stylemore' => array('imagep' => 'width:65px', 'descsp' => 'width:310px;'),
);
$new_tabfile[$k]['others'][$other['object']] = $this->getEntityManager()->getRepository(Spectacles::class)->getListSpectacles($params_sql_spectacle, $params_display);
}
}
// si c'est une image, on le precise
if (in_array($v['extension'], $images_extensions)) {
$new_tabfile[$k]['is_image'] = true;
}
// idem pour du son
if ($v['extension'] == 'mp3') {
$new_tabfile[$k]['is_sound'] = true;
}
if ($v['extension'] == 'pdf') {
if (empty($extra['vignette_width'])) {
$extra['vignette_width'] = 120;
}
$new_tabfile[$k]['vignette'] = $_ENV['URL_DIRECTORYUPLOAD'] . $v['extension'] . '/' . $images->pdf2thumbnail($v['file'], $_ENV['PATH_DIRECTORYUPLOAD'] . $v['extension'] . '/', $extra['vignette_width']);
}
if (!empty($v['language'])) {
$new_tabfile[$k]['language_str'] = $this->translator->trans($v['language']);
}
$new_tabfile[$k]['url_file_path'] = $_ENV['URL_DIRECTORYUPLOAD'] . $v['extension'] . '/' . $v['file'];
}
// un seul fichier
if (!empty($extra['idfile']) && !empty($new_tabfile)) {
foreach ($new_tabfile as $f) {
return $f;
}
}
return $new_tabfile;
}
return null;
}
// }}}
// {{{ deleteVignettes()
/** Supprimer les vignettes
*
* Supprimer toutes les vignettes d'un fichier
*
* @access public
* @param string $id id du fichier
* @param string $objet le type d'objet (personnes, spectacles...)
*/
public function deleteVignettes($idfile, $object = 'spectacles', $idobject = null, $filedata = array(), $thumbsdir = 'thumbs')
{
$debug = false;
if ($debug) file_put_contents('/tmp/files.txt', "idfile=$idfile object=$object idobject=$idobject\n", FILE_APPEND);
// retrouver les infos sur le fichier
if (empty($filedata) && !empty($idfile)) {
$filedata = $this->objToArray($this->get($idfile));
}
// parcourir les dossiers thumb et supprimer les vignettes
$thumbsdir = $_ENV['PATH_DIRECTORYUPLOAD'] . $thumbsdir . '/';
if (!empty($filedata['file'])
&& strpos($filedata['file'], '?') === false
&& strpos($filedata['file'], '*') === false
&& is_dir($thumbsdir)) {
if ($debug) file_put_contents('/tmp/files.txt', "thumbdir=$thumbsdir\n", FILE_APPEND);
$list = $this->func->rglob($filedata['file'], GLOB_NOSORT, $thumbsdir, 'f');
if ($debug) file_put_contents('/tmp/files.txt', print_r($list, true), FILE_APPEND);
foreach ($list as $thumb) {
@unlink($thumb);
}
}
$idobject = (int)$idobject;
if ($idobject > 0 && preg_match('/^[a-z0-9_-]+$/', $object)) {
// repertoire des vignettes
$vignettes_dir = $_ENV['PATH_DIRECTORYUPLOAD'] . $object . '/';
if (is_dir($vignettes_dir)) {
if ($debug) file_put_contents('/tmp/files.txt', "dir=$vignettes_dir\n", FILE_APPEND);
$list = $this->func->rglob('*-' . $idobject . '.jpg', GLOB_NOSORT, $vignettes_dir, 'f');
if ($debug) file_put_contents('/tmp/files.txt', print_r($list, true), FILE_APPEND);
foreach ($list as $vignette) {
@unlink($vignette);
}
}
}
return true;
}
// }}}
// {{{ deleteVignettesObject()
/** Supprime les vignettes d'un objet
*
* @access public
* @param string $object le type d'objet (personnes, spectacles...)
* @param int $idobject Identifiant de l'enregistrement
* @param string $classification la classification à supprimer
* @return bool
*/
public function deleteVignettesObject($object, $idobject, $classification)
{
// trouver l'idfile associé
$filedata = $this->getAssociateFile($idobject, $object, $classification);
return $this->deleteVignettes($filedata, $object, $idobject, $filedata);
}
// }}}
// {{{ getObjectTitle()
/** Infos de l'item recherché classification et titre
*
* @access public
* @param int $code Identifiant de l'enregistrement
* @return string
*/
public function getObjectTitle($code)
{
$sql = 'SELECT f.title,cl.classification
FROM files f, classifications cl, file_classification fc
WHERE f.idfile=' . (int)$code;
//recuperer la ligne
$data = $this->queryRow($sql);
if (empty($data)) {
return null;
}
return $data['title'] . ' ' . $this->translator->trans($data['classification']);
}
// }}}
// {{{ getAssociateFile()
/** Recuperer un fichier associé à un objet
*
* @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 array $params_content options supplémentaires (tag=>nom du tag, check_lng=>true|false)
* @return array
* @see Theatre_Classifications::getAssociate())
*/
public function getAssociateFile($idobject, $object, $classification, $params_content = array())
{
$fields = '*';
$extra = array(
'row' => true,
'mode' => 'file',
);
$conn = $this->getEntityManager();
$classifications = $conn->getRepository(Classifications::class);
$classifications->setPublishStatus($this->publish_status);
$data = $classifications->getAssociate($idobject, $object, $classification, $fields, $extra, $params_content);
// ajouter le chemin complet
if (!empty($data)) {
$data['filepath'] = $_ENV['URL_DIRECTORYUPLOAD'] . strtolower($data['extension']) . '/' . $data['file'];
//$data['fileAbsPath'] = PATH_IMG.'upload/'.strtolower($data['extension']).'/'.$data['file'];
}
//retourner le contenu
return $data;
}
// }}}
// {{{ getRelationsArray()
/** Description des relations
*
* @access public
* @param string|int $type si on souhaite retourner uniquement un type precis
* @see Theatre::getLinkedObject()
*/
public function getRelationsArray($type = null)
{
$array_types = array(
'file_classification' => array(// classifications associées
'type_join' => 'multiple',
'dest_table' => 'classifications',
'join_table' => 'file_classification',
'fields' => array('idclassification', 'classification', 'type'),
),
'file_template' => array(// classifications associées
'type_join' => 'multiple',
'dest_table' => 'templates',
'join_table' => 'file_template',
'fields' => array('idtemplate', 'description', 'fichier'),
),
);
// retourne uniquement un type précis
if (!empty($array_types[$type])) {
$array_types[$type]['type'] = $type;
return $array_types[$type];
} else {
return $array_types;
}
}
// }}}
// {{{ countAssociateFile()
/** compter les fichiers associes par type
*
* @access public
* @param string|int|array $classification classification recherchee
* @param int $idobject id de l'objet lié
* @param string $objet le type d'objet (personnes, spectacles...)
* @return array
* @see Theatre_Classifications::getAssociate())
*/
public function countAssociateFile($object, $idobject, $classification)
{
// string ou int pour classification
$classifications = $this->getEntityManager()->getRepository(Classifications::class);
return $classifications->getAssociate($idobject, $object, $classification);
}
// }}}
// {{{ getClassifications()
/** récup les classifications d'un fichier
*
* @access public
* @param int $idfile id du fichier
* @return array
*/
public function getClassifications($idfile)
{
$conn = $this->getEntityManager();
$classifications = $conn->getRepository(Classifications::class);
return $classifications->getObjectClassification($this->__table, $idfile, $this->getRelationsArray('file_classification'));
}
// }}}
// {{{ isImage()
/** image à afficher
*
* @access public
* @param string $mime_type Mime type du fichier
* @return array
*/
public function isImage($mime_type)
{
if ($mime_type == 'image/jpeg'
|| $mime_type == 'image/png'
|| $mime_type == 'image/gif') {
return true;
} else {
return false;
}
}
// }}}
// {{{ getFileByUrl()
/**
* télécharger une image et l'ajouter comme fichier associé
*
* @access public
* @return array
*/
function getFileByUrl($image, $idclassification, $object_infos)
{
$object = $object_infos['object'];
$idobject = $object_infos['idobject'];
$ext = strtolower(substr(strrchr($image, '.'), 1));
// telecharger le fichier dans tmp via wget
$image_sortie = '/tmp/' . uniqid($object . $idobject . '-') . '.' . $ext;
$output = array();
$return_code = -1;
exec('wget -O ' . escapeshellarg($image_sortie) . ' ' . escapeshellarg($image) . ' 2>&1', $output, $return_code);
if (!$return_code) {
// pas d'erreur
// nom de fichier aléatoire
do {
$nomfichier = uniqid($object . $idobject . '-') . '.jpg';
$relfichier = 'jpg/' . $nomfichier;
$absfichier = $_ENV['PATH_DIRECTORYUPLOAD'] . $relfichier;
$nomfichiertmp = 'tmp-' . $nomfichier;
$relfichiertmp = 'jpg/' . $nomfichiertmp;
$absfichiertmp = $_ENV['PATH_DIRECTORYUPLOAD'] . $relfichiertmp;
} while (file_exists($absfichier) || file_exists($absfichiertmp));
// conversion en jpg dans un fichier temporaire
$output = array();
$return_code = -1;
exec($_ENV['MAGICK_CONVERT'] . ' ' . escapeshellarg($image_sortie) . ' +repage -unsharp 0x0.5 -background white -quality 85 ' . escapeshellarg($absfichiertmp) . ' 2>&1', $output, $return_code);
$ret = false;
if (!$return_code) {
chmod($absfichiertmp, self::FILE_MODE);
// pas d'erreur, on renomme le fichier temporaire
$ret = @rename($absfichiertmp, $absfichier);
} else {
// on affiche les erreurs
print_r($output);
}
if (!$ret) {
// on efface le fichier temporaire en cas d'échec
@unlink($absfichiertmp);
} else {
// mise à jour de la base
$values = array(
'idtype' => 1,
//'idclassification' => $idclassification,
'file' => $nomfichier,
'title' => $object_infos['title'],
'publish' => 1,
'language' => $object_infos['language'],
'dateinsert' => $this->now(),
);
//objet dans la table OBJECT_FILE
$obj_files = $this->getEntityManager()->getRepository(Files::class);
$obj_objectfile = $this->getEntityManager()->getRepository(ObjectFile::class);
// commencer la transaction
$error = null;
if ($obj_files->supports('transactions')) {
$obj_files->beginTransaction();
}
//champ a mettre a jour
$obj_files->setUpdateFields($values);
$error = false;
//on va créer dans la table file le document
try {
$idfileinsere = $obj_files->setData(null, true);
} catch (\Exception $e) {
$error = $e->getError();
if ($obj_files->in_transaction) {
$obj_files->rollback();
}
}
if ($idfileinsere) {
//mise en forme des données
$values = array(
'idobject' => $idobject,
'object' => $object,
'idfile' => $idfileinsere
);
// champ a mettre a jour
$obj_objectfile->setUpdateFields($values);
// on va créer dans la table object_file le document
try {
$idobjectfile = $obj_objectfile->setData(null, true);
} catch (\Exception $e) {
$error = $e->getError();
if ($obj_files->in_transaction) {
$obj_files->rollback();
}
}
// ajouter dans files_classification
$file_classification = Theatre::factory('file_classification');
//mise en forme des données
$values = array(
'idclassification' => $idclassification,
'idfile' => $idfileinsere
);
// champ a mettre a jour
$file_classification->setUpdateFields($values);
// on va créer dans la table object_file le document
try {
$file_classification->setData(null);
} catch (\Exception $e) {
$error = $e->getError();
if ($obj_files->in_transaction) {
$obj_files->rollback();
}
}
if (empty($error)) {
if ($obj_files->in_transaction) {
$obj_files->commit();
}
} else {
// on efface le fichier image en cas d'échec
@unlink($absfichier);
}
}
}
}
}
// }}}
// {{{ getObjects()
/**
* Trouver les contenus associés à un fichier
*
* @access public
* @return array
*/
function getObjects($idfile, $not = array())
{
$conn = $this->getEntityManager();
$sql = 'SELECT *
FROM object_file
WHERE idfile=' . $idfile . ' ';
if (!empty($not['idobject'])) {
$sql .= ' AND idobject!=' . $not['idobject'] . ' ';
}
if (!empty($not['object'])) {
$sql .= ' AND object!=\'' . $not['object'] . '\' ';
}
$results = $this->queryAll($sql);
$associates = array();
if (!empty($results)) {
foreach ($results as $r) {
$associates[] = array(
'title' => $conn->getRepository('TheatreCore\Entity\\' . $r['object'])->getObjectTitle($r['idobject']),
'url_clean' => $this->getUrlClean($r['idobject'], $r['object']),
'idobject' => $r['idobject'],
'object' => $r['object'],
);
}
}
return $associates;
}
// }}}
// {{{ getItemsList()
/** récup les classifications d'un fichier
*
* @access public
* @param int $idcontent id du contenu
* @return array
*/
public function getItemsList($idobject = null, $type, $src = null)
{
// trouver les groupe de menu
if ($type == 'file_contact') {
$sql = 'SELECT of.*, c.organisation, c.idcontact
FROM object_file of
JOIN contacts c ON of.idobject=c.idcontact
WHERE
of.object=\'contacts\'
AND of.idfile=' . $idobject;
$results = $this->queryAll($sql);
$itemslist = [];
if (!empty($results)) {
foreach ($results as $r) {
$itemslist[$r['idcontact']]['id'] = $r['idcontact'];
$itemslist[$r['idcontact']]['view_name'] = $r['organisation'];
}
}
return $itemslist;
}
return $this->getItemsListTrait($idobject, $type, $src);
}
// }}}
// {{{ getSQLFiles()
/** Générer la requete standard pour des fichiers
*
*
* @access public
* @param array $query Les paramètres pour la requete
* @param bool $debug afficher la requête TODO
* @return string
*/
public function getSQLFiles($query = array(), $debug = false)
{
$conn = $this->getEntityManager();
// 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('files' => '*'),
array('file_classification' => '*'),
array('typesfiles' => '*'),
array('object_file' => '*')
));
$this->addSQLParams('join', $query, array(
'files.`idfile`' => 'file_classification.`idfile`',
'typesfiles.`idtype`' => 'files.`idtype`',
'files.`idfile`' => 'object_file.`idfile`',
'file_classification.`idfile`' => 'files.`idfile`',
));
// publié ou pas
if (empty($query['publish']) && $_ENV['CHECK_IF_ONLINE']) {
$this->addSQLParams('where', $query, array(
array('files', 'publish', 1)
));
} elseif (!empty($query['publish'])) {
$this->addSQLParams('where', $query, array(
array('files', 'publish', $query['publish'])
));
}
// pour les contacts
// champs par défaut
$this->addSQLParams('select', $query, array(
array('contacts' => 'url_clean,organisation,nom_suite,city')
));
$this->addSQLParams('join', $query, array(
'object_file.`idobject`' => 'contacts.`idcontact`',
));
$this->addSQLParams('where', $query, array(
array('object_file', 'object', 'contacts')
));
// type de structure
if (!empty($query['idtypestructure'])) {
$this->addSQLParams('where', $query, array(
array('contacts', 'idtypestructure', $query['idtypestructure'])
));
}
if (!empty($query['exclude_idtypestructure'])) {
$this->addSQLParams('where', $query, array(
array('contacts', 'idtypestructure', $query['exclude_idtypestructure'], 'AND', 'NOT IN')
));
}
// classification
if (!empty($query['idclassification'])) {
$this->addSQLParams('where', $query, array(
array('file_classification', 'idclassification', $query['idclassification'])
));
}
// région
if (!empty($query['area'])) {
$bigregions = $conn->getRepository(Bigregions::class);
$res_area = ' AND ' . $bigregions->getZipCode($query['area'], 'contacts');
if (!$bigregions->getZipCode($query['area'], 'contacts')) {
return false;
}
$this->addSQLParams('where', $query, array($res_area));
}
// plauqtettes d'un contact
if (!empty($query['idcontacts'])) {
$this->addSQLParams('where', $query, array(
array('contacts', 'idcontact', $query['idcontacts'])
));
}
// par saison
if (!empty($query['saison'])) {
// si plusieurs saisons
if (is_array($query['saison'])) {
foreach ($query['saison'] as $s) {
$s = explode('-', $s);
$sql_where_saison[] = ' (files.`date_start`=\'' . $s[0] . '-09-01\' AND files.`date_end`=\'' . $s[1] . '-08-31\') ';
}
$this->addSQLParams('where', $query, array(' AND (' . implode(' OR ', $sql_where_saison) . ') '));
} else {
$saison = explode('-', $query['saison']);
$this->addSQLParams('where', $query, array(
array('files', 'date_start', $saison[0] . '-09-01'),
array('files', 'date_end', $saison[1] . '-08-31'),
));
$this->addSQLParams('order', $query, array('files.`dateinsert`'));
$this->addSQLParams('direction', $query, 'DESC');
}
}
// le dernier
if (!empty($query['max'])) {
$this->addSQLParams('order', $query, array('files.`date_end`'));
$this->addSQLParams('limit', $query, array(0, 1));
}
return $this->getSQLObject($query);
}
// }}}
// {{{ getListFiles()
/** Retourne des listes de fichiers
*
* Retourne des listes de fichiers au format "standard""
*
* @access public
* @param array $params_sql paramètre pour la requete SQL
* @param array $format_vignette de la vignette si pas standard
* @param array $params_display paramètre pour l'affichage
* @return array
*/
public function getListFiles($params_sql = null, $format_vignette = array(), $params_display = array())
{
// si pas de tableau
if (!isset($params_sql['special'])) {
$params_sql['special'] = array();
}
if (!isset($params_sql['params'])) {
$params_sql['params'] = array();
}
// construction de la requête avec le passage de paramètres
$sql = $this->getSQLFiles($params_sql);
if (!$sql) {
return false;
}
// paramètre de debug
$dbg = (empty($params_sql['dbg'])) ? array() : $dbg = $params_sql['dbg'];
// executer la requete
$this->query($sql, $dbg);
// debug
$start_boucle = microtime(true);
$files = array();
// on boucle
while ($this->fetch()) {
// le total
if (!empty($params_sql['count_only'])) {
return $this->total;
}
$idfile = $this->idfile;
$files[$idfile] = $this->getInfosFile($idfile, array('all' => true));
}
// debug de la boucle
if ($this->isTraceMode('list_object')) {
$this->setTraceInfos(array(
'execution_time_boucle' => microtime(true) - $start_boucle,
'nb_occurence' => count($files),
'dbg' => $dbg,
));
}
// groupement par saison
if (!empty($files) && !empty($params_display['group_by_saison'])) {
foreach ($files as $file) {
$files_by_saison[$file['saison']]['saison'] = $file['saison'];
$files_by_saison[$file['saison']]['programmes'][] = $file;
}
return $files_by_saison;
}
$this->free();
return $files;
}
// }}}
// {{{ getSaisons()
/** Trouver les saisons qui ont des programmes
*
* @access public
* @return int
*/
public function getSaisons($params = array())
{
$sql_annees = '
SELECT `files`.date_start as `date`, CONCAT_WS(\'-\', YEAR(files.`date_start`), YEAR(files.`date_end`)) as saison, YEAR(files.`date_start`) as annee
FROM files
WHERE CONCAT_WS(\'-\', YEAR(files.`date_start`), YEAR(files.`date_end`))!=\'0-0\' ';
if (!empty($params['start_at'])) {
$sql_annees .= ' AND files.`date_start`>=\'' . $params['start_at'] . '\' ';
}
$sql_annees .= '
GROUP BY saison
ORDER BY saison';
$listdates = $this->queryAll($sql_annees);
// liste des saisons et des années
if (empty($listdates)) {
return array();
} else {
return $listdates;
}
}
// }}}
// {{{ getBookletsCurrent()
/** Programmes de saison ou le plus récent
*
*
* @access public
* @param integer $idcontact Contact
* @return array
*/
public function getBookletsCurrent($idcontact, $get_next = false)
{
// voir si il y a des booklets pour la saison courante
$current_saison = \TheatreCore\Classes\Date\DateTime::getLastSaison();
$list = $this->getListFiles(array(
'idcontacts' => $idcontact,
'idclassification' => array(112),
'saison' => array($current_saison),
'dbg' => array('booklet_saison_' . $current_saison, 'Programme de la saison ' . $current_saison . ' pour le contact ' . $idcontact),
));
// sinon, le dernier fichier
if (empty($list)) {
$list = $this->getListFiles(array(
'max' => true,
'idcontacts' => $idcontact,
'idclassification' => array(112),
'dbg' => array('booklet_saison', 'Programme le plus récent pour le contact ' . $idcontact),
));
} else {
// si demandé, vérifier également la saison suivante
if ($get_next) {
$current_saison = explode('-', $current_saison);
$next_saison = ($current_saison[0] + 1) . '-' . ($current_saison[1] + 1);
$list += $this->getListFiles(array(
'idcontacts' => $idcontact,
'idclassification' => array(112),
'saison' => array($next_saison),
'dbg' => array('booklet_saison_' . $next_saison, 'Programme de la saison ' . $next_saison . ' pour le contact ' . $idcontact),
));
}
}
// on retourne le premier de la liste
if (!empty($list)) {
return $list;
}
}
// }}}
// {{{ getBookletsBySaison()
/** Les programmes de saison
*
*
* @access public
* @param array $saison La saison
* @param integer $idcontact Le contact
* @return string
*/
public function getBookletsBySaison($saison, $idcontact)
{
$list = $this->getListFiles(array(
'saison' => $saison,
'idcontacts' => $idcontact,
'idclassification' => array(112),
'dbg' => array('booklet_saison', 'Programmes de la saison ' . $saison . ' pour le contact ' . $idcontact),
));
// on retourne le premier de la liste
if (!empty($list)) {
return $list;
}
}
// }}}
public function getExtension()
{
if ($this->hasFile()) {
echo 'ok';
exit;
}
}
}