[TASK] Re-work/simplify copyright header in PHP files - Part 8
[Packages/TYPO3.CMS.git] / typo3 / sysext / workspaces / Classes / ExtDirect / AbstractHandler.php
1 <?php
2 namespace TYPO3\CMS\Workspaces\ExtDirect;
3
4 /**
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16 /**
17 * Abstract ExtDirect handler
18 *
19 * @author Workspaces Team (http://forge.typo3.org/projects/show/typo3v4-workspaces)
20 */
21 abstract class AbstractHandler {
22
23 /**
24 * Gets the current workspace ID.
25 *
26 * @return integer The current workspace ID
27 */
28 protected function getCurrentWorkspace() {
29 return $this->getWorkspaceService()->getCurrentWorkspace();
30 }
31
32 /**
33 * Gets an error response to be shown in the grid component.
34 *
35 * @param string $errorLabel Name of the label in the locallang.xlf file
36 * @param integer $errorCode The error code to be used
37 * @param boolean $successFlagValue Value of the success flag to be delivered back (might be FALSE in most cases)
38 * @return array
39 */
40 protected function getErrorResponse($errorLabel, $errorCode = 0, $successFlagValue = FALSE) {
41 $localLangFile = 'LLL:EXT:workspaces/Resources/Private/Language/locallang.xlf';
42 $response = array(
43 'error' => array(
44 'code' => $errorCode,
45 'message' => $GLOBALS['LANG']->sL($localLangFile . ':' . $errorLabel)
46 ),
47 'success' => $successFlagValue
48 );
49 return $response;
50 }
51
52 /**
53 * Gets an instance of the workspaces service.
54 *
55 * @return \TYPO3\CMS\Workspaces\Service\WorkspaceService
56 */
57 protected function getWorkspaceService() {
58 return \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Workspaces\\Service\\WorkspaceService');
59 }
60
61 /**
62 * Validates whether the submitted language parameter can be
63 * interpreted as integer value.
64 *
65 * @param stdClass $parameters
66 * @return integer|NULL
67 */
68 protected function validateLanguageParameter(\stdClass $parameters) {
69 $language = NULL;
70 if (isset($parameters->language) && \TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($parameters->language)) {
71 $language = $parameters->language;
72 }
73 return $language;
74 }
75
76 /**
77 * Gets affected elements on publishing/swapping actions.
78 * Affected elements have a dependency, e.g. translation overlay
79 * and the default origin record - thus, the default record would be
80 * affected if the translation overlay shall be published.
81 *
82 * @param stdClass $parameters
83 * @return array
84 */
85 protected function getAffectedElements(\stdClass $parameters) {
86 $affectedElements = array();
87 if ($parameters->type === 'selection') {
88 foreach ((array) $parameters->selection as $element) {
89 $affectedElements[] = \TYPO3\CMS\Workspaces\Domain\Model\CombinedRecord::create($element->table, $element->liveId, $element->versionId);
90 }
91 } elseif ($parameters->type === 'all') {
92 $versions = $this->getWorkspaceService()->selectVersionsInWorkspace($this->getCurrentWorkspace(), 0, -99, -1, 0, 'tables_select', $this->validateLanguageParameter($parameters));
93 foreach ($versions as $table => $tableElements) {
94 foreach ($tableElements as $element) {
95 $affectedElement = \TYPO3\CMS\Workspaces\Domain\Model\CombinedRecord::create($table, $element['t3ver_oid'], $element['uid']);
96 $affectedElement->getVersionRecord()->setRow($element);
97 $affectedElements[] = $affectedElement;
98 }
99 }
100 }
101 return $affectedElements;
102 }
103
104 /**
105 * Creates a new instance of the integrity service for the
106 * given set of affected elements.
107 *
108 * @param \TYPO3\CMS\Workspaces\Domain\Model\CombinedRecord[] $affectedElements
109 * @return \TYPO3\CMS\Workspaces\Service\IntegrityService
110 * @see getAffectedElements
111 */
112 protected function createIntegrityService(array $affectedElements) {
113 /** @var $integrityService \TYPO3\CMS\Workspaces\Service\IntegrityService */
114 $integrityService = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Workspaces\\Service\\IntegrityService');
115 $integrityService->setAffectedElements($affectedElements);
116 return $integrityService;
117 }
118
119 }