Ejemplo n.º 1
0
 /**
  * (non-PHPdoc)
  * @see Tx_PtExtbase_Configuration_AbstractConfiguration::init()
  */
 protected function init()
 {
     $headerInclusionUtility = GeneralUtility::makeInstance('Tx_PtExtbase_Utility_HeaderInclusion');
     $this->setRequiredValue('columnIdentifier', 'Column identifier not given 1277889446');
     $this->setRequiredValue('fieldIdentifier', 'Field identifier for Column "' . $this->columnIdentifier . '" not given 1277889447');
     $fieldIdentifierList = GeneralUtility::trimExplode(',', $this->settings['fieldIdentifier']);
     $this->fieldIdentifier = $this->configurationBuilder->buildFieldsConfiguration()->extractCollectionByIdentifierList($fieldIdentifierList);
     foreach ($this->fieldIdentifier as $fieldConfig) {
         if ($fieldConfig->getExpandGroupRows()) {
             $this->containsArrayData = true;
             break;
         }
     }
     $this->setBooleanIfExistsAndNotNothing('isVisible');
     $this->setBooleanIfExistsAndNotNothing('isSortable');
     $this->setBooleanIfExistsAndNotNothing('rawFields');
     $this->setValueIfExistsAndNotNothing('renderTemplate');
     $this->setValueIfExistsAndNotNothing('sortingImageAsc');
     $this->setValueIfExistsAndNotNothing('sortingImageDesc');
     $this->setValueIfExistsAndNotNothing('sortingImageDefault');
     $this->setValueIfExistsAndNotNothing('specialCell');
     $this->setValueIfExistsAndNotNothing('cellCSSClass');
     $this->setValueIfExistsAndNotNothing('label');
     $this->setValueIfExistsAndNotNothing('headerThCssClass');
     $this->setBooleanIfExistsAndNotNothing('cacheRendering');
     $this->setBooleanIfExistsAndNotNothing('showInHeader');
     if (array_key_exists('renderUserFunctions', $this->settings) && is_array($this->settings['renderUserFunctions'])) {
         asort($this->settings['renderUserFunctions']);
         $this->renderUserFunctions = $this->settings['renderUserFunctions'];
     }
     if (array_key_exists('renderObj', $this->settings)) {
         $this->renderObj = GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Service\\TypoScriptService')->convertPlainArrayToTypoScriptArray(array('renderObj' => $this->settings['renderObj']));
     }
     /* Sorting configuration is set as follows:
     			  1. We check whether we have 'sortingFields' settings in column configuration
     			  2. We check whether we have 'sorting' settings in column configuration
     			  3. If we don't have either, we use first field identifier and make this sorting field of column
     		 */
     if (array_key_exists('sortingFields', $this->settings)) {
         $this->sortingConfigCollection = Tx_PtExtlist_Domain_Configuration_Columns_SortingConfigCollectionFactory::getInstanceBySortingFieldsSettings($this->settings['sortingFields']);
     } elseif (array_key_exists('sorting', $this->settings) && trim($this->settings['sorting'])) {
         $this->sortingConfigCollection = Tx_PtExtlist_Domain_Configuration_Columns_SortingConfigCollectionFactory::getInstanceBySortingSettings($this->settings['sorting']);
     } else {
         $this->sortingConfigCollection = Tx_PtExtlist_Domain_Configuration_Columns_SortingConfigCollectionFactory::getInstanceByFieldConfiguration($this->fieldIdentifier);
     }
     if (array_key_exists('accessGroups', $this->settings)) {
         $this->accessGroups = GeneralUtility::trimExplode(',', $this->settings['accessGroups']);
     }
     // Generate relative paths for sorting images
     $this->sortingImageDefault = $headerInclusionUtility->getFileRelFileName($this->sortingImageDefault);
     $this->sortingImageAsc = $headerInclusionUtility->getFileRelFileName($this->sortingImageAsc);
     $this->sortingImageDesc = $headerInclusionUtility->getFileRelFileName($this->sortingImageDesc);
     // Build the objectMapperConfig
     if (array_key_exists('objectMapper', $this->settings)) {
         $this->objectMapperConfig = new Tx_PtExtlist_Domain_Configuration_Columns_ObjectMapper_ObjectMapperConfig($this->configurationBuilder, $this->settings['objectMapper']);
     }
 }
 /** @test */
 public function getInstanceBySortingFieldsSettingsReturnsSortingFieldConfigCollection()
 {
     $configurationArray = array(10 => array('field' => 'field1', 'direction' => 'asc', 'forceDirection' => 1, 'label' => 'label1'), 20 => array('field' => 'field2', 'direction' => 'desc', 'forceDirection' => 0, 'label' => 'label2'));
     $sortingFieldConfigCollection = Tx_PtExtlist_Domain_Configuration_Columns_SortingConfigCollectionFactory::getInstanceBySortingFieldsSettings($configurationArray);
     $configurationForField1 = $sortingFieldConfigCollection->getItemById('field1');
     /* @var $configurationForField1 Tx_PtExtlist_Domain_Configuration_Columns_SortingConfig */
     $configurationForField2 = $sortingFieldConfigCollection->getItemById('field2');
     /* @var $configurationForField2 Tx_PtExtlist_Domain_Configuration_Columns_SortingConfig */
     $this->assertTrue(is_a($configurationForField1, 'Tx_PtExtlist_Domain_Configuration_Columns_SortingConfig'));
     $this->assertTrue(is_a($configurationForField2, 'Tx_PtExtlist_Domain_Configuration_Columns_SortingConfig'));
     $this->assertEquals($configurationForField1->getField(), 'field1');
     $this->assertEquals($configurationForField1->getDirection(), 1);
     $this->assertEquals($configurationForField1->getForceDirection(), 1);
     $this->assertEquals($configurationForField1->getLabel(), 'label1');
     $this->assertEquals($configurationForField2->getField(), 'field2');
     $this->assertEquals($configurationForField2->getDirection(), -1);
     $this->assertEquals($configurationForField2->getForceDirection(), 0);
     $this->assertEquals($configurationForField2->getLabel(), 'label2');
 }