Example #1
0
 /**
  * Rebuild the class cache
  *
  * @param array $parameters
  *
  * @throws \Evoweb\Extender\Exception\FileNotFoundException
  * @throws \TYPO3\CMS\Core\Cache\Exception\InvalidDataException
  * @return void
  */
 public function reBuild(array $parameters = array())
 {
     if (empty($parameters) || !empty($parameters['cacheCmd']) && GeneralUtility::inList('all,system', $parameters['cacheCmd']) && isset($GLOBALS['BE_USER'])) {
         foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF'] as $extensionKey => $extensionConfiguration) {
             if (!isset($extensionConfiguration['extender']) || !is_array($extensionConfiguration['extender'])) {
                 continue;
             }
             foreach ($extensionConfiguration['extender'] as $entity => $entityConfiguration) {
                 $key = 'Domain/Model/' . $entity;
                 // Get the file to extend, this needs to be loaded as first
                 $path = ExtensionManagementUtility::extPath($extensionKey) . 'Classes/' . $key . '.php';
                 if (!is_file($path)) {
                     throw new \Evoweb\Extender\Exception\FileNotFoundException('given file "' . $path . '" does not exist');
                 }
                 $code = $this->parseSingleFile($path, false);
                 // Get the files from all other extensions that are extending this domain model
                 if (is_array($entityConfiguration)) {
                     foreach ($entityConfiguration as $extendingExtension => $extendingFilepath) {
                         $path = GeneralUtility::getFileAbsFileName($extendingFilepath, false);
                         if (!is_file($path) && !is_numeric($extendingExtension)) {
                             $path = ExtensionManagementUtility::extPath($extendingExtension) . 'Classes/' . $key . '.php';
                         }
                         $code .= $this->parseSingleFile($path);
                     }
                 }
                 // Close the class definition
                 $code = $this->closeClassDefinition($code);
                 // Add the new file to the class cache
                 $cacheEntryIdentifier = GeneralUtility::underscoredToLowerCamelCase($extensionKey) . '_' . str_replace('/', '', $key);
                 $this->cacheInstance->set($cacheEntryIdentifier, $code);
             }
         }
     }
 }
 /**
  * Solution for {outer.{inner}} call in fluid
  *
  * @param object|array $obj object or array
  * @param string $prop property name
  * @return mixed
  */
 public function render($obj, $prop)
 {
     if (is_array($obj) && array_key_exists($prop, $obj)) {
         return $obj[$prop];
     }
     if (is_object($obj)) {
         return ObjectAccess::getProperty($obj, GeneralUtility::underscoredToLowerCamelCase($prop));
     }
     return null;
 }
 /**
  * Loads php files containing classes or interfaces found in the classes directory of
  * an extension.
  *
  * @param string $className: Name of the class/interface to load
  * @uses \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath()
  * @return void
  */
 public static function loadClass($className)
 {
     $delimiter = '\\';
     $index = 1;
     if (strpos($delimiter, $className) === FALSE) {
         $delimiter = '_';
         $index = 2;
     }
     $classNameParts = explode($delimiter, $className, 4);
     $extensionKey = \TYPO3\CMS\Core\Utility\GeneralUtility::underscoredToLowerCamelCase($classNameParts[$index]);
     $classFilePathAndName = PATH_typo3conf . 'ext/' . $extensionKey . '/Classes/' . strtr($classNameParts[$index + 1], $delimiter, '/') . '.php';
     if (file_exists($classFilePathAndName)) {
         require_once $classFilePathAndName;
     }
 }
Example #4
0
 /**
  * @return string
  */
 public function toPropertyName()
 {
     $fieldName = $this->getFieldName();
     $tableName = $this->getTableName();
     if (empty($this->storage[$tableName][$fieldName])) {
         if ($this->storage[$tableName]) {
             $this->storage[$tableName] = array();
         }
         // Special case when the field name does not follow the conventions "field_name" => "fieldName".
         // Rely on mapping for those cases.
         if (!empty($GLOBALS['TCA'][$tableName]['vidi']['mappings'][$fieldName])) {
             $propertyName = $GLOBALS['TCA'][$tableName]['vidi']['mappings'][$fieldName];
         } else {
             $propertyName = GeneralUtility::underscoredToLowerCamelCase($fieldName);
         }
         $this->storage[$tableName][$fieldName] = $propertyName;
     }
     return $this->storage[$tableName][$fieldName];
 }
Example #5
0
 /**
  * Validate ordering as extbase can't handle that currently
  *
  * @param string $fieldToCheck
  * @param string $allowedSettings
  * @return boolean
  */
 public static function isValidOrdering($fieldToCheck, $allowedSettings)
 {
     $isValid = TRUE;
     if (empty($fieldToCheck)) {
         return $isValid;
     } elseif (empty($allowedSettings)) {
         return FALSE;
     }
     $fields = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $fieldToCheck, TRUE);
     foreach ($GLOBALS['TCA']['tx_mooxnews_domain_model_news']['columns'] as $fieldname => $field) {
         if ($field['addToMooxNewsFrontendSorting']) {
             $allowedSettings .= "," . \TYPO3\CMS\Core\Utility\GeneralUtility::underscoredToLowerCamelCase($fieldname);
         } else {
             $nameParts = explode("_", $fieldname);
             if ($nameParts[count($nameParts) - 1] == "sortfield") {
                 if (isset($GLOBALS['TCA']['tx_mooxnews_domain_model_news']['columns'][str_replace("_sortfield", "", $fieldname)])) {
                     $allowedSettings .= "," . \TYPO3\CMS\Core\Utility\GeneralUtility::underscoredToLowerCamelCase($fieldname);
                 }
             }
         }
     }
     foreach ($fields as $field) {
         if ($isValid === TRUE) {
             $split = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(' ', $field, TRUE);
             $count = count($split);
             switch ($count) {
                 case 1:
                     if (!\TYPO3\CMS\Core\Utility\GeneralUtility::inList($allowedSettings, $split[0])) {
                         $isValid = FALSE;
                     }
                     break;
                 case 2:
                     if (strtolower($split[1]) !== 'desc' && strtolower($split[1]) !== 'asc' || !\TYPO3\CMS\Core\Utility\GeneralUtility::inList($allowedSettings, $split[0])) {
                         $isValid = FALSE;
                     }
                     break;
                 default:
                     $isValid = FALSE;
             }
         }
     }
     return $isValid;
 }
Example #6
0
 /**
  * @param string $string
  * @param string $case
  * @return string
  */
 public function render($string = null, $case = null)
 {
     if (null === $string) {
         $string = $this->renderChildren();
     }
     if ('BE' === TYPO3_MODE) {
         $tsfeBackup = FrontendSimulationUtility::simulateFrontendEnvironment();
     }
     $charset = $GLOBALS['TSFE']->renderCharset;
     switch ($case) {
         case self::CASE_LOWER:
             $string = $GLOBALS['TSFE']->csConvObj->conv_case($charset, $string, 'toLower');
             break;
         case self::CASE_UPPER:
             $string = $GLOBALS['TSFE']->csConvObj->conv_case($charset, $string, 'toUpper');
             break;
         case self::CASE_UCWORDS:
             $string = ucwords($string);
             break;
         case self::CASE_UCFIRST:
             $string = $GLOBALS['TSFE']->csConvObj->convCaseFirst($charset, $string, 'toUpper');
             break;
         case self::CASE_LCFIRST:
             $string = $GLOBALS['TSFE']->csConvObj->convCaseFirst($charset, $string, 'toLower');
             break;
         case self::CASE_CAMELCASE:
             $string = GeneralUtility::underscoredToUpperCamelCase($string);
             break;
         case self::CASE_LOWERCAMELCASE:
             $string = GeneralUtility::underscoredToLowerCamelCase($string);
             break;
         case self::CASE_UNDERSCORED:
             $string = GeneralUtility::camelCaseToLowerCaseUnderscored($string);
             break;
         default:
             break;
     }
     if ('BE' === TYPO3_MODE) {
         FrontendSimulationUtility::resetFrontendEnvironment($tsfeBackup);
     }
     return $string;
 }
 /**
  * Preprocess fields from database-record for use in fluid-templates
  *
  * @param ContentObjectRenderer $cObj The data of the content element or page
  * @param array $contentObjectConfiguration The configuration of Content Object
  * @param array $processorConfiguration The configuration of this processor
  * @param array $processedData Key/value store of processed data (e.g. to be passed to a Fluid View)
  * @return array the processed data as key/value store
  */
 public function process(ContentObjectRenderer $cObj, array $contentObjectConfiguration, array $processorConfiguration, array $processedData)
 {
     if (isset($processorConfiguration['if.']) && !$cObj->checkIf($processorConfiguration['if.'])) {
         return $processedData;
     }
     // The field name to process
     $fieldName = $cObj->stdWrapValue('fieldName', $processorConfiguration);
     if (empty($fieldName)) {
         return $processedData;
     }
     // Set the target variable
     $defaultTargetName = GeneralUtility::underscoredToLowerCamelCase($fieldName);
     $targetVariableName = $cObj->stdWrapValue('as', $processorConfiguration, $defaultTargetName);
     // Let's see if we got a parentField from which the values should be retrieved
     $parentField = $cObj->stdWrapValue('parentField', $processorConfiguration);
     // Get settings from TypoScript
     if (!empty($parentField)) {
         $settings = $contentObjectConfiguration['settings.'][$fieldName . '.'][$cObj->data[$parentField] . '.'];
     } else {
         $settings = $contentObjectConfiguration['settings.'][$fieldName . '.'];
     }
     // Get value database
     $fieldValue = $cObj->data[$fieldName];
     // Fill output with value from TypoScript
     if (!empty($fieldValue)) {
         // Use the value defined in database
         $output = $settings[$fieldValue];
     } else {
         if ($settings['default'] !== '' && $settings[$settings['default']] !== '') {
             // Use default value (if set)
             $output = $settings[$settings['default']];
         } else {
             $output = '';
         }
     }
     $processedData[$targetVariableName] = $output;
     return $processedData;
 }
