Je me trouve face un dilemme.
Pour effectuer un model de recherche avancée plus précis que celui proposé par Joomla j'ai créé mon propre model.
Code: Select all
/**
* @param \JDatabaseQuery $query
* @param boolean $overrideLimits
*
* @return void
*/
public function onAfterBuildQuery($query, $overrideLimits = false)
{
/**
* TMP FIX
*/
$db = $this->getDbo();
$query->clear('order');
$order = $this->input->get('filter_order');
$order = $db->qn($order);
$dir = strtoupper($this->getState('filter_order_Dir', null, 'cmd'));
if (!in_array($dir, ['ASC', 'DESC']))
{
$dir = 'ASC';
$this->setState('filter_order_Dir', $dir);
}
$query->order($order . ' ' . $dir);
/**
* /TMP FIX
*/
}
/**
* @param \JDatabaseQuery $query
* @param boolean $overrideLimits
*
* @return void
*/
public function onBeforeBuildQuery($query,$overrideLimits = false)
{
/**
* TMP FIX
*/
$query->clear('from')->from($this->getTableName() . ' AS book');
$this->setBehaviorParam('tableAlias', 'book');
$outerGlue = $this->input->get('_outerGlue');
$query->clear('select');
$query->select('book.*');
if ($this->input->get('_resetState') == 1)
{
// Save the state we need to keep
$limit = $this->getState('limit');
// Reset model and user state
$this->clearState()->reset();
\JFactory::getApplication()->setUserState(substr($this->getHash(), 0, -1), null);
// Set back the saved state
$this->input->set('limit', $limit);
$this->setState('limit', $limit);
}
//Process pour la recherche via le module
if($this->input->get('search') !=''){
$search = $this->input->get('search');
$books = $this->getState('books');
$copies = $this->getState('copies');
if($this->input->get('title') =='Y')
{ $this->input->set('title',NULL);
//$this->input->set('title',$this->input->getString('search'));
$this->input->set('books',
array_merge(['title' => $this->input->getString('search')],$this->input->get('books', [], 'array') )
);
$this->input->set('operateur_title', 'OR');
}
if($this->input->get('author_adv') =='Y')
{ $this->input->set('author_adv',NULL);
//$this->input->set('author_adv',$this->input->getString('search'));
$this->input->set('books',
array_merge(['author_adv' => $this->input->getString('search')],$this->input->get('books', [], 'array') )
);
}
}
//Process pour la recherche avancé
//Recherche dans la table __Copies
if($this->input->get('advancedsearch') !=''|| $this->input->get('search') !=''){
//Join _Copies
$query->innerjoin('#__nglibrary_copies AS copie ON book.nglibrary_book_id = copie.nglibrary_book_id');
//Join _Authors
$query->innerjoin('#__nglibrary_books_authors AS link_author ON book.nglibrary_book_id = link_author.nglibrary_book_id');
$query->innerjoin('#__nglibrary_authors AS author ON author.nglibrary_author_id = link_author.nglibrary_author_id');
//Join _Editors
$query->innerjoin('#__nglibrary_editors AS editor ON book.nglibrary_editor_id = editor.nglibrary_editor_id');
if ($this->input->get('copiesStatusId'))
{
$this->input->set('copies',
array_merge(['statusId' => $this->input->get('copiesStatusId')],$this->input->get('copies', [], 'array') )
);
}
Code: Select all
if(isset($sql) == false && $sql2 !=''){
$rsql =$sql2;
}else if(isset($sql2) == false && $sql !=''){
//$sql2 = '(`book`.`nglibrary_book_id` IS NOT NULL)';
$rsql=$sql;
}else{
$rsql= $sql2.' AND '.$sql;
}
if(substr($rsql,-strlen($rsql),2) == 'OR'){
$rsql = substr($rsql,2);
}else if(substr($rsql,-strlen($rsql),3) == 'AND'){
$rsql = substr($rsql,3);
}
$query->where($rsql);
return $query;
Celui-ci fonctionne correctement pour tout ce qui est de la recherche.
Le problème est que sur ma fenêtre de résultat les filtres affichés par Joomla pour le tri, l'ordre et le nombre de ligne re-initialise mon résultat de recherche systématiquement pour tout afficher.
Quelqu'un peut-il me dire comment cela se fais-ce ...
Merci ^pour votre aide