@@ -17,37 +17,37 @@ discard block |
||
17 | 17 | class RelationsCheck extends AbstractComponentView |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * @var array |
|
22 | - */ |
|
23 | - protected $invalidFields = []; |
|
24 | - |
|
25 | - /** |
|
26 | - * Renders a button for uploading assets. |
|
27 | - * |
|
28 | - * @return string |
|
29 | - */ |
|
30 | - public function render() |
|
31 | - { |
|
32 | - |
|
33 | - $result = ''; |
|
34 | - |
|
35 | - // Check whether storage is configured or not. |
|
36 | - if (!$this->isTcaValid()) { |
|
37 | - $result .= $this->formatMessageTcaIsNotValid(); |
|
38 | - } |
|
39 | - |
|
40 | - return $result; |
|
41 | - } |
|
42 | - |
|
43 | - /** |
|
44 | - * Format a message whenever the storage is offline. |
|
45 | - * |
|
46 | - * @return string |
|
47 | - */ |
|
48 | - protected function formatMessageTcaIsNotValid() |
|
49 | - { |
|
50 | - $result = <<< EOF |
|
20 | + /** |
|
21 | + * @var array |
|
22 | + */ |
|
23 | + protected $invalidFields = []; |
|
24 | + |
|
25 | + /** |
|
26 | + * Renders a button for uploading assets. |
|
27 | + * |
|
28 | + * @return string |
|
29 | + */ |
|
30 | + public function render() |
|
31 | + { |
|
32 | + |
|
33 | + $result = ''; |
|
34 | + |
|
35 | + // Check whether storage is configured or not. |
|
36 | + if (!$this->isTcaValid()) { |
|
37 | + $result .= $this->formatMessageTcaIsNotValid(); |
|
38 | + } |
|
39 | + |
|
40 | + return $result; |
|
41 | + } |
|
42 | + |
|
43 | + /** |
|
44 | + * Format a message whenever the storage is offline. |
|
45 | + * |
|
46 | + * @return string |
|
47 | + */ |
|
48 | + protected function formatMessageTcaIsNotValid() |
|
49 | + { |
|
50 | + $result = <<< EOF |
|
51 | 51 | <div class="-warning alert alert-warning"> |
52 | 52 | <div class="alert-title"> |
53 | 53 | Grid may have trouble to render because of wrong / missing TCA. |
@@ -62,19 +62,19 @@ discard block |
||
62 | 62 | </div> |
63 | 63 | </div> |
64 | 64 | EOF; |
65 | - return $result; |
|
66 | - } |
|
67 | - |
|
68 | - /** |
|
69 | - * Check relations of current data type in the Grid. |
|
70 | - * |
|
71 | - * @return string |
|
72 | - */ |
|
73 | - protected function formatMessageHelperText() |
|
74 | - { |
|
75 | - $helperText = ''; |
|
76 | - foreach ($this->invalidFields as $invalidField) { |
|
77 | - $helperText .= <<<EOF |
|
65 | + return $result; |
|
66 | + } |
|
67 | + |
|
68 | + /** |
|
69 | + * Check relations of current data type in the Grid. |
|
70 | + * |
|
71 | + * @return string |
|
72 | + */ |
|
73 | + protected function formatMessageHelperText() |
|
74 | + { |
|
75 | + $helperText = ''; |
|
76 | + foreach ($this->invalidFields as $invalidField) { |
|
77 | + $helperText .= <<<EOF |
|
78 | 78 | <br /> |
79 | 79 | In file EXT:my_ext/Configuration/TCA/{$this->getModuleLoader()->getDataType()}.php |
80 | 80 | <pre> |
@@ -108,42 +108,42 @@ discard block |
||
108 | 108 | |
109 | 109 | </pre> |
110 | 110 | EOF; |
111 | - } |
|
112 | - return $helperText; |
|
113 | - } |
|
114 | - |
|
115 | - /** |
|
116 | - * Check relations of current data type in the Grid. |
|
117 | - * |
|
118 | - * @return boolean |
|
119 | - */ |
|
120 | - protected function isTcaValid() |
|
121 | - { |
|
122 | - |
|
123 | - $dataType = $this->getModuleLoader()->getDataType(); |
|
124 | - $table = Tca::table($dataType); |
|
125 | - |
|
126 | - foreach (Tca::grid($dataType)->getFields() as $fieldName => $configuration) { |
|
127 | - |
|
128 | - if ($table->hasField($fieldName) && $table->field($fieldName)->hasMany()) { |
|
129 | - if ($table->field($fieldName)->hasRelationManyToMany()) { |
|
130 | - |
|
131 | - $foreignTable = $table->field($fieldName)->getForeignTable(); |
|
132 | - $manyToManyTable = $table->field($fieldName)->getManyToManyTable(); |
|
133 | - $foreignField = $table->field($fieldName)->getForeignField(); |
|
134 | - |
|
135 | - if (!$foreignField) { |
|
136 | - $this->invalidFields[] = $fieldName; |
|
137 | - } elseif (!$foreignTable) { |
|
138 | - $this->invalidFields[] = $fieldName; |
|
139 | - } elseif (!$manyToManyTable) { |
|
140 | - $this->invalidFields[] = $fieldName; |
|
141 | - } |
|
142 | - } |
|
143 | - } |
|
144 | - } |
|
145 | - |
|
146 | - return empty($this->invalidFields); |
|
147 | - } |
|
111 | + } |
|
112 | + return $helperText; |
|
113 | + } |
|
114 | + |
|
115 | + /** |
|
116 | + * Check relations of current data type in the Grid. |
|
117 | + * |
|
118 | + * @return boolean |
|
119 | + */ |
|
120 | + protected function isTcaValid() |
|
121 | + { |
|
122 | + |
|
123 | + $dataType = $this->getModuleLoader()->getDataType(); |
|
124 | + $table = Tca::table($dataType); |
|
125 | + |
|
126 | + foreach (Tca::grid($dataType)->getFields() as $fieldName => $configuration) { |
|
127 | + |
|
128 | + if ($table->hasField($fieldName) && $table->field($fieldName)->hasMany()) { |
|
129 | + if ($table->field($fieldName)->hasRelationManyToMany()) { |
|
130 | + |
|
131 | + $foreignTable = $table->field($fieldName)->getForeignTable(); |
|
132 | + $manyToManyTable = $table->field($fieldName)->getManyToManyTable(); |
|
133 | + $foreignField = $table->field($fieldName)->getForeignField(); |
|
134 | + |
|
135 | + if (!$foreignField) { |
|
136 | + $this->invalidFields[] = $fieldName; |
|
137 | + } elseif (!$foreignTable) { |
|
138 | + $this->invalidFields[] = $fieldName; |
|
139 | + } elseif (!$manyToManyTable) { |
|
140 | + $this->invalidFields[] = $fieldName; |
|
141 | + } |
|
142 | + } |
|
143 | + } |
|
144 | + } |
|
145 | + |
|
146 | + return empty($this->invalidFields); |
|
147 | + } |
|
148 | 148 | |
149 | 149 | } |
@@ -45,8 +45,8 @@ discard block |
||
45 | 45 | $expressionBuilder = GeneralUtility::makeInstance(ConnectionPool::class) |
46 | 46 | ->getQueryBuilderForTable($table) |
47 | 47 | ->expr(); |
48 | - return $withLogicalSeparator . ' ' . $expressionBuilder->eq( |
|
49 | - $table . '.' . $GLOBALS['TCA'][$table]['ctrl']['delete'], |
|
48 | + return $withLogicalSeparator.' '.$expressionBuilder->eq( |
|
49 | + $table.'.'.$GLOBALS['TCA'][$table]['ctrl']['delete'], |
|
50 | 50 | 0 |
51 | 51 | ); |
52 | 52 | } |
@@ -72,12 +72,12 @@ discard block |
||
72 | 72 | if (is_array($ctrl)) { |
73 | 73 | if (is_array($ctrl['enablecolumns'])) { |
74 | 74 | if ($ctrl['enablecolumns']['disabled'] ?? false) { |
75 | - $field = $table . '.' . $ctrl['enablecolumns']['disabled']; |
|
75 | + $field = $table.'.'.$ctrl['enablecolumns']['disabled']; |
|
76 | 76 | $query->add($expressionBuilder->eq($field, 0)); |
77 | 77 | $invQuery->add($expressionBuilder->neq($field, 0)); |
78 | 78 | } |
79 | 79 | if ($ctrl['enablecolumns']['starttime'] ?? false) { |
80 | - $field = $table . '.' . $ctrl['enablecolumns']['starttime']; |
|
80 | + $field = $table.'.'.$ctrl['enablecolumns']['starttime']; |
|
81 | 81 | $query->add($expressionBuilder->lte($field, (int)$GLOBALS['SIM_ACCESS_TIME'])); |
82 | 82 | $invQuery->add( |
83 | 83 | $expressionBuilder->andX( |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | ); |
88 | 88 | } |
89 | 89 | if ($ctrl['enablecolumns']['endtime'] ?? false) { |
90 | - $field = $table . '.' . $ctrl['enablecolumns']['endtime']; |
|
90 | + $field = $table.'.'.$ctrl['enablecolumns']['endtime']; |
|
91 | 91 | $query->add( |
92 | 92 | $expressionBuilder->orX( |
93 | 93 | $expressionBuilder->eq($field, 0), |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | return ''; |
109 | 109 | } |
110 | 110 | |
111 | - return ' AND ' . ($inv ? $invQuery : $query); |
|
111 | + return ' AND '.($inv ? $invQuery : $query); |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | /** |
@@ -18,115 +18,115 @@ |
||
18 | 18 | class BackendUtility |
19 | 19 | { |
20 | 20 | |
21 | - /******************************************* |
|
21 | + /******************************************* |
|
22 | 22 | * |
23 | 23 | * SQL-related, selecting records, searching |
24 | 24 | * |
25 | 25 | *******************************************/ |
26 | - /** |
|
27 | - * Returns the WHERE clause " AND NOT [tablename].[deleted-field]" if a deleted-field |
|
28 | - * is configured in $GLOBALS['TCA'] for the tablename, $table |
|
29 | - * This function should ALWAYS be called in the backend for selection on tables which |
|
30 | - * are configured in $GLOBALS['TCA'] since it will ensure consistent selection of records, |
|
31 | - * even if they are marked deleted (in which case the system must always treat them as non-existent!) |
|
32 | - * In the frontend a function, ->enableFields(), is known to filter hidden-field, start- and endtime |
|
33 | - * and fe_groups as well. But that is a job of the frontend, not the backend. If you need filtering |
|
34 | - * on those fields as well in the backend you can use ->BEenableFields() though. |
|
35 | - * |
|
36 | - * @param string $table Table name present in $GLOBALS['TCA'] |
|
37 | - * @param string $withLogicalSeparator Table alias if any |
|
38 | - * @return string WHERE clause for filtering out deleted records, eg " AND tablename.deleted=0 |
|
39 | - */ |
|
40 | - public static function deleteClause($table, $withLogicalSeparator = ' AND') |
|
41 | - { |
|
42 | - if (empty($GLOBALS['TCA'][$table]['ctrl']['delete'])) { |
|
43 | - return ''; |
|
44 | - } |
|
45 | - $expressionBuilder = GeneralUtility::makeInstance(ConnectionPool::class) |
|
46 | - ->getQueryBuilderForTable($table) |
|
47 | - ->expr(); |
|
48 | - return $withLogicalSeparator . ' ' . $expressionBuilder->eq( |
|
49 | - $table . '.' . $GLOBALS['TCA'][$table]['ctrl']['delete'], |
|
50 | - 0 |
|
51 | - ); |
|
52 | - } |
|
53 | - /** |
|
54 | - * Backend implementation of enableFields() |
|
55 | - * Notice that "fe_groups" is not selected for - only disabled, starttime and endtime. |
|
56 | - * Notice that deleted-fields are NOT filtered - you must ALSO call deleteClause in addition. |
|
57 | - * $GLOBALS["SIM_ACCESS_TIME"] is used for date. |
|
58 | - * |
|
59 | - * @param string $table The table from which to return enableFields WHERE clause. Table name must have a 'ctrl' section in $GLOBALS['TCA']. |
|
60 | - * @param bool $inv Means that the query will select all records NOT VISIBLE records (inverted selection) |
|
61 | - * @return string WHERE clause part |
|
62 | - */ |
|
63 | - public static function BEenableFields($table, $inv = false) |
|
64 | - { |
|
65 | - $ctrl = $GLOBALS['TCA'][$table]['ctrl']; |
|
66 | - $expressionBuilder = GeneralUtility::makeInstance(ConnectionPool::class) |
|
67 | - ->getConnectionForTable($table) |
|
68 | - ->getExpressionBuilder(); |
|
69 | - $query = $expressionBuilder->andX(); |
|
70 | - $invQuery = $expressionBuilder->orX(); |
|
26 | + /** |
|
27 | + * Returns the WHERE clause " AND NOT [tablename].[deleted-field]" if a deleted-field |
|
28 | + * is configured in $GLOBALS['TCA'] for the tablename, $table |
|
29 | + * This function should ALWAYS be called in the backend for selection on tables which |
|
30 | + * are configured in $GLOBALS['TCA'] since it will ensure consistent selection of records, |
|
31 | + * even if they are marked deleted (in which case the system must always treat them as non-existent!) |
|
32 | + * In the frontend a function, ->enableFields(), is known to filter hidden-field, start- and endtime |
|
33 | + * and fe_groups as well. But that is a job of the frontend, not the backend. If you need filtering |
|
34 | + * on those fields as well in the backend you can use ->BEenableFields() though. |
|
35 | + * |
|
36 | + * @param string $table Table name present in $GLOBALS['TCA'] |
|
37 | + * @param string $withLogicalSeparator Table alias if any |
|
38 | + * @return string WHERE clause for filtering out deleted records, eg " AND tablename.deleted=0 |
|
39 | + */ |
|
40 | + public static function deleteClause($table, $withLogicalSeparator = ' AND') |
|
41 | + { |
|
42 | + if (empty($GLOBALS['TCA'][$table]['ctrl']['delete'])) { |
|
43 | + return ''; |
|
44 | + } |
|
45 | + $expressionBuilder = GeneralUtility::makeInstance(ConnectionPool::class) |
|
46 | + ->getQueryBuilderForTable($table) |
|
47 | + ->expr(); |
|
48 | + return $withLogicalSeparator . ' ' . $expressionBuilder->eq( |
|
49 | + $table . '.' . $GLOBALS['TCA'][$table]['ctrl']['delete'], |
|
50 | + 0 |
|
51 | + ); |
|
52 | + } |
|
53 | + /** |
|
54 | + * Backend implementation of enableFields() |
|
55 | + * Notice that "fe_groups" is not selected for - only disabled, starttime and endtime. |
|
56 | + * Notice that deleted-fields are NOT filtered - you must ALSO call deleteClause in addition. |
|
57 | + * $GLOBALS["SIM_ACCESS_TIME"] is used for date. |
|
58 | + * |
|
59 | + * @param string $table The table from which to return enableFields WHERE clause. Table name must have a 'ctrl' section in $GLOBALS['TCA']. |
|
60 | + * @param bool $inv Means that the query will select all records NOT VISIBLE records (inverted selection) |
|
61 | + * @return string WHERE clause part |
|
62 | + */ |
|
63 | + public static function BEenableFields($table, $inv = false) |
|
64 | + { |
|
65 | + $ctrl = $GLOBALS['TCA'][$table]['ctrl']; |
|
66 | + $expressionBuilder = GeneralUtility::makeInstance(ConnectionPool::class) |
|
67 | + ->getConnectionForTable($table) |
|
68 | + ->getExpressionBuilder(); |
|
69 | + $query = $expressionBuilder->andX(); |
|
70 | + $invQuery = $expressionBuilder->orX(); |
|
71 | 71 | |
72 | - if (is_array($ctrl)) { |
|
73 | - if (is_array($ctrl['enablecolumns'])) { |
|
74 | - if ($ctrl['enablecolumns']['disabled'] ?? false) { |
|
75 | - $field = $table . '.' . $ctrl['enablecolumns']['disabled']; |
|
76 | - $query->add($expressionBuilder->eq($field, 0)); |
|
77 | - $invQuery->add($expressionBuilder->neq($field, 0)); |
|
78 | - } |
|
79 | - if ($ctrl['enablecolumns']['starttime'] ?? false) { |
|
80 | - $field = $table . '.' . $ctrl['enablecolumns']['starttime']; |
|
81 | - $query->add($expressionBuilder->lte($field, (int)$GLOBALS['SIM_ACCESS_TIME'])); |
|
82 | - $invQuery->add( |
|
83 | - $expressionBuilder->andX( |
|
84 | - $expressionBuilder->neq($field, 0), |
|
85 | - $expressionBuilder->gt($field, (int)$GLOBALS['SIM_ACCESS_TIME']) |
|
86 | - ) |
|
87 | - ); |
|
88 | - } |
|
89 | - if ($ctrl['enablecolumns']['endtime'] ?? false) { |
|
90 | - $field = $table . '.' . $ctrl['enablecolumns']['endtime']; |
|
91 | - $query->add( |
|
92 | - $expressionBuilder->orX( |
|
93 | - $expressionBuilder->eq($field, 0), |
|
94 | - $expressionBuilder->gt($field, (int)$GLOBALS['SIM_ACCESS_TIME']) |
|
95 | - ) |
|
96 | - ); |
|
97 | - $invQuery->add( |
|
98 | - $expressionBuilder->andX( |
|
99 | - $expressionBuilder->neq($field, 0), |
|
100 | - $expressionBuilder->lte($field, (int)$GLOBALS['SIM_ACCESS_TIME']) |
|
101 | - ) |
|
102 | - ); |
|
103 | - } |
|
104 | - } |
|
105 | - } |
|
72 | + if (is_array($ctrl)) { |
|
73 | + if (is_array($ctrl['enablecolumns'])) { |
|
74 | + if ($ctrl['enablecolumns']['disabled'] ?? false) { |
|
75 | + $field = $table . '.' . $ctrl['enablecolumns']['disabled']; |
|
76 | + $query->add($expressionBuilder->eq($field, 0)); |
|
77 | + $invQuery->add($expressionBuilder->neq($field, 0)); |
|
78 | + } |
|
79 | + if ($ctrl['enablecolumns']['starttime'] ?? false) { |
|
80 | + $field = $table . '.' . $ctrl['enablecolumns']['starttime']; |
|
81 | + $query->add($expressionBuilder->lte($field, (int)$GLOBALS['SIM_ACCESS_TIME'])); |
|
82 | + $invQuery->add( |
|
83 | + $expressionBuilder->andX( |
|
84 | + $expressionBuilder->neq($field, 0), |
|
85 | + $expressionBuilder->gt($field, (int)$GLOBALS['SIM_ACCESS_TIME']) |
|
86 | + ) |
|
87 | + ); |
|
88 | + } |
|
89 | + if ($ctrl['enablecolumns']['endtime'] ?? false) { |
|
90 | + $field = $table . '.' . $ctrl['enablecolumns']['endtime']; |
|
91 | + $query->add( |
|
92 | + $expressionBuilder->orX( |
|
93 | + $expressionBuilder->eq($field, 0), |
|
94 | + $expressionBuilder->gt($field, (int)$GLOBALS['SIM_ACCESS_TIME']) |
|
95 | + ) |
|
96 | + ); |
|
97 | + $invQuery->add( |
|
98 | + $expressionBuilder->andX( |
|
99 | + $expressionBuilder->neq($field, 0), |
|
100 | + $expressionBuilder->lte($field, (int)$GLOBALS['SIM_ACCESS_TIME']) |
|
101 | + ) |
|
102 | + ); |
|
103 | + } |
|
104 | + } |
|
105 | + } |
|
106 | 106 | |
107 | - if ($query->count() === 0) { |
|
108 | - return ''; |
|
109 | - } |
|
107 | + if ($query->count() === 0) { |
|
108 | + return ''; |
|
109 | + } |
|
110 | 110 | |
111 | - return ' AND ' . ($inv ? $invQuery : $query); |
|
112 | - } |
|
111 | + return ' AND ' . ($inv ? $invQuery : $query); |
|
112 | + } |
|
113 | 113 | |
114 | - /** |
|
115 | - * Returns the URL to a given module |
|
116 | - * |
|
117 | - * @param string $moduleName Name of the module |
|
118 | - * @param array $urlParameters URL parameters that should be added as key value pairs |
|
119 | - * @return string Calculated URL |
|
120 | - */ |
|
121 | - public static function getModuleUrl($moduleName, $urlParameters = []) |
|
122 | - { |
|
123 | - $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class); |
|
124 | - try { |
|
125 | - $uri = $uriBuilder->buildUriFromRoute($moduleName, $urlParameters); |
|
126 | - } catch (RouteNotFoundException $e) { |
|
127 | - $uri = $uriBuilder->buildUriFromRoutePath($moduleName, $urlParameters); |
|
128 | - } |
|
129 | - return (string)$uri; |
|
130 | - } |
|
114 | + /** |
|
115 | + * Returns the URL to a given module |
|
116 | + * |
|
117 | + * @param string $moduleName Name of the module |
|
118 | + * @param array $urlParameters URL parameters that should be added as key value pairs |
|
119 | + * @return string Calculated URL |
|
120 | + */ |
|
121 | + public static function getModuleUrl($moduleName, $urlParameters = []) |
|
122 | + { |
|
123 | + $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class); |
|
124 | + try { |
|
125 | + $uri = $uriBuilder->buildUriFromRoute($moduleName, $urlParameters); |
|
126 | + } catch (RouteNotFoundException $e) { |
|
127 | + $uri = $uriBuilder->buildUriFromRoutePath($moduleName, $urlParameters); |
|
128 | + } |
|
129 | + return (string)$uri; |
|
130 | + } |
|
131 | 131 | |
132 | 132 | } |
@@ -13,499 +13,499 @@ |
||
13 | 13 | */ |
14 | 14 | class Matcher |
15 | 15 | { |
16 | - /** |
|
17 | - * The logical OR |
|
18 | - */ |
|
19 | - const LOGICAL_OR = 'logicalOr'; |
|
20 | - |
|
21 | - /** |
|
22 | - * The logical AND |
|
23 | - */ |
|
24 | - const LOGICAL_AND = 'logicalAnd'; |
|
25 | - |
|
26 | - /** |
|
27 | - * @var string |
|
28 | - */ |
|
29 | - protected $dataType = ''; |
|
30 | - |
|
31 | - /** |
|
32 | - * @var string |
|
33 | - */ |
|
34 | - protected $searchTerm = ''; |
|
35 | - |
|
36 | - /** |
|
37 | - * @var array |
|
38 | - */ |
|
39 | - protected $supportedOperators = [ |
|
40 | - '=' => 'equals', |
|
41 | - '!=' => 'notEquals', |
|
42 | - 'in' => 'in', |
|
43 | - 'like' => 'like', |
|
44 | - '>' => 'greaterThan', |
|
45 | - '>=' => 'greaterThanOrEqual', |
|
46 | - '<' => 'lessThan', |
|
47 | - '<=' => 'lessThanOrEqual', |
|
48 | - ]; |
|
49 | - |
|
50 | - /** |
|
51 | - * @var array |
|
52 | - */ |
|
53 | - protected $equals = []; |
|
54 | - |
|
55 | - /** |
|
56 | - * @var array |
|
57 | - */ |
|
58 | - protected $notEquals = []; |
|
59 | - |
|
60 | - /** |
|
61 | - * @var array |
|
62 | - */ |
|
63 | - protected $greaterThan = []; |
|
64 | - |
|
65 | - /** |
|
66 | - * @var array |
|
67 | - */ |
|
68 | - protected $greaterThanOrEqual = []; |
|
69 | - |
|
70 | - /** |
|
71 | - * @var array |
|
72 | - */ |
|
73 | - protected $lessThan = []; |
|
74 | - |
|
75 | - /** |
|
76 | - * @var array |
|
77 | - */ |
|
78 | - protected $lessThanOrEqual = []; |
|
79 | - |
|
80 | - /** |
|
81 | - * @var array |
|
82 | - */ |
|
83 | - protected $in = []; |
|
84 | - |
|
85 | - /** |
|
86 | - * @var array |
|
87 | - */ |
|
88 | - protected $like = []; |
|
89 | - |
|
90 | - /** |
|
91 | - * @var array |
|
92 | - */ |
|
93 | - protected $matches = []; |
|
94 | - |
|
95 | - /** |
|
96 | - * @var string |
|
97 | - */ |
|
98 | - protected $defaultLogicalSeparator = self::LOGICAL_AND; |
|
99 | - |
|
100 | - /** |
|
101 | - * @var string |
|
102 | - */ |
|
103 | - protected $logicalSeparatorForEquals = self::LOGICAL_AND; |
|
104 | - |
|
105 | - /** |
|
106 | - * @var string |
|
107 | - */ |
|
108 | - protected $logicalSeparatorForGreaterThan = self::LOGICAL_AND; |
|
109 | - |
|
110 | - /** |
|
111 | - * @var string |
|
112 | - */ |
|
113 | - protected $logicalSeparatorForGreaterThanOrEqual = self::LOGICAL_AND; |
|
114 | - |
|
115 | - /** |
|
116 | - * @var string |
|
117 | - */ |
|
118 | - protected $logicalSeparatorForLessThan = self::LOGICAL_AND; |
|
119 | - |
|
120 | - /** |
|
121 | - * @var string |
|
122 | - */ |
|
123 | - protected $logicalSeparatorForLessThanOrEqual = self::LOGICAL_AND; |
|
124 | - |
|
125 | - /** |
|
126 | - * @var string |
|
127 | - */ |
|
128 | - protected $logicalSeparatorForIn = self::LOGICAL_AND; |
|
129 | - |
|
130 | - /** |
|
131 | - * @var string |
|
132 | - */ |
|
133 | - protected $logicalSeparatorForLike = self::LOGICAL_AND; |
|
134 | - |
|
135 | - /** |
|
136 | - * @var string |
|
137 | - */ |
|
138 | - protected $logicalSeparatorForSearchTerm = self::LOGICAL_OR; |
|
139 | - |
|
140 | - /** |
|
141 | - * Constructs a new Matcher |
|
142 | - * |
|
143 | - * @param array $matches associative [$field => $value] |
|
144 | - * @param string $dataType which corresponds to an entry of the TCA (table name). |
|
145 | - */ |
|
146 | - public function __construct($matches = [], $dataType = '') |
|
147 | - { |
|
148 | - $this->dataType = $dataType; |
|
149 | - $this->matches = $matches; |
|
150 | - } |
|
151 | - |
|
152 | - /** |
|
153 | - * @param string $searchTerm |
|
154 | - * @return \Fab\Vidi\Persistence\Matcher |
|
155 | - */ |
|
156 | - public function setSearchTerm($searchTerm): Matcher |
|
157 | - { |
|
158 | - $this->searchTerm = $searchTerm; |
|
159 | - return $this; |
|
160 | - } |
|
161 | - |
|
162 | - /** |
|
163 | - * @return string |
|
164 | - */ |
|
165 | - public function getSearchTerm(): string |
|
166 | - { |
|
167 | - return $this->searchTerm; |
|
168 | - } |
|
169 | - |
|
170 | - /** |
|
171 | - * @return array |
|
172 | - */ |
|
173 | - public function getEquals(): array |
|
174 | - { |
|
175 | - return $this->equals; |
|
176 | - } |
|
177 | - |
|
178 | - /** |
|
179 | - * @param $fieldNameAndPath |
|
180 | - * @param $operand |
|
181 | - * @return $this |
|
182 | - */ |
|
183 | - public function equals($fieldNameAndPath, $operand): self |
|
184 | - { |
|
185 | - $this->equals[] = ['fieldNameAndPath' => $fieldNameAndPath, 'operand' => $operand]; |
|
186 | - return $this; |
|
187 | - } |
|
188 | - |
|
189 | - /** |
|
190 | - * @return array |
|
191 | - */ |
|
192 | - public function getNotEquals(): array |
|
193 | - { |
|
194 | - return $this->notEquals; |
|
195 | - } |
|
196 | - |
|
197 | - /** |
|
198 | - * @param $fieldNameAndPath |
|
199 | - * @param $operand |
|
200 | - * @return $this |
|
201 | - */ |
|
202 | - public function notEquals($fieldNameAndPath, $operand): self |
|
203 | - { |
|
204 | - $this->notEquals[] = ['fieldNameAndPath' => $fieldNameAndPath, 'operand' => $operand]; |
|
205 | - return $this; |
|
206 | - } |
|
207 | - |
|
208 | - /** |
|
209 | - * @return array |
|
210 | - */ |
|
211 | - public function getGreaterThan(): array |
|
212 | - { |
|
213 | - return $this->greaterThan; |
|
214 | - } |
|
215 | - |
|
216 | - /** |
|
217 | - * @param $fieldNameAndPath |
|
218 | - * @param $operand |
|
219 | - * @return $this |
|
220 | - */ |
|
221 | - public function greaterThan($fieldNameAndPath, $operand): self |
|
222 | - { |
|
223 | - $this->greaterThan[] = ['fieldNameAndPath' => $fieldNameAndPath, 'operand' => $operand]; |
|
224 | - return $this; |
|
225 | - } |
|
226 | - |
|
227 | - /** |
|
228 | - * @return array |
|
229 | - */ |
|
230 | - public function getGreaterThanOrEqual(): array |
|
231 | - { |
|
232 | - return $this->greaterThanOrEqual; |
|
233 | - } |
|
234 | - |
|
235 | - /** |
|
236 | - * @param $fieldNameAndPath |
|
237 | - * @param $operand |
|
238 | - * @return $this |
|
239 | - */ |
|
240 | - public function greaterThanOrEqual($fieldNameAndPath, $operand): self |
|
241 | - { |
|
242 | - $this->greaterThanOrEqual[] = ['fieldNameAndPath' => $fieldNameAndPath, 'operand' => $operand]; |
|
243 | - return $this; |
|
244 | - } |
|
245 | - |
|
246 | - /** |
|
247 | - * @return array |
|
248 | - */ |
|
249 | - public function getLessThan(): array |
|
250 | - { |
|
251 | - return $this->lessThan; |
|
252 | - } |
|
253 | - |
|
254 | - /** |
|
255 | - * @param $fieldNameAndPath |
|
256 | - * @param $operand |
|
257 | - * @return $this |
|
258 | - */ |
|
259 | - public function lessThan($fieldNameAndPath, $operand): self |
|
260 | - { |
|
261 | - $this->lessThan[] = ['fieldNameAndPath' => $fieldNameAndPath, 'operand' => $operand]; |
|
262 | - return $this; |
|
263 | - } |
|
264 | - |
|
265 | - /** |
|
266 | - * @return array |
|
267 | - */ |
|
268 | - public function getLessThanOrEqual(): array |
|
269 | - { |
|
270 | - return $this->lessThanOrEqual; |
|
271 | - } |
|
272 | - |
|
273 | - /** |
|
274 | - * @param $fieldNameAndPath |
|
275 | - * @param $operand |
|
276 | - * @return $this |
|
277 | - */ |
|
278 | - public function lessThanOrEqual($fieldNameAndPath, $operand): self |
|
279 | - { |
|
280 | - $this->lessThanOrEqual[] = ['fieldNameAndPath' => $fieldNameAndPath, 'operand' => $operand]; |
|
281 | - return $this; |
|
282 | - } |
|
283 | - |
|
284 | - /** |
|
285 | - * @return array |
|
286 | - */ |
|
287 | - public function getLike(): array |
|
288 | - { |
|
289 | - return $this->like; |
|
290 | - } |
|
291 | - |
|
292 | - /** |
|
293 | - * @param $fieldNameAndPath |
|
294 | - * @param $operand |
|
295 | - * @return $this |
|
296 | - */ |
|
297 | - public function in($fieldNameAndPath, $operand): self |
|
298 | - { |
|
299 | - $this->in[] = ['fieldNameAndPath' => $fieldNameAndPath, 'operand' => $operand]; |
|
300 | - return $this; |
|
301 | - } |
|
302 | - |
|
303 | - /** |
|
304 | - * @return array |
|
305 | - */ |
|
306 | - public function getIn(): array |
|
307 | - { |
|
308 | - return $this->in; |
|
309 | - } |
|
310 | - |
|
311 | - /** |
|
312 | - * @param $fieldNameAndPath |
|
313 | - * @param $operand |
|
314 | - * @param bool $addWildCard |
|
315 | - * @return $this |
|
316 | - */ |
|
317 | - public function like($fieldNameAndPath, $operand, $addWildCard = true): self |
|
318 | - { |
|
319 | - $wildCardSymbol = $addWildCard ? '%' : ''; |
|
320 | - $this->like[] = ['fieldNameAndPath' => $fieldNameAndPath, 'operand' => $wildCardSymbol . $operand . $wildCardSymbol]; |
|
321 | - return $this; |
|
322 | - } |
|
323 | - |
|
324 | - /** |
|
325 | - * @return string |
|
326 | - */ |
|
327 | - public function getDefaultLogicalSeparator(): string |
|
328 | - { |
|
329 | - return $this->defaultLogicalSeparator; |
|
330 | - } |
|
331 | - |
|
332 | - /** |
|
333 | - * @param string $defaultLogicalSeparator |
|
334 | - * @return $this |
|
335 | - */ |
|
336 | - public function setDefaultLogicalSeparator($defaultLogicalSeparator): self |
|
337 | - { |
|
338 | - $this->defaultLogicalSeparator = $defaultLogicalSeparator; |
|
339 | - return $this; |
|
340 | - } |
|
341 | - |
|
342 | - /** |
|
343 | - * @return string |
|
344 | - */ |
|
345 | - public function getLogicalSeparatorForEquals(): string |
|
346 | - { |
|
347 | - return $this->logicalSeparatorForEquals; |
|
348 | - } |
|
349 | - |
|
350 | - /** |
|
351 | - * @param string $logicalSeparatorForEquals |
|
352 | - * @return $this |
|
353 | - */ |
|
354 | - public function setLogicalSeparatorForEquals($logicalSeparatorForEquals): self |
|
355 | - { |
|
356 | - $this->logicalSeparatorForEquals = $logicalSeparatorForEquals; |
|
357 | - return $this; |
|
358 | - } |
|
359 | - |
|
360 | - /** |
|
361 | - * @return string |
|
362 | - */ |
|
363 | - public function getLogicalSeparatorForGreaterThan(): string |
|
364 | - { |
|
365 | - return $this->logicalSeparatorForGreaterThan; |
|
366 | - } |
|
367 | - |
|
368 | - /** |
|
369 | - * @param string $logicalSeparatorForGreaterThan |
|
370 | - * @return $this |
|
371 | - */ |
|
372 | - public function setLogicalSeparatorForGreaterThan($logicalSeparatorForGreaterThan): self |
|
373 | - { |
|
374 | - $this->logicalSeparatorForGreaterThan = $logicalSeparatorForGreaterThan; |
|
375 | - return $this; |
|
376 | - } |
|
377 | - |
|
378 | - /** |
|
379 | - * @return string |
|
380 | - */ |
|
381 | - public function getLogicalSeparatorForGreaterThanOrEqual(): string |
|
382 | - { |
|
383 | - return $this->logicalSeparatorForGreaterThanOrEqual; |
|
384 | - } |
|
385 | - |
|
386 | - /** |
|
387 | - * @param string $logicalSeparatorForGreaterThanOrEqual |
|
388 | - * @return $this |
|
389 | - */ |
|
390 | - public function setLogicalSeparatorForGreaterThanOrEqual($logicalSeparatorForGreaterThanOrEqual): self |
|
391 | - { |
|
392 | - $this->logicalSeparatorForGreaterThanOrEqual = $logicalSeparatorForGreaterThanOrEqual; |
|
393 | - return $this; |
|
394 | - } |
|
395 | - |
|
396 | - /** |
|
397 | - * @return string |
|
398 | - */ |
|
399 | - public function getLogicalSeparatorForLessThan(): string |
|
400 | - { |
|
401 | - return $this->logicalSeparatorForLessThan; |
|
402 | - } |
|
403 | - |
|
404 | - /** |
|
405 | - * @param string $logicalSeparatorForLessThan |
|
406 | - * @return $this |
|
407 | - */ |
|
408 | - public function setLogicalSeparatorForLessThan($logicalSeparatorForLessThan): self |
|
409 | - { |
|
410 | - $this->logicalSeparatorForLessThan = $logicalSeparatorForLessThan; |
|
411 | - return $this; |
|
412 | - } |
|
413 | - |
|
414 | - /** |
|
415 | - * @return string |
|
416 | - */ |
|
417 | - public function getLogicalSeparatorForLessThanOrEqual(): string |
|
418 | - { |
|
419 | - return $this->logicalSeparatorForLessThanOrEqual; |
|
420 | - } |
|
421 | - |
|
422 | - /** |
|
423 | - * @param string $logicalSeparatorForLessThanOrEqual |
|
424 | - * @return $this |
|
425 | - */ |
|
426 | - public function setLogicalSeparatorForLessThanOrEqual($logicalSeparatorForLessThanOrEqual): self |
|
427 | - { |
|
428 | - $this->logicalSeparatorForLessThanOrEqual = $logicalSeparatorForLessThanOrEqual; |
|
429 | - return $this; |
|
430 | - } |
|
431 | - |
|
432 | - /** |
|
433 | - * @return string |
|
434 | - */ |
|
435 | - public function getLogicalSeparatorForIn(): string |
|
436 | - { |
|
437 | - return $this->logicalSeparatorForIn; |
|
438 | - } |
|
439 | - |
|
440 | - /** |
|
441 | - * @param string $logicalSeparatorForIn |
|
442 | - * @return $this |
|
443 | - */ |
|
444 | - public function setLogicalSeparatorForIn($logicalSeparatorForIn): self |
|
445 | - { |
|
446 | - $this->logicalSeparatorForIn = $logicalSeparatorForIn; |
|
447 | - return $this; |
|
448 | - } |
|
449 | - |
|
450 | - /** |
|
451 | - * @return string |
|
452 | - */ |
|
453 | - public function getLogicalSeparatorForLike(): string |
|
454 | - { |
|
455 | - return $this->logicalSeparatorForLike; |
|
456 | - } |
|
457 | - |
|
458 | - /** |
|
459 | - * @param string $logicalSeparatorForLike |
|
460 | - * @return $this |
|
461 | - */ |
|
462 | - public function setLogicalSeparatorForLike($logicalSeparatorForLike): self |
|
463 | - { |
|
464 | - $this->logicalSeparatorForLike = $logicalSeparatorForLike; |
|
465 | - return $this; |
|
466 | - } |
|
467 | - |
|
468 | - /** |
|
469 | - * @return string |
|
470 | - */ |
|
471 | - public function getLogicalSeparatorForSearchTerm(): string |
|
472 | - { |
|
473 | - return $this->logicalSeparatorForSearchTerm; |
|
474 | - } |
|
475 | - |
|
476 | - /** |
|
477 | - * @param string $logicalSeparatorForSearchTerm |
|
478 | - * @return $this |
|
479 | - */ |
|
480 | - public function setLogicalSeparatorForSearchTerm($logicalSeparatorForSearchTerm): self |
|
481 | - { |
|
482 | - $this->logicalSeparatorForSearchTerm = $logicalSeparatorForSearchTerm; |
|
483 | - return $this; |
|
484 | - } |
|
485 | - |
|
486 | - /** |
|
487 | - * @return array |
|
488 | - */ |
|
489 | - public function getSupportedOperators(): array |
|
490 | - { |
|
491 | - return $this->supportedOperators; |
|
492 | - } |
|
493 | - |
|
494 | - /** |
|
495 | - * @return string |
|
496 | - */ |
|
497 | - public function getDataType(): string |
|
498 | - { |
|
499 | - return $this->dataType; |
|
500 | - } |
|
501 | - |
|
502 | - /** |
|
503 | - * @param string $dataType |
|
504 | - * @return $this |
|
505 | - */ |
|
506 | - public function setDataType($dataType): self |
|
507 | - { |
|
508 | - $this->dataType = $dataType; |
|
509 | - return $this; |
|
510 | - } |
|
16 | + /** |
|
17 | + * The logical OR |
|
18 | + */ |
|
19 | + const LOGICAL_OR = 'logicalOr'; |
|
20 | + |
|
21 | + /** |
|
22 | + * The logical AND |
|
23 | + */ |
|
24 | + const LOGICAL_AND = 'logicalAnd'; |
|
25 | + |
|
26 | + /** |
|
27 | + * @var string |
|
28 | + */ |
|
29 | + protected $dataType = ''; |
|
30 | + |
|
31 | + /** |
|
32 | + * @var string |
|
33 | + */ |
|
34 | + protected $searchTerm = ''; |
|
35 | + |
|
36 | + /** |
|
37 | + * @var array |
|
38 | + */ |
|
39 | + protected $supportedOperators = [ |
|
40 | + '=' => 'equals', |
|
41 | + '!=' => 'notEquals', |
|
42 | + 'in' => 'in', |
|
43 | + 'like' => 'like', |
|
44 | + '>' => 'greaterThan', |
|
45 | + '>=' => 'greaterThanOrEqual', |
|
46 | + '<' => 'lessThan', |
|
47 | + '<=' => 'lessThanOrEqual', |
|
48 | + ]; |
|
49 | + |
|
50 | + /** |
|
51 | + * @var array |
|
52 | + */ |
|
53 | + protected $equals = []; |
|
54 | + |
|
55 | + /** |
|
56 | + * @var array |
|
57 | + */ |
|
58 | + protected $notEquals = []; |
|
59 | + |
|
60 | + /** |
|
61 | + * @var array |
|
62 | + */ |
|
63 | + protected $greaterThan = []; |
|
64 | + |
|
65 | + /** |
|
66 | + * @var array |
|
67 | + */ |
|
68 | + protected $greaterThanOrEqual = []; |
|
69 | + |
|
70 | + /** |
|
71 | + * @var array |
|
72 | + */ |
|
73 | + protected $lessThan = []; |
|
74 | + |
|
75 | + /** |
|
76 | + * @var array |
|
77 | + */ |
|
78 | + protected $lessThanOrEqual = []; |
|
79 | + |
|
80 | + /** |
|
81 | + * @var array |
|
82 | + */ |
|
83 | + protected $in = []; |
|
84 | + |
|
85 | + /** |
|
86 | + * @var array |
|
87 | + */ |
|
88 | + protected $like = []; |
|
89 | + |
|
90 | + /** |
|
91 | + * @var array |
|
92 | + */ |
|
93 | + protected $matches = []; |
|
94 | + |
|
95 | + /** |
|
96 | + * @var string |
|
97 | + */ |
|
98 | + protected $defaultLogicalSeparator = self::LOGICAL_AND; |
|
99 | + |
|
100 | + /** |
|
101 | + * @var string |
|
102 | + */ |
|
103 | + protected $logicalSeparatorForEquals = self::LOGICAL_AND; |
|
104 | + |
|
105 | + /** |
|
106 | + * @var string |
|
107 | + */ |
|
108 | + protected $logicalSeparatorForGreaterThan = self::LOGICAL_AND; |
|
109 | + |
|
110 | + /** |
|
111 | + * @var string |
|
112 | + */ |
|
113 | + protected $logicalSeparatorForGreaterThanOrEqual = self::LOGICAL_AND; |
|
114 | + |
|
115 | + /** |
|
116 | + * @var string |
|
117 | + */ |
|
118 | + protected $logicalSeparatorForLessThan = self::LOGICAL_AND; |
|
119 | + |
|
120 | + /** |
|
121 | + * @var string |
|
122 | + */ |
|
123 | + protected $logicalSeparatorForLessThanOrEqual = self::LOGICAL_AND; |
|
124 | + |
|
125 | + /** |
|
126 | + * @var string |
|
127 | + */ |
|
128 | + protected $logicalSeparatorForIn = self::LOGICAL_AND; |
|
129 | + |
|
130 | + /** |
|
131 | + * @var string |
|
132 | + */ |
|
133 | + protected $logicalSeparatorForLike = self::LOGICAL_AND; |
|
134 | + |
|
135 | + /** |
|
136 | + * @var string |
|
137 | + */ |
|
138 | + protected $logicalSeparatorForSearchTerm = self::LOGICAL_OR; |
|
139 | + |
|
140 | + /** |
|
141 | + * Constructs a new Matcher |
|
142 | + * |
|
143 | + * @param array $matches associative [$field => $value] |
|
144 | + * @param string $dataType which corresponds to an entry of the TCA (table name). |
|
145 | + */ |
|
146 | + public function __construct($matches = [], $dataType = '') |
|
147 | + { |
|
148 | + $this->dataType = $dataType; |
|
149 | + $this->matches = $matches; |
|
150 | + } |
|
151 | + |
|
152 | + /** |
|
153 | + * @param string $searchTerm |
|
154 | + * @return \Fab\Vidi\Persistence\Matcher |
|
155 | + */ |
|
156 | + public function setSearchTerm($searchTerm): Matcher |
|
157 | + { |
|
158 | + $this->searchTerm = $searchTerm; |
|
159 | + return $this; |
|
160 | + } |
|
161 | + |
|
162 | + /** |
|
163 | + * @return string |
|
164 | + */ |
|
165 | + public function getSearchTerm(): string |
|
166 | + { |
|
167 | + return $this->searchTerm; |
|
168 | + } |
|
169 | + |
|
170 | + /** |
|
171 | + * @return array |
|
172 | + */ |
|
173 | + public function getEquals(): array |
|
174 | + { |
|
175 | + return $this->equals; |
|
176 | + } |
|
177 | + |
|
178 | + /** |
|
179 | + * @param $fieldNameAndPath |
|
180 | + * @param $operand |
|
181 | + * @return $this |
|
182 | + */ |
|
183 | + public function equals($fieldNameAndPath, $operand): self |
|
184 | + { |
|
185 | + $this->equals[] = ['fieldNameAndPath' => $fieldNameAndPath, 'operand' => $operand]; |
|
186 | + return $this; |
|
187 | + } |
|
188 | + |
|
189 | + /** |
|
190 | + * @return array |
|
191 | + */ |
|
192 | + public function getNotEquals(): array |
|
193 | + { |
|
194 | + return $this->notEquals; |
|
195 | + } |
|
196 | + |
|
197 | + /** |
|
198 | + * @param $fieldNameAndPath |
|
199 | + * @param $operand |
|
200 | + * @return $this |
|
201 | + */ |
|
202 | + public function notEquals($fieldNameAndPath, $operand): self |
|
203 | + { |
|
204 | + $this->notEquals[] = ['fieldNameAndPath' => $fieldNameAndPath, 'operand' => $operand]; |
|
205 | + return $this; |
|
206 | + } |
|
207 | + |
|
208 | + /** |
|
209 | + * @return array |
|
210 | + */ |
|
211 | + public function getGreaterThan(): array |
|
212 | + { |
|
213 | + return $this->greaterThan; |
|
214 | + } |
|
215 | + |
|
216 | + /** |
|
217 | + * @param $fieldNameAndPath |
|
218 | + * @param $operand |
|
219 | + * @return $this |
|
220 | + */ |
|
221 | + public function greaterThan($fieldNameAndPath, $operand): self |
|
222 | + { |
|
223 | + $this->greaterThan[] = ['fieldNameAndPath' => $fieldNameAndPath, 'operand' => $operand]; |
|
224 | + return $this; |
|
225 | + } |
|
226 | + |
|
227 | + /** |
|
228 | + * @return array |
|
229 | + */ |
|
230 | + public function getGreaterThanOrEqual(): array |
|
231 | + { |
|
232 | + return $this->greaterThanOrEqual; |
|
233 | + } |
|
234 | + |
|
235 | + /** |
|
236 | + * @param $fieldNameAndPath |
|
237 | + * @param $operand |
|
238 | + * @return $this |
|
239 | + */ |
|
240 | + public function greaterThanOrEqual($fieldNameAndPath, $operand): self |
|
241 | + { |
|
242 | + $this->greaterThanOrEqual[] = ['fieldNameAndPath' => $fieldNameAndPath, 'operand' => $operand]; |
|
243 | + return $this; |
|
244 | + } |
|
245 | + |
|
246 | + /** |
|
247 | + * @return array |
|
248 | + */ |
|
249 | + public function getLessThan(): array |
|
250 | + { |
|
251 | + return $this->lessThan; |
|
252 | + } |
|
253 | + |
|
254 | + /** |
|
255 | + * @param $fieldNameAndPath |
|
256 | + * @param $operand |
|
257 | + * @return $this |
|
258 | + */ |
|
259 | + public function lessThan($fieldNameAndPath, $operand): self |
|
260 | + { |
|
261 | + $this->lessThan[] = ['fieldNameAndPath' => $fieldNameAndPath, 'operand' => $operand]; |
|
262 | + return $this; |
|
263 | + } |
|
264 | + |
|
265 | + /** |
|
266 | + * @return array |
|
267 | + */ |
|
268 | + public function getLessThanOrEqual(): array |
|
269 | + { |
|
270 | + return $this->lessThanOrEqual; |
|
271 | + } |
|
272 | + |
|
273 | + /** |
|
274 | + * @param $fieldNameAndPath |
|
275 | + * @param $operand |
|
276 | + * @return $this |
|
277 | + */ |
|
278 | + public function lessThanOrEqual($fieldNameAndPath, $operand): self |
|
279 | + { |
|
280 | + $this->lessThanOrEqual[] = ['fieldNameAndPath' => $fieldNameAndPath, 'operand' => $operand]; |
|
281 | + return $this; |
|
282 | + } |
|
283 | + |
|
284 | + /** |
|
285 | + * @return array |
|
286 | + */ |
|
287 | + public function getLike(): array |
|
288 | + { |
|
289 | + return $this->like; |
|
290 | + } |
|
291 | + |
|
292 | + /** |
|
293 | + * @param $fieldNameAndPath |
|
294 | + * @param $operand |
|
295 | + * @return $this |
|
296 | + */ |
|
297 | + public function in($fieldNameAndPath, $operand): self |
|
298 | + { |
|
299 | + $this->in[] = ['fieldNameAndPath' => $fieldNameAndPath, 'operand' => $operand]; |
|
300 | + return $this; |
|
301 | + } |
|
302 | + |
|
303 | + /** |
|
304 | + * @return array |
|
305 | + */ |
|
306 | + public function getIn(): array |
|
307 | + { |
|
308 | + return $this->in; |
|
309 | + } |
|
310 | + |
|
311 | + /** |
|
312 | + * @param $fieldNameAndPath |
|
313 | + * @param $operand |
|
314 | + * @param bool $addWildCard |
|
315 | + * @return $this |
|
316 | + */ |
|
317 | + public function like($fieldNameAndPath, $operand, $addWildCard = true): self |
|
318 | + { |
|
319 | + $wildCardSymbol = $addWildCard ? '%' : ''; |
|
320 | + $this->like[] = ['fieldNameAndPath' => $fieldNameAndPath, 'operand' => $wildCardSymbol . $operand . $wildCardSymbol]; |
|
321 | + return $this; |
|
322 | + } |
|
323 | + |
|
324 | + /** |
|
325 | + * @return string |
|
326 | + */ |
|
327 | + public function getDefaultLogicalSeparator(): string |
|
328 | + { |
|
329 | + return $this->defaultLogicalSeparator; |
|
330 | + } |
|
331 | + |
|
332 | + /** |
|
333 | + * @param string $defaultLogicalSeparator |
|
334 | + * @return $this |
|
335 | + */ |
|
336 | + public function setDefaultLogicalSeparator($defaultLogicalSeparator): self |
|
337 | + { |
|
338 | + $this->defaultLogicalSeparator = $defaultLogicalSeparator; |
|
339 | + return $this; |
|
340 | + } |
|
341 | + |
|
342 | + /** |
|
343 | + * @return string |
|
344 | + */ |
|
345 | + public function getLogicalSeparatorForEquals(): string |
|
346 | + { |
|
347 | + return $this->logicalSeparatorForEquals; |
|
348 | + } |
|
349 | + |
|
350 | + /** |
|
351 | + * @param string $logicalSeparatorForEquals |
|
352 | + * @return $this |
|
353 | + */ |
|
354 | + public function setLogicalSeparatorForEquals($logicalSeparatorForEquals): self |
|
355 | + { |
|
356 | + $this->logicalSeparatorForEquals = $logicalSeparatorForEquals; |
|
357 | + return $this; |
|
358 | + } |
|
359 | + |
|
360 | + /** |
|
361 | + * @return string |
|
362 | + */ |
|
363 | + public function getLogicalSeparatorForGreaterThan(): string |
|
364 | + { |
|
365 | + return $this->logicalSeparatorForGreaterThan; |
|
366 | + } |
|
367 | + |
|
368 | + /** |
|
369 | + * @param string $logicalSeparatorForGreaterThan |
|
370 | + * @return $this |
|
371 | + */ |
|
372 | + public function setLogicalSeparatorForGreaterThan($logicalSeparatorForGreaterThan): self |
|
373 | + { |
|
374 | + $this->logicalSeparatorForGreaterThan = $logicalSeparatorForGreaterThan; |
|
375 | + return $this; |
|
376 | + } |
|
377 | + |
|
378 | + /** |
|
379 | + * @return string |
|
380 | + */ |
|
381 | + public function getLogicalSeparatorForGreaterThanOrEqual(): string |
|
382 | + { |
|
383 | + return $this->logicalSeparatorForGreaterThanOrEqual; |
|
384 | + } |
|
385 | + |
|
386 | + /** |
|
387 | + * @param string $logicalSeparatorForGreaterThanOrEqual |
|
388 | + * @return $this |
|
389 | + */ |
|
390 | + public function setLogicalSeparatorForGreaterThanOrEqual($logicalSeparatorForGreaterThanOrEqual): self |
|
391 | + { |
|
392 | + $this->logicalSeparatorForGreaterThanOrEqual = $logicalSeparatorForGreaterThanOrEqual; |
|
393 | + return $this; |
|
394 | + } |
|
395 | + |
|
396 | + /** |
|
397 | + * @return string |
|
398 | + */ |
|
399 | + public function getLogicalSeparatorForLessThan(): string |
|
400 | + { |
|
401 | + return $this->logicalSeparatorForLessThan; |
|
402 | + } |
|
403 | + |
|
404 | + /** |
|
405 | + * @param string $logicalSeparatorForLessThan |
|
406 | + * @return $this |
|
407 | + */ |
|
408 | + public function setLogicalSeparatorForLessThan($logicalSeparatorForLessThan): self |
|
409 | + { |
|
410 | + $this->logicalSeparatorForLessThan = $logicalSeparatorForLessThan; |
|
411 | + return $this; |
|
412 | + } |
|
413 | + |
|
414 | + /** |
|
415 | + * @return string |
|
416 | + */ |
|
417 | + public function getLogicalSeparatorForLessThanOrEqual(): string |
|
418 | + { |
|
419 | + return $this->logicalSeparatorForLessThanOrEqual; |
|
420 | + } |
|
421 | + |
|
422 | + /** |
|
423 | + * @param string $logicalSeparatorForLessThanOrEqual |
|
424 | + * @return $this |
|
425 | + */ |
|
426 | + public function setLogicalSeparatorForLessThanOrEqual($logicalSeparatorForLessThanOrEqual): self |
|
427 | + { |
|
428 | + $this->logicalSeparatorForLessThanOrEqual = $logicalSeparatorForLessThanOrEqual; |
|
429 | + return $this; |
|
430 | + } |
|
431 | + |
|
432 | + /** |
|
433 | + * @return string |
|
434 | + */ |
|
435 | + public function getLogicalSeparatorForIn(): string |
|
436 | + { |
|
437 | + return $this->logicalSeparatorForIn; |
|
438 | + } |
|
439 | + |
|
440 | + /** |
|
441 | + * @param string $logicalSeparatorForIn |
|
442 | + * @return $this |
|
443 | + */ |
|
444 | + public function setLogicalSeparatorForIn($logicalSeparatorForIn): self |
|
445 | + { |
|
446 | + $this->logicalSeparatorForIn = $logicalSeparatorForIn; |
|
447 | + return $this; |
|
448 | + } |
|
449 | + |
|
450 | + /** |
|
451 | + * @return string |
|
452 | + */ |
|
453 | + public function getLogicalSeparatorForLike(): string |
|
454 | + { |
|
455 | + return $this->logicalSeparatorForLike; |
|
456 | + } |
|
457 | + |
|
458 | + /** |
|
459 | + * @param string $logicalSeparatorForLike |
|
460 | + * @return $this |
|
461 | + */ |
|
462 | + public function setLogicalSeparatorForLike($logicalSeparatorForLike): self |
|
463 | + { |
|
464 | + $this->logicalSeparatorForLike = $logicalSeparatorForLike; |
|
465 | + return $this; |
|
466 | + } |
|
467 | + |
|
468 | + /** |
|
469 | + * @return string |
|
470 | + */ |
|
471 | + public function getLogicalSeparatorForSearchTerm(): string |
|
472 | + { |
|
473 | + return $this->logicalSeparatorForSearchTerm; |
|
474 | + } |
|
475 | + |
|
476 | + /** |
|
477 | + * @param string $logicalSeparatorForSearchTerm |
|
478 | + * @return $this |
|
479 | + */ |
|
480 | + public function setLogicalSeparatorForSearchTerm($logicalSeparatorForSearchTerm): self |
|
481 | + { |
|
482 | + $this->logicalSeparatorForSearchTerm = $logicalSeparatorForSearchTerm; |
|
483 | + return $this; |
|
484 | + } |
|
485 | + |
|
486 | + /** |
|
487 | + * @return array |
|
488 | + */ |
|
489 | + public function getSupportedOperators(): array |
|
490 | + { |
|
491 | + return $this->supportedOperators; |
|
492 | + } |
|
493 | + |
|
494 | + /** |
|
495 | + * @return string |
|
496 | + */ |
|
497 | + public function getDataType(): string |
|
498 | + { |
|
499 | + return $this->dataType; |
|
500 | + } |
|
501 | + |
|
502 | + /** |
|
503 | + * @param string $dataType |
|
504 | + * @return $this |
|
505 | + */ |
|
506 | + public function setDataType($dataType): self |
|
507 | + { |
|
508 | + $this->dataType = $dataType; |
|
509 | + return $this; |
|
510 | + } |
|
511 | 511 | } |
@@ -317,7 +317,7 @@ |
||
317 | 317 | public function like($fieldNameAndPath, $operand, $addWildCard = true): self |
318 | 318 | { |
319 | 319 | $wildCardSymbol = $addWildCard ? '%' : ''; |
320 | - $this->like[] = ['fieldNameAndPath' => $fieldNameAndPath, 'operand' => $wildCardSymbol . $operand . $wildCardSymbol]; |
|
320 | + $this->like[] = ['fieldNameAndPath' => $fieldNameAndPath, 'operand' => $wildCardSymbol.$operand.$wildCardSymbol]; |
|
321 | 321 | return $this; |
322 | 322 | } |
323 | 323 |
@@ -20,144 +20,144 @@ |
||
20 | 20 | class StandardFacet implements FacetInterface |
21 | 21 | { |
22 | 22 | |
23 | - /** |
|
24 | - * @var string |
|
25 | - */ |
|
26 | - protected $name; |
|
27 | - |
|
28 | - /** |
|
29 | - * @var string |
|
30 | - */ |
|
31 | - protected $label; |
|
32 | - |
|
33 | - /** |
|
34 | - * @var array |
|
35 | - */ |
|
36 | - protected $suggestions = []; |
|
37 | - |
|
38 | - /** |
|
39 | - * @var string |
|
40 | - */ |
|
41 | - protected $dataType; |
|
42 | - |
|
43 | - /** |
|
44 | - * @var bool |
|
45 | - */ |
|
46 | - protected $canModifyMatcher = false; |
|
47 | - |
|
48 | - /** |
|
49 | - * Constructor of a Generic Facet in Vidi. |
|
50 | - * |
|
51 | - * @param string $name |
|
52 | - * @param string $label |
|
53 | - * @param array $suggestions |
|
54 | - */ |
|
55 | - public function __construct($name, $label = '', array $suggestions = []) |
|
56 | - { |
|
57 | - $this->name = $name; |
|
58 | - if (empty($label)) { |
|
59 | - $label = $this->name; |
|
60 | - } |
|
61 | - $this->label = $label; |
|
62 | - $this->suggestions = $suggestions; |
|
63 | - } |
|
64 | - |
|
65 | - /** |
|
66 | - * @return string |
|
67 | - */ |
|
68 | - public function getName(): string |
|
69 | - { |
|
70 | - return $this->name; |
|
71 | - } |
|
72 | - |
|
73 | - /** |
|
74 | - * @return string |
|
75 | - */ |
|
76 | - public function getLabel(): string |
|
77 | - { |
|
78 | - if ($this->label === $this->name) { |
|
79 | - $label = Tca::table($this->dataType)->field($this->getName())->getLabel(); |
|
80 | - } else { |
|
81 | - try { |
|
82 | - $label = LocalizationUtility::translate($this->label, ''); |
|
83 | - } catch (\InvalidArgumentException $e) { |
|
84 | - } |
|
85 | - if (empty($label)) { |
|
86 | - $label = $this->label; |
|
87 | - } |
|
88 | - } |
|
89 | - |
|
90 | - return $label; |
|
91 | - } |
|
92 | - |
|
93 | - /** |
|
94 | - * @return array |
|
95 | - */ |
|
96 | - public function getSuggestions(): array |
|
97 | - { |
|
98 | - |
|
99 | - $values = []; |
|
100 | - foreach ($this->suggestions as $key => $label) { |
|
101 | - $localizedLabel = $this->getLanguageService()->sL($label); |
|
102 | - if (!empty($localizedLabel)) { |
|
103 | - $label = $localizedLabel; |
|
104 | - } |
|
105 | - |
|
106 | - $values[] = [$key => $label]; |
|
107 | - } |
|
108 | - |
|
109 | - return $values; |
|
110 | - } |
|
111 | - |
|
112 | - /** |
|
113 | - * @return LanguageService |
|
114 | - */ |
|
115 | - protected function getLanguageService(): LanguageService |
|
116 | - { |
|
117 | - /** @var LanguageService $langService */ |
|
118 | - $langService = $GLOBALS['LANG']; |
|
119 | - if (!$langService) { |
|
120 | - $langService = GeneralUtility::makeInstance(LanguageService::class); |
|
121 | - $langService->init('en'); |
|
122 | - } |
|
123 | - |
|
124 | - return $langService; |
|
125 | - } |
|
126 | - |
|
127 | - /** |
|
128 | - * @return bool |
|
129 | - */ |
|
130 | - public function hasSuggestions(): bool |
|
131 | - { |
|
132 | - return !empty($this->suggestions); |
|
133 | - } |
|
134 | - |
|
135 | - /** |
|
136 | - * @param string $dataType |
|
137 | - * @return $this |
|
138 | - */ |
|
139 | - public function setDataType($dataType): self |
|
140 | - { |
|
141 | - $this->dataType = $dataType; |
|
142 | - return $this; |
|
143 | - } |
|
144 | - |
|
145 | - /** |
|
146 | - * @return bool |
|
147 | - */ |
|
148 | - public function canModifyMatcher(): bool |
|
149 | - { |
|
150 | - return $this->canModifyMatcher; |
|
151 | - } |
|
152 | - |
|
153 | - /** |
|
154 | - * @param Matcher $matcher |
|
155 | - * @param $value |
|
156 | - * @return Matcher |
|
157 | - */ |
|
158 | - public function modifyMatcher(Matcher $matcher, $value): Matcher |
|
159 | - { |
|
160 | - return $matcher; |
|
161 | - } |
|
23 | + /** |
|
24 | + * @var string |
|
25 | + */ |
|
26 | + protected $name; |
|
27 | + |
|
28 | + /** |
|
29 | + * @var string |
|
30 | + */ |
|
31 | + protected $label; |
|
32 | + |
|
33 | + /** |
|
34 | + * @var array |
|
35 | + */ |
|
36 | + protected $suggestions = []; |
|
37 | + |
|
38 | + /** |
|
39 | + * @var string |
|
40 | + */ |
|
41 | + protected $dataType; |
|
42 | + |
|
43 | + /** |
|
44 | + * @var bool |
|
45 | + */ |
|
46 | + protected $canModifyMatcher = false; |
|
47 | + |
|
48 | + /** |
|
49 | + * Constructor of a Generic Facet in Vidi. |
|
50 | + * |
|
51 | + * @param string $name |
|
52 | + * @param string $label |
|
53 | + * @param array $suggestions |
|
54 | + */ |
|
55 | + public function __construct($name, $label = '', array $suggestions = []) |
|
56 | + { |
|
57 | + $this->name = $name; |
|
58 | + if (empty($label)) { |
|
59 | + $label = $this->name; |
|
60 | + } |
|
61 | + $this->label = $label; |
|
62 | + $this->suggestions = $suggestions; |
|
63 | + } |
|
64 | + |
|
65 | + /** |
|
66 | + * @return string |
|
67 | + */ |
|
68 | + public function getName(): string |
|
69 | + { |
|
70 | + return $this->name; |
|
71 | + } |
|
72 | + |
|
73 | + /** |
|
74 | + * @return string |
|
75 | + */ |
|
76 | + public function getLabel(): string |
|
77 | + { |
|
78 | + if ($this->label === $this->name) { |
|
79 | + $label = Tca::table($this->dataType)->field($this->getName())->getLabel(); |
|
80 | + } else { |
|
81 | + try { |
|
82 | + $label = LocalizationUtility::translate($this->label, ''); |
|
83 | + } catch (\InvalidArgumentException $e) { |
|
84 | + } |
|
85 | + if (empty($label)) { |
|
86 | + $label = $this->label; |
|
87 | + } |
|
88 | + } |
|
89 | + |
|
90 | + return $label; |
|
91 | + } |
|
92 | + |
|
93 | + /** |
|
94 | + * @return array |
|
95 | + */ |
|
96 | + public function getSuggestions(): array |
|
97 | + { |
|
98 | + |
|
99 | + $values = []; |
|
100 | + foreach ($this->suggestions as $key => $label) { |
|
101 | + $localizedLabel = $this->getLanguageService()->sL($label); |
|
102 | + if (!empty($localizedLabel)) { |
|
103 | + $label = $localizedLabel; |
|
104 | + } |
|
105 | + |
|
106 | + $values[] = [$key => $label]; |
|
107 | + } |
|
108 | + |
|
109 | + return $values; |
|
110 | + } |
|
111 | + |
|
112 | + /** |
|
113 | + * @return LanguageService |
|
114 | + */ |
|
115 | + protected function getLanguageService(): LanguageService |
|
116 | + { |
|
117 | + /** @var LanguageService $langService */ |
|
118 | + $langService = $GLOBALS['LANG']; |
|
119 | + if (!$langService) { |
|
120 | + $langService = GeneralUtility::makeInstance(LanguageService::class); |
|
121 | + $langService->init('en'); |
|
122 | + } |
|
123 | + |
|
124 | + return $langService; |
|
125 | + } |
|
126 | + |
|
127 | + /** |
|
128 | + * @return bool |
|
129 | + */ |
|
130 | + public function hasSuggestions(): bool |
|
131 | + { |
|
132 | + return !empty($this->suggestions); |
|
133 | + } |
|
134 | + |
|
135 | + /** |
|
136 | + * @param string $dataType |
|
137 | + * @return $this |
|
138 | + */ |
|
139 | + public function setDataType($dataType): self |
|
140 | + { |
|
141 | + $this->dataType = $dataType; |
|
142 | + return $this; |
|
143 | + } |
|
144 | + |
|
145 | + /** |
|
146 | + * @return bool |
|
147 | + */ |
|
148 | + public function canModifyMatcher(): bool |
|
149 | + { |
|
150 | + return $this->canModifyMatcher; |
|
151 | + } |
|
152 | + |
|
153 | + /** |
|
154 | + * @param Matcher $matcher |
|
155 | + * @param $value |
|
156 | + * @return Matcher |
|
157 | + */ |
|
158 | + public function modifyMatcher(Matcher $matcher, $value): Matcher |
|
159 | + { |
|
160 | + return $matcher; |
|
161 | + } |
|
162 | 162 | |
163 | 163 | } |
@@ -20,164 +20,164 @@ |
||
20 | 20 | class CompositeFacet implements FacetInterface |
21 | 21 | { |
22 | 22 | |
23 | - /** |
|
24 | - * @var string |
|
25 | - */ |
|
26 | - protected $name; |
|
27 | - |
|
28 | - /** |
|
29 | - * @var string |
|
30 | - */ |
|
31 | - protected $label; |
|
32 | - |
|
33 | - /** |
|
34 | - * @var array |
|
35 | - */ |
|
36 | - protected $suggestions = [ |
|
37 | - '0' => 'LLL:EXT:vidi/Resources/Private/Language/locallang.xlf:active.0', |
|
38 | - ]; |
|
39 | - |
|
40 | - /** |
|
41 | - * @var array |
|
42 | - */ |
|
43 | - protected $configuration = []; |
|
44 | - |
|
45 | - /** |
|
46 | - * @var string |
|
47 | - */ |
|
48 | - protected $dataType; |
|
49 | - |
|
50 | - /** |
|
51 | - * @var bool |
|
52 | - */ |
|
53 | - protected $canModifyMatcher = true; |
|
54 | - |
|
55 | - /** |
|
56 | - * Constructor of a Generic Facet in Vidi. |
|
57 | - * |
|
58 | - * @param string $name |
|
59 | - * @param string $label |
|
60 | - * @param array $suggestions |
|
61 | - * @param array $configuration |
|
62 | - */ |
|
63 | - public function __construct($name, $label = '', array $suggestions = [], $configuration = []) |
|
64 | - { |
|
65 | - $this->name = $name; |
|
66 | - if (empty($label)) { |
|
67 | - $label = $this->name; |
|
68 | - } |
|
69 | - $this->label = $label; |
|
70 | - if ($suggestions) { |
|
71 | - $this->suggestions = $suggestions; |
|
72 | - } |
|
73 | - if ($configuration) { |
|
74 | - $this->configuration = $configuration; |
|
75 | - } |
|
76 | - } |
|
77 | - |
|
78 | - /** |
|
79 | - * @return string |
|
80 | - */ |
|
81 | - public function getName(): string |
|
82 | - { |
|
83 | - return $this->name; |
|
84 | - } |
|
85 | - |
|
86 | - /** |
|
87 | - * @return string |
|
88 | - */ |
|
89 | - public function getLabel(): string |
|
90 | - { |
|
91 | - if ($this->label === $this->name) { |
|
92 | - $label = Tca::table($this->dataType)->field($this->getName())->getLabel(); |
|
93 | - } else { |
|
94 | - try { |
|
95 | - $label = LocalizationUtility::translate($this->label, ''); |
|
96 | - } catch (\InvalidArgumentException $e) { |
|
97 | - } |
|
98 | - if (empty($label)) { |
|
99 | - $label = $this->label; |
|
100 | - } |
|
101 | - } |
|
102 | - |
|
103 | - return $label; |
|
104 | - } |
|
105 | - |
|
106 | - /** |
|
107 | - * @return array |
|
108 | - */ |
|
109 | - public function getSuggestions(): array |
|
110 | - { |
|
111 | - |
|
112 | - $values = []; |
|
113 | - foreach ($this->suggestions as $key => $label) { |
|
114 | - $localizedLabel = $this->getLanguageService()->sL($label); |
|
115 | - if (!empty($localizedLabel)) { |
|
116 | - $label = $localizedLabel; |
|
117 | - } |
|
118 | - |
|
119 | - $values[] = [$key => $label]; |
|
120 | - } |
|
121 | - |
|
122 | - return $values; |
|
123 | - } |
|
124 | - |
|
125 | - /** |
|
126 | - * @return LanguageService |
|
127 | - */ |
|
128 | - protected function getLanguageService(): LanguageService |
|
129 | - { |
|
130 | - /** @var LanguageService $langService */ |
|
131 | - $langService = $GLOBALS['LANG']; |
|
132 | - if (!$langService) { |
|
133 | - $langService = GeneralUtility::makeInstance(LanguageService::class); |
|
134 | - $langService->init('en'); |
|
135 | - } |
|
136 | - |
|
137 | - return $langService; |
|
138 | - } |
|
139 | - |
|
140 | - /** |
|
141 | - * @return bool |
|
142 | - */ |
|
143 | - public function hasSuggestions(): bool |
|
144 | - { |
|
145 | - return !empty($this->suggestions); |
|
146 | - } |
|
147 | - |
|
148 | - /** |
|
149 | - * @param string $dataType |
|
150 | - * @return $this |
|
151 | - */ |
|
152 | - public function setDataType($dataType): self |
|
153 | - { |
|
154 | - $this->dataType = $dataType; |
|
155 | - return $this; |
|
156 | - } |
|
157 | - |
|
158 | - /** |
|
159 | - * @return bool |
|
160 | - */ |
|
161 | - public function canModifyMatcher(): bool |
|
162 | - { |
|
163 | - return $this->canModifyMatcher; |
|
164 | - } |
|
165 | - |
|
166 | - /** |
|
167 | - * @param Matcher $matcher |
|
168 | - * @param $value |
|
169 | - * @return Matcher |
|
170 | - */ |
|
171 | - public function modifyMatcher(Matcher $matcher, $value): Matcher |
|
172 | - { |
|
173 | - foreach ($this->configuration as $fieldNameAndPath => $operand) { |
|
174 | - if ($operand === '*') { |
|
175 | - $matcher->notEquals($fieldNameAndPath, ''); |
|
176 | - } else { |
|
177 | - $matcher->equals($fieldNameAndPath, $operand); |
|
178 | - } |
|
179 | - } |
|
180 | - return $matcher; |
|
181 | - } |
|
23 | + /** |
|
24 | + * @var string |
|
25 | + */ |
|
26 | + protected $name; |
|
27 | + |
|
28 | + /** |
|
29 | + * @var string |
|
30 | + */ |
|
31 | + protected $label; |
|
32 | + |
|
33 | + /** |
|
34 | + * @var array |
|
35 | + */ |
|
36 | + protected $suggestions = [ |
|
37 | + '0' => 'LLL:EXT:vidi/Resources/Private/Language/locallang.xlf:active.0', |
|
38 | + ]; |
|
39 | + |
|
40 | + /** |
|
41 | + * @var array |
|
42 | + */ |
|
43 | + protected $configuration = []; |
|
44 | + |
|
45 | + /** |
|
46 | + * @var string |
|
47 | + */ |
|
48 | + protected $dataType; |
|
49 | + |
|
50 | + /** |
|
51 | + * @var bool |
|
52 | + */ |
|
53 | + protected $canModifyMatcher = true; |
|
54 | + |
|
55 | + /** |
|
56 | + * Constructor of a Generic Facet in Vidi. |
|
57 | + * |
|
58 | + * @param string $name |
|
59 | + * @param string $label |
|
60 | + * @param array $suggestions |
|
61 | + * @param array $configuration |
|
62 | + */ |
|
63 | + public function __construct($name, $label = '', array $suggestions = [], $configuration = []) |
|
64 | + { |
|
65 | + $this->name = $name; |
|
66 | + if (empty($label)) { |
|
67 | + $label = $this->name; |
|
68 | + } |
|
69 | + $this->label = $label; |
|
70 | + if ($suggestions) { |
|
71 | + $this->suggestions = $suggestions; |
|
72 | + } |
|
73 | + if ($configuration) { |
|
74 | + $this->configuration = $configuration; |
|
75 | + } |
|
76 | + } |
|
77 | + |
|
78 | + /** |
|
79 | + * @return string |
|
80 | + */ |
|
81 | + public function getName(): string |
|
82 | + { |
|
83 | + return $this->name; |
|
84 | + } |
|
85 | + |
|
86 | + /** |
|
87 | + * @return string |
|
88 | + */ |
|
89 | + public function getLabel(): string |
|
90 | + { |
|
91 | + if ($this->label === $this->name) { |
|
92 | + $label = Tca::table($this->dataType)->field($this->getName())->getLabel(); |
|
93 | + } else { |
|
94 | + try { |
|
95 | + $label = LocalizationUtility::translate($this->label, ''); |
|
96 | + } catch (\InvalidArgumentException $e) { |
|
97 | + } |
|
98 | + if (empty($label)) { |
|
99 | + $label = $this->label; |
|
100 | + } |
|
101 | + } |
|
102 | + |
|
103 | + return $label; |
|
104 | + } |
|
105 | + |
|
106 | + /** |
|
107 | + * @return array |
|
108 | + */ |
|
109 | + public function getSuggestions(): array |
|
110 | + { |
|
111 | + |
|
112 | + $values = []; |
|
113 | + foreach ($this->suggestions as $key => $label) { |
|
114 | + $localizedLabel = $this->getLanguageService()->sL($label); |
|
115 | + if (!empty($localizedLabel)) { |
|
116 | + $label = $localizedLabel; |
|
117 | + } |
|
118 | + |
|
119 | + $values[] = [$key => $label]; |
|
120 | + } |
|
121 | + |
|
122 | + return $values; |
|
123 | + } |
|
124 | + |
|
125 | + /** |
|
126 | + * @return LanguageService |
|
127 | + */ |
|
128 | + protected function getLanguageService(): LanguageService |
|
129 | + { |
|
130 | + /** @var LanguageService $langService */ |
|
131 | + $langService = $GLOBALS['LANG']; |
|
132 | + if (!$langService) { |
|
133 | + $langService = GeneralUtility::makeInstance(LanguageService::class); |
|
134 | + $langService->init('en'); |
|
135 | + } |
|
136 | + |
|
137 | + return $langService; |
|
138 | + } |
|
139 | + |
|
140 | + /** |
|
141 | + * @return bool |
|
142 | + */ |
|
143 | + public function hasSuggestions(): bool |
|
144 | + { |
|
145 | + return !empty($this->suggestions); |
|
146 | + } |
|
147 | + |
|
148 | + /** |
|
149 | + * @param string $dataType |
|
150 | + * @return $this |
|
151 | + */ |
|
152 | + public function setDataType($dataType): self |
|
153 | + { |
|
154 | + $this->dataType = $dataType; |
|
155 | + return $this; |
|
156 | + } |
|
157 | + |
|
158 | + /** |
|
159 | + * @return bool |
|
160 | + */ |
|
161 | + public function canModifyMatcher(): bool |
|
162 | + { |
|
163 | + return $this->canModifyMatcher; |
|
164 | + } |
|
165 | + |
|
166 | + /** |
|
167 | + * @param Matcher $matcher |
|
168 | + * @param $value |
|
169 | + * @return Matcher |
|
170 | + */ |
|
171 | + public function modifyMatcher(Matcher $matcher, $value): Matcher |
|
172 | + { |
|
173 | + foreach ($this->configuration as $fieldNameAndPath => $operand) { |
|
174 | + if ($operand === '*') { |
|
175 | + $matcher->notEquals($fieldNameAndPath, ''); |
|
176 | + } else { |
|
177 | + $matcher->equals($fieldNameAndPath, $operand); |
|
178 | + } |
|
179 | + } |
|
180 | + return $matcher; |
|
181 | + } |
|
182 | 182 | |
183 | 183 | } |
@@ -208,7 +208,7 @@ |
||
208 | 208 | $page = $query->select('doktype') |
209 | 209 | ->from('pages') |
210 | 210 | ->where('deleted = 0', |
211 | - 'uid = ' . $configuredPid) |
|
211 | + 'uid = '.$configuredPid) |
|
212 | 212 | ->execute() |
213 | 213 | ->fetch(); |
214 | 214 |
@@ -20,212 +20,212 @@ |
||
20 | 20 | */ |
21 | 21 | class ModulePidService |
22 | 22 | { |
23 | - /** |
|
24 | - * The data type (table) |
|
25 | - * |
|
26 | - * @var string |
|
27 | - */ |
|
28 | - protected $dataType = ''; |
|
29 | - |
|
30 | - /** |
|
31 | - * A collection of speaking error messages why the pid is invalid. |
|
32 | - * |
|
33 | - * @var array |
|
34 | - */ |
|
35 | - protected $errors = []; |
|
36 | - |
|
37 | - /** |
|
38 | - * ModulePidService constructor. |
|
39 | - */ |
|
40 | - public function __construct() |
|
41 | - { |
|
42 | - $this->dataType = $this->getModuleLoader()->getDataType(); |
|
43 | - } |
|
44 | - |
|
45 | - /** |
|
46 | - * Returns a class instance |
|
47 | - * |
|
48 | - * @return \Fab\Vidi\Module\ModulePidService|object |
|
49 | - */ |
|
50 | - static public function getInstance() |
|
51 | - { |
|
52 | - return GeneralUtility::makeInstance(self::class); |
|
53 | - } |
|
54 | - |
|
55 | - /** |
|
56 | - * @return bool |
|
57 | - */ |
|
58 | - public function isConfiguredPidValid(): bool |
|
59 | - { |
|
60 | - $errors = $this->validateConfiguredPid(); |
|
61 | - return empty($errors); |
|
62 | - } |
|
63 | - |
|
64 | - /** |
|
65 | - * @return array |
|
66 | - */ |
|
67 | - public function validateConfiguredPid(): array |
|
68 | - { |
|
69 | - $configuredPid = $this->getConfiguredNewRecordPid(); |
|
70 | - $this->validateRootLevel($configuredPid); |
|
71 | - $this->validatePageExist($configuredPid); |
|
72 | - $this->validateDoktype($configuredPid); |
|
73 | - return $this->errors; |
|
74 | - } |
|
75 | - |
|
76 | - /** |
|
77 | - * Return the default configured pid. |
|
78 | - * |
|
79 | - * @return int |
|
80 | - */ |
|
81 | - public function getConfiguredNewRecordPid(): int |
|
82 | - { |
|
83 | - if (GeneralUtility::_GP(Parameter::PID)) { |
|
84 | - $configuredPid = (int)GeneralUtility::_GP(Parameter::PID); |
|
85 | - } else { |
|
86 | - |
|
87 | - // Get pid from User TSConfig if any. |
|
88 | - $tsConfigPath = sprintf('tx_vidi.dataType.%s.storagePid', $this->dataType); |
|
89 | - $result = $this->getBackendUser()->getTSConfig($tsConfigPath); |
|
90 | - $configuredPid = isset($result['value']) |
|
91 | - ? $configuredPid = (int)$result['value'] |
|
92 | - : $this->getModuleLoader()->getDefaultPid(); |
|
93 | - } |
|
94 | - |
|
95 | - return $configuredPid; |
|
96 | - } |
|
97 | - |
|
98 | - /** |
|
99 | - * Check if pid is 0 and given table is allowed on root level. |
|
100 | - * |
|
101 | - * @param int $configuredPid |
|
102 | - * @return void |
|
103 | - */ |
|
104 | - protected function validateRootLevel(int $configuredPid): void |
|
105 | - { |
|
106 | - if ($configuredPid > 0) { |
|
107 | - return; |
|
108 | - } |
|
109 | - |
|
110 | - $isRootLevel = (bool)Tca::table()->get('rootLevel'); |
|
111 | - if (!$isRootLevel) { |
|
112 | - $this->errors[] = sprintf( |
|
113 | - 'You are not allowed to use page id "0" unless you set $GLOBALS[\'TCA\'][\'%1$s\'][\'ctrl\'][\'rootLevel\'] = 1;', |
|
114 | - $this->dataType |
|
115 | - ); |
|
116 | - } |
|
117 | - } |
|
118 | - |
|
119 | - /** |
|
120 | - * Check if a page exists for the configured pid |
|
121 | - * |
|
122 | - * @param int $configuredPid |
|
123 | - * @return void |
|
124 | - */ |
|
125 | - protected function validatePageExist(int $configuredPid): void |
|
126 | - { |
|
127 | - if ($configuredPid === 0) { |
|
128 | - return; |
|
129 | - } |
|
130 | - |
|
131 | - $page = $this->getPage($configuredPid); |
|
132 | - if (empty($page)) { |
|
133 | - $this->errors[] = sprintf( |
|
134 | - 'No page found for the configured page id "%s".', |
|
135 | - $configuredPid |
|
136 | - ); |
|
137 | - } |
|
138 | - } |
|
139 | - |
|
140 | - /** |
|
141 | - * Check if configured page is a sysfolder and if it is allowed. |
|
142 | - * |
|
143 | - * @param int $configuredPid |
|
144 | - * @return void |
|
145 | - */ |
|
146 | - protected function validateDoktype(int $configuredPid): void |
|
147 | - { |
|
148 | - if ($configuredPid === 0) { |
|
149 | - return; |
|
150 | - } |
|
151 | - |
|
152 | - $page = $this->getPage($configuredPid); |
|
153 | - if (!empty($page) |
|
154 | - && (int)$page['doktype'] !== PageRepository::DOKTYPE_SYSFOLDER |
|
155 | - && !$this->isTableAllowedOnStandardPages() |
|
156 | - && $this->getModuleLoader()->hasComponentInDocHeader(NewButton::class)) { |
|
157 | - $this->errors[] = sprintf( |
|
158 | - 'The page with the id "%s" either has to be of the type "folder" (doktype=254) or the table "%s" has to be allowed on standard pages.', |
|
159 | - $configuredPid, |
|
160 | - $this->dataType |
|
161 | - ); |
|
162 | - } |
|
163 | - } |
|
164 | - |
|
165 | - /** |
|
166 | - * Check if given table is allowed on standard pages |
|
167 | - * |
|
168 | - * @return bool |
|
169 | - * @see \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::allowTableOnStandardPages() |
|
170 | - */ |
|
171 | - protected function isTableAllowedOnStandardPages(): bool |
|
172 | - { |
|
173 | - $allowedTables = explode(',', $GLOBALS['PAGES_TYPES']['default']['allowedTables']); |
|
174 | - return in_array($this->dataType, $allowedTables, true); |
|
175 | - } |
|
176 | - |
|
177 | - /** |
|
178 | - * Returns the page record of the configured pid |
|
179 | - * |
|
180 | - * @param int $configuredPid |
|
181 | - * @return array |
|
182 | - */ |
|
183 | - protected function getPage(int $configuredPid): ?array |
|
184 | - { |
|
185 | - $query = $this->getQueryBuilder('pages'); |
|
186 | - $query->getRestrictions()->removeAll(); // we are in BE context. |
|
187 | - |
|
188 | - $page = $query->select('doktype') |
|
189 | - ->from('pages') |
|
190 | - ->where('deleted = 0', |
|
191 | - 'uid = ' . $configuredPid) |
|
192 | - ->execute() |
|
193 | - ->fetch(); |
|
194 | - |
|
195 | - return is_array($page) |
|
196 | - ? $page |
|
197 | - : []; |
|
198 | - } |
|
199 | - |
|
200 | - /** |
|
201 | - * @param string $tableName |
|
202 | - * @return object|QueryBuilder |
|
203 | - */ |
|
204 | - protected function getQueryBuilder($tableName): QueryBuilder |
|
205 | - { |
|
206 | - /** @var ConnectionPool $connectionPool */ |
|
207 | - $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class); |
|
208 | - return $connectionPool->getQueryBuilderForTable($tableName); |
|
209 | - } |
|
210 | - |
|
211 | - /** |
|
212 | - * Returns an instance of the current Backend User. |
|
213 | - * |
|
214 | - * @return BackendUserAuthentication |
|
215 | - */ |
|
216 | - protected function getBackendUser() |
|
217 | - { |
|
218 | - return $GLOBALS['BE_USER']; |
|
219 | - } |
|
220 | - |
|
221 | - /** |
|
222 | - * Get the Vidi Module Loader. |
|
223 | - * |
|
224 | - * @return ModuleLoader|object |
|
225 | - */ |
|
226 | - protected function getModuleLoader() |
|
227 | - { |
|
228 | - return GeneralUtility::makeInstance(ModuleLoader::class); |
|
229 | - } |
|
23 | + /** |
|
24 | + * The data type (table) |
|
25 | + * |
|
26 | + * @var string |
|
27 | + */ |
|
28 | + protected $dataType = ''; |
|
29 | + |
|
30 | + /** |
|
31 | + * A collection of speaking error messages why the pid is invalid. |
|
32 | + * |
|
33 | + * @var array |
|
34 | + */ |
|
35 | + protected $errors = []; |
|
36 | + |
|
37 | + /** |
|
38 | + * ModulePidService constructor. |
|
39 | + */ |
|
40 | + public function __construct() |
|
41 | + { |
|
42 | + $this->dataType = $this->getModuleLoader()->getDataType(); |
|
43 | + } |
|
44 | + |
|
45 | + /** |
|
46 | + * Returns a class instance |
|
47 | + * |
|
48 | + * @return \Fab\Vidi\Module\ModulePidService|object |
|
49 | + */ |
|
50 | + static public function getInstance() |
|
51 | + { |
|
52 | + return GeneralUtility::makeInstance(self::class); |
|
53 | + } |
|
54 | + |
|
55 | + /** |
|
56 | + * @return bool |
|
57 | + */ |
|
58 | + public function isConfiguredPidValid(): bool |
|
59 | + { |
|
60 | + $errors = $this->validateConfiguredPid(); |
|
61 | + return empty($errors); |
|
62 | + } |
|
63 | + |
|
64 | + /** |
|
65 | + * @return array |
|
66 | + */ |
|
67 | + public function validateConfiguredPid(): array |
|
68 | + { |
|
69 | + $configuredPid = $this->getConfiguredNewRecordPid(); |
|
70 | + $this->validateRootLevel($configuredPid); |
|
71 | + $this->validatePageExist($configuredPid); |
|
72 | + $this->validateDoktype($configuredPid); |
|
73 | + return $this->errors; |
|
74 | + } |
|
75 | + |
|
76 | + /** |
|
77 | + * Return the default configured pid. |
|
78 | + * |
|
79 | + * @return int |
|
80 | + */ |
|
81 | + public function getConfiguredNewRecordPid(): int |
|
82 | + { |
|
83 | + if (GeneralUtility::_GP(Parameter::PID)) { |
|
84 | + $configuredPid = (int)GeneralUtility::_GP(Parameter::PID); |
|
85 | + } else { |
|
86 | + |
|
87 | + // Get pid from User TSConfig if any. |
|
88 | + $tsConfigPath = sprintf('tx_vidi.dataType.%s.storagePid', $this->dataType); |
|
89 | + $result = $this->getBackendUser()->getTSConfig($tsConfigPath); |
|
90 | + $configuredPid = isset($result['value']) |
|
91 | + ? $configuredPid = (int)$result['value'] |
|
92 | + : $this->getModuleLoader()->getDefaultPid(); |
|
93 | + } |
|
94 | + |
|
95 | + return $configuredPid; |
|
96 | + } |
|
97 | + |
|
98 | + /** |
|
99 | + * Check if pid is 0 and given table is allowed on root level. |
|
100 | + * |
|
101 | + * @param int $configuredPid |
|
102 | + * @return void |
|
103 | + */ |
|
104 | + protected function validateRootLevel(int $configuredPid): void |
|
105 | + { |
|
106 | + if ($configuredPid > 0) { |
|
107 | + return; |
|
108 | + } |
|
109 | + |
|
110 | + $isRootLevel = (bool)Tca::table()->get('rootLevel'); |
|
111 | + if (!$isRootLevel) { |
|
112 | + $this->errors[] = sprintf( |
|
113 | + 'You are not allowed to use page id "0" unless you set $GLOBALS[\'TCA\'][\'%1$s\'][\'ctrl\'][\'rootLevel\'] = 1;', |
|
114 | + $this->dataType |
|
115 | + ); |
|
116 | + } |
|
117 | + } |
|
118 | + |
|
119 | + /** |
|
120 | + * Check if a page exists for the configured pid |
|
121 | + * |
|
122 | + * @param int $configuredPid |
|
123 | + * @return void |
|
124 | + */ |
|
125 | + protected function validatePageExist(int $configuredPid): void |
|
126 | + { |
|
127 | + if ($configuredPid === 0) { |
|
128 | + return; |
|
129 | + } |
|
130 | + |
|
131 | + $page = $this->getPage($configuredPid); |
|
132 | + if (empty($page)) { |
|
133 | + $this->errors[] = sprintf( |
|
134 | + 'No page found for the configured page id "%s".', |
|
135 | + $configuredPid |
|
136 | + ); |
|
137 | + } |
|
138 | + } |
|
139 | + |
|
140 | + /** |
|
141 | + * Check if configured page is a sysfolder and if it is allowed. |
|
142 | + * |
|
143 | + * @param int $configuredPid |
|
144 | + * @return void |
|
145 | + */ |
|
146 | + protected function validateDoktype(int $configuredPid): void |
|
147 | + { |
|
148 | + if ($configuredPid === 0) { |
|
149 | + return; |
|
150 | + } |
|
151 | + |
|
152 | + $page = $this->getPage($configuredPid); |
|
153 | + if (!empty($page) |
|
154 | + && (int)$page['doktype'] !== PageRepository::DOKTYPE_SYSFOLDER |
|
155 | + && !$this->isTableAllowedOnStandardPages() |
|
156 | + && $this->getModuleLoader()->hasComponentInDocHeader(NewButton::class)) { |
|
157 | + $this->errors[] = sprintf( |
|
158 | + 'The page with the id "%s" either has to be of the type "folder" (doktype=254) or the table "%s" has to be allowed on standard pages.', |
|
159 | + $configuredPid, |
|
160 | + $this->dataType |
|
161 | + ); |
|
162 | + } |
|
163 | + } |
|
164 | + |
|
165 | + /** |
|
166 | + * Check if given table is allowed on standard pages |
|
167 | + * |
|
168 | + * @return bool |
|
169 | + * @see \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::allowTableOnStandardPages() |
|
170 | + */ |
|
171 | + protected function isTableAllowedOnStandardPages(): bool |
|
172 | + { |
|
173 | + $allowedTables = explode(',', $GLOBALS['PAGES_TYPES']['default']['allowedTables']); |
|
174 | + return in_array($this->dataType, $allowedTables, true); |
|
175 | + } |
|
176 | + |
|
177 | + /** |
|
178 | + * Returns the page record of the configured pid |
|
179 | + * |
|
180 | + * @param int $configuredPid |
|
181 | + * @return array |
|
182 | + */ |
|
183 | + protected function getPage(int $configuredPid): ?array |
|
184 | + { |
|
185 | + $query = $this->getQueryBuilder('pages'); |
|
186 | + $query->getRestrictions()->removeAll(); // we are in BE context. |
|
187 | + |
|
188 | + $page = $query->select('doktype') |
|
189 | + ->from('pages') |
|
190 | + ->where('deleted = 0', |
|
191 | + 'uid = ' . $configuredPid) |
|
192 | + ->execute() |
|
193 | + ->fetch(); |
|
194 | + |
|
195 | + return is_array($page) |
|
196 | + ? $page |
|
197 | + : []; |
|
198 | + } |
|
199 | + |
|
200 | + /** |
|
201 | + * @param string $tableName |
|
202 | + * @return object|QueryBuilder |
|
203 | + */ |
|
204 | + protected function getQueryBuilder($tableName): QueryBuilder |
|
205 | + { |
|
206 | + /** @var ConnectionPool $connectionPool */ |
|
207 | + $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class); |
|
208 | + return $connectionPool->getQueryBuilderForTable($tableName); |
|
209 | + } |
|
210 | + |
|
211 | + /** |
|
212 | + * Returns an instance of the current Backend User. |
|
213 | + * |
|
214 | + * @return BackendUserAuthentication |
|
215 | + */ |
|
216 | + protected function getBackendUser() |
|
217 | + { |
|
218 | + return $GLOBALS['BE_USER']; |
|
219 | + } |
|
220 | + |
|
221 | + /** |
|
222 | + * Get the Vidi Module Loader. |
|
223 | + * |
|
224 | + * @return ModuleLoader|object |
|
225 | + */ |
|
226 | + protected function getModuleLoader() |
|
227 | + { |
|
228 | + return GeneralUtility::makeInstance(ModuleLoader::class); |
|
229 | + } |
|
230 | 230 | |
231 | 231 | } |
@@ -19,33 +19,33 @@ discard block |
||
19 | 19 | */ |
20 | 20 | class PidCheck extends AbstractComponentView |
21 | 21 | { |
22 | - /** |
|
23 | - * Renders warnings if storagePid is not properly configured. |
|
24 | - * |
|
25 | - * @return string |
|
26 | - */ |
|
27 | - public function render(): string |
|
28 | - { |
|
29 | - $errors = $this->getModulePidService()->validateConfiguredPid(); |
|
22 | + /** |
|
23 | + * Renders warnings if storagePid is not properly configured. |
|
24 | + * |
|
25 | + * @return string |
|
26 | + */ |
|
27 | + public function render(): string |
|
28 | + { |
|
29 | + $errors = $this->getModulePidService()->validateConfiguredPid(); |
|
30 | 30 | |
31 | - return empty($errors) |
|
32 | - ? '' |
|
33 | - : $this->formatMessagePidIsNotValid($errors); |
|
34 | - } |
|
31 | + return empty($errors) |
|
32 | + ? '' |
|
33 | + : $this->formatMessagePidIsNotValid($errors); |
|
34 | + } |
|
35 | 35 | |
36 | - /** |
|
37 | - * Format a message whenever the storage is offline. |
|
38 | - * |
|
39 | - * @param array $errors |
|
40 | - * @return string |
|
41 | - */ |
|
42 | - protected function formatMessagePidIsNotValid(array $errors): string |
|
43 | - { |
|
44 | - $configuredPid = $this->getModulePidService()->getConfiguredNewRecordPid(); |
|
36 | + /** |
|
37 | + * Format a message whenever the storage is offline. |
|
38 | + * |
|
39 | + * @param array $errors |
|
40 | + * @return string |
|
41 | + */ |
|
42 | + protected function formatMessagePidIsNotValid(array $errors): string |
|
43 | + { |
|
44 | + $configuredPid = $this->getModulePidService()->getConfiguredNewRecordPid(); |
|
45 | 45 | |
46 | - $error = implode('<br />', $errors); |
|
47 | - $dataType = $this->getModuleLoader()->getDataType(); |
|
48 | - $result = <<< EOF |
|
46 | + $error = implode('<br />', $errors); |
|
47 | + $dataType = $this->getModuleLoader()->getDataType(); |
|
48 | + $result = <<< EOF |
|
49 | 49 | <div class="alert alert-warning"> |
50 | 50 | <div class="alert-title"> |
51 | 51 | Page id "{$configuredPid}" has found to be a wrong configuration for "{$dataType}" |
@@ -73,16 +73,16 @@ discard block |
||
73 | 73 | </div> |
74 | 74 | EOF; |
75 | 75 | |
76 | - return $result; |
|
77 | - } |
|
76 | + return $result; |
|
77 | + } |
|
78 | 78 | |
79 | - /** |
|
80 | - * @return ModulePidService|object |
|
81 | - */ |
|
82 | - public function getModulePidService() |
|
83 | - { |
|
84 | - /** @var ModulePidService $modulePidService */ |
|
85 | - return GeneralUtility::makeInstance(ModulePidService::class); |
|
86 | - } |
|
79 | + /** |
|
80 | + * @return ModulePidService|object |
|
81 | + */ |
|
82 | + public function getModulePidService() |
|
83 | + { |
|
84 | + /** @var ModulePidService $modulePidService */ |
|
85 | + return GeneralUtility::makeInstance(ModulePidService::class); |
|
86 | + } |
|
87 | 87 | |
88 | 88 | } |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | $this->tableName = $tableName; |
69 | 69 | |
70 | 70 | if (empty($GLOBALS['TCA'][$this->tableName])) { |
71 | - throw new InvalidKeyInArrayException('No TCA existence for table name: ' . $this->tableName, 1356945108); |
|
71 | + throw new InvalidKeyInArrayException('No TCA existence for table name: '.$this->tableName, 1356945108); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | $this->tca = $GLOBALS['TCA'][$this->tableName]['grid']; |
@@ -170,7 +170,7 @@ discard block |
||
170 | 170 | { |
171 | 171 | $fields = array_keys($this->getFields()); |
172 | 172 | if (empty($fields[$position])) { |
173 | - throw new InvalidKeyInArrayException('No field exist for position: ' . $position, 1356945119); |
|
173 | + throw new InvalidKeyInArrayException('No field exist for position: '.$position, 1356945119); |
|
174 | 174 | } |
175 | 175 | |
176 | 176 | return (string)$fields[$position]; |
@@ -686,7 +686,7 @@ discard block |
||
686 | 686 | $facet = GeneralUtility::makeInstance(StandardFacet::class, $facetName, $label); |
687 | 687 | |
688 | 688 | if (!$facet instanceof StandardFacet) { |
689 | - throw new \RuntimeException('I could not instantiate a facet for facet name "' . $facetName . '""', 1445856345); |
|
689 | + throw new \RuntimeException('I could not instantiate a facet for facet name "'.$facetName.'""', 1445856345); |
|
690 | 690 | } |
691 | 691 | return $facet; |
692 | 692 | } |
@@ -24,708 +24,708 @@ |
||
24 | 24 | class GridService extends AbstractTca |
25 | 25 | { |
26 | 26 | |
27 | - /** |
|
28 | - * @var array |
|
29 | - */ |
|
30 | - protected $tca; |
|
31 | - |
|
32 | - /** |
|
33 | - * @var string |
|
34 | - */ |
|
35 | - protected $tableName; |
|
36 | - |
|
37 | - /** |
|
38 | - * All fields available in the Grid. |
|
39 | - * |
|
40 | - * @var array |
|
41 | - */ |
|
42 | - protected $fields; |
|
43 | - |
|
44 | - /** |
|
45 | - * All fields regardless whether they have been excluded or not. |
|
46 | - * |
|
47 | - * @var array |
|
48 | - */ |
|
49 | - protected $allFields; |
|
50 | - |
|
51 | - /** |
|
52 | - * @var array |
|
53 | - */ |
|
54 | - protected $instances; |
|
55 | - |
|
56 | - /** |
|
57 | - * @var array |
|
58 | - */ |
|
59 | - protected $facets; |
|
60 | - |
|
61 | - /** |
|
62 | - * __construct |
|
63 | - * |
|
64 | - * @param string $tableName |
|
65 | - */ |
|
66 | - public function __construct($tableName) |
|
67 | - { |
|
68 | - |
|
69 | - $this->tableName = $tableName; |
|
70 | - |
|
71 | - if (empty($GLOBALS['TCA'][$this->tableName])) { |
|
72 | - throw new InvalidKeyInArrayException('No TCA existence for table name: ' . $this->tableName, 1356945108); |
|
73 | - } |
|
74 | - |
|
75 | - $this->tca = $GLOBALS['TCA'][$this->tableName]['grid']; |
|
76 | - } |
|
77 | - |
|
78 | - /** |
|
79 | - * Returns an array containing column names. |
|
80 | - * |
|
81 | - * @return array |
|
82 | - */ |
|
83 | - public function getFieldNames(): array |
|
84 | - { |
|
85 | - $fields = $this->getFields(); |
|
86 | - return array_keys($fields) ?: []; |
|
87 | - } |
|
88 | - |
|
89 | - /** |
|
90 | - * Returns an array containing column names. |
|
91 | - * |
|
92 | - * @return array |
|
93 | - */ |
|
94 | - public function getAllFieldNames(): array |
|
95 | - { |
|
96 | - $allFields = $this->getAllFields(); |
|
97 | - return array_keys($allFields); |
|
98 | - } |
|
99 | - |
|
100 | - /** |
|
101 | - * Get the label key. |
|
102 | - * |
|
103 | - * @param string $fieldNameAndPath |
|
104 | - * @return string |
|
105 | - */ |
|
106 | - public function getLabelKey($fieldNameAndPath): string |
|
107 | - { |
|
108 | - |
|
109 | - $field = $this->getField($fieldNameAndPath); |
|
110 | - |
|
111 | - // First option is to get the label from the Grid TCA. |
|
112 | - $rawLabel = ''; |
|
113 | - if (isset($field['label'])) { |
|
114 | - $rawLabel = $field['label']; |
|
115 | - } |
|
116 | - |
|
117 | - // Second option is to fetch the label from the Column Renderer object. |
|
118 | - if (!$rawLabel && $this->hasRenderers($fieldNameAndPath)) { |
|
119 | - $renderers = $this->getRenderers($fieldNameAndPath); |
|
120 | - /** @var $renderer ColumnRendererInterface */ |
|
121 | - foreach ($renderers as $renderer) { |
|
122 | - if (isset($renderer['label'])) { |
|
123 | - $rawLabel = $renderer['label']; |
|
124 | - break; |
|
125 | - } |
|
126 | - } |
|
127 | - } |
|
128 | - return $rawLabel; |
|
129 | - } |
|
130 | - |
|
131 | - /** |
|
132 | - * Get the translation of a label given a column name. |
|
133 | - * |
|
134 | - * @param string $fieldNameAndPath |
|
135 | - * @return string |
|
136 | - */ |
|
137 | - public function getLabel($fieldNameAndPath) |
|
138 | - { |
|
139 | - $label = ''; |
|
140 | - if ($this->hasLabel($fieldNameAndPath)) { |
|
141 | - $labelKey = $this->getLabelKey($fieldNameAndPath); |
|
142 | - try { |
|
143 | - $label = $this->getLanguageService()->sL($labelKey); |
|
144 | - } catch (\InvalidArgumentException $e) { |
|
145 | - } |
|
146 | - if (empty($label)) { |
|
147 | - $label = $labelKey; |
|
148 | - } |
|
149 | - } else { |
|
150 | - |
|
151 | - // Important to notice the label can contains a path, e.g. metadata.categories and must be resolved. |
|
152 | - $dataType = $this->getFieldPathResolver()->getDataType($fieldNameAndPath, $this->tableName); |
|
153 | - $fieldName = $this->getFieldPathResolver()->stripFieldPath($fieldNameAndPath, $this->tableName); |
|
154 | - $table = Tca::table($dataType); |
|
155 | - |
|
156 | - if ($table->hasField($fieldName) && $table->field($fieldName)->hasLabel()) { |
|
157 | - $label = $table->field($fieldName)->getLabel(); |
|
158 | - } |
|
159 | - } |
|
160 | - |
|
161 | - return $label; |
|
162 | - } |
|
163 | - |
|
164 | - /** |
|
165 | - * Returns the field name given its position. |
|
166 | - * |
|
167 | - * @param string $position the position of the field in the grid |
|
168 | - * @return string |
|
169 | - */ |
|
170 | - public function getFieldNameByPosition($position): string |
|
171 | - { |
|
172 | - $fields = array_keys($this->getFields()); |
|
173 | - if (empty($fields[$position])) { |
|
174 | - throw new InvalidKeyInArrayException('No field exist for position: ' . $position, 1356945119); |
|
175 | - } |
|
176 | - |
|
177 | - return (string)$fields[$position]; |
|
178 | - } |
|
179 | - |
|
180 | - /** |
|
181 | - * Returns a field name. |
|
182 | - * |
|
183 | - * @param string $fieldName |
|
184 | - * @return array |
|
185 | - */ |
|
186 | - public function getField($fieldName): array |
|
187 | - { |
|
188 | - $fields = $this->getFields(); |
|
189 | - return $fields[$fieldName] ?: []; |
|
190 | - } |
|
191 | - |
|
192 | - /** |
|
193 | - * Returns an array containing column names for the Grid. |
|
194 | - * |
|
195 | - * @return array |
|
196 | - */ |
|
197 | - public function getFields(): array |
|
198 | - { |
|
199 | - // Cache this operation since it can take some time. |
|
200 | - if ($this->fields === null) { |
|
201 | - |
|
202 | - // Fetch all available fields first. |
|
203 | - $fields = $this->getAllFields(); |
|
204 | - |
|
205 | - if ($this->isBackendMode()) { |
|
206 | - |
|
207 | - // Then remove the not allowed. |
|
208 | - $fields = $this->filterByIncludedFields($fields); |
|
209 | - $fields = $this->filterByBackendUser($fields); |
|
210 | - $fields = $this->filterByExcludedFields($fields); |
|
211 | - } |
|
212 | - |
|
213 | - $this->fields = $fields; |
|
214 | - } |
|
215 | - |
|
216 | - return $this->fields; |
|
217 | - } |
|
218 | - |
|
219 | - /** |
|
220 | - * Remove fields according to Grid configuration. |
|
221 | - * |
|
222 | - * @param $fields |
|
223 | - * @return array |
|
224 | - */ |
|
225 | - protected function filterByIncludedFields($fields): array |
|
226 | - { |
|
227 | - |
|
228 | - $filteredFields = $fields; |
|
229 | - $includedFields = $this->getIncludedFields(); |
|
230 | - if (count($includedFields) > 0) { |
|
231 | - $filteredFields = []; |
|
232 | - foreach ($fields as $fieldNameAndPath => $configuration) { |
|
233 | - if (in_array($fieldNameAndPath, $includedFields, true) || !Tca::table($this->tableName)->hasField($fieldNameAndPath)) { |
|
234 | - $filteredFields[$fieldNameAndPath] = $configuration; |
|
235 | - } |
|
236 | - } |
|
237 | - } |
|
238 | - return $filteredFields; |
|
239 | - } |
|
240 | - |
|
241 | - /** |
|
242 | - * Remove fields according to BE User permission. |
|
243 | - * |
|
244 | - * @param $fields |
|
245 | - * @return array |
|
246 | - */ |
|
247 | - protected function filterByBackendUser($fields): array |
|
248 | - { |
|
249 | - if (!$this->getBackendUser()->isAdmin()) { |
|
250 | - foreach ($fields as $fieldName => $field) { |
|
251 | - if (Tca::table($this->tableName)->hasField($fieldName) && !Tca::table($this->tableName)->field($fieldName)->hasAccess()) { |
|
252 | - unset($fields[$fieldName]); |
|
253 | - } |
|
254 | - } |
|
255 | - } |
|
256 | - return $fields; |
|
257 | - } |
|
258 | - |
|
259 | - /** |
|
260 | - * Remove fields according to Grid configuration. |
|
261 | - * |
|
262 | - * @param $fields |
|
263 | - * @return array |
|
264 | - */ |
|
265 | - protected function filterByExcludedFields($fields): array |
|
266 | - { |
|
267 | - |
|
268 | - // Unset excluded fields. |
|
269 | - foreach ($this->getExcludedFields() as $excludedField) { |
|
270 | - if (isset($fields[$excludedField])) { |
|
271 | - unset($fields[$excludedField]); |
|
272 | - } |
|
273 | - } |
|
274 | - |
|
275 | - return $fields; |
|
276 | - } |
|
277 | - |
|
278 | - /** |
|
279 | - * Returns an array containing column names for the Grid. |
|
280 | - * |
|
281 | - * @return array |
|
282 | - */ |
|
283 | - public function getAllFields(): array |
|
284 | - { |
|
285 | - |
|
286 | - // Cache this operation since it can take some time. |
|
287 | - if ($this->allFields === null) { |
|
288 | - |
|
289 | - $fields = is_array($this->tca['columns']) ? $this->tca['columns'] : []; |
|
290 | - $gridFieldNames = array_keys($fields); |
|
291 | - |
|
292 | - // Fetch all fields of the TCA and merge it back to the fields configured for Grid. |
|
293 | - $tableFieldNames = Tca::table($this->tableName)->getFields(); |
|
294 | - |
|
295 | - // Just remove system fields from the Grid. |
|
296 | - foreach ($tableFieldNames as $key => $fieldName) { |
|
297 | - if (in_array($fieldName, Tca::getSystemFields())) { |
|
298 | - unset($tableFieldNames[$key]); |
|
299 | - } |
|
300 | - } |
|
301 | - |
|
302 | - $additionalFields = array_diff($tableFieldNames, $gridFieldNames); |
|
303 | - |
|
304 | - if (!empty($additionalFields)) { |
|
305 | - |
|
306 | - // Pop out last element of the key |
|
307 | - // Idea is to place new un-configured columns in between. By default, they will be hidden. |
|
308 | - end($fields); |
|
309 | - $lastColumnKey = key($fields); |
|
310 | - $lastColumn = array_pop($fields); |
|
311 | - |
|
312 | - // Feed up the grid fields with un configured elements |
|
313 | - foreach ($additionalFields as $additionalField) { |
|
314 | - $fields[$additionalField] = array( |
|
315 | - 'visible' => false |
|
316 | - ); |
|
317 | - |
|
318 | - // Try to guess the format of the field. |
|
319 | - $fieldType = Tca::table($this->tableName)->field($additionalField)->getType(); |
|
320 | - if ($fieldType === FieldType::DATE) { |
|
321 | - $fields[$additionalField]['format'] = 'Fab\Vidi\Formatter\Date'; |
|
322 | - } elseif ($fieldType === FieldType::DATETIME) { |
|
323 | - $fields[$additionalField]['format'] = 'Fab\Vidi\Formatter\Datetime'; |
|
324 | - } |
|
325 | - } |
|
326 | - $fields[$lastColumnKey] = $lastColumn; |
|
327 | - } |
|
328 | - |
|
329 | - $this->allFields = $fields; |
|
330 | - } |
|
331 | - |
|
332 | - return $this->allFields; |
|
333 | - } |
|
334 | - |
|
335 | - /** |
|
336 | - * Tell whether the field exists in the grid or not. |
|
337 | - * |
|
338 | - * @param string $fieldName |
|
339 | - * @return bool |
|
340 | - */ |
|
341 | - public function hasField($fieldName): bool |
|
342 | - { |
|
343 | - $fields = $this->getFields(); |
|
344 | - return isset($fields[$fieldName]); |
|
345 | - } |
|
346 | - |
|
347 | - /** |
|
348 | - * Tell whether the facet exists in the grid or not. |
|
349 | - * |
|
350 | - * @param string $facetName |
|
351 | - * @return bool |
|
352 | - */ |
|
353 | - public function hasFacet($facetName): bool |
|
354 | - { |
|
355 | - $facets = $this->getFacets(); |
|
356 | - return isset($facets[$facetName]); |
|
357 | - } |
|
358 | - |
|
359 | - /** |
|
360 | - * Returns an array containing facets fields. |
|
361 | - * |
|
362 | - * @return FacetInterface[] |
|
363 | - */ |
|
364 | - public function getFacets(): array |
|
365 | - { |
|
366 | - if ($this->facets === null) { |
|
367 | - $this->facets = []; |
|
368 | - |
|
369 | - if (is_array($this->tca['facets'])) { |
|
370 | - foreach ($this->tca['facets'] as $key => $facetNameOrArray) { |
|
371 | - if (is_array($facetNameOrArray)) { |
|
372 | - |
|
373 | - $name = $facetNameOrArray['name'] ?? ''; |
|
374 | - |
|
375 | - $label = isset($facetNameOrArray['label']) |
|
376 | - ? $this->getLanguageService()->sL($facetNameOrArray['label']) |
|
377 | - : ''; |
|
378 | - |
|
379 | - $suggestions = $facetNameOrArray['suggestions'] ?? []; |
|
380 | - $configuration = $facetNameOrArray['configuration'] ?? []; |
|
381 | - |
|
382 | - /** @var FacetInterface $facetObject */ |
|
383 | - $facetObject = GeneralUtility::makeInstance($key, $name, $label, $suggestions, $configuration); |
|
384 | - $this->facets[$facetObject->getName()] = $facetObject; |
|
385 | - } else { |
|
386 | - $this->facets[$facetNameOrArray] = $this->instantiateStandardFacet($facetNameOrArray); |
|
387 | - } |
|
388 | - } |
|
389 | - } |
|
390 | - } |
|
391 | - return $this->facets; |
|
392 | - } |
|
393 | - |
|
394 | - /** |
|
395 | - * Returns the "sortable" value of the column. |
|
396 | - * |
|
397 | - * @param string $fieldName |
|
398 | - * @return int|string |
|
399 | - */ |
|
400 | - public function isSortable($fieldName) |
|
401 | - { |
|
402 | - $defaultValue = true; |
|
403 | - $hasSortableField = Tca::table($this->tableName)->hasSortableField(); |
|
404 | - if ($hasSortableField) { |
|
405 | - $isSortable = false; |
|
406 | - } else { |
|
407 | - $isSortable = $this->get($fieldName, 'sortable', $defaultValue); |
|
408 | - } |
|
409 | - return $isSortable; |
|
410 | - } |
|
411 | - |
|
412 | - /** |
|
413 | - * Returns the "canBeHidden" value of the column. |
|
414 | - * |
|
415 | - * @param string $fieldName |
|
416 | - * @return bool |
|
417 | - */ |
|
418 | - public function canBeHidden($fieldName): bool |
|
419 | - { |
|
420 | - $defaultValue = true; |
|
421 | - return $this->get($fieldName, 'canBeHidden', $defaultValue); |
|
422 | - } |
|
423 | - |
|
424 | - /** |
|
425 | - * Returns the "width" value of the column. |
|
426 | - * |
|
427 | - * @param string $fieldName |
|
428 | - * @return int|string |
|
429 | - */ |
|
430 | - public function getWidth($fieldName) |
|
431 | - { |
|
432 | - $defaultValue = 'auto'; |
|
433 | - return $this->get($fieldName, 'width', $defaultValue); |
|
434 | - } |
|
435 | - |
|
436 | - /** |
|
437 | - * Returns the "visible" value of the column. |
|
438 | - * |
|
439 | - * @param string $fieldName |
|
440 | - * @return bool |
|
441 | - */ |
|
442 | - public function isVisible($fieldName): bool |
|
443 | - { |
|
444 | - $defaultValue = true; |
|
445 | - return $this->get($fieldName, 'visible', $defaultValue); |
|
446 | - } |
|
447 | - |
|
448 | - /** |
|
449 | - * Returns the "editable" value of the column. |
|
450 | - * |
|
451 | - * @param string $columnName |
|
452 | - * @return bool |
|
453 | - */ |
|
454 | - public function isEditable($columnName): bool |
|
455 | - { |
|
456 | - $defaultValue = false; |
|
457 | - return $this->get($columnName, 'editable', $defaultValue); |
|
458 | - } |
|
459 | - |
|
460 | - /** |
|
461 | - * Returns the "localized" value of the column. |
|
462 | - * |
|
463 | - * @param string $columnName |
|
464 | - * @return bool |
|
465 | - */ |
|
466 | - public function isLocalized($columnName): bool |
|
467 | - { |
|
468 | - $defaultValue = true; |
|
469 | - return $this->get($columnName, 'localized', $defaultValue); |
|
470 | - } |
|
471 | - |
|
472 | - /** |
|
473 | - * |
|
474 | - * Returns the "html" value of the column. |
|
475 | - * |
|
476 | - * @param string $fieldName |
|
477 | - * @return string |
|
478 | - */ |
|
479 | - public function getHeader($fieldName): string |
|
480 | - { |
|
481 | - $defaultValue = ''; |
|
482 | - return $this->get($fieldName, 'html', $defaultValue); |
|
483 | - } |
|
484 | - |
|
485 | - /** |
|
486 | - * Fetch a possible from a Grid Renderer. If no value is found, returns null |
|
487 | - * |
|
488 | - * @param string $fieldName |
|
489 | - * @param string $key |
|
490 | - * @param mixed $defaultValue |
|
491 | - * @return null|mixed |
|
492 | - */ |
|
493 | - public function get($fieldName, $key, $defaultValue = null) |
|
494 | - { |
|
495 | - $value = $defaultValue; |
|
496 | - |
|
497 | - $field = $this->getField($fieldName); |
|
498 | - if (isset($field[$key])) { |
|
499 | - $value = $field[$key]; |
|
500 | - } elseif ($this->hasRenderers($fieldName)) { |
|
501 | - $renderers = $this->getRenderers($fieldName); |
|
502 | - foreach ($renderers as $rendererConfiguration) { |
|
503 | - if (isset($rendererConfiguration[$key])) { |
|
504 | - $value = $rendererConfiguration[$key]; |
|
505 | - } |
|
506 | - } |
|
507 | - } |
|
508 | - return $value; |
|
509 | - } |
|
510 | - |
|
511 | - /** |
|
512 | - * Returns whether the column has a renderer. |
|
513 | - * |
|
514 | - * @param string $fieldName |
|
515 | - * @return bool |
|
516 | - */ |
|
517 | - public function hasRenderers($fieldName): bool |
|
518 | - { |
|
519 | - $field = $this->getField($fieldName); |
|
520 | - return empty($field['renderer']) && empty($field['renderers']) ? false : true; |
|
521 | - } |
|
522 | - |
|
523 | - /** |
|
524 | - * Returns a renderer. |
|
525 | - * |
|
526 | - * @param string $fieldName |
|
527 | - * @return array |
|
528 | - */ |
|
529 | - public function getRenderers($fieldName): array |
|
530 | - { |
|
531 | - $field = $this->getField($fieldName); |
|
532 | - $renderers = []; |
|
533 | - if (!empty($field['renderer'])) { |
|
534 | - $renderers = $this->convertRendererToArray($field['renderer'], $field); |
|
535 | - } elseif (!empty($field['renderers']) && is_array($field['renderers'])) { |
|
536 | - foreach ($field['renderers'] as $renderer) { |
|
537 | - $rendererNameAndConfiguration = $this->convertRendererToArray($renderer, $field); |
|
538 | - $renderers = array_merge($renderers, $rendererNameAndConfiguration); |
|
539 | - } |
|
540 | - } |
|
541 | - |
|
542 | - return $renderers; |
|
543 | - } |
|
544 | - |
|
545 | - /** |
|
546 | - * @param string $renderer |
|
547 | - * @return array |
|
548 | - */ |
|
549 | - protected function convertRendererToArray($renderer, array $field): array |
|
550 | - { |
|
551 | - $result = []; |
|
552 | - if (is_string($renderer)) { |
|
553 | - $configuration = empty($field['rendererConfiguration']) |
|
554 | - ? [] |
|
555 | - : $field['rendererConfiguration']; |
|
556 | - |
|
557 | - /** @var ColumnRendererInterface $rendererObject */ |
|
558 | - $rendererObject = GeneralUtility::makeInstance($renderer); |
|
559 | - |
|
560 | - $result[$renderer] = array_merge($rendererObject->getConfiguration(), $configuration); |
|
561 | - // TODO: throw alert message because this is not compatible anymore as of TYPO3 8.7.7 |
|
562 | - } elseif ($renderer instanceof ColumnRendererInterface) { |
|
563 | - /** @var ColumnRendererInterface $renderer */ |
|
564 | - $result[get_class($renderer)] = $renderer->getConfiguration(); |
|
565 | - } |
|
566 | - return $result; |
|
567 | - } |
|
568 | - |
|
569 | - /** |
|
570 | - * Returns the class names applied to a cell |
|
571 | - * |
|
572 | - * @param string $fieldName |
|
573 | - * @return bool |
|
574 | - */ |
|
575 | - public function getClass($fieldName): bool |
|
576 | - { |
|
577 | - $field = $this->getField($fieldName); |
|
578 | - return isset($field['class']) ? $field['class'] : ''; |
|
579 | - } |
|
580 | - |
|
581 | - /** |
|
582 | - * Returns whether the column has a label. |
|
583 | - * |
|
584 | - * @param string $fieldNameAndPath |
|
585 | - * @return bool |
|
586 | - */ |
|
587 | - public function hasLabel($fieldNameAndPath): bool |
|
588 | - { |
|
589 | - $field = $this->getField($fieldNameAndPath); |
|
590 | - |
|
591 | - $hasLabel = empty($field['label']) ? false : true; |
|
592 | - |
|
593 | - if (!$hasLabel && $this->hasRenderers($fieldNameAndPath)) { |
|
594 | - $renderers = $this->getRenderers($fieldNameAndPath); |
|
595 | - /** @var $renderer ColumnRendererInterface */ |
|
596 | - foreach ($renderers as $renderer) { |
|
597 | - if (isset($renderer['label'])) { |
|
598 | - $hasLabel = true; |
|
599 | - break; |
|
600 | - } |
|
601 | - } |
|
602 | - } |
|
603 | - return $hasLabel; |
|
604 | - } |
|
605 | - |
|
606 | - /** |
|
607 | - * @return array |
|
608 | - */ |
|
609 | - public function getTca(): array |
|
610 | - { |
|
611 | - return $this->tca; |
|
612 | - } |
|
613 | - |
|
614 | - /** |
|
615 | - * @return array |
|
616 | - */ |
|
617 | - public function getIncludedFields(): array |
|
618 | - { |
|
619 | - return empty($this->tca['included_fields']) ? [] : GeneralUtility::trimExplode(',', $this->tca['included_fields'], true); |
|
620 | - } |
|
621 | - |
|
622 | - /** |
|
623 | - * Return excluded fields from configuration + preferences. |
|
624 | - * |
|
625 | - * @return array |
|
626 | - */ |
|
627 | - public function getExcludedFields(): array |
|
628 | - { |
|
629 | - $configurationFields = $this->getExcludedFieldsFromConfiguration(); |
|
630 | - $preferencesFields = $this->getExcludedFieldsFromPreferences(); |
|
631 | - |
|
632 | - return array_merge($configurationFields, $preferencesFields); |
|
633 | - } |
|
634 | - |
|
635 | - /** |
|
636 | - * Fetch excluded fields from configuration. |
|
637 | - * |
|
638 | - * @return array |
|
639 | - */ |
|
640 | - protected function getExcludedFieldsFromConfiguration(): array |
|
641 | - { |
|
642 | - $excludedFields = []; |
|
643 | - if (!empty($this->tca['excluded_fields'])) { |
|
644 | - $excludedFields = GeneralUtility::trimExplode(',', $this->tca['excluded_fields'], true); |
|
645 | - } elseif (!empty($this->tca['export']['excluded_fields'])) { // only for export for legacy reason. |
|
646 | - $excludedFields = GeneralUtility::trimExplode(',', $this->tca['export']['excluded_fields'], true); |
|
647 | - } |
|
648 | - return $excludedFields; |
|
649 | - |
|
650 | - } |
|
651 | - |
|
652 | - /** |
|
653 | - * Fetch excluded fields from preferences. |
|
654 | - * |
|
655 | - * @return array |
|
656 | - */ |
|
657 | - protected function getExcludedFieldsFromPreferences(): array |
|
658 | - { |
|
659 | - $excludedFields = $this->getModulePreferences()->get(ConfigurablePart::EXCLUDED_FIELDS, $this->tableName); |
|
660 | - return is_array($excludedFields) ? $excludedFields : []; |
|
661 | - } |
|
662 | - |
|
663 | - /** |
|
664 | - * @return bool |
|
665 | - */ |
|
666 | - public function areFilesIncludedInExport(): bool |
|
667 | - { |
|
668 | - $isIncluded = true; |
|
669 | - |
|
670 | - if (isset($this->tca['export']['include_files'])) { |
|
671 | - $isIncluded = (bool)$this->tca['export']['include_files']; |
|
672 | - } |
|
673 | - return $isIncluded; |
|
674 | - } |
|
675 | - |
|
676 | - /** |
|
677 | - * Returns a "facet" service instance. |
|
678 | - * |
|
679 | - * @param string|FacetInterface $facetName |
|
680 | - * @return StandardFacet |
|
681 | - */ |
|
682 | - protected function instantiateStandardFacet($facetName): StandardFacet |
|
683 | - { |
|
684 | - $label = $this->getLabel($facetName); |
|
685 | - |
|
686 | - /** @var StandardFacet $facetName */ |
|
687 | - $facet = GeneralUtility::makeInstance(StandardFacet::class, $facetName, $label); |
|
688 | - |
|
689 | - if (!$facet instanceof StandardFacet) { |
|
690 | - throw new \RuntimeException('I could not instantiate a facet for facet name "' . $facetName . '""', 1445856345); |
|
691 | - } |
|
692 | - return $facet; |
|
693 | - } |
|
694 | - |
|
695 | - /** |
|
696 | - * Returns a "facet" service instance. |
|
697 | - * |
|
698 | - * @param string|FacetInterface $facetName |
|
699 | - * @return FacetInterface |
|
700 | - */ |
|
701 | - public function facet($facetName = ''): FacetInterface |
|
702 | - { |
|
703 | - $facets = $this->getFacets(); |
|
704 | - return $facets[$facetName]; |
|
705 | - } |
|
706 | - |
|
707 | - /** |
|
708 | - * @return FieldPathResolver|object |
|
709 | - */ |
|
710 | - protected function getFieldPathResolver() |
|
711 | - { |
|
712 | - return GeneralUtility::makeInstance(FieldPathResolver::class); |
|
713 | - } |
|
714 | - |
|
715 | - /** |
|
716 | - * @return ModulePreferences|object |
|
717 | - */ |
|
718 | - protected function getModulePreferences() |
|
719 | - { |
|
720 | - return GeneralUtility::makeInstance(ModulePreferences::class); |
|
721 | - } |
|
722 | - |
|
723 | - /** |
|
724 | - * @return LanguageService|object |
|
725 | - */ |
|
726 | - protected function getLanguageService() |
|
727 | - { |
|
728 | - return GeneralUtility::makeInstance(LanguageService::class); |
|
729 | - } |
|
27 | + /** |
|
28 | + * @var array |
|
29 | + */ |
|
30 | + protected $tca; |
|
31 | + |
|
32 | + /** |
|
33 | + * @var string |
|
34 | + */ |
|
35 | + protected $tableName; |
|
36 | + |
|
37 | + /** |
|
38 | + * All fields available in the Grid. |
|
39 | + * |
|
40 | + * @var array |
|
41 | + */ |
|
42 | + protected $fields; |
|
43 | + |
|
44 | + /** |
|
45 | + * All fields regardless whether they have been excluded or not. |
|
46 | + * |
|
47 | + * @var array |
|
48 | + */ |
|
49 | + protected $allFields; |
|
50 | + |
|
51 | + /** |
|
52 | + * @var array |
|
53 | + */ |
|
54 | + protected $instances; |
|
55 | + |
|
56 | + /** |
|
57 | + * @var array |
|
58 | + */ |
|
59 | + protected $facets; |
|
60 | + |
|
61 | + /** |
|
62 | + * __construct |
|
63 | + * |
|
64 | + * @param string $tableName |
|
65 | + */ |
|
66 | + public function __construct($tableName) |
|
67 | + { |
|
68 | + |
|
69 | + $this->tableName = $tableName; |
|
70 | + |
|
71 | + if (empty($GLOBALS['TCA'][$this->tableName])) { |
|
72 | + throw new InvalidKeyInArrayException('No TCA existence for table name: ' . $this->tableName, 1356945108); |
|
73 | + } |
|
74 | + |
|
75 | + $this->tca = $GLOBALS['TCA'][$this->tableName]['grid']; |
|
76 | + } |
|
77 | + |
|
78 | + /** |
|
79 | + * Returns an array containing column names. |
|
80 | + * |
|
81 | + * @return array |
|
82 | + */ |
|
83 | + public function getFieldNames(): array |
|
84 | + { |
|
85 | + $fields = $this->getFields(); |
|
86 | + return array_keys($fields) ?: []; |
|
87 | + } |
|
88 | + |
|
89 | + /** |
|
90 | + * Returns an array containing column names. |
|
91 | + * |
|
92 | + * @return array |
|
93 | + */ |
|
94 | + public function getAllFieldNames(): array |
|
95 | + { |
|
96 | + $allFields = $this->getAllFields(); |
|
97 | + return array_keys($allFields); |
|
98 | + } |
|
99 | + |
|
100 | + /** |
|
101 | + * Get the label key. |
|
102 | + * |
|
103 | + * @param string $fieldNameAndPath |
|
104 | + * @return string |
|
105 | + */ |
|
106 | + public function getLabelKey($fieldNameAndPath): string |
|
107 | + { |
|
108 | + |
|
109 | + $field = $this->getField($fieldNameAndPath); |
|
110 | + |
|
111 | + // First option is to get the label from the Grid TCA. |
|
112 | + $rawLabel = ''; |
|
113 | + if (isset($field['label'])) { |
|
114 | + $rawLabel = $field['label']; |
|
115 | + } |
|
116 | + |
|
117 | + // Second option is to fetch the label from the Column Renderer object. |
|
118 | + if (!$rawLabel && $this->hasRenderers($fieldNameAndPath)) { |
|
119 | + $renderers = $this->getRenderers($fieldNameAndPath); |
|
120 | + /** @var $renderer ColumnRendererInterface */ |
|
121 | + foreach ($renderers as $renderer) { |
|
122 | + if (isset($renderer['label'])) { |
|
123 | + $rawLabel = $renderer['label']; |
|
124 | + break; |
|
125 | + } |
|
126 | + } |
|
127 | + } |
|
128 | + return $rawLabel; |
|
129 | + } |
|
130 | + |
|
131 | + /** |
|
132 | + * Get the translation of a label given a column name. |
|
133 | + * |
|
134 | + * @param string $fieldNameAndPath |
|
135 | + * @return string |
|
136 | + */ |
|
137 | + public function getLabel($fieldNameAndPath) |
|
138 | + { |
|
139 | + $label = ''; |
|
140 | + if ($this->hasLabel($fieldNameAndPath)) { |
|
141 | + $labelKey = $this->getLabelKey($fieldNameAndPath); |
|
142 | + try { |
|
143 | + $label = $this->getLanguageService()->sL($labelKey); |
|
144 | + } catch (\InvalidArgumentException $e) { |
|
145 | + } |
|
146 | + if (empty($label)) { |
|
147 | + $label = $labelKey; |
|
148 | + } |
|
149 | + } else { |
|
150 | + |
|
151 | + // Important to notice the label can contains a path, e.g. metadata.categories and must be resolved. |
|
152 | + $dataType = $this->getFieldPathResolver()->getDataType($fieldNameAndPath, $this->tableName); |
|
153 | + $fieldName = $this->getFieldPathResolver()->stripFieldPath($fieldNameAndPath, $this->tableName); |
|
154 | + $table = Tca::table($dataType); |
|
155 | + |
|
156 | + if ($table->hasField($fieldName) && $table->field($fieldName)->hasLabel()) { |
|
157 | + $label = $table->field($fieldName)->getLabel(); |
|
158 | + } |
|
159 | + } |
|
160 | + |
|
161 | + return $label; |
|
162 | + } |
|
163 | + |
|
164 | + /** |
|
165 | + * Returns the field name given its position. |
|
166 | + * |
|
167 | + * @param string $position the position of the field in the grid |
|
168 | + * @return string |
|
169 | + */ |
|
170 | + public function getFieldNameByPosition($position): string |
|
171 | + { |
|
172 | + $fields = array_keys($this->getFields()); |
|
173 | + if (empty($fields[$position])) { |
|
174 | + throw new InvalidKeyInArrayException('No field exist for position: ' . $position, 1356945119); |
|
175 | + } |
|
176 | + |
|
177 | + return (string)$fields[$position]; |
|
178 | + } |
|
179 | + |
|
180 | + /** |
|
181 | + * Returns a field name. |
|
182 | + * |
|
183 | + * @param string $fieldName |
|
184 | + * @return array |
|
185 | + */ |
|
186 | + public function getField($fieldName): array |
|
187 | + { |
|
188 | + $fields = $this->getFields(); |
|
189 | + return $fields[$fieldName] ?: []; |
|
190 | + } |
|
191 | + |
|
192 | + /** |
|
193 | + * Returns an array containing column names for the Grid. |
|
194 | + * |
|
195 | + * @return array |
|
196 | + */ |
|
197 | + public function getFields(): array |
|
198 | + { |
|
199 | + // Cache this operation since it can take some time. |
|
200 | + if ($this->fields === null) { |
|
201 | + |
|
202 | + // Fetch all available fields first. |
|
203 | + $fields = $this->getAllFields(); |
|
204 | + |
|
205 | + if ($this->isBackendMode()) { |
|
206 | + |
|
207 | + // Then remove the not allowed. |
|
208 | + $fields = $this->filterByIncludedFields($fields); |
|
209 | + $fields = $this->filterByBackendUser($fields); |
|
210 | + $fields = $this->filterByExcludedFields($fields); |
|
211 | + } |
|
212 | + |
|
213 | + $this->fields = $fields; |
|
214 | + } |
|
215 | + |
|
216 | + return $this->fields; |
|
217 | + } |
|
218 | + |
|
219 | + /** |
|
220 | + * Remove fields according to Grid configuration. |
|
221 | + * |
|
222 | + * @param $fields |
|
223 | + * @return array |
|
224 | + */ |
|
225 | + protected function filterByIncludedFields($fields): array |
|
226 | + { |
|
227 | + |
|
228 | + $filteredFields = $fields; |
|
229 | + $includedFields = $this->getIncludedFields(); |
|
230 | + if (count($includedFields) > 0) { |
|
231 | + $filteredFields = []; |
|
232 | + foreach ($fields as $fieldNameAndPath => $configuration) { |
|
233 | + if (in_array($fieldNameAndPath, $includedFields, true) || !Tca::table($this->tableName)->hasField($fieldNameAndPath)) { |
|
234 | + $filteredFields[$fieldNameAndPath] = $configuration; |
|
235 | + } |
|
236 | + } |
|
237 | + } |
|
238 | + return $filteredFields; |
|
239 | + } |
|
240 | + |
|
241 | + /** |
|
242 | + * Remove fields according to BE User permission. |
|
243 | + * |
|
244 | + * @param $fields |
|
245 | + * @return array |
|
246 | + */ |
|
247 | + protected function filterByBackendUser($fields): array |
|
248 | + { |
|
249 | + if (!$this->getBackendUser()->isAdmin()) { |
|
250 | + foreach ($fields as $fieldName => $field) { |
|
251 | + if (Tca::table($this->tableName)->hasField($fieldName) && !Tca::table($this->tableName)->field($fieldName)->hasAccess()) { |
|
252 | + unset($fields[$fieldName]); |
|
253 | + } |
|
254 | + } |
|
255 | + } |
|
256 | + return $fields; |
|
257 | + } |
|
258 | + |
|
259 | + /** |
|
260 | + * Remove fields according to Grid configuration. |
|
261 | + * |
|
262 | + * @param $fields |
|
263 | + * @return array |
|
264 | + */ |
|
265 | + protected function filterByExcludedFields($fields): array |
|
266 | + { |
|
267 | + |
|
268 | + // Unset excluded fields. |
|
269 | + foreach ($this->getExcludedFields() as $excludedField) { |
|
270 | + if (isset($fields[$excludedField])) { |
|
271 | + unset($fields[$excludedField]); |
|
272 | + } |
|
273 | + } |
|
274 | + |
|
275 | + return $fields; |
|
276 | + } |
|
277 | + |
|
278 | + /** |
|
279 | + * Returns an array containing column names for the Grid. |
|
280 | + * |
|
281 | + * @return array |
|
282 | + */ |
|
283 | + public function getAllFields(): array |
|
284 | + { |
|
285 | + |
|
286 | + // Cache this operation since it can take some time. |
|
287 | + if ($this->allFields === null) { |
|
288 | + |
|
289 | + $fields = is_array($this->tca['columns']) ? $this->tca['columns'] : []; |
|
290 | + $gridFieldNames = array_keys($fields); |
|
291 | + |
|
292 | + // Fetch all fields of the TCA and merge it back to the fields configured for Grid. |
|
293 | + $tableFieldNames = Tca::table($this->tableName)->getFields(); |
|
294 | + |
|
295 | + // Just remove system fields from the Grid. |
|
296 | + foreach ($tableFieldNames as $key => $fieldName) { |
|
297 | + if (in_array($fieldName, Tca::getSystemFields())) { |
|
298 | + unset($tableFieldNames[$key]); |
|
299 | + } |
|
300 | + } |
|
301 | + |
|
302 | + $additionalFields = array_diff($tableFieldNames, $gridFieldNames); |
|
303 | + |
|
304 | + if (!empty($additionalFields)) { |
|
305 | + |
|
306 | + // Pop out last element of the key |
|
307 | + // Idea is to place new un-configured columns in between. By default, they will be hidden. |
|
308 | + end($fields); |
|
309 | + $lastColumnKey = key($fields); |
|
310 | + $lastColumn = array_pop($fields); |
|
311 | + |
|
312 | + // Feed up the grid fields with un configured elements |
|
313 | + foreach ($additionalFields as $additionalField) { |
|
314 | + $fields[$additionalField] = array( |
|
315 | + 'visible' => false |
|
316 | + ); |
|
317 | + |
|
318 | + // Try to guess the format of the field. |
|
319 | + $fieldType = Tca::table($this->tableName)->field($additionalField)->getType(); |
|
320 | + if ($fieldType === FieldType::DATE) { |
|
321 | + $fields[$additionalField]['format'] = 'Fab\Vidi\Formatter\Date'; |
|
322 | + } elseif ($fieldType === FieldType::DATETIME) { |
|
323 | + $fields[$additionalField]['format'] = 'Fab\Vidi\Formatter\Datetime'; |
|
324 | + } |
|
325 | + } |
|
326 | + $fields[$lastColumnKey] = $lastColumn; |
|
327 | + } |
|
328 | + |
|
329 | + $this->allFields = $fields; |
|
330 | + } |
|
331 | + |
|
332 | + return $this->allFields; |
|
333 | + } |
|
334 | + |
|
335 | + /** |
|
336 | + * Tell whether the field exists in the grid or not. |
|
337 | + * |
|
338 | + * @param string $fieldName |
|
339 | + * @return bool |
|
340 | + */ |
|
341 | + public function hasField($fieldName): bool |
|
342 | + { |
|
343 | + $fields = $this->getFields(); |
|
344 | + return isset($fields[$fieldName]); |
|
345 | + } |
|
346 | + |
|
347 | + /** |
|
348 | + * Tell whether the facet exists in the grid or not. |
|
349 | + * |
|
350 | + * @param string $facetName |
|
351 | + * @return bool |
|
352 | + */ |
|
353 | + public function hasFacet($facetName): bool |
|
354 | + { |
|
355 | + $facets = $this->getFacets(); |
|
356 | + return isset($facets[$facetName]); |
|
357 | + } |
|
358 | + |
|
359 | + /** |
|
360 | + * Returns an array containing facets fields. |
|
361 | + * |
|
362 | + * @return FacetInterface[] |
|
363 | + */ |
|
364 | + public function getFacets(): array |
|
365 | + { |
|
366 | + if ($this->facets === null) { |
|
367 | + $this->facets = []; |
|
368 | + |
|
369 | + if (is_array($this->tca['facets'])) { |
|
370 | + foreach ($this->tca['facets'] as $key => $facetNameOrArray) { |
|
371 | + if (is_array($facetNameOrArray)) { |
|
372 | + |
|
373 | + $name = $facetNameOrArray['name'] ?? ''; |
|
374 | + |
|
375 | + $label = isset($facetNameOrArray['label']) |
|
376 | + ? $this->getLanguageService()->sL($facetNameOrArray['label']) |
|
377 | + : ''; |
|
378 | + |
|
379 | + $suggestions = $facetNameOrArray['suggestions'] ?? []; |
|
380 | + $configuration = $facetNameOrArray['configuration'] ?? []; |
|
381 | + |
|
382 | + /** @var FacetInterface $facetObject */ |
|
383 | + $facetObject = GeneralUtility::makeInstance($key, $name, $label, $suggestions, $configuration); |
|
384 | + $this->facets[$facetObject->getName()] = $facetObject; |
|
385 | + } else { |
|
386 | + $this->facets[$facetNameOrArray] = $this->instantiateStandardFacet($facetNameOrArray); |
|
387 | + } |
|
388 | + } |
|
389 | + } |
|
390 | + } |
|
391 | + return $this->facets; |
|
392 | + } |
|
393 | + |
|
394 | + /** |
|
395 | + * Returns the "sortable" value of the column. |
|
396 | + * |
|
397 | + * @param string $fieldName |
|
398 | + * @return int|string |
|
399 | + */ |
|
400 | + public function isSortable($fieldName) |
|
401 | + { |
|
402 | + $defaultValue = true; |
|
403 | + $hasSortableField = Tca::table($this->tableName)->hasSortableField(); |
|
404 | + if ($hasSortableField) { |
|
405 | + $isSortable = false; |
|
406 | + } else { |
|
407 | + $isSortable = $this->get($fieldName, 'sortable', $defaultValue); |
|
408 | + } |
|
409 | + return $isSortable; |
|
410 | + } |
|
411 | + |
|
412 | + /** |
|
413 | + * Returns the "canBeHidden" value of the column. |
|
414 | + * |
|
415 | + * @param string $fieldName |
|
416 | + * @return bool |
|
417 | + */ |
|
418 | + public function canBeHidden($fieldName): bool |
|
419 | + { |
|
420 | + $defaultValue = true; |
|
421 | + return $this->get($fieldName, 'canBeHidden', $defaultValue); |
|
422 | + } |
|
423 | + |
|
424 | + /** |
|
425 | + * Returns the "width" value of the column. |
|
426 | + * |
|
427 | + * @param string $fieldName |
|
428 | + * @return int|string |
|
429 | + */ |
|
430 | + public function getWidth($fieldName) |
|
431 | + { |
|
432 | + $defaultValue = 'auto'; |
|
433 | + return $this->get($fieldName, 'width', $defaultValue); |
|
434 | + } |
|
435 | + |
|
436 | + /** |
|
437 | + * Returns the "visible" value of the column. |
|
438 | + * |
|
439 | + * @param string $fieldName |
|
440 | + * @return bool |
|
441 | + */ |
|
442 | + public function isVisible($fieldName): bool |
|
443 | + { |
|
444 | + $defaultValue = true; |
|
445 | + return $this->get($fieldName, 'visible', $defaultValue); |
|
446 | + } |
|
447 | + |
|
448 | + /** |
|
449 | + * Returns the "editable" value of the column. |
|
450 | + * |
|
451 | + * @param string $columnName |
|
452 | + * @return bool |
|
453 | + */ |
|
454 | + public function isEditable($columnName): bool |
|
455 | + { |
|
456 | + $defaultValue = false; |
|
457 | + return $this->get($columnName, 'editable', $defaultValue); |
|
458 | + } |
|
459 | + |
|
460 | + /** |
|
461 | + * Returns the "localized" value of the column. |
|
462 | + * |
|
463 | + * @param string $columnName |
|
464 | + * @return bool |
|
465 | + */ |
|
466 | + public function isLocalized($columnName): bool |
|
467 | + { |
|
468 | + $defaultValue = true; |
|
469 | + return $this->get($columnName, 'localized', $defaultValue); |
|
470 | + } |
|
471 | + |
|
472 | + /** |
|
473 | + * |
|
474 | + * Returns the "html" value of the column. |
|
475 | + * |
|
476 | + * @param string $fieldName |
|
477 | + * @return string |
|
478 | + */ |
|
479 | + public function getHeader($fieldName): string |
|
480 | + { |
|
481 | + $defaultValue = ''; |
|
482 | + return $this->get($fieldName, 'html', $defaultValue); |
|
483 | + } |
|
484 | + |
|
485 | + /** |
|
486 | + * Fetch a possible from a Grid Renderer. If no value is found, returns null |
|
487 | + * |
|
488 | + * @param string $fieldName |
|
489 | + * @param string $key |
|
490 | + * @param mixed $defaultValue |
|
491 | + * @return null|mixed |
|
492 | + */ |
|
493 | + public function get($fieldName, $key, $defaultValue = null) |
|
494 | + { |
|
495 | + $value = $defaultValue; |
|
496 | + |
|
497 | + $field = $this->getField($fieldName); |
|
498 | + if (isset($field[$key])) { |
|
499 | + $value = $field[$key]; |
|
500 | + } elseif ($this->hasRenderers($fieldName)) { |
|
501 | + $renderers = $this->getRenderers($fieldName); |
|
502 | + foreach ($renderers as $rendererConfiguration) { |
|
503 | + if (isset($rendererConfiguration[$key])) { |
|
504 | + $value = $rendererConfiguration[$key]; |
|
505 | + } |
|
506 | + } |
|
507 | + } |
|
508 | + return $value; |
|
509 | + } |
|
510 | + |
|
511 | + /** |
|
512 | + * Returns whether the column has a renderer. |
|
513 | + * |
|
514 | + * @param string $fieldName |
|
515 | + * @return bool |
|
516 | + */ |
|
517 | + public function hasRenderers($fieldName): bool |
|
518 | + { |
|
519 | + $field = $this->getField($fieldName); |
|
520 | + return empty($field['renderer']) && empty($field['renderers']) ? false : true; |
|
521 | + } |
|
522 | + |
|
523 | + /** |
|
524 | + * Returns a renderer. |
|
525 | + * |
|
526 | + * @param string $fieldName |
|
527 | + * @return array |
|
528 | + */ |
|
529 | + public function getRenderers($fieldName): array |
|
530 | + { |
|
531 | + $field = $this->getField($fieldName); |
|
532 | + $renderers = []; |
|
533 | + if (!empty($field['renderer'])) { |
|
534 | + $renderers = $this->convertRendererToArray($field['renderer'], $field); |
|
535 | + } elseif (!empty($field['renderers']) && is_array($field['renderers'])) { |
|
536 | + foreach ($field['renderers'] as $renderer) { |
|
537 | + $rendererNameAndConfiguration = $this->convertRendererToArray($renderer, $field); |
|
538 | + $renderers = array_merge($renderers, $rendererNameAndConfiguration); |
|
539 | + } |
|
540 | + } |
|
541 | + |
|
542 | + return $renderers; |
|
543 | + } |
|
544 | + |
|
545 | + /** |
|
546 | + * @param string $renderer |
|
547 | + * @return array |
|
548 | + */ |
|
549 | + protected function convertRendererToArray($renderer, array $field): array |
|
550 | + { |
|
551 | + $result = []; |
|
552 | + if (is_string($renderer)) { |
|
553 | + $configuration = empty($field['rendererConfiguration']) |
|
554 | + ? [] |
|
555 | + : $field['rendererConfiguration']; |
|
556 | + |
|
557 | + /** @var ColumnRendererInterface $rendererObject */ |
|
558 | + $rendererObject = GeneralUtility::makeInstance($renderer); |
|
559 | + |
|
560 | + $result[$renderer] = array_merge($rendererObject->getConfiguration(), $configuration); |
|
561 | + // TODO: throw alert message because this is not compatible anymore as of TYPO3 8.7.7 |
|
562 | + } elseif ($renderer instanceof ColumnRendererInterface) { |
|
563 | + /** @var ColumnRendererInterface $renderer */ |
|
564 | + $result[get_class($renderer)] = $renderer->getConfiguration(); |
|
565 | + } |
|
566 | + return $result; |
|
567 | + } |
|
568 | + |
|
569 | + /** |
|
570 | + * Returns the class names applied to a cell |
|
571 | + * |
|
572 | + * @param string $fieldName |
|
573 | + * @return bool |
|
574 | + */ |
|
575 | + public function getClass($fieldName): bool |
|
576 | + { |
|
577 | + $field = $this->getField($fieldName); |
|
578 | + return isset($field['class']) ? $field['class'] : ''; |
|
579 | + } |
|
580 | + |
|
581 | + /** |
|
582 | + * Returns whether the column has a label. |
|
583 | + * |
|
584 | + * @param string $fieldNameAndPath |
|
585 | + * @return bool |
|
586 | + */ |
|
587 | + public function hasLabel($fieldNameAndPath): bool |
|
588 | + { |
|
589 | + $field = $this->getField($fieldNameAndPath); |
|
590 | + |
|
591 | + $hasLabel = empty($field['label']) ? false : true; |
|
592 | + |
|
593 | + if (!$hasLabel && $this->hasRenderers($fieldNameAndPath)) { |
|
594 | + $renderers = $this->getRenderers($fieldNameAndPath); |
|
595 | + /** @var $renderer ColumnRendererInterface */ |
|
596 | + foreach ($renderers as $renderer) { |
|
597 | + if (isset($renderer['label'])) { |
|
598 | + $hasLabel = true; |
|
599 | + break; |
|
600 | + } |
|
601 | + } |
|
602 | + } |
|
603 | + return $hasLabel; |
|
604 | + } |
|
605 | + |
|
606 | + /** |
|
607 | + * @return array |
|
608 | + */ |
|
609 | + public function getTca(): array |
|
610 | + { |
|
611 | + return $this->tca; |
|
612 | + } |
|
613 | + |
|
614 | + /** |
|
615 | + * @return array |
|
616 | + */ |
|
617 | + public function getIncludedFields(): array |
|
618 | + { |
|
619 | + return empty($this->tca['included_fields']) ? [] : GeneralUtility::trimExplode(',', $this->tca['included_fields'], true); |
|
620 | + } |
|
621 | + |
|
622 | + /** |
|
623 | + * Return excluded fields from configuration + preferences. |
|
624 | + * |
|
625 | + * @return array |
|
626 | + */ |
|
627 | + public function getExcludedFields(): array |
|
628 | + { |
|
629 | + $configurationFields = $this->getExcludedFieldsFromConfiguration(); |
|
630 | + $preferencesFields = $this->getExcludedFieldsFromPreferences(); |
|
631 | + |
|
632 | + return array_merge($configurationFields, $preferencesFields); |
|
633 | + } |
|
634 | + |
|
635 | + /** |
|
636 | + * Fetch excluded fields from configuration. |
|
637 | + * |
|
638 | + * @return array |
|
639 | + */ |
|
640 | + protected function getExcludedFieldsFromConfiguration(): array |
|
641 | + { |
|
642 | + $excludedFields = []; |
|
643 | + if (!empty($this->tca['excluded_fields'])) { |
|
644 | + $excludedFields = GeneralUtility::trimExplode(',', $this->tca['excluded_fields'], true); |
|
645 | + } elseif (!empty($this->tca['export']['excluded_fields'])) { // only for export for legacy reason. |
|
646 | + $excludedFields = GeneralUtility::trimExplode(',', $this->tca['export']['excluded_fields'], true); |
|
647 | + } |
|
648 | + return $excludedFields; |
|
649 | + |
|
650 | + } |
|
651 | + |
|
652 | + /** |
|
653 | + * Fetch excluded fields from preferences. |
|
654 | + * |
|
655 | + * @return array |
|
656 | + */ |
|
657 | + protected function getExcludedFieldsFromPreferences(): array |
|
658 | + { |
|
659 | + $excludedFields = $this->getModulePreferences()->get(ConfigurablePart::EXCLUDED_FIELDS, $this->tableName); |
|
660 | + return is_array($excludedFields) ? $excludedFields : []; |
|
661 | + } |
|
662 | + |
|
663 | + /** |
|
664 | + * @return bool |
|
665 | + */ |
|
666 | + public function areFilesIncludedInExport(): bool |
|
667 | + { |
|
668 | + $isIncluded = true; |
|
669 | + |
|
670 | + if (isset($this->tca['export']['include_files'])) { |
|
671 | + $isIncluded = (bool)$this->tca['export']['include_files']; |
|
672 | + } |
|
673 | + return $isIncluded; |
|
674 | + } |
|
675 | + |
|
676 | + /** |
|
677 | + * Returns a "facet" service instance. |
|
678 | + * |
|
679 | + * @param string|FacetInterface $facetName |
|
680 | + * @return StandardFacet |
|
681 | + */ |
|
682 | + protected function instantiateStandardFacet($facetName): StandardFacet |
|
683 | + { |
|
684 | + $label = $this->getLabel($facetName); |
|
685 | + |
|
686 | + /** @var StandardFacet $facetName */ |
|
687 | + $facet = GeneralUtility::makeInstance(StandardFacet::class, $facetName, $label); |
|
688 | + |
|
689 | + if (!$facet instanceof StandardFacet) { |
|
690 | + throw new \RuntimeException('I could not instantiate a facet for facet name "' . $facetName . '""', 1445856345); |
|
691 | + } |
|
692 | + return $facet; |
|
693 | + } |
|
694 | + |
|
695 | + /** |
|
696 | + * Returns a "facet" service instance. |
|
697 | + * |
|
698 | + * @param string|FacetInterface $facetName |
|
699 | + * @return FacetInterface |
|
700 | + */ |
|
701 | + public function facet($facetName = ''): FacetInterface |
|
702 | + { |
|
703 | + $facets = $this->getFacets(); |
|
704 | + return $facets[$facetName]; |
|
705 | + } |
|
706 | + |
|
707 | + /** |
|
708 | + * @return FieldPathResolver|object |
|
709 | + */ |
|
710 | + protected function getFieldPathResolver() |
|
711 | + { |
|
712 | + return GeneralUtility::makeInstance(FieldPathResolver::class); |
|
713 | + } |
|
714 | + |
|
715 | + /** |
|
716 | + * @return ModulePreferences|object |
|
717 | + */ |
|
718 | + protected function getModulePreferences() |
|
719 | + { |
|
720 | + return GeneralUtility::makeInstance(ModulePreferences::class); |
|
721 | + } |
|
722 | + |
|
723 | + /** |
|
724 | + * @return LanguageService|object |
|
725 | + */ |
|
726 | + protected function getLanguageService() |
|
727 | + { |
|
728 | + return GeneralUtility::makeInstance(LanguageService::class); |
|
729 | + } |
|
730 | 730 | |
731 | 731 | } |
@@ -15,19 +15,19 @@ |
||
15 | 15 | abstract class AbstractDataHandler implements DataHandlerInterface, SingletonInterface |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * @var array |
|
20 | - */ |
|
21 | - protected $errorMessages = []; |
|
18 | + /** |
|
19 | + * @var array |
|
20 | + */ |
|
21 | + protected $errorMessages = []; |
|
22 | 22 | |
23 | - /** |
|
24 | - * Return error that have occurred while processing the data. |
|
25 | - * |
|
26 | - * @return array |
|
27 | - */ |
|
28 | - public function getErrorMessages() |
|
29 | - { |
|
30 | - return $this->errorMessages; |
|
31 | - } |
|
23 | + /** |
|
24 | + * Return error that have occurred while processing the data. |
|
25 | + * |
|
26 | + * @return array |
|
27 | + */ |
|
28 | + public function getErrorMessages() |
|
29 | + { |
|
30 | + return $this->errorMessages; |
|
31 | + } |
|
32 | 32 | |
33 | 33 | } |