Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

Commit

Permalink
Consider the values of referenced fields in the back end search (see #…
Browse files Browse the repository at this point in the history
  • Loading branch information
leofeyer committed Sep 9, 2014
1 parent 3610214 commit be4a790
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 6 deletions.
3 changes: 3 additions & 0 deletions system/docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ Contao Open Source CMS changelog
Version 3.4.0-beta1 (2014-10-XX)
--------------------------------

### Improved
Consider the values of referenced fields in the back end search (see #4376).

### New
Add an option to export style sheets (see #7049).

Expand Down
3 changes: 2 additions & 1 deletion system/modules/calendar/dca/tl_calendar_events.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,10 @@
'label' => &$GLOBALS['TL_LANG']['tl_calendar_events']['author'],
'default' => BackendUser::getInstance()->id,
'exclude' => true,
'search' => true,
'filter' => true,
'sorting' => true,
'flag' => 1,
'flag' => 11,
'inputType' => 'select',
'foreignKey' => 'tl_user.name',
'eval' => array('doNotCopy'=>true, 'chosen'=>true, 'mandatory'=>true, 'includeBlankOption'=>true, 'tl_class'=>'w50'),
Expand Down
1 change: 1 addition & 0 deletions system/modules/core/dca/tl_article.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@
'label' => &$GLOBALS['TL_LANG']['tl_article']['author'],
'default' => BackendUser::getInstance()->id,
'exclude' => true,
'search' => true,
'inputType' => 'select',
'foreignKey' => 'tl_user.name',
'eval' => array('doNotCopy'=>true, 'mandatory'=>true, 'chosen'=>true, 'includeBlankOption'=>true, 'tl_class'=>'w50'),
Expand Down
2 changes: 2 additions & 0 deletions system/modules/core/dca/tl_page.php
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,7 @@
'label' => &$GLOBALS['TL_LANG']['tl_page']['cuser'],
'default' => intval(Config::get('defaultUser')),
'exclude' => true,
'search' => true,
'inputType' => 'select',
'foreignKey' => 'tl_user.username',
'eval' => array('mandatory'=>true, 'chosen'=>true, 'includeBlankOption'=>true, 'tl_class'=>'w50'),
Expand All @@ -523,6 +524,7 @@
'label' => &$GLOBALS['TL_LANG']['tl_page']['cgroup'],
'default' => intval(Config::get('defaultGroup')),
'exclude' => true,
'search' => true,
'inputType' => 'select',
'foreignKey' => 'tl_user_group.name',
'eval' => array('mandatory'=>true, 'chosen'=>true, 'includeBlankOption'=>true, 'tl_class'=>'w50'),
Expand Down
38 changes: 34 additions & 4 deletions system/modules/core/drivers/DC_Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -3263,8 +3263,27 @@ protected function treeView()
}
else
{
$objRoot = $this->Database->prepare("SELECT $for FROM {$this->strTable} WHERE CAST(".$session['search'][$this->strTable]['field']." AS CHAR) REGEXP ? GROUP BY $for")
->execute($session['search'][$this->strTable]['value']);
$strPattern = "CAST(%s AS CHAR) REGEXP ?";

if (substr(\Config::get('dbCollation'), -3) == '_ci')
{
$strPattern = "LOWER(CAST(%s AS CHAR)) REGEXP LOWER(?)";
}

$fld = $session['search'][$this->strTable]['field'];

if (isset($GLOBALS['TL_DCA'][$this->strTable]['fields'][$fld]['foreignKey']))
{
list($t, $f) = explode('.', $GLOBALS['TL_DCA'][$this->strTable]['fields'][$fld]['foreignKey']);

$objRoot = $this->Database->prepare("SELECT $for FROM {$this->strTable} WHERE (" . sprintf($strPattern, $fld) . " OR " . sprintf($strPattern, "(SELECT $f FROM $t WHERE $t.id={$this->strTable}.$fld)") . ") GROUP BY $for")
->execute($session['search'][$this->strTable]['value'], $session['search'][$this->strTable]['value']);
}
else
{
$objRoot = $this->Database->prepare("SELECT $for FROM {$this->strTable} WHERE " . sprintf($strPattern, $fld) . " GROUP BY $for")
->execute($session['search'][$this->strTable]['value']);
}
}

if ($objRoot->numRows < 1)
Expand Down Expand Up @@ -4807,13 +4826,24 @@ protected function searchMenu()
// Set the search value from the session
elseif ($session['search'][$this->strTable]['value'] != '')
{
$strPattern = "CAST(%s AS CHAR) REGEXP ?";

if (substr(\Config::get('dbCollation'), -3) == '_ci')
{
$this->procedure[] = "LOWER(CAST(".$session['search'][$this->strTable]['field']." AS CHAR)) REGEXP LOWER(?)";
$strPattern = "LOWER(CAST(%s AS CHAR)) REGEXP LOWER(?)";
}

$fld = $session['search'][$this->strTable]['field'];

if (isset($GLOBALS['TL_DCA'][$this->strTable]['fields'][$fld]['foreignKey']))
{
list($t, $f) = explode('.', $GLOBALS['TL_DCA'][$this->strTable]['fields'][$fld]['foreignKey']);
$this->procedure[] = "(" . sprintf($strPattern, $fld) . " OR " . sprintf($strPattern, "(SELECT $f FROM $t WHERE $t.id={$this->strTable}.$fld)") . ")";
$this->values[] = $session['search'][$this->strTable]['value'];
}
else
{
$this->procedure[] = "CAST(".$session['search'][$this->strTable]['field']." AS CHAR) REGEXP ?";
$this->procedure[] = sprintf($strPattern, $fld);
}

$this->values[] = $session['search'][$this->strTable]['value'];
Expand Down
3 changes: 2 additions & 1 deletion system/modules/faq/dca/tl_faq.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,9 @@
'default' => BackendUser::getInstance()->id,
'exclude' => true,
'search' => true,
'filter' => true,
'sorting' => true,
'flag' => 1,
'flag' => 11,
'inputType' => 'select',
'foreignKey' => 'tl_user.name',
'eval' => array('doNotCopy'=>true, 'chosen'=>true, 'mandatory'=>true, 'includeBlankOption'=>true, 'tl_class'=>'w50'),
Expand Down
1 change: 1 addition & 0 deletions system/modules/news/dca/tl_news.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@
'label' => &$GLOBALS['TL_LANG']['tl_news']['author'],
'default' => BackendUser::getInstance()->id,
'exclude' => true,
'search' => true,
'filter' => true,
'sorting' => true,
'flag' => 11,
Expand Down

0 comments on commit be4a790

Please sign in to comment.