Example #8
0
 /**
  * Loads php files containing classes or interfaces part of the
  * classes directory of an extension.
  *
  * @param string $className Name of the class/interface to load
  *
  * @return bool
  */
 public function loadClass($className)
 {
     $className = ltrim($className, '\\');
     $extensionKey = $this->getExtensionKey($className);
     $classNameParts = GeneralUtility::trimExplode('\\', $className);
     $entityKey = array_pop($classNameParts);
     if (!$this->isValidClassName($className, $extensionKey, $entityKey)) {
         return false;
     }
     $cacheEntryIdentifier = GeneralUtility::underscoredToLowerCamelCase($extensionKey) . '_' . str_replace('/', '', 'Domain/Model/' . $entityKey);
     $classCache = $this->initializeCache();
     if (!$classCache->has($cacheEntryIdentifier)) {
         /**
          * Class cache manager
          *
          * @var \Evoweb\Extender\Utility\ClassCacheManager $classCacheManager
          */
         $classCacheManager = GeneralUtility::makeInstance('Evoweb\\Extender\\Utility\\ClassCacheManager');
         $classCacheManager->reBuild();
     }
     $classCache->requireOnce($cacheEntryIdentifier);
     return true;
 }
Example #9
0
 /**
  * Checks for attribute in _contentRow
  *
  * @param string $name Name of unknown method
  * @param array arguments Arguments of call
  * @return mixed
  */
 public function __call($name, $arguments)
 {
     if (substr(strtolower($name), 0, 3) == 'get' && strlen($name) > 3) {
         $attributeName = lcfirst(substr($name, 3));
         if (empty($this->_contentRow)) {
             /** @var \TYPO3\CMS\Frontend\Page\PageRepository $pageSelect */
             $pageSelect = $GLOBALS['TSFE']->sys_page;
             $contentRow = $pageSelect->getRawRecord('tt_content', $this->getUid());
             foreach ($contentRow as $key => $value) {
                 $this->_contentRow[\TYPO3\CMS\Core\Utility\GeneralUtility::underscoredToLowerCamelCase($key)] = $value;
             }
         }
         if (isset($this->_contentRow[$attributeName])) {
             return $this->_contentRow[$attributeName];
         }
     }
 }
 /**
  *	Aller TCA Felder holen für bestimmte Tabelle
  *
  */
 public static function getTCAColumns($table = 'tx_nnmembers_domain_model_member')
 {
     $cols = $GLOBALS['TCA'][$table]['columns'];
     foreach ($cols as $k => $v) {
         $cols[\TYPO3\CMS\Core\Utility\GeneralUtility::underscoredToLowerCamelCase($k)] = $v;
     }
     return $cols;
 }
Example #11
0
 /**
  * transforms a columnName to a property name
  * 
  * @param  string $columnName
  * @return string
  */
 public static function columnToProperty($columnName)
 {
     return \TYPO3\CMS\Core\Utility\GeneralUtility::underscoredToLowerCamelCase($columnName);
 }
Example #12
0
 protected function generatePluginFiles()
 {
     if ($this->extension->getPlugins()) {
         try {
             $fileContents = $this->renderTemplate(GeneralUtility::underscoredToLowerCamelCase('ext_localconf.phpt'), array('extension' => $this->extension));
             $this->writeFile($this->extensionDirectory . 'ext_localconf.php', $fileContents);
             GeneralUtility::devlog('Generated ext_localconf.php', 'extension_builder', 0, array('Content' => $fileContents));
         } catch (\Exception $e) {
             throw new \Exception('Could not write ext_localconf.php. Error: ' . $e->getMessage());
         }
         $currentPluginKey = '';
         try {
             foreach ($this->extension->getPlugins() as $plugin) {
                 /**
                  * @var $plugin \EBT\ExtensionBuilder\Domain\Model\Plugin
                  */
                 if ($plugin->getSwitchableControllerActions()) {
                     if (!is_dir($this->extensionDirectory . 'Configuration/FlexForms')) {
                         $this->mkdir_deep($this->extensionDirectory, 'Configuration/FlexForms');
                     }
                     $currentPluginKey = $plugin->getKey();
                     $fileContents = $this->renderTemplate('Configuration/Flexforms/flexform.xmlt', array('plugin' => $plugin));
                     $this->writeFile($this->extensionDirectory . 'Configuration/FlexForms/flexform_' . $currentPluginKey . '.xml', $fileContents);
                     GeneralUtility::devlog('Generated flexform_' . $currentPluginKey . '.xml', 'extension_builder', 0, array('Content' => $fileContents));
                 }
             }
         } catch (\Exception $e) {
             throw new \Exception('Could not write  flexform_' . $currentPluginKey . '.xml. Error: ' . $e->getMessage());
         }
     }
 }
Example #13
0
 /**
  * Renders browsable schema for ViewHelpers in extension selected in
  * plugin onfiguration. Has a maximum namespace depth of five levels
  * from the Tx_ExtensionKey_ViewHelpers location which should fit
  * all reasonable setups.
  *
  * @param string $extensionKey
  * @param string $version
  * @param string $p1
  * @param string $p2
  * @param string $p3
  * @param string $p4
  * @param string $p5
  * @return string
  * @route NoMatch('bypass')
  */
 public function schemaAction($extensionKey = NULL, $version = NULL, $p1 = NULL, $p2 = NULL, $p3 = NULL, $p4 = NULL, $p5 = NULL)
 {
     if (NULL === $extensionKey) {
         $extensionKey = $this->getExtensionKeySetting();
         if (NULL === $extensionKey) {
             $extensionKey = 'TYPO3.Fluid';
         }
         if (NULL === $version) {
             $version = 'master';
         }
     }
     list($vendor, $extensionKey) = $this->schemaService->getRealExtensionKeyAndVendorFromCombinedExtensionKey($extensionKey);
     $schemaFile = $this->getXsdStoragePathSetting() . $extensionKey . '-' . $version . '.xsd';
     $schemaFile = GeneralUtility::getFileAbsFileName($schemaFile);
     $namespaceName = str_replace('_', '', $extensionKey);
     $namespaceName = strtolower($namespaceName);
     $namespaceAlias = str_replace('_', '', $extensionKey);
     if (isset($this->extensionKeyToNamespaceMap[$extensionKey])) {
         $namespaceAlias = $this->extensionKeyToNamespaceMap[$extensionKey];
     }
     $relativeSchemaFile = substr($schemaFile, strlen(GeneralUtility::getFileAbsFileName('.')) - 1);
     $segments = array($p1, $p2, $p3, $p4, $p5);
     $segments = $this->trimPathSegments($segments);
     if (TRUE === empty($version)) {
         $version = 'master';
     }
     $arguments = $this->segmentsToArguments($extensionKey, $version, $segments);
     $extensionName = GeneralUtility::underscoredToLowerCamelCase($extensionKey);
     $extensionName = ucfirst($extensionName);
     $extensionKeys = $this->getExtensionKeysSetting();
     $versions = $this->getVersionsByExtensionKey($extensionKey);
     $displayHeadsUp = FALSE;
     if (isset($this->extensionKeyToNamespaceMap[$namespaceName])) {
         $namespaceName = $this->extensionKeyToNamespaceMap[$namespaceName];
     }
     list($tree, $node, $viewHelperArguments, $docComment, $targetNamespaceUrl) = $this->getSchemaData($extensionKey, $version, $segments);
     $gitCommand = '/usr/bin/git';
     if (FALSE === file_exists($gitCommand)) {
         $gitCommand = '/usr/local/bin/git';
     }
     $className = implode('/', $segments);
     if (TRUE === ExtensionManagementUtility::isLoaded($extensionKey)) {
         if (empty($className)) {
             $extensionPath = ExtensionManagementUtility::extPath($extensionKey);
             $readmeFile = $extensionPath . 'Classes/ViewHelpers/README.md';
             if (TRUE === file_exists($readmeFile)) {
                 $readmeFile = file_get_contents($readmeFile);
             } else {
                 unset($readmeFile);
             }
         }
     }
     $variables = array('action' => 'schema', 'readmeFile' => $readmeFile, 'name' => end($segments), 'schemaFile' => $relativeSchemaFile, 'keys' => array(), 'namespaceUrl' => $targetNamespaceUrl, 'displayHeadsUp' => $displayHeadsUp, 'namespaceName' => $namespaceName, 'namespaceAlias' => $namespaceAlias, 'className' => $className, 'ns' => $namespaceName, 'isFile' => NULL !== $node, 'arguments' => $arguments, 'segments' => $segments, 'markdownBlacklisted' => in_array($extensionKey, $this->markdownBlacklistedExtensionKeys), 'viewHelperArguments' => $viewHelperArguments, 'docComment' => $docComment, 'tree' => $tree, 'version' => $version, 'versions' => $versions, 'extensionKey' => $extensionKey, 'extensionKeys' => $extensionKeys, 'extensionName' => $extensionName, 'showJumpLinks' => TRUE);
     $this->view->assignMultiple($variables);
 }
 /**
  * Changing character case of a string, converting typically used western charset characters as well.
  *
  * @param string $theValue The string to change case for.
  * @param string $case The direction; either "upper" or "lower
  * @return string
  * @see HTMLcaseshift()
  */
 public function caseshift($theValue, $case)
 {
     $tsfe = $this->getTypoScriptFrontendController();
     switch (strtolower($case)) {
         case 'upper':
             $theValue = $tsfe->csConvObj->conv_case($tsfe->renderCharset, $theValue, 'toUpper');
             break;
         case 'lower':
             $theValue = $tsfe->csConvObj->conv_case($tsfe->renderCharset, $theValue, 'toLower');
             break;
         case 'capitalize':
             $theValue = ucwords($theValue);
             break;
         case 'ucfirst':
             $theValue = $tsfe->csConvObj->convCaseFirst($tsfe->renderCharset, $theValue, 'toUpper');
             break;
         case 'lcfirst':
             $theValue = $tsfe->csConvObj->convCaseFirst($tsfe->renderCharset, $theValue, 'toLower');
             break;
         case 'uppercamelcase':
             $theValue = GeneralUtility::underscoredToUpperCamelCase($theValue);
             break;
         case 'lowercamelcase':
             $theValue = GeneralUtility::underscoredToLowerCamelCase($theValue);
             break;
     }
     return $theValue;
 }
