Ejemplo n.º 1
0
 /**
  * Renders a select element to select an entity
  *
  * @param array $params: Field information to be rendered
  * @param \TYPO3\CMS\Core\TypoScript\ExtendedTemplateService $pObj: The calling parent object.
  * @return string The HTML input field
  */
 public function buildEntitySelector(array $params, \TYPO3\CMS\Core\TypoScript\ExtendedTemplateService $pObj, $arg = '')
 {
     $field = '';
     $this->objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
     switch ($params['fieldName']) {
         case 'data[plugin.tx_staticinfotables_pi1.countryCode]':
         case 'data[plugin.tx_staticinfotables_pi1.countriesAllowed]':
             $repository = $this->objectManager->get('SJBR\\StaticInfoTables\\Domain\\Repository\\CountryRepository');
             $entities = $repository->findAllOrderedBy('nameLocalized');
             break;
         case 'data[plugin.tx_staticinfotables_pi1.countryZoneCode]':
             $repository = $this->objectManager->get('SJBR\\StaticInfoTables\\Domain\\Repository\\CountryZoneRepository');
             $countryCode = $this->getConfiguredCountryCode();
             if ($countryCode) {
                 $countryRepository = $this->objectManager->get('SJBR\\StaticInfoTables\\Domain\\Repository\\CountryRepository');
                 $country = $countryRepository->findOneByIsoCodeA3($countryCode);
                 if (is_object($country)) {
                     $entities = $repository->findByCountryOrderedByLocalizedName($country);
                 }
             }
             if (!$countryCode || empty($entities) && $params['fieldValue']) {
                 $entities = $repository->findAllOrderedBy('nameLocalized');
             }
             break;
         case 'data[plugin.tx_staticinfotables_pi1.currencyCode]':
             $repository = $this->objectManager->get('SJBR\\StaticInfoTables\\Domain\\Repository\\CurrencyRepository');
             $entities = $repository->findAllOrderedBy('nameLocalized');
             break;
         case 'data[plugin.tx_staticinfotables_pi1.languageCode]':
             $repository = $this->objectManager->get('SJBR\\StaticInfoTables\\Domain\\Repository\\LanguageRepository');
             $entities = $repository->findAllNonConstructedNonSacred();
             $entities = $repository->localizedSort($entities);
             break;
     }
     if (is_array($entities) && count($entities)) {
         $options = array();
         foreach ($entities as $entity) {
             switch ($params['fieldName']) {
                 case 'data[plugin.tx_staticinfotables_pi1.countryZoneCode]':
                     $value = $entity->getIsoCode();
                     $options[] = array('name' => $entity->getNameLocalized() . ' (' . $value . ')', 'value' => $value);
                     break;
                 case 'data[plugin.tx_staticinfotables_pi1.countryCode]':
                 case 'data[plugin.tx_staticinfotables_pi1.countriesAllowed]':
                 case 'data[plugin.tx_staticinfotables_pi1.currencyCode]':
                     $value = $entity->getIsoCodeA3();
                     $options[] = array('name' => $entity->getNameLocalized() . ' (' . $value . ')', 'value' => $value);
                     break;
                 case 'data[plugin.tx_staticinfotables_pi1.languageCode]':
                     $countryCode = $entity->getCountryIsoCodeA2();
                     $value = $entity->getIsoCodeA2() . ($countryCode ? '_' . $countryCode : '');
                     $options[] = array('name' => $entity->getNameLocalized() . ' (' . $value . ')', 'value' => $value);
                     break;
             }
         }
         $outSelected = array();
         $size = $params['fieldName'] == 'data[plugin.tx_staticinfotables_pi1.countriesAllowed]' ? 5 : 1;
         $field = \SJBR\StaticInfoTables\Utility\HtmlElementUtility::selectConstructor($options, array($params['fieldValue']), $outSelected, $params['fieldName'], '', '', '', '', $size);
     }
     return $field;
 }
