/**
  * Gets affected elements on publishing/swapping actions.
  * Affected elements have a dependency, e.g. translation overlay
  * and the default origin record - thus, the default record would be
  * affected if the translation overlay shall be published.
  *
  * @param stdClass $parameters
  * @return array
  */
 protected function getAffectedElements(\stdClass $parameters)
 {
     $affectedElements = array();
     if ($parameters->type === 'selection') {
         foreach ((array) $parameters->selection as $element) {
             $affectedElements[] = \TYPO3\CMS\Workspaces\Domain\Model\CombinedRecord::create($element->table, $element->liveId, $element->versionId);
         }
     } elseif ($parameters->type === 'all') {
         $versions = $this->getWorkspaceService()->selectVersionsInWorkspace($this->getCurrentWorkspace(), 0, -99, -1, 0, 'tables_select', $this->validateLanguageParameter($parameters));
         foreach ($versions as $table => $tableElements) {
             foreach ($tableElements as $element) {
                 $affectedElement = \TYPO3\CMS\Workspaces\Domain\Model\CombinedRecord::create($table, $element['t3ver_oid'], $element['uid']);
                 $affectedElement->getVersionRecord()->setRow($element);
                 $affectedElements[] = $affectedElement;
             }
         }
     }
     return $affectedElements;
 }
 /**
  * Generates grid list array from given versions.
  *
  * @param array $versions All available version records
  * @param string $filterTxt Text to be used to filter record result
  * @return void
  */
 protected function generateDataArray(array $versions, $filterTxt)
 {
     $workspaceAccess = $GLOBALS['BE_USER']->checkWorkspace($GLOBALS['BE_USER']->workspace);
     $swapStage = $workspaceAccess['publish_access'] & 1 ? \TYPO3\CMS\Workspaces\Service\StagesService::STAGE_PUBLISH_ID : 0;
     $swapAccess = $GLOBALS['BE_USER']->workspacePublishAccess($GLOBALS['BE_USER']->workspace) && $GLOBALS['BE_USER']->workspaceSwapAccess();
     $this->initializeWorkspacesCachingFramework();
     // check for dataArray in cache
     if ($this->getDataArrayFromCache($versions, $filterTxt) === FALSE) {
         /** @var $stagesObj \TYPO3\CMS\Workspaces\Service\StagesService */
         $stagesObj = GeneralUtility::makeInstance('TYPO3\\CMS\\Workspaces\\Service\\StagesService');
         $defaultGridColumns = array(self::GridColumn_Collection => 0, self::GridColumn_CollectionLevel => 0, self::GridColumn_CollectionParent => '', self::GridColumn_CollectionCurrent => '', self::GridColumn_CollectionChildren => 0);
         foreach ($versions as $table => $records) {
             $hiddenField = $this->getTcaEnableColumnsFieldName($table, 'disabled');
             $isRecordTypeAllowedToModify = $GLOBALS['BE_USER']->check('tables_modify', $table);
             foreach ($records as $record) {
                 $origRecord = BackendUtility::getRecord($table, $record['t3ver_oid']);
                 $versionRecord = BackendUtility::getRecord($table, $record['uid']);
                 $combinedRecord = \TYPO3\CMS\Workspaces\Domain\Model\CombinedRecord::createFromArrays($table, $origRecord, $versionRecord);
                 $this->getIntegrityService()->checkElement($combinedRecord);
                 if ($hiddenField !== NULL) {
                     $recordState = $this->workspaceState($versionRecord['t3ver_state'], $origRecord[$hiddenField], $versionRecord[$hiddenField]);
                 } else {
                     $recordState = $this->workspaceState($versionRecord['t3ver_state']);
                 }
                 $isDeletedPage = $table == 'pages' && $recordState == 'deleted';
                 $viewUrl = \TYPO3\CMS\Workspaces\Service\WorkspaceService::viewSingleRecord($table, $record['uid'], $origRecord, $versionRecord);
                 $versionArray = array();
                 $versionArray['table'] = $table;
                 $versionArray['id'] = $table . ':' . $record['uid'];
                 $versionArray['uid'] = $record['uid'];
                 $versionArray['workspace'] = $versionRecord['t3ver_id'];
                 $versionArray = array_merge($versionArray, $defaultGridColumns);
                 $versionArray['label_Workspace'] = htmlspecialchars(BackendUtility::getRecordTitle($table, $versionRecord));
                 $versionArray['label_Live'] = htmlspecialchars(BackendUtility::getRecordTitle($table, $origRecord));
                 $versionArray['label_Stage'] = htmlspecialchars($stagesObj->getStageTitle($versionRecord['t3ver_stage']));
                 $tempStage = $stagesObj->getNextStage($versionRecord['t3ver_stage']);
                 $versionArray['label_nextStage'] = htmlspecialchars($stagesObj->getStageTitle($tempStage['uid']));
                 $tempStage = $stagesObj->getPrevStage($versionRecord['t3ver_stage']);
                 $versionArray['label_prevStage'] = htmlspecialchars($stagesObj->getStageTitle($tempStage['uid']));
                 $versionArray['path_Live'] = htmlspecialchars(BackendUtility::getRecordPath($record['livepid'], '', 999));
                 $versionArray['path_Workspace'] = htmlspecialchars(BackendUtility::getRecordPath($record['wspid'], '', 999));
                 $versionArray['workspace_Title'] = htmlspecialchars(\TYPO3\CMS\Workspaces\Service\WorkspaceService::getWorkspaceTitle($versionRecord['t3ver_wsid']));
                 $versionArray['workspace_Tstamp'] = $versionRecord['tstamp'];
                 $versionArray['workspace_Formated_Tstamp'] = BackendUtility::datetime($versionRecord['tstamp']);
                 $versionArray['t3ver_wsid'] = $versionRecord['t3ver_wsid'];
                 $versionArray['t3ver_oid'] = $record['t3ver_oid'];
                 $versionArray['livepid'] = $record['livepid'];
                 $versionArray['stage'] = $versionRecord['t3ver_stage'];
                 $versionArray['icon_Live'] = \TYPO3\CMS\Backend\Utility\IconUtility::mapRecordTypeToSpriteIconClass($table, $origRecord);
                 $versionArray['icon_Workspace'] = \TYPO3\CMS\Backend\Utility\IconUtility::mapRecordTypeToSpriteIconClass($table, $versionRecord);
                 $languageValue = $this->getLanguageValue($table, $versionRecord);
                 $versionArray['languageValue'] = $languageValue;
                 $versionArray['language'] = array('cls' => \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconClasses($this->getSystemLanguageValue($languageValue, 'flagIcon')), 'title' => htmlspecialchars($this->getSystemLanguageValue($languageValue, 'title')));
                 $versionArray['allowedAction_nextStage'] = $isRecordTypeAllowedToModify && $stagesObj->isNextStageAllowedForUser($versionRecord['t3ver_stage']);
                 $versionArray['allowedAction_prevStage'] = $isRecordTypeAllowedToModify && $stagesObj->isPrevStageAllowedForUser($versionRecord['t3ver_stage']);
                 if ($swapAccess && $swapStage != 0 && $versionRecord['t3ver_stage'] == $swapStage) {
                     $versionArray['allowedAction_swap'] = $isRecordTypeAllowedToModify && $stagesObj->isNextStageAllowedForUser($swapStage);
                 } elseif ($swapAccess && $swapStage == 0) {
                     $versionArray['allowedAction_swap'] = $isRecordTypeAllowedToModify;
                 } else {
                     $versionArray['allowedAction_swap'] = FALSE;
                 }
                 $versionArray['allowedAction_delete'] = $isRecordTypeAllowedToModify;
                 // preview and editing of a deleted page won't work ;)
                 $versionArray['allowedAction_view'] = !$isDeletedPage && $viewUrl;
                 $versionArray['allowedAction_edit'] = $isRecordTypeAllowedToModify && !$isDeletedPage;
                 $versionArray['allowedAction_editVersionedPage'] = $isRecordTypeAllowedToModify && !$isDeletedPage;
                 $versionArray['state_Workspace'] = $recordState;
                 $versionArray = array_merge($versionArray, $this->getAdditionalColumnService()->getData($combinedRecord));
                 if ($filterTxt == '' || $this->isFilterTextInVisibleColumns($filterTxt, $versionArray)) {
                     $versionIdentifier = $versionArray['id'];
                     $this->dataArray[$versionIdentifier] = $versionArray;
                 }
             }
         }
         // Suggested slot method:
         // methodName(\TYPO3\CMS\Workspaces\Service\GridDataService $gridData, array &$dataArray, array $versions)
         $this->emitSignal(self::SIGNAL_GenerateDataArray_BeforeCaching, $this->dataArray, $versions);
         // Enrich elements after everything has been processed:
         foreach ($this->dataArray as &$element) {
             $identifier = $element['table'] . ':' . $element['t3ver_oid'];
             $element['integrity'] = array('status' => $this->getIntegrityService()->getStatusRepresentation($identifier), 'messages' => htmlspecialchars($this->getIntegrityService()->getIssueMessages($identifier, TRUE)));
         }
         $this->setDataArrayIntoCache($versions, $filterTxt);
     }
     // Suggested slot method:
     // methodName(\TYPO3\CMS\Workspaces\Service\GridDataService $gridData, array &$dataArray, array $versions)
     $this->emitSignal(self::SIGNAL_GenerateDataArray_PostProcesss, $this->dataArray, $versions);
     $this->sortDataArray();
     $this->resolveDataArrayDependencies();
 }
 /**
  * Checks workspace localization integrity of a single elements.
  * If current record is a localization and its localization parent
  * is new in this workspace (has only a placeholder record in live),
  * then boths (localization and localization parent) should be published.
  *
  * @param \TYPO3\CMS\Workspaces\Domain\Model\CombinedRecord $element
  * @return void
  */
 protected function checkLocalization(\TYPO3\CMS\Workspaces\Domain\Model\CombinedRecord $element)
 {
     $table = $element->getTable();
     if (BackendUtility::isTableLocalizable($table)) {
         $languageField = $GLOBALS['TCA'][$table]['ctrl']['languageField'];
         $languageParentField = $GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField'];
         $versionRow = $element->getVersionRecord()->getRow();
         // If element is a localization:
         if ($versionRow[$languageField] > 0) {
             // Get localization parent from live workspace:
             $languageParentRecord = BackendUtility::getRecord($table, $versionRow[$languageParentField], 'uid,t3ver_state');
             // If localization parent is a "new placeholder" record:
             if (VersionState::cast($languageParentRecord['t3ver_state'])->equals(VersionState::NEW_PLACEHOLDER)) {
                 $title = BackendUtility::getRecordTitle($table, $versionRow);
                 // Add warning for current versionized record:
                 $this->addIssue($element->getLiveRecord()->getIdentifier(), self::STATUS_Warning, sprintf(\TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('integrity.dependsOnDefaultLanguageRecord', 'workspaces'), $title));
                 // Add info for related localization parent record:
                 $this->addIssue($table . ':' . $languageParentRecord['uid'], self::STATUS_Info, sprintf(\TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('integrity.isDefaultLanguageRecord', 'workspaces'), $title));
             }
         }
     }
 }