Example #15
0
 /**
  * @param string $table
  * @param string $type
  * @return string
  */
 protected function getLabelPropertyName($table, $type)
 {
     $typoScript = $this->getConfigurationService()->getAllTypoScript();
     if (TRUE === isset($typoScript['config']['tx_extbase']['persistence']['classes'][$type])) {
         $mapping = $typoScript['config']['tx_extbase']['persistence']['classes'][$type];
         if (TRUE === isset($mapping['mapping']['tableName'])) {
             $table = $mapping['mapping']['tableName'];
         }
     }
     $labelField = $GLOBALS['TCA'][$table]['ctrl']['label'];
     $propertyName = GeneralUtility::underscoredToLowerCamelCase($labelField);
     return $propertyName;
 }
 /**
  * Is {outer.{inner}} a datetime?
  *
  * @param object $obj
  * @param string $prop Property
  * @return bool
  */
 public function render($obj, $prop)
 {
     return is_a(ObjectAccess::getProperty($obj, GeneralUtility::underscoredToLowerCamelCase($prop)), '\\DateTime');
 }
 /**
  * Changing character case of a string, converting typically used western charset characters as well.
  *
  * @param string $theValue The string to change case for.
  * @param string $case The direction; either "upper" or "lower
  * @return string
  * @see HTMLcaseshift()
  */
 public function caseshift($theValue, $case)
 {
     /** @var CharsetConverter $charsetConverter */
     $charsetConverter = GeneralUtility::makeInstance(CharsetConverter::class);
     switch (strtolower($case)) {
         case 'upper':
             $theValue = $charsetConverter->conv_case('utf-8', $theValue, 'toUpper');
             break;
         case 'lower':
             $theValue = $charsetConverter->conv_case('utf-8', $theValue, 'toLower');
             break;
         case 'capitalize':
             $theValue = ucwords($theValue);
             break;
         case 'ucfirst':
             $theValue = $charsetConverter->convCaseFirst('utf-8', $theValue, 'toUpper');
             break;
         case 'lcfirst':
             $theValue = $charsetConverter->convCaseFirst('utf-8', $theValue, 'toLower');
             break;
         case 'uppercamelcase':
             $theValue = GeneralUtility::underscoredToUpperCamelCase($theValue);
             break;
         case 'lowercamelcase':
             $theValue = GeneralUtility::underscoredToLowerCamelCase($theValue);
             break;
     }
     return $theValue;
 }
