예제 #1
0
 /**
  * Create a new instance.
  *
  * @param string $strTable         The table name.
  *
  * @param array  $arrBackendModule The backend module information array.
  */
 public function __construct($strTable, array &$arrBackendModule = null)
 {
     $strTable = $this->getTablenameCallback($strTable);
     $dispatcher = $GLOBALS['container']['event-dispatcher'];
     /** @var \Symfony\Component\EventDispatcher\EventDispatcher $dispatcher */
     $dispatcher->addListener(PopulateEnvironmentEvent::NAME, array($this, 'handlePopulateEnvironment'), 4800);
     $propagator = new EventPropagator($dispatcher);
     $translator = new TranslatorChain();
     $translator->add(new LangArrayTranslator($dispatcher));
     $factory = new DcGeneralFactory();
     $factory->setContainerName($strTable)->setEventPropagator($propagator)->setTranslator($translator)->createDcGeneral();
     $dispatcher->removeListener(PopulateEnvironmentEvent::NAME, array($this, 'handlePopulateEnvironment'));
     // Switch user for FE / BE support.
     switch (TL_MODE) {
         case 'FE':
             $this->import('FrontendUser', 'User');
             break;
         default:
         case 'BE':
             $this->import('BackendUser', 'User');
             break;
     }
     // Load the clipboard.
     $this->getEnvironment()->getClipboard()->loadFrom($this->getEnvironment());
     // Execute AJAX request, called from Backend::getBackendModule
     // we have to do this here, as otherwise the script will exit as it only checks for DC_Table and DC_File
     // derived classes.
     // @codingStandardsIgnoreStart - The access to $_POST is sane here.
     if ($_POST && (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest')) {
         $this->getViewHandler()->handleAjaxCall();
     }
 }
예제 #2
0
 /**
  * Create a new instance.
  *
  * @param string $strTable The table name.
  *
  * @SuppressWarnings(PHPMD.CamelCaseVariableName)
  * @SuppressWarnings(PHPMD.Superglobals)
  */
 public function __construct($strTable)
 {
     $strTable = $this->getTablenameCallback($strTable);
     $translator = $this->getTranslator();
     $dispatcher = $this->getEventDispatcher();
     $dispatcher->addListener(PopulateEnvironmentEvent::NAME, array($this, 'handlePopulateEnvironment'), 4800);
     $factory = new DcGeneralFactory();
     $factory->setContainerName($strTable)->setEventDispatcher($dispatcher)->setTranslator($translator)->createDcGeneral();
     $dispatcher->removeListener(PopulateEnvironmentEvent::NAME, array($this, 'handlePopulateEnvironment'));
     // Load the clipboard.
     $this->getEnvironment()->getClipboard()->loadFrom($this->getEnvironment());
     // Execute AJAX request, called from Backend::getBackendModule
     // we have to do this here, as otherwise the script will exit as it only checks for DC_Table and DC_File
     // derived classes.
     $this->checkAjaxCall();
 }
 /**
  * @param array $options
  *
  * @return array
  */
 public function getImportableRecipientFieldOptions($options = array())
 {
     global $container;
     // todo issue to dc-general
     \System::loadLanguageFile('orm_avisota_recipient');
     /** @var EventDispatcher $eventDispatcher */
     $eventDispatcher = $container['event-dispatcher'];
     $dcGeneralFactory = new DcGeneralFactory();
     $dcGeneralFactory->setContainerName('orm_avisota_recipient');
     $dcGeneralFactory->setEventDispatcher($eventDispatcher);
     $containerFactory = $dcGeneralFactory->createContainer();
     foreach ($containerFactory->getPropertiesDefinition()->getProperties() as $property) {
         $extra = $property->getExtra();
         if (isset($extra['importable']) && $extra['importable']) {
             $options[$property->getName()] = $property->getLabel();
         }
     }
     return $options;
 }
 /**
  * Create the dc-general and return it's environment instance.
  *
  * @param string $containerName The name of the data container to edit.
  *
  * @return EnvironmentInterface
  */
 private function createDcGeneral($containerName)
 {
     $factory = new DcGeneralFactory();
     $dcGeneral = $factory->setContainerName($containerName)->setEventDispatcher($this->dispatcher)->setTranslator($this->translator)->createDcGeneral();
     return $dcGeneral->getEnvironment();
 }
예제 #5
0
 /**
  * Setup all local values and create the dc instance for the referenced data source.
  *
  * @param DC_General $dataContainer The data container to use.
  *
  * @return void
  */
 protected function setUp(DC_General $dataContainer = null)
 {
     $this->dataContainer = $dataContainer ?: $this->objDca;
     if (!$this->dataContainer) {
         return;
     }
     $environment = $this->dataContainer->getEnvironment();
     if (!$this->sourceName) {
         $property = $environment->getDataDefinition()->getPropertiesDefinition()->getProperty($environment->getInputProvider()->getValue('name'));
         foreach ($property->getExtra() as $k => $v) {
             $this->{$k} = $v;
         }
         $name = $environment->getInputProvider()->getValue('name');
         $this->strField = $name;
         $this->strName = $name;
         $this->strId = $name;
         $this->label = $property->getLabel() ?: $name;
         $this->strTable = $environment->getDataDefinition()->getName();
     }
     $factory = new DcGeneralFactory();
     $this->itemContainer = $factory->setContainerName($this->sourceName)->setTranslator($environment->getTranslator())->setEventDispatcher($environment->getEventDispatcher())->createDcGeneral();
 }
예제 #6
0
 /**
  * Run the controller and parse the template.
  *
  * @return void
  */
 public function run()
 {
     $template = new \BackendTemplate('be_picker');
     $template->main = '';
     // Ajax request.
     // @codingStandardsIgnoreStart - We need POST access here.
     if ($_POST && \Environment::get('isAjaxRequest')) {
         $ajax = new \Ajax(\Input::post('action'));
         $ajax->executePreActions();
     }
     $strTable = \Input::get('table');
     $strField = \Input::get('field');
     // Define the current ID.
     define('CURRENT_ID', $strTable ? \Session::getInstance()->get('CURRENT_ID') : \Input::get('id'));
     $dispatcher = $GLOBALS['container']['event-dispatcher'];
     /** @var \Symfony\Component\EventDispatcher\EventDispatcher $dispatcher */
     $propagator = new EventPropagator($dispatcher);
     $translator = new TranslatorChain();
     $translator->add(new LangArrayTranslator($dispatcher));
     $factory = new DcGeneralFactory();
     $this->itemContainer = $factory->setContainerName($strTable)->setTranslator($translator)->setEventPropagator($propagator)->createDcGeneral();
     $information = (array) $GLOBALS['TL_DCA'][$strTable]['fields'][$strField];
     // Merge with the information from the data container.
     $property = $this->itemContainer->getEnvironment()->getDataDefinition()->getPropertiesDefinition()->getProperty($strField);
     $extra = $property->getExtra();
     $information['eval']['sourceName'] = $extra['sourceName'];
     $information['eval']['fieldType'] = $extra['fieldType'];
     /** @var \ContaoCommunityAlliance\DcGeneral\Contao\View\Contao2BackendView\TreePicker $objTreeSelector */
     $objTreeSelector = new $GLOBALS['BE_FFL']['DcGeneralTreePicker'](\Widget::getAttributesFromDca($information, $strField, array_filter(explode(',', \Input::get('value'))), $strField, $strTable, new DcCompat($this->itemContainer->getEnvironment())));
     // AJAX request.
     if (isset($ajax)) {
         $objTreeSelector->generateAjax();
         $ajax->executePostActions(new DcCompat($this->itemContainer->getEnvironment()));
     }
     $template->main = $objTreeSelector->generatePopup();
     $template->theme = \Backend::getTheme();
     $template->base = \Environment::get('base');
     $template->language = $GLOBALS['TL_LANGUAGE'];
     $template->title = specialchars($GLOBALS['TL_LANG']['MSC']['treepicker']);
     $template->charset = $GLOBALS['TL_CONFIG']['characterSet'];
     $template->addSearch = $objTreeSelector->searchField;
     $template->search = $GLOBALS['TL_LANG']['MSC']['search'];
     $template->action = ampersand(\Environment::get('request'));
     $template->value = \Session::getInstance()->get($objTreeSelector->getSearchSessionKey());
     $template->manager = $GLOBALS['TL_LANG']['MSC']['treepickerManager'];
     $template->breadcrumb = $GLOBALS['TL_DCA'][$objTreeSelector->foreignTable]['list']['sorting']['breadcrumb'];
     $template->managerHref = '';
     // Add the manager link.
     if ($objTreeSelector->managerHref) {
         $template->managerHref = 'contao/main.php?' . ampersand($objTreeSelector->managerHref) . '&popup=1';
     }
     // Prevent debug output at all cost.
     $GLOBALS['TL_CONFIG']['debugMode'] = false;
     $template->output();
 }
예제 #7
0
 /**
  * Obtain the values of a property within a dc-general instance.
  *
  * @param IMetaModel           $metaModel   The metamodel instance to obtain the values from.
  *
  * @param EnvironmentInterface $environment The environment used in the input screen table dc-general.
  *
  * @param IAttribute           $attribute   The attribute to obtain the values for.
  *
  * @return array
  */
 private function getOptionsViaDcGeneral($metaModel, $environment, $attribute)
 {
     $factory = new DcGeneralFactory();
     $dcGeneral = $factory->setContainerName($metaModel->getTableName())->setEventDispatcher($environment->getEventDispatcher())->setTranslator($environment->getTranslator())->createDcGeneral();
     $subEnv = $dcGeneral->getEnvironment();
     $optEv = new GetPropertyOptionsEvent($subEnv, $subEnv->getDataProvider()->getEmptyModel());
     $optEv->setPropertyName($attribute->getColName());
     $subEnv->getEventDispatcher()->dispatch(GetPropertyOptionsEvent::NAME, $optEv);
     $options = $optEv->getOptions();
     return $options;
 }