public function toggleVisibility($intId, $blnVisible, DataContainer $dc = null)
{
// Set the ID and action
Input::setGet('id', $intId);
Input::setGet('act', 'toggle');
if ($dc) {
$dc->id = $intId;
// see #8043
}
// Check the field access
if (!$this->User->hasAccess('tl_member::disable', 'alexf')) {
throw new Contao\CoreBundle\Exception\AccessDeniedException('Not enough permissions to activate/deactivate member ID ' . $intId . '.');
}
$objVersions = new Versions('tl_member', $intId);
$objVersions->initialize();
// Reverse the logic (members have disabled=1)
$blnVisible = !$blnVisible;
// Trigger the save_callback
if (is_array($GLOBALS['TL_DCA']['tl_member']['fields']['disable']['save_callback'])) {
foreach ($GLOBALS['TL_DCA']['tl_member']['fields']['disable']['save_callback'] as $callback) {
if (is_array($callback)) {
$this->import($callback[0]);
$blnVisible = $this->{$callback[0]}->{$callback[1]}($blnVisible, $dc ?: $this);
} elseif (is_callable($callback)) {
$blnVisible = $callback($blnVisible, $dc ?: $this);
}
}
}
$time = time();
// Update the database
$this->Database->prepare("UPDATE tl_member SET tstamp={$time}, disable='" . ($blnVisible ? '1' : '') . "' WHERE id=?")->execute($intId);
$objVersions->create();
// Remove the session if the user is disabled (see #5353)
if (!$blnVisible) {
$this->Database->prepare("DELETE FROM tl_session WHERE name='FE_USER_AUTH' AND pid=?")->execute($intId);
}
}