Example #18
0
 /**
  * Get extended filters from external extensions
  *
  * @param Tx_MooxNews_Domain_Model_Dto_NewsDemand $demand
  * @param array $overwriteDemand
  * @return array extendedFields
  */
 public function getExtendedFilters($demand, $overwriteDemand = NULL)
 {
     $extendedFilters = array();
     if ($this->settings['addExtendedFilter']) {
         foreach ($GLOBALS['TCA']['tx_mooxnews_domain_model_news']['columns'] as $fieldname => $field) {
             if ($field['addToMooxNewsFrontendFilter'] && ($demand->getType() == "" || $demand->getType() == $field['extkey'])) {
                 $fieldnameLCC = \TYPO3\CMS\Core\Utility\GeneralUtility::underscoredToLowerCamelCase($fieldname);
                 $fieldnameUCC = \TYPO3\CMS\Core\Utility\GeneralUtility::underscoredToUpperCamelCase($fieldname);
                 $extkey = \TYPO3\CMS\Core\Utility\GeneralUtility::underscoredToLowerCamelCase($field['extkey']);
                 $label = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate($field['label'], $field['extkey']);
                 if ($this->isAjaxRequest) {
                     if ($field['config']['type'] == "select") {
                         $type = "select";
                     } elseif ($field['config']['type'] == "input" && $field['addToMooxNewsFrontendFilter']['type'] == "select") {
                         $type = "select";
                     } else {
                         $type = "default";
                     }
                     $extendedFilters[] = array("name" => $fieldnameLCC, "type" => $type);
                 } else {
                     if ($field['config']['type'] == "select") {
                         $items = array();
                         if (is_array($field['config']['items'])) {
                             foreach ($field['config']['items'] as $item) {
                                 if ($item[1] == "") {
                                     $item[1] = "all";
                                 }
                                 if ($item[1] == "all") {
                                     if ($field['addToMooxNewsFrontendFilter']['selectAllLabel'] != "") {
                                         $item[0] = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate($field['addToMooxNewsFrontendFilter']['selectAllLabel'], $field['extkey']);
                                     } else {
                                         $item[0] = "Alle";
                                     }
                                     $items[$item[1]] = $item[0];
                                 } else {
                                     $label = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate($item[0], $field['extkey']);
                                     if ($label == "") {
                                         $label = $item[0];
                                     }
                                     $items[$item[1]] = $label;
                                 }
                             }
                         }
                         $depends = array();
                         $dependFields = array();
                         $displayDepends = array();
                         if (count($field['addToMooxNewsFrontendFilter']['depends'])) {
                             foreach ($field['addToMooxNewsFrontendFilter']['depends'] as $depend) {
                                 if (isset($GLOBALS['TCA']['tx_mooxnews_domain_model_news']['columns'][$depend])) {
                                     $dependField = $GLOBALS['TCA']['tx_mooxnews_domain_model_news']['columns'][$depend];
                                     if ($dependField['config']['type'] == "select" || $dependField['config']['type'] == "input" && $dependField['addToMooxNewsFrontendFilter']['type'] == "select") {
                                         $depends[] = \TYPO3\CMS\Core\Utility\GeneralUtility::underscoredToLowerCamelCase($depend);
                                         $dependField = \TYPO3\CMS\Core\Utility\GeneralUtility::underscoredToLowerCamelCase($depend);
                                         if (isset($overwriteDemand[$dependField]) && $overwriteDemand[$dependField] != "all") {
                                             $dependFields[$depend] = $overwriteDemand[$dependField];
                                         }
                                     }
                                 }
                             }
                         }
                         if (count($field['addToMooxNewsFrontendFilter']['displayDepends'])) {
                             foreach ($field['addToMooxNewsFrontendFilter']['displayDepends'] as $displayDepend) {
                                 if (isset($GLOBALS['TCA']['tx_mooxnews_domain_model_news']['columns'][$displayDepend])) {
                                     $displayDependField = $GLOBALS['TCA']['tx_mooxnews_domain_model_news']['columns'][$displayDepend];
                                     if ($displayDependField['config']['type'] == "select" || $displayDependField['config']['type'] == "input" && $displayDependField['addToMooxNewsFrontendFilter']['type'] == "select") {
                                         $displayDepends[] = \TYPO3\CMS\Core\Utility\GeneralUtility::underscoredToLowerCamelCase($displayDepend);
                                     }
                                 }
                             }
                         }
                         if ($field['config']['foreign_table'] != "") {
                             $itemsFromDb = $this->newsRepository->findExtendedFilterItems($fieldname, $demand->getStoragePage(), $field['config']['foreign_table'], $field['config']['foreign_table_where'], $dependFields);
                             foreach ($itemsFromDb as $item) {
                                 $items[$item['uid']] = $item['title'];
                             }
                         }
                         if (count($items)) {
                             if (!isset($items['all'])) {
                                 if ($field['addToMooxNewsFrontendFilter']['selectAllLabel'] != "") {
                                     $selectAllLabel = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate($field['addToMooxNewsFrontendFilter']['selectAllLabel'], $field['extkey']);
                                 } else {
                                     $selectAllLabel = "Alle";
                                 }
                                 $itemsTmp = $items;
                                 $items = array();
                                 $items["all"] = $selectAllLabel;
                                 foreach ($itemsTmp as $key => $value) {
                                     $items[$key] = $value;
                                 }
                                 unset($itemsTmp);
                             }
                             $extendedFilters[] = array("label" => $label, "name" => $fieldnameLCC, "type" => 'select', "field" => $fieldname, "fieldUCC" => $fieldnameUCC, "items" => $items, "depends" => $depends, "displayDepends" => $displayDepends);
                         }
                     } elseif ($field['config']['type'] == "input" && $field['addToMooxNewsFrontendFilter']['type'] == "select") {
                         if (!isset($overwriteDemand[$fieldnameLCC])) {
                             //$overwriteDemand[$fieldnameLCC] = "all";
                         }
                         $depends = array();
                         $dependFields = array();
                         $displayDepends = array();
                         if (count($field['addToMooxNewsFrontendFilter']['depends'])) {
                             foreach ($field['addToMooxNewsFrontendFilter']['depends'] as $depend) {
                                 if (isset($GLOBALS['TCA']['tx_mooxnews_domain_model_news']['columns'][$depend])) {
                                     $dependField = $GLOBALS['TCA']['tx_mooxnews_domain_model_news']['columns'][$depend];
                                     if ($dependField['config']['type'] == "select" || $dependField['config']['type'] == "input" && $dependField['addToMooxNewsFrontendFilter']['type'] == "select") {
                                         $depends[] = \TYPO3\CMS\Core\Utility\GeneralUtility::underscoredToLowerCamelCase($depend);
                                         $dependField = \TYPO3\CMS\Core\Utility\GeneralUtility::underscoredToLowerCamelCase($depend);
                                         if (isset($overwriteDemand[$dependField]) && $overwriteDemand[$dependField] != "all") {
                                             $dependFields[$depend] = $overwriteDemand[$dependField];
                                         }
                                     }
                                 }
                             }
                         }
                         if (count($field['addToMooxNewsFrontendFilter']['displayDepends'])) {
                             foreach ($field['addToMooxNewsFrontendFilter']['displayDepends'] as $displayDepend) {
                                 if (isset($GLOBALS['TCA']['tx_mooxnews_domain_model_news']['columns'][$displayDepend])) {
                                     $displayDependField = $GLOBALS['TCA']['tx_mooxnews_domain_model_news']['columns'][$displayDepend];
                                     if ($displayDependField['config']['type'] == "select" || $displayDependField['config']['type'] == "input" && $displayDependField['addToMooxNewsFrontendFilter']['type'] == "select") {
                                         $displayDepends[] = \TYPO3\CMS\Core\Utility\GeneralUtility::underscoredToLowerCamelCase($displayDepend);
                                     }
                                 }
                             }
                         }
                         $values = array();
                         $valuesFromDb = $this->newsRepository->findExtendedFilterUniqueValues($fieldname, $demand->getStoragePage(), $dependFields);
                         if (count($valuesFromDb)) {
                             if ($field['addToMooxNewsFrontendFilter']['selectAllLabel'] != "") {
                                 $values['all'] = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate($field['addToMooxNewsFrontendFilter']['selectAllLabel'], $field['extkey']);
                             } else {
                                 $values['all'] = "Alle";
                             }
                             $valueCnt = 0;
                             foreach ($valuesFromDb as $value) {
                                 if ($value == "empty") {
                                     if ($field['addToMooxNewsFrontendFilter']['selectEmptyLabel'] != "") {
                                         $valueLabel = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate($field['addToMooxNewsFrontendFilter']['selectEmptyLabel'], $field['extkey']);
                                         $values[$value] = $valueLabel;
                                     } else {
                                         $valueLabel = "Ohne Wert";
                                     }
                                 } else {
                                     $values[$value] = $value;
                                     $valueCnt++;
                                 }
                             }
                             if ($valueCnt) {
                                 $extendedFilters[] = array("label" => $label, "name" => $fieldnameLCC, "type" => 'select', "field" => $fieldname, "fieldUCC" => $fieldnameUCC, "items" => $values, "depends" => $depends, "displayDepends" => $displayDepends);
                             }
                         }
                     } else {
                         $extendedFilters[] = array("label" => $label, "name" => $fieldnameLCC, "type" => 'default', "field" => $fieldname, "fieldUCC" => $fieldnameUCC);
                     }
                 }
             }
         }
     }
     return $extendedFilters;
 }
 /**
  * Replace the selector's uid index with configured indexField
  *
  * @param array	 $PA: TCA select field parameters array
  * @return array The new $items array
  */
 protected function replaceSelectorIndexField($PA)
 {
     $items = $PA['items'];
     $indexFields = GeneralUtility::trimExplode(',', $PA['config']['itemsProcFunc_config']['indexField'], TRUE);
     if (!empty($indexFields)) {
         $rows = array();
         // Collect items uid's
         $uids = array();
         foreach ($items as $key => $item) {
             if ($items[$key][1]) {
                 $uids[] = $item[1];
             }
         }
         $uidList = implode(',', $uids);
         if (!empty($uidList)) {
             /** @var \TYPO3\CMS\Extbase\Object\ObjectManager $objectManager */
             $objectManager = GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
             switch ($PA['config']['foreign_table']) {
                 case 'static_territories':
                     /** @var $territoryRepository SJBR\StaticInfoTables\Domain\Repository\TerritoryRepository */
                     $territoryRepository = $objectManager->get('SJBR\\StaticInfoTables\\Domain\\Repository\\TerritoryRepository');
                     $objects = $territoryRepository->findAllByUidInList($uidList)->toArray();
                     $columnsMapping = ModelUtility::getModelMapping('SJBR\\StaticInfoTables\\Domain\\Model\\Territory', ModelUtility::MAPPING_COLUMNS);
                     break;
                 case 'static_countries':
                     /** @var $countryRepository SJBR\StaticInfoTables\Domain\Repository\CountryRepository */
                     $countryRepository = $objectManager->get('SJBR\\StaticInfoTables\\Domain\\Repository\\CountryRepository');
                     $objects = $countryRepository->findAllByUidInList($uidList)->toArray();
                     $columnsMapping = ModelUtility::getModelMapping('SJBR\\StaticInfoTables\\Domain\\Model\\Country', ModelUtility::MAPPING_COLUMNS);
                     break;
                 case 'static_country_zones':
                     /** @var $countryZoneRepository SJBR\StaticInfoTables\Domain\Repository\CountryZoneRepository */
                     $countryZoneRepository = $objectManager->get('SJBR\\StaticInfoTables\\Domain\\Repository\\CountryZoneRepository');
                     $objects = $countryZoneRepository->findAllByUidInList($uidList)->toArray();
                     $columnsMapping = ModelUtility::getModelMapping('SJBR\\StaticInfoTables\\Domain\\Model\\CountryZone', ModelUtility::MAPPING_COLUMNS);
                     break;
                 case 'static_languages':
                     /** @var $languageRepository SJBR\StaticInfoTables\Domain\Repository\LanguageRepository */
                     $languageRepository = $objectManager->get('SJBR\\StaticInfoTables\\Domain\\Repository\\LanguageRepository');
                     $objects = $languageRepository->findAllByUidInList($uidList)->toArray();
                     $columnsMapping = ModelUtility::getModelMapping('SJBR\\StaticInfoTables\\Domain\\Model\\Language', ModelUtility::MAPPING_COLUMNS);
                     break;
                 case 'static_currencies':
                     /** @var $currencyRepository SJBR\StaticInfoTables\Domain\Repository\CurrencyRepository */
                     $currencyRepository = $objectManager->get('SJBR\\StaticInfoTables\\Domain\\Repository\\CurrencyRepository');
                     $objects = $currencyRepository->findAllByUidInList($uidList)->toArray();
                     $columnsMapping = ModelUtility::getModelMapping('SJBR\\StaticInfoTables\\Domain\\Model\\Currency', ModelUtility::MAPPING_COLUMNS);
                     break;
                 default:
                     break;
             }
             if (!empty($objects)) {
                 // Map table column to object property
                 $indexProperties = array();
                 foreach ($indexFields as $indexField) {
                     if ($columnsMapping[$indexField]['mapOnProperty']) {
                         $indexProperties[] = $columnsMapping[$indexField]['mapOnProperty'];
                     } else {
                         $indexProperties[] = GeneralUtility::underscoredToLowerCamelCase($indexField);
                     }
                 }
                 // Index rows by uid
                 $uidIndexedRows = array();
                 foreach ($objects as $object) {
                     $uidIndexedObjects[$object->getUid()] = $object;
                 }
                 // Replace the items index field
                 foreach ($items as $key => $item) {
                     if ($items[$key][1]) {
                         $object = $uidIndexedObjects[$items[$key][1]];
                         $items[$key][1] = $object->_getProperty($indexProperties[0]);
                         if ($indexFields[1] && $object->_getProperty($indexProperties[1])) {
                             $items[$key][1] .= '_' . $object->_getProperty($indexProperties[1]);
                         }
                     }
                 }
             }
         }
     }
     return $items;
 }
 /**
  * Get list view fields	
  *	
  * @param \string $type
  * @return	array	list view fields 	
  */
 public function getListViewFields($type = 0)
 {
     $varTypes = array("text", "date", "datetime", "currency");
     $dateFields = array("datetime", "archive", "tstamp");
     $dateTimeFields = array();
     $listViewFields = array();
     if (isset($GLOBALS['TCA']['tx_mooxnews_domain_model_news']['listViewFields'][$type]) && $GLOBALS['TCA']['tx_mooxnews_domain_model_news']['listViewFields'][$type] != "") {
         $listViewFieldsString = $GLOBALS['TCA']['tx_mooxnews_domain_model_news']['listViewFields'][$type];
     } else {
         $listViewFieldsString = $GLOBALS['TCA']['tx_mooxnews_domain_model_news']['listViewFields']['moox_news'];
     }
     if ($listViewFieldsString != "") {
         $listViewFieldsTmp = explode(",", $listViewFieldsString);
         foreach ($listViewFieldsTmp as $listViewField) {
             $listViewField = explode(":", $listViewField);
             if (in_array(trim($listViewField[0]), $this->getAllowedFields())) {
                 $fieldTCA = $GLOBALS['TCA']['tx_mooxnews_domain_model_news']['columns'][trim($listViewField[0])];
                 $fieldType = "text";
                 if (isset($fieldTCA['addToMooxNewsBackendPreview']['type']) && in_array($fieldTCA['addToMooxNewsBackendPreview']['type'], $varTypes)) {
                     $fieldType = $fieldTCA['addToMooxNewsBackendPreview']['type'];
                 } elseif (in_array(trim($listViewField[0]), $dateFields)) {
                     $fieldType = "date";
                 } elseif (in_array(trim($listViewField[0]), $dateTimeFields)) {
                     $fieldType = "datetime";
                 }
                 $extkey = $fieldTCA['extkey'] != "" ? $fieldTCA['extkey'] : "moox_news";
                 if ($extkey == "moox_news") {
                     $label = "LLL:EXT:moox_news/Resources/Private/Language/locallang_db.xlf:tx_mooxnews_domain_model_news." . trim($listViewField[0]);
                 } else {
                     $label = $fieldTCA['label'] != "" ? $fieldTCA['label'] : "";
                 }
                 $listViewFields[] = array("name" => \TYPO3\CMS\Core\Utility\GeneralUtility::underscoredToLowerCamelCase(trim($listViewField[0])), "lenght" => trim($listViewField[1]) > 0 ? trim($listViewField[1]) : 10000, "additional" => array(), "type" => $fieldType, "extkey" => $extkey, "label" => $label);
             } else {
                 $additionalFieldsAccepted = true;
                 $listViewAdditionalFields = array();
                 $listViewAdditionalFieldsTmp = explode("|", $listViewField[0]);
                 if (count($listViewAdditionalFieldsTmp) > 1) {
                     foreach ($listViewAdditionalFieldsTmp as $listViewAdditionalField) {
                         if (in_array(trim($listViewAdditionalField), $this->getAllowedFields())) {
                             $fieldTCA = $GLOBALS['TCA']['tx_mooxnews_domain_model_news']['columns'][trim($listViewAdditionalField)];
                             $fieldType = "text";
                             if (isset($fieldTCA['addToMooxNewsBackendPreview']['type']) && in_array($fieldTCA['addToMooxNewsBackendPreview']['type'], $varTypes)) {
                                 $fieldType = $fieldTCA['addToMooxNewsBackendPreview']['type'];
                             } elseif (in_array(trim($listViewAdditionalField), $dateFields)) {
                                 $fieldType = "date";
                             } elseif (in_array(trim($listViewAdditionalField), $dateTimeFields)) {
                                 $fieldType = "datetime";
                             }
                             $extkey = $fieldTCA['extkey'] != "" ? $fieldTCA['extkey'] : "moox_news";
                             if ($extkey == "moox_news") {
                                 $label = "LLL:EXT:moox_news/Resources/Private/Language/locallang_db.xlf:tx_mooxnews_domain_model_news." . trim($listViewAdditionalField);
                             } else {
                                 $label = $fieldTCA['label'] != "" ? $fieldTCA['label'] : "";
                             }
                             $listViewAdditionalFields[] = array("name" => \TYPO3\CMS\Core\Utility\GeneralUtility::underscoredToLowerCamelCase(trim($listViewAdditionalField)), "type" => $fieldType, "extkey" => $extkey, "label" => $label);
                         } else {
                             $additionalFieldsAccepted = false;
                             break;
                         }
                     }
                 } else {
                     $additionalFieldsAccepted = false;
                 }
                 if ($additionalFieldsAccepted) {
                     $mainViewField = $listViewAdditionalFields[0];
                     $fieldTCA = $GLOBALS['TCA']['tx_mooxnews_domain_model_news']['columns'][$mainViewField];
                     $fieldType = "text";
                     if (isset($fieldTCA['addToMooxNewsBackendPreview']['type']) && in_array($fieldTCA['addToMooxNewsBackendPreview']['type'], $varTypes)) {
                         $fieldType = $fieldTCA['addToMooxNewsBackendPreview']['type'];
                     } elseif (in_array(trim($listViewAdditionalField), $dateFields)) {
                         $fieldType = "date";
                     } elseif (in_array(trim($listViewAdditionalField), $dateTimeFields)) {
                         $fieldType = "datetime";
                     }
                     $extkey = $fieldTCA['extkey'] != "" ? $fieldTCA['extkey'] : "moox_news";
                     if ($extkey == "moox_news") {
                         $label = "LLL:EXT:moox_news/Resources/Private/Language/locallang_db.xlf:tx_mooxnews_domain_model_news." . $mainViewField;
                     } else {
                         $label = $fieldTCA['label'] != "" ? $fieldTCA['label'] : "";
                     }
                     unset($listViewAdditionalFields[0]);
                     $listViewFields[] = array("name" => \TYPO3\CMS\Core\Utility\GeneralUtility::underscoredToLowerCamelCase($mainViewField), "lenght" => trim($listViewField[1]) > 0 ? trim($listViewField[1]) : 10000, "additional" => $listViewAdditionalFields, "type" => $fieldType, "extkey" => $extkey, "label" => $label);
                 }
             }
         }
     }
     if (!count($listViewFields)) {
         $listViewFields[0] = array("name" => "datetime", "length" => 10000, "additional" => array(), "type" => 'date', "extkey" => 'moox_news', "label" => 'LLL:EXT:moox_news/Resources/Private/Language/locallang_db.xlf:tx_mooxnews_domain_model_news.datetime');
         $listViewFields[1] = array("name" => "archive", "length" => 10000, "additional" => array(), "type" => 'date', "extkey" => 'moox_news', "label" => 'LLL:EXT:moox_news/Resources/Private/Language/locallang_db.xlf:tx_mooxnews_domain_model_news.archive');
         $listViewFields[2] = array("name" => "tstamp", "length" => 10000, "additional" => array(), "type" => 'date', "extkey" => 'moox_news', "label" => 'LLL:EXT:moox_news/Resources/Private/Language/locallang_db.xlf:tx_mooxnews_domain_model_news.tstamp');
     }
     return $listViewFields;
 }
