Skip to content

Commit

Permalink
Use the DataContainer::panel() method in the DC_Folder class (see con…
Browse files Browse the repository at this point in the history
  • Loading branch information
leofeyer committed Aug 30, 2017
1 parent fe60d01 commit 337ed3f
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 176 deletions.
131 changes: 131 additions & 0 deletions src/Resources/contao/classes/DataContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -979,6 +979,137 @@ protected function getPickerInputField($value, $attributes='')
}


/**
* Build the sort panel and return it as string
*
* @return string
*/
protected function panel()
{
if ($GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['panelLayout'] == '')
{
return '';
}

// Reset all filters
if (isset($_POST['filter_reset']) && \Input::post('FORM_SUBMIT') == 'tl_filters')
{
/** @var AttributeBagInterface $objSessionBag */
$objSessionBag = \System::getContainer()->get('session')->getBag('contao_backend');

$data = $objSessionBag->all();

unset($data['filter'][$this->strTable]);
unset($data['filter'][$this->strTable.'_'.CURRENT_ID]);
unset($data['sorting'][$this->strTable]);
unset($data['search'][$this->strTable]);

$objSessionBag->replace($data);

$this->reload();
}

$intFilterPanel = 0;
$arrPanels = array();
$arrPanes = \StringUtil::trimsplit(';', $GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['panelLayout']);

foreach ($arrPanes as $strPanel)
{
$panels = '';
$arrSubPanels = \StringUtil::trimsplit(',', $strPanel);

foreach ($arrSubPanels as $strSubPanel)
{
$panel = '';

// Regular panels
if ($strSubPanel == 'search' || $strSubPanel == 'limit' || $strSubPanel == 'sort')
{
$panel = $this->{$strSubPanel . 'Menu'}();
}

// Multiple filter subpanels can be defined to split the fields across panels
elseif ($strSubPanel == 'filter')
{
$panel = $this->{$strSubPanel . 'Menu'}(++$intFilterPanel);
}

// Call the panel_callback
else
{
$arrCallback = $GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['panel_callback'][$strSubPanel];

if (is_array($arrCallback))
{
$this->import($arrCallback[0]);
$panel = $this->{$arrCallback[0]}->{$arrCallback[1]}($this);
}
elseif (is_callable($arrCallback))
{
$panel = $arrCallback($this);
}
}

// Add the panel if it is not empty
if ($panel != '')
{
$panels = $panel . $panels;
}
}

// Add the group if it is not empty
if ($panels != '')
{
$arrPanels[] = $panels;
}
}

if (empty($arrPanels))
{
return '';
}

if (\Input::post('FORM_SUBMIT') == 'tl_filters')
{
$this->reload();
}

$return = '';
$intTotal = count($arrPanels);
$intLast = $intTotal - 1;

for ($i=0; $i<$intTotal; $i++)
{
$submit = '';

if ($i == $intLast)
{
$submit = '
<div class="tl_submit_panel tl_subpanel">
<button name="filter" id="filter" class="tl_img_submit filter_apply" title="' . \StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['applyTitle']) . '">' . $GLOBALS['TL_LANG']['MSC']['apply'] . '</button>
<button name="filter_reset" id="filter_reset" value="1" class="tl_img_submit filter_reset" title="' . \StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['resetTitle']) . '">' . $GLOBALS['TL_LANG']['MSC']['reset'] . '</button>
</div>';
}

$return .= '
<div class="tl_panel cf">
' . $submit . $arrPanels[$i] . '
</div>';
}

$return = '
<form action="'.ampersand(\Environment::get('request'), true).'" class="tl_form" method="post">
<div class="tl_formbody">
<input type="hidden" name="FORM_SUBMIT" value="tl_filters">
<input type="hidden" name="REQUEST_TOKEN" value="'.REQUEST_TOKEN.'">
' . $return . '
</div>
</form>';

return $return;
}


