<?php
namespace TheatreCore\Repository;
use TheatreCore\Entity\Templates;
use TheatreCore\Traits\TheatreTrait;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* TemplatesRepository
*
* This class was generated by the Doctrine ORM. Add your own custom
* repository methods below.
*/
class TemplatesRepository extends ServiceEntityRepository
{
use TheatreTrait;
private $em;
public $__table;
public $__table_object;
public $__idtable;
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Templates::class);
$this->__table = $this->getClassMetadata()->getTableName();
$this->__table_object = $this->getClassMetadata()->name;
$this->__idtable = $this->getClassMetadata()->getSingleIdentifierFieldName();
// $this->__table = 'persons';
// $this->__table_object = '\\App\\Entity\\Persons';
}
// {{{ getAssociateTemplates()
/** Récupère le(s) template(s) associé(s) à un objet
*
* @access public
* @param string $object Objet concerné
* @param int $idobject Identifiant de l'objet
* @return array
*/
public function getAssociateTemplates($object, $idobject)
{
$templates = array();
$conn = $this->getEntityManager();
// type - s
$dbdo = 'content';
$obj = $conn->getRepository('TheatreCore\Entity\\' . ucfirst($object));
$sql = 'SELECT fichier FROM ' . $dbdo . '_template dbo_tpl, ' . $this->__table . ' tpl
WHERE dbo_tpl.idtemplate=tpl.idtemplate
AND dbo_tpl.' . $obj->__idtable . '=' . (int)$idobject;
$templates = $this->queryAll($sql);
return $templates;
}
// }}}
// {{{ getListSearch()
/** Liste de templates
*
* 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, $type_object = null)
{
$qb = $this->createQueryBuilder('c');
$qb->select('c')
->orderBy('c.description', 'ASC');
return $qb;
// recherche par description ou fichier
$sql = 'SELECT tpl.description, tpl.fichier, tpl.idtemplate
FROM ' . $this->__table . ' tpl
WHERE 1 ';
if (strpos($type, '_template')) {
$type_tab = explode('_', $type);
$type_src = $type_tab[0] . 's';
}
if (!empty($type_src) && $type_src == $type_object) {
$sql .= ' AND cl.type=\'' . $type_object . '\' ';
}
// selection par ordre alpha sur la description uniquement
if (!empty($lettre) && $lettre != 'tous') {
$sql .= ' AND LOWER(LEFT(LTRIM(tpl.description),1))=\'' . $this->escape($lettre) . '\' ';
}
// recherche avec un mot cle sur la description ou le fichier
$list = $this->splitKeywords($keywords);
if ($list) {
$subsql = '';
if (!empty($list[$this->IDSTR])) {
$ssubsql = '';
foreach ($list[$this->IDSTR] as $s) {
if ($ssubsql) {
$ssubsql .= ' AND ';
}
$ssubsql .= ' (tpl.description LIKE \'%' . $s . '%\' OR tpl.fichier LIKE \'%' . $s . '%\'';
}
$subsql .= '(' . $ssubsql . ') ';
}
// par numero de fiche
if (!empty($list[$this->IDNUM])) {
// recherche par numéro d'id pour les mots clés numériques
if ($subsql) {
$subsql .= ' OR ';
}
$subsql .= 'tpl.idtemplate IN (' . implode(',', $list[$this->IDNUM]) . ')';
}
if ($subsql) {
$sql .= $subsql;
}
}
$sql .= ' ORDER BY tpl.description';
$result = $this->queryAll($sql);
$r = array();
foreach ($result as $k => $v) {
$r[$v['idtemplate']] = $v['description'];
// 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;
}
}
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())
{
// identifiant
if (!$idobject) {
$idobject = $$this->_idtable;
}
// champs
$params['fields'] = array('description');
// appel la méthode standard
$infos_object = $this->getObjectTitleSimple($idobject, $infos_object, $params);
return $infos_object['description'];
}
// }}}
}