Example #21
0
 /**
  * @param string $table
  * @param string $type
  * @return string
  */
 protected function getLabelPropertyName($table, $type)
 {
     $typoScript = $this->configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT);
     if (TRUE === isset($typoScript['config.']['tx_extbase.']['persistence.']['classes.'][$type . '.'])) {
         $mapping = $typoScript['config.']['tx_extbase.']['persistence.']['classes.'][$type . '.'];
         if (TRUE === isset($mapping['mapping.']['tableName'])) {
             $table = $mapping['mapping.']['tableName'];
         }
     }
     $labelField = $GLOBALS['TCA'][$table]['ctrl']['label'];
     $propertyName = GeneralUtility::underscoredToLowerCamelCase($labelField);
     return $propertyName;
 }
Example #22
0
 /**
  * Returns an array of constraints created from a given demand object.
  *
  * @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query
  * @param Tx_MooxNews_Domain_Model_DemandInterface $demand
  * @throws UnexpectedValueException
  * @throws InvalidArgumentException
  * @throws Exception
  * @return array<\TYPO3\CMS\Extbase\Persistence\Generic\Qom\ConstraintInterface>
  */
 protected function createConstraintsFromDemand(\TYPO3\CMS\Extbase\Persistence\QueryInterface $query, Tx_MooxNews_Domain_Model_DemandInterface $demand)
 {
     $constraints = array();
     if (is_array($demand->getTypes()) && count($demand->getTypes())) {
         $constraints[] = $query->in('type', $demand->getTypes());
     } elseif ($demand->getType() != "") {
         $constraints[] = $query->equals('type', (string) $demand->getType());
     }
     if ($demand->getIncludeOnlySelectedNewsInRss()) {
         $constraints[] = $query->equals('shareRss', 1);
     }
     if ($demand->getCategories() && $demand->getCategories() !== '0') {
         $constraints[] = $this->createCategoryConstraint($query, $demand->getCategories(), $demand->getCategoryConjunction(), $demand->getIncludeSubCategories());
     }
     if ($demand->getAuthor()) {
         $constraints[] = $query->equals('author', $demand->getAuthor());
     }
     $listViewSearchFields = $GLOBALS['TCA']['tx_mooxnews_domain_model_news']['listViewSearchFields']['moox_news']['default'];
     if ($demand->getQuery()) {
         $listViewSearchFields = $GLOBALS['TCA']['tx_mooxnews_domain_model_news']['listViewSearchFields']['moox_news']['default'];
         if (is_array($demand->getTypes())) {
             $type = reset($demand->getTypes());
         }
         if ($type != "" && isset($GLOBALS['TCA']['tx_mooxnews_domain_model_news']['listViewSearchFields'][$type]['default']) && $GLOBALS['TCA']['tx_mooxnews_domain_model_news']['listViewSearchFields'][$type]['default'] != "") {
             $listViewSearchFields = $GLOBALS['TCA']['tx_mooxnews_domain_model_news']['listViewSearchFields'][$type]['default'];
         } else {
             $listViewSearchFields = $GLOBALS['TCA']['tx_mooxnews_domain_model_news']['listViewSearchFields']['moox_news']['default'];
         }
         if ($listViewSearchFields != "") {
             $listViewSearchFields = explode(",", $listViewSearchFields);
         } else {
             $listViewSearchFields = array("title");
         }
         $queryConstraints = array();
         foreach ($listViewSearchFields as $listViewSearchField) {
             $queryConstraints[] = $query->like($listViewSearchField, "%" . $demand->getQuery() . "%");
         }
         $constraints[] = $query->logicalOr($queryConstraints);
     }
     if ($demand->getChar()) {
         if ($demand->getChar() != "other") {
             $char = substr($demand->getChar(), 0, 1);
             if (in_array($char, $demand->getCharList())) {
                 $constraints[] = $query->like("title", $char . "%");
             }
         } else {
             $charConstraints = array();
             foreach ($demand->getCharList() as $char) {
                 if ($char != "all" && $char != "other") {
                     $charConstraints[] = $query->logicalNot($query->like("title", $char . "%"));
                 }
             }
             if (count($charConstraints)) {
                 $constraints[] = $query->logicalAnd($charConstraints);
             }
         }
     }
     // archived
     if ($demand->getArchiveRestriction() == 'archived') {
         $constraints[] = $query->logicalAnd($query->lessThan('archive', $GLOBALS['EXEC_TIME']), $query->greaterThan('archive', 0));
     } elseif ($demand->getArchiveRestriction() == 'active') {
         $constraints[] = $query->logicalOr($query->greaterThanOrEqual('archive', $GLOBALS['EXEC_TIME']), $query->equals('archive', 0));
     }
     if ($demand->getDateField() == "type" && is_array($demand->getTypes()) && count($demand->getTypes()) == 1) {
         $type = reset($demand->getTypes());
         if (isset($GLOBALS['TCA']['tx_mooxnews_domain_model_news']['dateTimeDefaultField'][$type]) && $GLOBALS['TCA']['tx_mooxnews_domain_model_news']['dateTimeDefaultField'][$type] != "") {
             $dateTimeDefaultField = $GLOBALS['TCA']['tx_mooxnews_domain_model_news']['dateTimeDefaultField'][$type];
         } else {
             $dateTimeDefaultField = $GLOBALS['TCA']['tx_mooxnews_domain_model_news']['dateTimeDefaultField']['moox_news'];
         }
         $demand->setDateField($dateTimeDefaultField);
     } elseif ($demand->getDateField() == "type") {
         $dateTimeDefaultField = $GLOBALS['TCA']['tx_mooxnews_domain_model_news']['dateTimeDefaultField']['moox_news'];
         $demand->setDateField($dateTimeDefaultField);
     }
     // Time restriction greater than or equal
     $timeRestrictionField = $demand->getDateField();
     $timeRestrictionField = empty($timeRestrictionField) ? 'datetime' : $timeRestrictionField;
     if ($demand->getTimeRestriction()) {
         $timeLimit = 0;
         // integer = timestamp
         if (\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($demand->getTimeRestriction())) {
             $timeLimit = $GLOBALS['EXEC_TIME'] - $demand->getTimeRestriction();
         } else {
             // try to check strtotime
             $timeFromString = strtotime($demand->getTimeRestriction());
             if ($timeFromString) {
                 $timeLimit = $timeFromString;
             } else {
                 throw new Exception('Time limit Low could not be resolved to an integer. Given was: ' . htmlspecialchars($timeLimit));
             }
         }
         $constraints[] = $query->greaterThanOrEqual($timeRestrictionField, $timeLimit);
     }
     // Time restriction less than or equal
     if ($demand->getTimeRestrictionHigh()) {
         $timeLimit = 0;
         // integer = timestamp
         if (\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($demand->getTimeRestrictionHigh())) {
             $timeLimit = $GLOBALS['EXEC_TIME'] + $demand->getTimeRestrictionHigh();
         } else {
             // try to check strtotime
             $timeFromString = strtotime($demand->getTimeRestrictionHigh());
             if ($timeFromString) {
                 $timeLimit = $timeFromString;
             } else {
                 throw new Exception('Time limit High could not be resolved to an integer. Given was: ' . htmlspecialchars($timeLimit));
             }
         }
         $constraints[] = $query->lessThanOrEqual($timeRestrictionField, $timeLimit);
     }
     // top news
     if ($demand->getTopNewsRestriction() == 1) {
         $constraints[] = $query->equals('istopnews', 1);
     } elseif ($demand->getTopNewsRestriction() == 2) {
         $constraints[] = $query->equals('istopnews', 0);
     }
     // top news
     if ($demand->getExcludeFromRss() == 1) {
         $constraints[] = $query->equals('excludeFromRss', 0);
     }
     // storage page
     if ($demand->getStoragePage() != 0) {
         $pidList = \TYPO3\CMS\Core\Utility\GeneralUtility::intExplode(',', $demand->getStoragePage(), TRUE);
         $constraints[] = $query->in('pid', $pidList);
     }
     // datepicker filter
     $datepickerConstraints = array();
     if ($demand->getDateFrom() != "") {
         $dateFrom = strtotime($demand->getDateFrom());
         if ($dateFrom > 0) {
             $dateFrom = mktime(0, 0, 0, date("n", $dateFrom), date("j", $dateFrom), date("Y", $dateFrom));
             $datepickerConstraints[] = $query->greaterThanOrEqual($timeRestrictionField, $dateFrom);
         }
     }
     if ($demand->getDateTo() != "") {
         $dateTo = strtotime($demand->getDateTo());
         if ($dateTo > 0) {
             $dateTo = mktime(23, 59, 59, date("n", $dateTo), date("j", $dateTo), date("Y", $dateTo));
             $datepickerConstraints[] = $query->lessThanOrEqual($timeRestrictionField, $dateTo);
         }
     }
     if (count($datepickerConstraints) > 1) {
         $constraints[] = $query->logicalAnd($datepickerConstraints);
     } elseif (count($datepickerConstraints) > 0) {
         $constraints[] = $datepickerConstraints[0];
     }
     // month & year OR year only
     if (is_numeric($demand->getYear())) {
         if ($demand->getYear() > 0) {
             if ($demand->getMonth() > 0) {
                 if ($demand->getDay() > 0) {
                     $begin = mktime(0, 0, 0, $demand->getMonth(), $demand->getDay(), $demand->getYear());
                     $end = mktime(23, 59, 59, $demand->getMonth(), $demand->getDay(), $demand->getYear());
                 } else {
                     $begin = mktime(0, 0, 0, $demand->getMonth(), 1, $demand->getYear());
                     $end = mktime(23, 59, 59, $demand->getMonth() + 1, 0, $demand->getYear());
                 }
             } else {
                 $begin = mktime(0, 0, 0, 1, 1, $demand->getYear());
                 $end = mktime(23, 59, 59, 12, 31, $demand->getYear());
             }
             $constraints[] = $query->logicalAnd($query->greaterThanOrEqual($timeRestrictionField, $begin), $query->lessThanOrEqual($timeRestrictionField, $end));
         } else {
             $constraints[] = $query->equals($timeRestrictionField, 0);
         }
     }
     if (is_array($GLOBALS['TCA']['tx_mooxnews_domain_model_news']['listViewSearchFields'])) {
         foreach ($GLOBALS['TCA']['tx_mooxnews_domain_model_news']['listViewSearchFields'] as $extkey => $queryFields) {
             if ($extkey != "moox_news") {
                 foreach ($queryFields as $fieldname => $queryField) {
                     if ($fieldname != "default" && $queryField != "") {
                         $fieldname = \TYPO3\CMS\Core\Utility\GeneralUtility::underscoredToLowerCamelCase($fieldname);
                         $getCall = "get" . ucfirst($fieldname);
                         if (method_exists($demand, $getCall)) {
                             $fieldvalue = $demand->{$getCall}();
                             if ($fieldvalue != "") {
                                 $listViewSearchFields = explode(",", $queryField);
                                 $queryConstraints = array();
                                 foreach ($listViewSearchFields as $listViewSearchField) {
                                     $queryConstraints[] = $query->like($listViewSearchField, "%" . $fieldvalue . "%");
                                 }
                                 $constraints[] = $query->logicalOr($queryConstraints);
                             }
                         }
                     }
                 }
             }
         }
     }
     // set constraints based on extended filter fields from external extensions
     foreach ($GLOBALS['TCA']['tx_mooxnews_domain_model_news']['columns'] as $fieldname => $field) {
         if ($field['addToMooxNewsFrontendDemand']) {
             $fieldname = \TYPO3\CMS\Core\Utility\GeneralUtility::underscoredToLowerCamelCase($fieldname);
             $getCall = "get" . ucfirst($fieldname);
             if (method_exists($demand, $getCall)) {
                 $fieldvalue = $demand->{$getCall}();
                 if (trim($fieldvalue) != "" && trim($fieldvalue) != "all") {
                     if (in_array($field['config']['type'], array("input", "text")) && !in_array($field['addToMooxNewsFrontendFilter']['type'], array("select"))) {
                         $constraints[] = $query->like($fieldname, '%' . $fieldvalue . '%');
                     } else {
                         if (in_array($field['addToMooxNewsFrontendFilter']['type'], array("select")) && $fieldvalue == "empty") {
                             $constraints[] = $query->logicalOr($query->equals($fieldname, ""), $query->equals($fieldname, NULL));
                         } else {
                             $constraints[] = $query->equals($fieldname, $fieldvalue);
                         }
                     }
                 }
             }
         }
     }
     // sys language
     if (TYPO3_MODE == 'BE') {
         $query->getQuerySettings()->setRespectSysLanguage(false);
         $constraints[] = $query->equals('t3_origuid', 0);
         if (is_numeric($demand->getSysLanguageUid())) {
             $constraints[] = $query->equals('sys_language_uid', $demand->getSysLanguageUid());
         }
     }
     // Tags
     if (is_array($demand->getTags()) && count($demand->getTags())) {
         $tags = $demand->getTags();
         if (count($tags) > 1) {
             $tagConstraints = array();
             foreach ($tags as $tag) {
                 $tagConstraints[] = $query->contains('tags', $tag);
             }
             $constraints[] = $query->logicalOr($tagConstraints);
         } else {
             $constraints[] = $query->contains('tags', $tags[0]);
         }
     } elseif ($demand->getTag() != "") {
         $constraints[] = $query->contains('tags', $demand->getTag());
     }
     // Targets
     if (is_array($demand->getTargets()) && count($demand->getTargets())) {
         $targets = $demand->getTargets();
         if (count($targets) > 1) {
             $targetConstraints = array();
             foreach ($targets as $target) {
                 $targetConstraints[] = $query->contains('targets', $target);
             }
             $constraints[] = $query->logicalOr($targetConstraints);
         } else {
             $constraints[] = $query->contains('targets', $targets[0]);
         }
     } elseif ($demand->getTarget() != "") {
         $constraints[] = $query->contains('targets', $demand->getTarget());
     }
     // mailer frequency
     if (TYPO3_MODE == 'BE') {
         if (is_numeric($demand->getMailerFrequency())) {
             $constraints[] = $query->equals('mailerFrequency', $demand->getMailerFrequency());
         }
     }
     // Search
     $searchConstraints = $this->getSearchConstraints($query, $demand);
     if (!empty($searchConstraints)) {
         $constraints[] = $query->logicalAnd($searchConstraints);
     }
     // Exclude already displayed
     if ($demand->getExcludeAlreadyDisplayedNews() && isset($GLOBALS['EXT']['moox_news']['alreadyDisplayed']) && !empty($GLOBALS['EXT']['moox_news']['alreadyDisplayed'])) {
         $constraints[] = $query->logicalNot($query->in('uid', $GLOBALS['EXT']['moox_news']['alreadyDisplayed']));
     }
     // Clean not used constraints
     foreach ($constraints as $key => $value) {
         if (is_null($value)) {
             unset($constraints[$key]);
         }
     }
     /*
     $parser = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Storage\\Typo3DbQueryParser');  
     $queryParts = $parser->parseQuery($query); 
     \TYPO3\CMS\Core\Utility\DebugUtility::debug($queryParts, 'Query');
     exit();
     */
     return $constraints;
 }
 /**
  * Changing character case of a string, converting typically used western charset characters as well.
  *
  * @param string $theValue The string to change case for.
  * @param string $case The direction; either "upper" or "lower
  * @return string
  * @see HTMLcaseshift()
  */
 public function caseshift($theValue, $case)
 {
     $case = strtolower($case);
     switch ($case) {
         case 'upper':
             $theValue = $GLOBALS['TSFE']->csConvObj->conv_case($GLOBALS['TSFE']->renderCharset, $theValue, 'toUpper');
             break;
         case 'lower':
             $theValue = $GLOBALS['TSFE']->csConvObj->conv_case($GLOBALS['TSFE']->renderCharset, $theValue, 'toLower');
             break;
         case 'capitalize':
             $theValue = ucwords($theValue);
             break;
         case 'ucfirst':
             $theValue = $GLOBALS['TSFE']->csConvObj->convCaseFirst($GLOBALS['TSFE']->renderCharset, $theValue, 'toUpper');
             break;
         case 'lcfirst':
             $theValue = $GLOBALS['TSFE']->csConvObj->convCaseFirst($GLOBALS['TSFE']->renderCharset, $theValue, 'toLower');
             break;
         case 'uppercamelcase':
             $theValue = GeneralUtility::underscoredToUpperCamelCase($theValue);
             break;
         case 'lowercamelcase':
             $theValue = GeneralUtility::underscoredToLowerCamelCase($theValue);
             break;
     }
     return $theValue;
 }
