/**
  * @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;
 }
Example #2
0
 /**
  * @param $name
  */
 public function hookLoadDataContainer($name)
 {
     if (isset($GLOBALS['TL_DCA'][$name]['dcatools'])) {
         $definition = Definition::getDataContainer($name);
         $definition->registerCallback('onload', array('\\DcaTools\\Bridge', 'callbackInitialize'));
         if ($definition->get('config/dataContainer') == 'General') {
             $definition->registerCallback('onload', array('\\DcaTools\\Bridge', 'callbackDcGeneralOnLoad'));
         }
     }
 }
 public function testGetDataContainer()
 {
     $this->assertInstanceOf('DcaTools\\Definition\\DataContainer', Definition::getDataContainer('tl_test'));
 }
Example #4
0
 /**
  * @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');
 }
 /**
  * @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;
 }
Example #7
0
 /**
  * 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();
 }