/**
  * @return array
  */
 public function calculateDimensionCombinations()
 {
     $dimensionPresets = $this->contentDimensionPresetSource->getAllPresets();
     $dimensionValueCountByDimension = array();
     $possibleCombinationCount = 1;
     $combinations = array();
     foreach ($dimensionPresets as $dimensionName => $dimensionPreset) {
         if (isset($dimensionPreset['presets']) && !empty($dimensionPreset['presets'])) {
             $dimensionValueCountByDimension[$dimensionName] = count($dimensionPreset['presets']);
             $possibleCombinationCount = $possibleCombinationCount * $dimensionValueCountByDimension[$dimensionName];
         }
     }
     foreach ($dimensionPresets as $dimensionName => $dimensionPreset) {
         for ($i = 0; $i < $possibleCombinationCount; $i++) {
             if (!isset($combinations[$i]) || !is_array($combinations[$i])) {
                 $combinations[$i] = array();
             }
             $currentDimensionCurrentPreset = current($dimensionPresets[$dimensionName]['presets']);
             $combinations[$i][$dimensionName] = $currentDimensionCurrentPreset['values'];
             if (!next($dimensionPresets[$dimensionName]['presets'])) {
                 reset($dimensionPresets[$dimensionName]['presets']);
             }
         }
     }
     return $combinations;
 }
 /**
  * Creates a new content context based on the given workspace and the NodeData object.
  *
  * @param Workspace $workspace Workspace for the new context
  * @param array $dimensionValues The dimension values for the new context
  * @param array $contextProperties Additional pre-defined context properties
  * @return Context
  */
 protected function createContext(Workspace $workspace, array $dimensionValues, array $contextProperties = array())
 {
     $presetsMatchingDimensionValues = $this->contentDimensionPresetSource->findPresetsByTargetValues($dimensionValues);
     $dimensions = array_map(function ($preset) {
         return $preset['values'];
     }, $presetsMatchingDimensionValues);
     $contextProperties += array('workspaceName' => $workspace->getName(), 'inaccessibleContentShown' => true, 'invisibleContentShown' => true, 'removedContentShown' => true, 'dimensions' => $dimensions);
     return $this->contextFactory->create($contextProperties);
 }
 /**
  * Array of all possible dimension configurations allowed by configured presets.
  *
  * @return array
  */
 public function getAllAllowedCombinations()
 {
     $configuration = $this->contentDimensionPresetSource->getAllPresets();
     $dimensionCombinations = [];
     $dimensionNames = array_keys($configuration);
     $dimensionCount = count($dimensionNames);
     if ($dimensionCount === 0) {
         // This is correct, we have one allowed combination which is no dimension values (empty array).
         return [[]];
     }
     // Reset all presets first just to be sure
     foreach ($configuration as $dimensionName => &$dimensionConfiguration) {
         reset($dimensionConfiguration['presets']);
     }
     unset($dimensionConfiguration);
     while (true) {
         $skipCurrentCombination = false;
         $currentPresetCombination = ['withPresetIdentifiers' => [], 'withDimensionValues' => []];
         foreach ($dimensionNames as $dimensionName) {
             $presetIdentifierForDimension = key($configuration[$dimensionName]['presets']);
             $presetForDimension = current($configuration[$dimensionName]['presets']);
             if (!is_array($presetForDimension) || !isset($presetForDimension['values'])) {
                 $skipCurrentCombination = true;
             }
             $currentPresetCombination['withPresetIdentifiers'][$dimensionName] = $presetIdentifierForDimension;
             $currentPresetCombination['withDimensionValues'][$dimensionName] = $presetForDimension['values'];
         }
         if ($skipCurrentCombination === false && $this->contentDimensionPresetSource->isPresetCombinationAllowedByConstraints($currentPresetCombination['withPresetIdentifiers'])) {
             $dimensionCombinations[] = $currentPresetCombination['withDimensionValues'];
         }
         $nextDimension = 0;
         $hasValue = next($configuration[$dimensionNames[$nextDimension]]['presets']);
         while ($hasValue === false) {
             reset($configuration[$dimensionNames[$nextDimension]]['presets']);
             $nextDimension++;
             if (!isset($dimensionNames[$nextDimension])) {
                 // we have gone through all dimension combinations now.
                 return $dimensionCombinations;
             }
             $hasValue = next($configuration[$dimensionNames[$nextDimension]]['presets']);
         }
     }
 }
 public function setUp()
 {
     $this->publishingService = new PublishingService();
     $this->mockWorkspaceRepository = $this->getMockBuilder('TYPO3\\TYPO3CR\\Domain\\Repository\\WorkspaceRepository')->disableOriginalConstructor()->setMethods(array('findOneByName'))->getMock();
     $this->inject($this->publishingService, 'workspaceRepository', $this->mockWorkspaceRepository);
     $this->mockNodeDataRepository = $this->getMockBuilder('TYPO3\\TYPO3CR\\Domain\\Repository\\NodeDataRepository')->disableOriginalConstructor()->setMethods(array('findByWorkspace'))->getMock();
     $this->inject($this->publishingService, 'nodeDataRepository', $this->mockNodeDataRepository);
     $this->mockNodeFactory = $this->getMockBuilder('TYPO3\\TYPO3CR\\Domain\\Factory\\NodeFactory')->disableOriginalConstructor()->getMock();
     $this->inject($this->publishingService, 'nodeFactory', $this->mockNodeFactory);
     $this->mockContextFactory = $this->getMockBuilder('TYPO3\\TYPO3CR\\Domain\\Service\\ContextFactoryInterface')->disableOriginalConstructor()->getMock();
     $this->inject($this->publishingService, 'contextFactory', $this->mockContextFactory);
     $this->mockBaseWorkspace = $this->getMockBuilder('TYPO3\\TYPO3CR\\Domain\\Model\\Workspace')->disableOriginalConstructor()->getMock();
     $this->mockBaseWorkspace->expects($this->any())->method('getName')->will($this->returnValue('live'));
     $this->mockBaseWorkspace->expects($this->any())->method('getBaseWorkspace')->will($this->returnValue(null));
     $this->mockContentDimensionPresetSource = $this->getMockBuilder(ContentDimensionPresetSourceInterface::class)->disableOriginalConstructor()->getMock();
     $this->mockContentDimensionPresetSource->expects($this->any())->method('findPresetsByTargetValues')->will($this->returnArgument(0));
     $this->inject($this->publishingService, 'contentDimensionPresetSource', $this->mockContentDimensionPresetSource);
     $this->mockWorkspace = $this->getMockBuilder('TYPO3\\TYPO3CR\\Domain\\Model\\Workspace')->disableOriginalConstructor()->getMock();
     $this->mockWorkspace->expects($this->any())->method('getName')->will($this->returnValue('workspace-name'));
     $this->mockWorkspace->expects($this->any())->method('getBaseWorkspace')->will($this->returnValue($this->mockBaseWorkspace));
 }
 /**
  * Matches if the currently-selected preset in the passed $dimensionName is one of $presets.
  *
  * Example: isInDimensionPreset('language', 'de') checks whether the currently-selected language
  * preset (in the Neos backend) is "de".
  *
  * Implementation Note: We deliberately work on the Dimension Preset Name, and not on the
  * dimension values itself; as the preset is user-visible and the actual dimension-values
  * for a preset are just implementation details.
  *
  * @param string $dimensionName
  * @param string|array $presets
  * @return boolean
  */
 public function isInDimensionPreset($dimensionName, $presets)
 {
     if ($this->node === NULL) {
         return TRUE;
     }
     $dimensionValues = $this->node->getContext()->getDimensions();
     if (!isset($dimensionValues[$dimensionName])) {
         return FALSE;
     }
     $preset = $this->contentDimensionPresetSource->findPresetByDimensionValues($dimensionName, $dimensionValues[$dimensionName]);
     if ($preset === NULL) {
         return FALSE;
     }
     $presetIdentifier = $preset['identifier'];
     if (!is_array($presets)) {
         $presets = array($presets);
     }
     return in_array($presetIdentifier, $presets);
 }