Example #24
0
 /**
  * Returns the true class name of the ViewHelper as defined
  * by the extensionKey (which may be vendorname.extensionkey)
  * and the class name. If vendorname is used, namespaced
  * classes are assumed. If no vendorname is used a namespaced
  * class is first attempted, if this does not exist the old
  * Tx_ prefixed class name is tried. If this too does not exist,
  * an Exception is thrown.
  *
  * @param string $combinedExtensionKey
  * @param string $filename
  * @return string
  * @throws \Exception
  */
 protected function getRealClassNameBasedOnExtensionAndFilenameAndExistence($combinedExtensionKey, $filename)
 {
     list($vendor, $extensionKey) = $this->getRealExtensionKeyAndVendorFromCombinedExtensionKey($combinedExtensionKey);
     $filename = str_replace(ExtensionManagementUtility::extPath($extensionKey, 'Classes/ViewHelpers/'), '', $filename);
     $stripped = substr($filename, 0, -4);
     if ($vendor) {
         $classNamePart = str_replace('/', '\\', $stripped);
         $className = $vendor . '\\' . ucfirst(GeneralUtility::underscoredToLowerCamelCase($extensionKey)) . '\\ViewHelpers\\' . $classNamePart;
     } else {
         $classNamePart = str_replace('/', '_', $stripped);
         $className = 'Tx_' . ucfirst(GeneralUtility::underscoredToLowerCamelCase($extensionKey)) . '_ViewHelpers_' . $classNamePart;
     }
     return $className;
 }
