/** * 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(); }
/** * @param CheckPermissionEvent $objEvent * @param array $arrConfig * * @return bool */ public static function hasGenericPermission(CheckPermissionEvent $objEvent, array $arrConfig = array()) { $objEvent->addError(Permissions::prepareErrorMessage($arrConfig, $arrConfig['error'])); $blnAccess = true; if (isset($arrConfig['act'])) { if ($arrConfig['act'] == '*' && \Input::get('act') != '') { return true; } if (!is_array($arrConfig['act'])) { $arrConfig['act'] = array($arrConfig['act']); } if ($arrConfig['act'][0] == '*') { if (\Input::get('act') != '*' && !in_array(\Input::get('act'), $arrConfig['act'])) { return true; } } elseif (in_array(\Input::get('act'), $arrConfig['act'])) { return true; } $blnAccess = false; } if (isset($arrConfig['key'])) { if ($arrConfig['key'] == '*' && \Input::get('act') != '') { return true; } if (!is_array($arrConfig['key'])) { $arrConfig['key'] = array($arrConfig['key']); } if ($arrConfig['key'][0] == '*') { if (\Input::get('key') != '*' && !in_array(\Input::get('key'), $arrConfig['key'])) { return true; } } elseif (in_array(\Input::get('key'), $arrConfig['key'])) { return true; } $blnAccess = false; } return $blnAccess; }