/**
* Return the name of the current palette
*
Expand Down
4 changes: 4 additions & 0 deletions src/Resources/contao/dca/tl_files.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@
// List
'list' => array
(
'sorting' => array
(
'panelLayout' => 'search'
),
'global_operations' => array
(
'sync' => array
Expand Down
45 changes: 0 additions & 45 deletions src/Resources/contao/drivers/DC_Folder.php
Original file line number Diff line number Diff line change
Expand Up @@ -2765,51 +2765,6 @@ protected function generateTree($path, $intMargin, $mount=false, $blnProtected=t
}


/**
* Build the sort panel and return it as string
*
* @return string
*/
protected function panel()
{
// Reset all filters
if (isset($_POST['filter_reset']) && \Input::post('FORM_SUBMIT') == 'tl_filters')
{
/** @var AttributeBagInterface $objSessionBag */
$objSessionBag = \System::getContainer()->get('session')->getBag('contao_backend');

$data = $objSessionBag->all();

unset($data['search'][$this->strTable]);

$objSessionBag->replace($data);

$this->reload();
}

$search = $this->searchMenu();

if (\Input::post('FORM_SUBMIT') == 'tl_filters')
{
$this->reload();
}

return '
<form action="'.ampersand(\Environment::get('request'), true).'" class="tl_form" method="post">
<div class="tl_formbody">
<input type="hidden" name="FORM_SUBMIT" value="tl_filters">
<input type="hidden" name="REQUEST_TOKEN" value="'.REQUEST_TOKEN.'">
<div class="tl_panel cf">
<div class="tl_submit_panel tl_subpanel">
<button name="filter" id="filter" class="tl_img_submit filter_apply" title="' . \StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['applyTitle']) . '">' . $GLOBALS['TL_LANG']['MSC']['apply'] . '</button>
<button name="filter_reset" id="filter_reset" value="1" class="tl_img_submit filter_reset" title="' . \StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['resetTitle']) . '">' . $GLOBALS['TL_LANG']['MSC']['reset'] . '</button>
</div>'.$search.'
</div>
</div>
</form>';
}


/**
* Return a search form that allows to search results using regular expressions
*
Expand Down
131 changes: 0 additions & 131 deletions src/Resources/contao/drivers/DC_Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -5018,137 +5018,6 @@ protected function listView()
}


/**
* Build the sort panel and return it as string
*
* @return string
*/
protected function panel()
{
if ($GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['panelLayout'] == '')
{
return '';
}

// Reset all filters
if (isset($_POST['filter_reset']) && \Input::post('FORM_SUBMIT') == 'tl_filters')
{
/** @var AttributeBagInterface $objSessionBag */
$objSessionBag = \System::getContainer()->get('session')->getBag('contao_backend');

$data = $objSessionBag->all();

unset($data['filter'][$this->strTable]);
unset($data['filter'][$this->strTable.'_'.CURRENT_ID]);
unset($data['sorting'][$this->strTable]);
unset($data['search'][$this->strTable]);

$objSessionBag->replace($data);

$this->reload();
}

$intFilterPanel = 0;
$arrPanels = array();
$arrPanes = \StringUtil::trimsplit(';', $GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['panelLayout']);

foreach ($arrPanes as $strPanel)
{
$panels = '';
$arrSubPanels = \StringUtil::trimsplit(',', $strPanel);

foreach ($arrSubPanels as $strSubPanel)
{
$panel = '';

// Regular panels
if ($strSubPanel == 'search' || $strSubPanel == 'limit' || $strSubPanel == 'sort')
{
$panel = $this->{$strSubPanel . 'Menu'}();
}

// Multiple filter subpanels can be defined to split the fields across panels
elseif ($strSubPanel == 'filter')
{
$panel = $this->{$strSubPanel . 'Menu'}(++$intFilterPanel);
}

// Call the panel_callback
else
{
$arrCallback = $GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['panel_callback'][$strSubPanel];

if (is_array($arrCallback))
{
$this->import($arrCallback[0]);
$panel = $this->{$arrCallback[0]}->{$arrCallback[1]}($this);
}
elseif (is_callable($arrCallback))
{
$panel = $arrCallback($this);
}
}

// Add the panel if it is not empty
if ($panel != '')
{
$panels = $panel . $panels;
}
}

// Add the group if it is not empty
if ($panels != '')
{
$arrPanels[] = $panels;
}
}

if (empty($arrPanels))
{
return '';
}

if (\Input::post('FORM_SUBMIT') == 'tl_filters')
{
$this->reload();
}

$return = '';
$intTotal = count($arrPanels);
$intLast = $intTotal - 1;

for ($i=0; $i<$intTotal; $i++)
{
$submit = '';

if ($i == $intLast)
{
$submit = '
<div class="tl_submit_panel tl_subpanel">
<button name="filter" id="filter" class="tl_img_submit filter_apply" title="' . \StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['applyTitle']) . '">' . $GLOBALS['TL_LANG']['MSC']['apply'] . '</button>
<button name="filter_reset" id="filter_reset" value="1" class="tl_img_submit filter_reset" title="' . \StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['resetTitle']) . '">' . $GLOBALS['TL_LANG']['MSC']['reset'] . '</button>
</div>';
}

$return .= '
<div class="tl_panel cf">
' . $submit . $arrPanels[$i] . '
</div>';
}

$return = '
<form action="'.ampersand(\Environment::get('request'), true).'" class="tl_form" method="post">
<div class="tl_formbody">
<input type="hidden" name="FORM_SUBMIT" value="tl_filters">
<input type="hidden" name="REQUEST_TOKEN" value="'.REQUEST_TOKEN.'">
' . $return . '
</div>
</form>';

return $return;
}


/**
* Return a search form that allows to search results using regular expressions
*
Expand Down

0 comments on commit 337ed3f

Please sign in to comment.