Example #25
0
 /**
  * Renders the items in the top toolbar
  *
  * @return string top toolbar elements as HTML
  */
 protected function renderToolbar()
 {
     $toolbar = array();
     foreach ($this->toolbarItems as $toolbarItem) {
         /** @var \TYPO3\CMS\Backend\Toolbar\ToolbarItemInterface $toolbarItem */
         if ($toolbarItem->checkAccess()) {
             $hasDropDown = (bool) $toolbarItem->hasDropDown();
             $additionalAttributes = (array) $toolbarItem->getAdditionalAttributes();
             $liAttributes = array();
             // Merge class: Add dropdown class if hasDropDown, add classes from additonal attributes
             $classes = array();
             if ($hasDropDown) {
                 $classes[] = 'dropdown';
             }
             if (isset($additionalAttributes['class'])) {
                 $classes[] = $additionalAttributes['class'];
                 unset($additionalAttributes['class']);
             }
             $liAttributes[] = 'class="' . implode(' ', $classes) . '"';
             // Add further attributes
             foreach ($additionalAttributes as $name => $value) {
                 $liAttributes[] = $name . '="' . $value . '"';
             }
             // Create a unique id from class name
             $className = get_class($toolbarItem);
             $className = GeneralUtility::underscoredToLowerCamelCase($className);
             $className = GeneralUtility::camelCaseToLowerCaseUnderscored($className);
             $className = str_replace(array('_', '\\'), '-', $className);
             $liAttributes[] = 'id="' . $className . '"';
             $toolbar[] = '<li ' . implode(' ', $liAttributes) . '>';
             if ($hasDropDown) {
                 $toolbar[] = '<a href="#" class="dropdown-toggle" data-toggle="dropdown">';
                 $toolbar[] = $toolbarItem->getItem();
                 $toolbar[] = '</a>';
                 $toolbar[] = '<div class="dropdown-menu" role="menu">';
                 $toolbar[] = $toolbarItem->getDropDown();
                 $toolbar[] = '</div>';
             } else {
                 $toolbar[] = $toolbarItem->getItem();
             }
             $toolbar[] = '</li>';
         }
     }
     return implode(LF, $toolbar);
 }
