/** * Publish/unpublish a product * * @param int $intId * @param bool $blnVisible */ protected function toggleVisibility($intId, $blnVisible) { // Check permissions to edit \Input::setGet('id', $intId); \Input::setGet('act', 'toggle'); Permission::check(); /** @var \BackendUser $user */ $user = \BackendUser::getInstance(); // Check permissions to publish if (!$user->isAdmin && !$user->hasAccess('tl_iso_product::published', 'alexf')) { \System::log('Not enough permissions to publish/unpublish product ID "' . $intId . '"', __METHOD__, TL_ERROR); \Controller::redirect('contao/main.php?act=error'); } $objVersions = new \Versions('tl_iso_product', $intId); $objVersions->initialize(); // Trigger the save_callback if (is_array($GLOBALS['TL_DCA']['tl_iso_product']['fields']['published']['save_callback'])) { foreach ($GLOBALS['TL_DCA']['tl_iso_product']['fields']['published']['save_callback'] as $callback) { $objCallback = \System::importStatic($callback[0]); $blnVisible = $objCallback->{$callback}[1]($blnVisible, $this); } } // Update the database \Database::getInstance()->prepare("UPDATE tl_iso_product SET published='" . ($blnVisible ? 1 : '') . "' WHERE id=?")->execute($intId); $objVersions->create(); $this->log('A new version of record "tl_iso_product.id=' . $intId . '" has been created' . $this->getParentEntries('tl_iso_product', $intId), __METHOD__, TL_GENERAL); }