tl_page::toggleVisibility PHP Method

toggleVisibility() public method

Disable/enable a user group
public toggleVisibility ( integer $intId, boolean $blnVisible, DataContainer $dc = null )
$intId integer
$blnVisible boolean
$dc DataContainer
    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
        }
        $this->checkPermission();
        // Check the field access
        if (!$this->User->hasAccess('tl_page::published', 'alexf')) {
            throw new Contao\CoreBundle\Exception\AccessDeniedException('Not enough permissions to publish/unpublish page ID ' . $intId . '.');
        }
        $objVersions = new Versions('tl_page', $intId);
        $objVersions->initialize();
        // Trigger the save_callback
        if (is_array($GLOBALS['TL_DCA']['tl_page']['fields']['published']['save_callback'])) {
            foreach ($GLOBALS['TL_DCA']['tl_page']['fields']['published']['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);
                }
            }
        }
        // Update the database
        $this->Database->prepare("UPDATE tl_page SET tstamp=" . time() . ", published='" . ($blnVisible ? '1' : '') . "' WHERE id=?")->execute($intId);
        $objVersions->create();
    }