Skip to content

Commit

Permalink
Correctly apply the sorting flags in the list and parent view (see co…
Browse files Browse the repository at this point in the history
  • Loading branch information
leofeyer committed Jul 12, 2019
1 parent 4abfdb8 commit fc9a686
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 17 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,8 @@

## DEV

* Correctly apply the sorting flags in the list and parent view (see contao/core-bundle#1536).
* Purge the search index when a page alias changes (see #472).
* Show only newsletter channels with redirect page in the newsletter list module (see #494).
* Use `scssphp/scssphp` instead of `leafo/scssphp` (see #506).
* Hide empty legends in the `member_grouped.html5` template (see #514).
Expand Down
Expand Up @@ -56,7 +56,7 @@
'sorting' => array
(
'mode' => 4,
'fields' => array('startTime DESC'),
'fields' => array('startTime'),
'headerFields' => array('title', 'jumpTo', 'tstamp', 'protected', 'allowComments'),
'panelLayout' => 'filter;sort,search,limit',
'child_record_callback' => array('tl_calendar_events', 'listEvents')
Expand Down
3 changes: 1 addition & 2 deletions comments-bundle/src/Resources/contao/dca/tl_comments.php
Expand Up @@ -43,8 +43,7 @@
'sorting' => array
(
'mode' => 2,
'fields' => array('date DESC'),
'flag' => 8,
'fields' => array('date'),
'panelLayout' => 'filter;sort,search,limit'
),
'label' => array
Expand Down
1 change: 0 additions & 1 deletion core-bundle/src/Resources/contao/dca/tl_article.php
Expand Up @@ -44,7 +44,6 @@
'sorting' => array
(
'mode' => 6,
'fields' => array('published DESC', 'title', 'author'),
'paste_button_callback' => array('tl_article', 'pasteArticle'),
'panelLayout' => 'filter;search'
),
Expand Down
2 changes: 1 addition & 1 deletion core-bundle/src/Resources/contao/dca/tl_log.php
Expand Up @@ -33,7 +33,7 @@
'sorting' => array
(
'mode' => 2,
'fields' => array('tstamp DESC', 'id DESC'),
'fields' => array('tstamp'),
'panelLayout' => 'filter;sort,search,limit'
),
'label' => array
Expand Down
3 changes: 1 addition & 2 deletions core-bundle/src/Resources/contao/dca/tl_member.php
Expand Up @@ -44,8 +44,7 @@
'sorting' => array
(
'mode' => 2,
'fields' => array('dateAdded DESC'),
'flag' => 1,
'fields' => array('dateAdded'),
'panelLayout' => 'filter;sort,search,limit'
),
'label' => array
Expand Down
2 changes: 1 addition & 1 deletion core-bundle/src/Resources/contao/dca/tl_undo.php
Expand Up @@ -36,7 +36,7 @@
'sorting' => array
(
'mode' => 2,
'fields' => array('tstamp DESC'),
'fields' => array('tstamp'),
'panelLayout' => 'sort,search,limit'
),
'label' => array
Expand Down
2 changes: 1 addition & 1 deletion core-bundle/src/Resources/contao/dca/tl_user.php
Expand Up @@ -46,7 +46,7 @@
'sorting' => array
(
'mode' => 2,
'fields' => array('dateAdded DESC'),
'fields' => array('dateAdded'),
'flag' => 1,
'panelLayout' => 'filter;sort,search,limit'
),
Expand Down
35 changes: 29 additions & 6 deletions core-bundle/src/Resources/contao/drivers/DC_Table.php
Expand Up @@ -4313,6 +4313,14 @@ protected function parentView()
// ORDER BY
if (!empty($orderBy) && \is_array($orderBy))
{
foreach ($orderBy as $k=>$v)
{
if (isset($GLOBALS['TL_DCA'][$this->strTable]['fields'][$v]['flag']) && ($GLOBALS['TL_DCA'][$this->strTable]['fields'][$v]['flag'] % 2) == 0)
{
$orderBy[$k] .= ' DESC';
}
}

$query .= " ORDER BY " . implode(', ', $orderBy);
}

Expand Down Expand Up @@ -4617,8 +4625,23 @@ protected function listView()
{
list($key, $direction) = explode(' ', $v, 2);

// If there is no direction, check the global flag in sorting mode 1 or the field flag in all other sorting modes
if (!$direction)
{
if ($GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['mode'] == 1 && isset($GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['flag']) && ($GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['flag'] % 2) == 0)
{
$direction = 'DESC';
}
elseif (isset($GLOBALS['TL_DCA'][$this->strTable]['fields'][$key]['flag']) && ($GLOBALS['TL_DCA'][$this->strTable]['fields'][$key]['flag'] % 2) == 0)
{
$direction = 'DESC';
}
}

if ($GLOBALS['TL_DCA'][$this->strTable]['fields'][$key]['eval']['findInSet'])
{
$direction = null;

if (\is_array($GLOBALS['TL_DCA'][$this->strTable]['fields'][$key]['options_callback']))
{
$strClass = $GLOBALS['TL_DCA'][$this->strTable]['fields'][$key]['options_callback'][0];
Expand All @@ -4645,7 +4668,12 @@ protected function listView()
}
elseif (\in_array($GLOBALS['TL_DCA'][$this->strTable]['fields'][$key]['flag'], array(5, 6, 7, 8, 9, 10)))
{
$orderBy[$k] = "CAST($key AS SIGNED)" . ($direction ? " $direction" : ""); // see #5503
$orderBy[$k] = "CAST($key AS SIGNED)"; // see #5503
}

if ($direction)
{
$orderBy[$k] = $key . ' ' . $direction;
}
}

Expand All @@ -4672,11 +4700,6 @@ protected function listView()
}
}

if ($GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['mode'] == 1 && ($GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['flag'] % 2) == 0)
{
$query .= " DESC";
}

$objRowStmt = $this->Database->prepare($query);

if ($this->limit != '')
Expand Down
2 changes: 1 addition & 1 deletion news-bundle/src/Resources/contao/dca/tl_news.php
Expand Up @@ -56,7 +56,7 @@
'sorting' => array
(
'mode' => 4,
'fields' => array('date DESC'),
'fields' => array('date'),
'headerFields' => array('title', 'jumpTo', 'tstamp', 'protected', 'allowComments'),
'panelLayout' => 'filter;sort,search,limit',
'child_record_callback' => array('tl_news', 'listNewsArticles'),
Expand Down
Expand Up @@ -37,7 +37,7 @@
'sorting' => array
(
'mode' => 4,
'fields' => array('sent', 'date DESC', 'tstamp DESC'),
'fields' => array('sent', 'date'),
'headerFields' => array('title', 'jumpTo', 'tstamp', 'sender'),
'panelLayout' => 'filter;sort,search,limit',
'child_record_callback' => array('tl_newsletter', 'listNewsletters')
Expand Down

0 comments on commit fc9a686

Please sign in to comment.