/** * @param GenerateEvent $objEvent * @param array $arrCallback */ public static function generateOperation(GenerateEvent $objEvent, array $arrCallback) { $objCallback = new $arrCallback[0](); /** @var \DcaTools\Component\Operation\View $objView */ $controller = $objEvent->getController(); $objView = $controller->getView(); /** @var \DcaTools\Definition\DataContainer $objDataContainer */ $objDataContainer = $controller->getDefinition()->getDataContainer(); // $arrRow, $v['href'], $label, $title, $v['icon'], $attributes, $strTable, $arrRootIds, $arrChildRecordIds, $blnCircularReference, $strPrevious, $strNext $strBuffer = $objCallback->{$arrCallback[1]}($objEvent->getController()->getModel() ? $objEvent->getController()->getModel()->getPropertiesAsArray() : array(), $objView->getHref(), $objView->getLabel(), $objView->getTitle(), $objView->getIcon(), $objView->getAttributes(), $controller->getConfigAttribute('table', $objDataContainer->getName()), $controller->getConfigAttribute('rootIds', array()), $controller->getConfigAttribute('childRecordIds', array()), $controller->getConfigAttribute('circularReference', false), $controller->getConfigAttribute('previous'), $controller->getConfigAttribute('next')); if ($strBuffer == '') { $objView->setVisible(false); } else { $objEvent->setOutput($strBuffer); } }
/** * Toggle state of a value * * @param Event\GenerateEvent $objEvent * @param array $arrConfig * @param $intId * * @param $blnVisible */ protected static function toggleState(Event\GenerateEvent $objEvent, array $arrConfig, $intId, $blnVisible) { // Check permissions to edit \Input::setGet('id', $intId); \Input::setGet('act', 'toggle'); // trigger permission checking $name = $objEvent->getModel()->getProviderName(); $objEvent->getDispatcher()->dispatch(sprintf('dcatools.%s.check-permission', $name)); /** @var \BackendUser $objUser */ $objUser = \BackendUser::getInstance(); if (isset($arrConfig['inverted'])) { $blnVisible = !$blnVisible; } $strTable = isset($arrConfig['table']) ? $arrConfig['table'] : $name; $strProperty = isset($arrConfig['property']) ? $arrConfig['property'] : 'published'; // Check permissions to publish if (!$objUser->isAdmin && !$objUser->hasAccess($strTable . '::' . $strProperty, 'alexf')) { $strError = 'Not enough permissions to toggle state of item ID "' . $intId . '"'; $strError = Permissions::prepareErrorMessage($arrConfig, $strError); DcaTools::error($strError); } $objVersions = new \Versions($strTable, $intId); $objVersions->initialize(); // Trigger the save_callback if (is_array($GLOBALS['TL_DCA'][$strTable]['propertys'][$strProperty]['save_callback'])) { foreach ($GLOBALS['TL_DCA'][$strTable]['propertys'][$strProperty]['save_callback'] as $callback) { $objCallback = new $callback[0](); $blnVisible = $objCallback->{$callback}[1]($blnVisible, $objEvent); } } // Update the database \Database::getInstance()->prepare("UPDATE {$strTable} SET tstamp=" . time() . ", {$strProperty} ='" . ($blnVisible ? 1 : '') . "' WHERE id=?")->execute($intId); $objVersions->create(); }