/** * @param $tableName * @param array $arrConfig * @return bool */ public static function hasAccess($tableName, array $arrConfig) { /** @var \BackendUser $objUser */ $objUser = \BackendUser::getInstance(); if ($objUser->isAdmin) { return true; } // Has access to an module if (isset($arrConfig['module'])) { return $objUser->hasAccess($arrConfig['module'], 'modules'); } // Get table if ($arrConfig['ptable']) { $definition = Definition::getDataContainer($tableName); $tableName = $definition->get('config/ptable'); } else { $tableName = isset($arrConfig['table']) ? $arrConfig['table'] : $tableName; } // Check access for an action if (isset($arrConfig['permission']) && isset($arrConfig['action'])) { if ($arrConfig['action'] == 'alexf') { $arrConfig['action'] = $tableName . '::' . $arrConfig['action']; } return $objUser->hasAccess($arrConfig['action'], $arrConfig['permission']); } elseif (isset($arrConfig['alexf'])) { return $objUser->hasAccess($tableName . '::' . $arrConfig['alexf'], 'alexf'); } elseif (isset($arrConfig['fop'])) { return $objUser->hasAccess($arrConfig['fop'], 'fop'); } return false; }
public function testGetProperty() { $this->assertInstanceOf('DcaTools\\Definition\\Property', Definition::getProperty('tl_test', 'test')); $this->assertEquals($this->objDataContainer->getProperty('test'), Definition::getProperty('tl_test', 'test')); }
public function setUp() { $GLOBALS['TL_DCA']['tl_test'] = $GLOBALS['TEST_DCA']; $this->objProperty = Definition::getProperty('tl_test', 'test'); }
public function setUp() { $GLOBALS['TL_DCA']['tl_test'] = $GLOBALS['TEST_DCA']; $this->objLegend = Definition::getPalette('tl_test', 'default')->getLegend('title'); }
/** * @param string $name * @param $dispatcher */ protected function __construct($name, $dispatcher) { $this->definition = Definition::getDataContainer($name); $this->dispatcher = $dispatcher; }
public function setUp() { $GLOBALS['TL_DCA']['tl_test'] = $GLOBALS['TEST_DCA']; $this->objDataContainer = Definition::getDataContainer('tl_test'); }
public function setUp() { $GLOBALS['TL_DCA']['tl_test'] = $GLOBALS['TEST_DCA']; $this->objPalette = Definition::getSubPalette('tl_test', 'sub'); }
/** * Use magic stuff for generating operations * * @param $method * @param $arguments * * @return mixed */ public function __call($method, $arguments) { if (strncmp($method, 'operationCallback', 17) === 0) { $operationName = substr($method, 17); $definition = Definition::getOperation($arguments[6], $operationName); $dispatcher = $GLOBALS['container']['event-dispatcher']; $controller = new Operation\Controller($definition, $dispatcher); $row = array_shift($arguments); $model = ModelFactory::create($arguments[5], $row['id'], $row); $controller->setModel($model); $view = new Operation\View(); $view->setHref($arguments[0]); $view->setLabel($arguments[1]); $view->setTitle($arguments[2]); $view->setIcon($arguments[3]); $view->setAttributes($arguments[4]); $controller->setView($view); $config = array(); $config['rootIds'] = $arguments[6]; $config['childRecordIds'] = $arguments[7]; $config['circularReference'] = $arguments[8]; $config['previous'] = $arguments[9]; $config['next'] = $arguments[10]; $controller->setConfig($config); return $controller->generate(); } elseif (strncmp($method, 'globalOperationCallback', 23) === 0) { $operationName = substr($method, 23); $definition = Definition::getGlobalOperation($arguments[5], $operationName); $dispatcher = $GLOBALS['container']['event-dispatcher']; $controller = new GlobalOperation\Controller($definition, $dispatcher); $view = new GlobalOperation\View(); $view->setHref($arguments[0]); $view->setLabel($arguments[1]); $view->setTitle($arguments[2]); $view->setIcon($arguments[3]); $view->setAttributes($arguments[4]); $controller->setView($view); $config = array(); $config['rootIds'] = $arguments[6]; $config['childRecordIds'] = $arguments[7]; $config['circularReference'] = $arguments[8]; $config['previous'] = $arguments[9]; $config['next'] = $arguments[10]; $controller->setConfig($config); return $controller->generate(); } return null; }
/** * @param Event\GenerateEvent $objEvent * @param array $arrConfig * @param bool $blnStop * * @return bool */ public static function toggleIcon(Event\GenerateEvent $objEvent, array $arrConfig = array(), $blnStop = true) { if (strlen(\Input::get('tid'))) { static::toggleState($objEvent, $arrConfig, \Input::get('tid'), \Input::get('state') == 1); \Controller::redirect(\Controller::getReferer()); } $objEvent->setOutput(null); /** @var \BackendUser $objUser */ $objUser = \BackendUser::getInstance(); /** @var \DcaTools\Component\Operation\View $objView */ $objView = $objEvent->getView(); /** @var \DcaTools\Definition\DataContainer $objController */ $objDataContainer = Definition::getDataContainer($objEvent->getModel()->getProviderName()); $arrRow = $objEvent->getModel()->getPropertiesAsArray(); $strTable = isset($arrConfig['table']) ? $arrConfig['table'] : $objDataContainer->getName(); $strProperty = isset($arrConfig['property']) ? $arrConfig['property'] : 'published'; $blnVisible = isset($arrConfig['inverted']) ? $arrRow[$strProperty] : !$arrRow[$strProperty]; // Check permissions AFTER checking the tid, so hacking attempts are logged if ($objUser->isAdmin && !$objUser->hasAccess($strTable . '::' . $strProperty, 'alexf')) { if ($blnStop) { $objEvent->stopPropagation(); } return false; } $strHref = $objView->getHref(); $strHref .= '&id=' . $arrRow['pid'] . '&tid=' . $arrRow['id'] . '&state=' . ($blnVisible ? 1 : ''); $objView->setHref($strHref); $objEvent->setConfigAttribute('id', false); if ($blnVisible) { $objView->setIcon(isset($arrConfig['icon']) ? $arrConfig['icon'] : 'invisible.gif'); } return true; }
/** * Construct * @param $table */ public function __construct($table) { $this->definition = Definition::getDataContainer($table); }
/** * Extend an existing DataContainer * * @param Node $objNode * * @return $this|void * * @throws \RuntimeException */ public function extend($objNode) { if (is_string($objNode)) { $objNode = Definition::getDataContainer($objNode); } elseif (!$objNode instanceof DataContainer) { throw new \RuntimeException("Node '{$objNode->getName()}' is not a DataContainer"); } // extend Properties and make sure that and Properties are cloned foreach ($objNode->getProperties() as $strProperty => $objProperty) { if (isset($this->arrProperties[$strProperty])) { $this->arrProperties[$strProperty]->extend($objProperty); } else { $this->arrProperties[$strProperty] = clone $objProperty; } } // extend Palettes and make sure that Legends and Properties are also combined foreach ($objNode->getPalettes() as $strPalette => $objPalette) { if (isset($this->arrPalettes[$strPalette])) { $this->arrPalettes[$strPalette]->extend($objPalette); } else { $this->arrPalettes[$strPalette] = $objPalette; } } // extend SubPalettes and make sure that Legends and Properties are also combined foreach ($objNode->getSubPalettes() as $strPalette => $objPalette) { if (isset($this->arrSubPalettes[$strPalette])) { $this->arrSubPalettes[$strPalette]->extend($objPalette); } else { $this->arrSubPalettes[$strPalette] = $objPalette; } } $this->updateDefinition(); }