Example #26
0
 /**
  * @return array
  */
 public function getItems()
 {
     $items = array();
     if (TRUE === is_string($this->items)) {
         $itemNames = GeneralUtility::trimExplode(',', $this->items);
         foreach ($itemNames as $itemName) {
             array_push($items, array($itemName, $itemName));
         }
     } elseif (TRUE === is_array($this->items) || TRUE === $this->items instanceof Traversable) {
         foreach ($this->items as $itemIndex => $itemValue) {
             if (TRUE === is_array($itemValue) || TRUE === $itemValue instanceof ArrayObject) {
                 array_push($items, $itemValue);
             } else {
                 array_push($items, array($itemValue, $itemIndex));
             }
         }
     } elseif (TRUE === $this->items instanceof Query) {
         /** @var Query $query */
         $query = $this->items;
         $results = $query->execute();
         $type = $query->getType();
         $typoScript = $this->configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT);
         $table = strtolower(str_replace('\\', '_', $type));
         if (TRUE === isset($typoScript['config.']['tx_extbase.']['persistence.']['classes.'][$type . '.'])) {
             $mapping = $typoScript['config.']['tx_extbase.']['persistence.']['classes.'][$type . '.'];
             if (TRUE === isset($mapping['mapping.']['tableName'])) {
                 $table = $mapping['mapping.']['tableName'];
             }
         }
         $labelField = $GLOBALS['TCA'][$table]['ctrl']['label'];
         $propertyName = GeneralUtility::underscoredToLowerCamelCase($labelField);
         foreach ($results as $result) {
             $uid = $result->getUid();
             array_push($items, array(ObjectAccess::getProperty($result, $propertyName), $uid));
         }
     }
     $emptyOption = $this->getEmptyOption();
     if (FALSE !== $emptyOption) {
         array_unshift($items, array('', $emptyOption));
     }
     return $items;
 }
Example #27
0
 /**
  * Modifies the select box of date fields
  *
  * @param array &$config configuration array
  * @return void
  */
 public function user_dateField(array &$config)
 {
     foreach ($GLOBALS['TCA']['tx_mooxnews_domain_model_news']['columns'] as $fieldname => $field) {
         $ll = 'LLL:EXT:' . $field['extkey'] . '/Resources/Private/Language/locallang_db.xml:';
         if ($field['addToMooxNewsFrontendDateFields']) {
             $prefix = $ll . 'tx_' . str_replace("_", "", $field['extkey']) . '_domain_model_news';
             $prefix = $GLOBALS['LANG']->sL($prefix, TRUE) . ": ";
             $label = $GLOBALS['LANG']->sL($field['label'], TRUE);
             array_push($config['items'], array($prefix . $label, \TYPO3\CMS\Core\Utility\GeneralUtility::underscoredToLowerCamelCase($fieldname)));
         }
     }
 }
Example #28
0
 /**
  * Builds a data map by adding column maps for all the configured columns in the $TCA.
  * It also resolves the type of values the column is holding and the typo of relation the column
  * represents.
  *
  * @param string $className The class name you want to fetch the Data Map for
  * @throws \TYPO3\CMS\Extbase\Persistence\Generic\Exception\InvalidClassException
  * @return \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMap The data map
  */
 protected function buildDataMapInternal($className)
 {
     if (!class_exists($className)) {
         throw new \TYPO3\CMS\Extbase\Persistence\Generic\Exception\InvalidClassException('Could not find class definition for name "' . $className . '". This could be caused by a mis-spelling of the class name in the class definition.', 1476045117);
     }
     $recordType = null;
     $subclasses = [];
     $tableName = $this->resolveTableName($className);
     $columnMapping = [];
     $frameworkConfiguration = $this->configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK);
     $classSettings = $frameworkConfiguration['persistence']['classes'][$className];
     if ($classSettings !== null) {
         if (isset($classSettings['subclasses']) && is_array($classSettings['subclasses'])) {
             $subclasses = $this->resolveSubclassesRecursive($frameworkConfiguration['persistence']['classes'], $classSettings['subclasses']);
         }
         if (isset($classSettings['mapping']['recordType']) && $classSettings['mapping']['recordType'] !== '') {
             $recordType = $classSettings['mapping']['recordType'];
         }
         if (isset($classSettings['mapping']['tableName']) && $classSettings['mapping']['tableName'] !== '') {
             $tableName = $classSettings['mapping']['tableName'];
         }
         $classHierarchy = array_merge([$className], class_parents($className));
         foreach ($classHierarchy as $currentClassName) {
             if (in_array($currentClassName, [\TYPO3\CMS\Extbase\DomainObject\AbstractEntity::class, \TYPO3\CMS\Extbase\DomainObject\AbstractValueObject::class])) {
                 break;
             }
             $currentClassSettings = $frameworkConfiguration['persistence']['classes'][$currentClassName];
             if ($currentClassSettings !== null) {
                 if (isset($currentClassSettings['mapping']['columns']) && is_array($currentClassSettings['mapping']['columns'])) {
                     \TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule($columnMapping, $currentClassSettings['mapping']['columns'], true, false);
                 }
             }
         }
     }
     /** @var $dataMap \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMap */
     $dataMap = $this->objectManager->get(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMap::class, $className, $tableName, $recordType, $subclasses);
     $dataMap = $this->addMetaDataColumnNames($dataMap, $tableName);
     // $classPropertyNames = $this->reflectionService->getClassPropertyNames($className);
     $tcaColumnsDefinition = $this->getColumnsDefinition($tableName);
     \TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule($tcaColumnsDefinition, $columnMapping);
     // @todo Is this is too powerful?
     foreach ($tcaColumnsDefinition as $columnName => $columnDefinition) {
         if (isset($columnDefinition['mapOnProperty'])) {
             $propertyName = $columnDefinition['mapOnProperty'];
         } else {
             $propertyName = \TYPO3\CMS\Core\Utility\GeneralUtility::underscoredToLowerCamelCase($columnName);
         }
         // if (in_array($propertyName, $classPropertyNames)) {
         // @todo Enable check for property existence
         $columnMap = $this->createColumnMap($columnName, $propertyName);
         $propertyMetaData = $this->reflectionService->getClassSchema($className)->getProperty($propertyName);
         $columnMap = $this->setType($columnMap, $columnDefinition['config']);
         $columnMap = $this->setRelations($columnMap, $columnDefinition['config'], $propertyMetaData);
         $columnMap = $this->setFieldEvaluations($columnMap, $columnDefinition['config']);
         $dataMap->addColumnMap($columnMap);
     }
     return $dataMap;
 }
 /**
  * @test
  * @dataProvider underscoredToLowerCamelCaseDataProvider
  */
 public function underscoredToLowerCamelCase($expected, $inputString)
 {
     $this->assertEquals($expected, Utility\GeneralUtility::underscoredToLowerCamelCase($inputString));
 }
 /**
  * Underscored value to lower camel case value (nice_field => niceField)
  *
  * @param string $val
  * @return string
  */
 public function render($val = '')
 {
     return GeneralUtility::underscoredToLowerCamelCase($val);
 }