1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace HDNET\Focuspoint\Service\WizardHandler; |
4
|
|
|
|
5
|
|
|
use HDNET\Focuspoint\Domain\Repository\FileStandaloneRepository; |
6
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Group. |
10
|
|
|
*/ |
11
|
|
|
class Group extends AbstractWizardHandler |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* Check if the handler can handle the current request. |
15
|
|
|
* |
16
|
|
|
* @return bool |
17
|
|
|
*/ |
18
|
|
|
public function canHandle() |
19
|
|
|
{ |
20
|
|
|
return null !== $this->getRelativeFilePath(); |
|
|
|
|
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Return the current point. |
25
|
|
|
* |
26
|
|
|
* @return int[] |
27
|
|
|
*/ |
28
|
|
|
public function getCurrentPoint() |
29
|
|
|
{ |
30
|
|
|
$fileStandaloneRepository = GeneralUtility::makeInstance(FileStandaloneRepository::class); |
31
|
|
|
$row = $fileStandaloneRepository->findOneByRelativeFilePath($this->getRelativeFilePath()); |
32
|
|
|
if (!isset($row['focus_point_x'])) { |
33
|
|
|
return [0, 0]; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
return $this->cleanupPosition([ |
37
|
|
|
$row['focus_point_x'], |
38
|
|
|
$row['focus_point_y'], |
39
|
|
|
]); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Set the point (between -100 and 100). |
44
|
|
|
* |
45
|
|
|
* @param int $x |
46
|
|
|
* @param int $y |
47
|
|
|
*/ |
48
|
|
|
public function setCurrentPoint($x, $y) |
49
|
|
|
{ |
50
|
|
|
$fileStandaloneRepository = GeneralUtility::makeInstance(FileStandaloneRepository::class); |
51
|
|
|
$row = $fileStandaloneRepository->findOneByRelativeFilePath($this->getRelativeFilePath()); |
52
|
|
|
|
53
|
|
|
$values = [ |
54
|
|
|
'focus_point_x' => $x, |
55
|
|
|
'focus_point_y' => $y, |
56
|
|
|
'relative_file_path' => $this->getRelativeFilePath(), |
57
|
|
|
]; |
58
|
|
|
|
59
|
|
|
if (isset($row['uid'])) { |
60
|
|
|
$fileStandaloneRepository->update( |
61
|
|
|
(int) $row['uid'], |
62
|
|
|
$values |
63
|
|
|
); |
64
|
|
|
} else { |
65
|
|
|
$fileStandaloneRepository->insert( |
66
|
|
|
$values |
67
|
|
|
); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Get the public URL for the current handler. |
73
|
|
|
* |
74
|
|
|
* @return string |
75
|
|
|
*/ |
76
|
|
|
public function getPublicUrl() |
77
|
|
|
{ |
78
|
|
|
return $this->displayableImageUrl($this->getRelativeFilePath()); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* get the arguments for same request call. |
83
|
|
|
* |
84
|
|
|
* @return array |
85
|
|
|
*/ |
86
|
|
|
public function getArguments() |
87
|
|
|
{ |
88
|
|
|
$parameter = GeneralUtility::_GET(); |
89
|
|
|
$p = $parameter['P']; |
90
|
|
|
|
91
|
|
|
return [ |
92
|
|
|
'P' => [ |
93
|
|
|
'table' => $p['table'], |
94
|
|
|
'field' => $p['field'], |
95
|
|
|
'file' => $p['file'], |
96
|
|
|
], |
97
|
|
|
]; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* get the file name. |
102
|
|
|
* |
103
|
|
|
* @return string|null |
104
|
|
|
*/ |
105
|
|
|
protected function getRelativeFilePath() |
106
|
|
|
{ |
107
|
|
|
$parameter = GeneralUtility::_GET(); |
108
|
|
|
if (!isset($parameter['P'])) { |
109
|
|
|
return; |
110
|
|
|
} |
111
|
|
|
$p = $parameter['P']; |
112
|
|
|
if (!isset($p['table']) || !isset($p['field']) || !isset($p['file'])) { |
113
|
|
|
return; |
114
|
|
|
} |
115
|
|
|
if (!isset($GLOBALS['TCA'][$p['table']])) { |
116
|
|
|
return; |
117
|
|
|
} |
118
|
|
|
$tableTca = $GLOBALS['TCA'][$p['table']]; |
119
|
|
|
if (!isset($tableTca['columns'][$p['field']])) { |
120
|
|
|
return; |
121
|
|
|
} |
122
|
|
|
$fieldTca = $tableTca['columns'][$p['field']]; |
123
|
|
|
|
124
|
|
|
$uploadFolder = $fieldTca['config']['uploadfolder'] ?? ''; |
125
|
|
|
$baseFolder = ''; |
126
|
|
|
if ('' !== \trim($uploadFolder, '/')) { |
127
|
|
|
$baseFolder = \rtrim($uploadFolder, '/') . '/'; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
$filePath = $baseFolder . $p['file']; |
131
|
|
|
if (!\is_file(GeneralUtility::getFileAbsFileName($filePath))) { |
132
|
|
|
return; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
return $filePath; |
136
|
|
|
} |
137
|
|
|
} |
138
|
|
|
|
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.
Let’s take a look at an example:
Our function
my_function
expects aPost
object, and outputs the author of the post. The base classPost
returns a simple string and outputting a simple string will work just fine. However, the child classBlogPost
which is a sub-type ofPost
instead decided to return anobject
, and is therefore violating the SOLID principles. If aBlogPost
were passed tomy_function
, PHP would not complain, but ultimately fail when executing thestrtoupper
call in its body.