Ejemplo n.º 2
0
 /**
  * Return a single input form field.
  *
  * @param string $fieldName Name of the field
  * @param array $fieldConfig Configuration of this field
  * @param string $fieldValue Current value of this field
  * @param string $step Name of the step
  *
  * @return string Single input field
  */
 protected function getInputField($fieldName, array $fieldConfig, $fieldValue, $step)
 {
     $this->debug($step, '$step', __FILE__ . ' ' . __LINE__);
     $this->debug($fieldConfig, '$fieldConfig', __FILE__ . ' ' . __LINE__);
     $this->debug($fieldValue, '$fieldValue', __FILE__ . ' ' . __LINE__);
     switch (strtolower($fieldConfig['type'])) {
         case 'select':
             $result = $this->getSelectInputField($fieldName, $fieldConfig, $fieldValue, $step);
             break;
         case 'static_info_tables':
             $selected = $fieldValue != '' ? $fieldValue : $fieldConfig['default'];
             $result = $this->staticInfo->buildStaticInfoSelector($fieldConfig['field'], $this->prefixId . '[' . $step . '][' . $fieldName . ']', $fieldConfig['cssClass'], $selected, '', '', $step . '-' . $fieldName, '', $fieldConfig['select'], $this->getFrontendController()->tmpl->setup['config.']['language']);
             break;
         case 'static_info_country':
             $nameArray = $this->staticInfo->initCountries($fieldConfig['country_association'], $this->getFrontendController()->tmpl->setup['config.']['language'], 1, $fieldConfig['select']);
             asort($nameArray, SORT_LOCALE_STRING);
             $countries = array();
             foreach ($nameArray as $itemKey => $itemName) {
                 $countries[] = array('name' => $itemName, 'value' => $itemKey);
             }
             $selected = $fieldValue != '' ? $fieldValue : $fieldConfig['default'];
             $result = '<select id="' . $step . '-' . $fieldName . '" name="' . $this->prefixId . '[' . $step . '][' . $fieldName . ']" class="' . $fieldConfig['cssClass'] . '">' . LF;
             $options = array();
             $result .= \SJBR\StaticInfoTables\Utility\HtmlElementUtility::optionsConstructor($countries, array($selected), $options);
             $result .= implode(LF, $options) . '</select>' . LF;
             break;
         case 'check':
             $result = $this->getCheckboxInputField($fieldName, $fieldConfig, $fieldValue, $step);
             break;
         case 'hidden':
             // fall through
         // fall through
         case 'single':
             // fall through
         // fall through
         default:
             $result = $this->getSingleInputField($fieldName, $fieldConfig, $step);
     }
     return $result;
 }
Ejemplo n.º 3
0
 /**
  * Buils a HTML drop-down selector of countries, country subdivisions, currencies or languages
  *
  * @param	string		Defines the type of entries to be presented in the drop-down selector: 'COUNTRIES', 'SUBDIVISIONS', 'CURRENCIES' or 'LANGUAGES'
  * @param	string		A value for the name attribute of the <select> tag
  * @param	string		A value for the class attribute of the <select> tag
  * @param	array		The values of the code of the entries to be pre-selected in the drop-down selector: value of cn_iso_3, zn_code, cu_iso_3 or lg_iso_2
  * @param	string		The value of the country code (cn_iso_3) for which a drop-down selector of type 'SUBDIVISIONS' is requested (meaningful only in this case)
  * @param	boolean/string		If set to 1, an onchange attribute will be added to the <select> tag for immediate submit of the changed value; if set to other than 1, overrides the onchange script
  * @param	string		A value for the id attribute of the <select> tag
  * @param	string		A value for the title attribute of the <select> tag
  * @param	string		A where clause for the records
  * @param	string		language to be used
  * @param	boolean		$local: If set, we are looking for the "local" title field
  * @param	array		additional array to be merged as key => value pair
  * @param	int		max elements that can be selected. Default: 1
  * @param	array		out: resulting selected array with the ISO alpha-3 code of the countries
  * @return	string		A set of HTML <select> and <option> tags
  */
 public function buildStaticInfoSelector($type = 'COUNTRIES', $name = '', $class = '', $selectedArray = array(), $country = '', $submit = 0, $id = '', $title = '', $addWhere = '', $lang = '', $local = FALSE, $mergeArray = array(), $size = 1, &$outSelectedArray = array())
 {
     $selector = '';
     if (isset($selectedArray) && !is_array($selectedArray)) {
         $selectedArray = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $selectedArray);
     }
     $country = trim($country);
     $onChange = '';
     if ($submit) {
         if ($submit == 1) {
             $onChange = $this->conf['onChangeAttribute'];
         } else {
             $onChange = $submit;
         }
     }
     switch ($type) {
         case 'COUNTRIES':
             $nameArray = $this->initCountries('ALL', $lang, $local, $addWhere);
             $defaultSelectedArray = array($this->defaultCountry);
             break;
         case 'SUBDIVISIONS':
             $param = trim($country) ? trim($country) : $this->defaultCountry;
             $nameArray = $this->initCountrySubdivisions($param, $addWhere);
             if ($param == $this->defaultCountry) {
                 $defaultSelectedArray = array($this->defaultCountryZone);
             }
             break;
         case 'CURRENCIES':
             $nameArray = $this->initCurrencies($addWhere);
             $defaultSelectedArray = array($this->currency);
             break;
         case 'LANGUAGES':
             $nameArray = $this->initLanguages($addWhere);
             $defaultSelectedArray = array($this->defaultLanguage);
             break;
     }
     if (!$defaultSelectedArray) {
         reset($nameArray);
         $defaultSelectedArray = array(key($nameArray));
     }
     $bEmptySelected = empty($selectedArray) || count($selectedArray) == 1 && empty($selectedArray[0]);
     $selectedArray = !$bEmptySelected || count($mergeArray) ? $selectedArray : $defaultSelectedArray;
     if (count($mergeArray)) {
         $nameArray = array_merge($nameArray, $mergeArray);
         uasort($nameArray, 'strcoll');
     }
     if (count($nameArray) > 0) {
         $items = array();
         foreach ($nameArray as $itemKey => $itemName) {
             $items[] = array('name' => $itemName, 'value' => $itemKey);
         }
         $selector = \SJBR\StaticInfoTables\Utility\HtmlElementUtility::selectConstructor($items, $selectedArray, $outSelectedArray, $name, $class, $id, $title, $onChange, $size);
     }
     return $selector;
 }