Skip to content

Commit

Permalink
[TASK] Code cleanup
Browse files Browse the repository at this point in the history
- Add missing visibility to methods
- Indent code correctly
- Remove unused variables
- Sort namespaces
- Remove unused namespaces
  • Loading branch information
simonschaufi committed Mar 23, 2024
1 parent 5b56218 commit 4a8b28e
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 94 deletions.
20 changes: 14 additions & 6 deletions Classes/Div.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ class Div
{
const RESOURCE_BASE_PATH = 'EXT:ods_osm/Resources/Public/';

public static function getConstraintsForQueryBuilder($table, ContentObjectRenderer $cObj,
QueryBuilder $queryBuilder) : array
{
public static function getConstraintsForQueryBuilder(
$table,
ContentObjectRenderer $cObj,
QueryBuilder $queryBuilder
): array {
$constraints = [];

if (is_string($table)) {
Expand All @@ -41,9 +43,15 @@ public static function getConstraintsForQueryBuilder($table, ContentObjectRender
// Translation
if ($ctrl['languageField'] ?? null) {
$orConstraints = [
$queryBuilder->expr()->eq($table . '.' . $ctrl['languageField'], $queryBuilder->createNamedParameter(0, Connection::PARAM_INT)),
$queryBuilder->expr()->eq($table . '.' . $ctrl['languageField'], $queryBuilder->createNamedParameter(-1, Connection::PARAM_INT))
];
$queryBuilder->expr()->eq(
$table . '.' . $ctrl['languageField'],
$queryBuilder->createNamedParameter(0, Connection::PARAM_INT)
),
$queryBuilder->expr()->eq(
$table . '.' . $ctrl['languageField'],
$queryBuilder->createNamedParameter(-1, Connection::PARAM_INT)
),
];

$languageAspect = GeneralUtility::makeInstance(Context::class)->getAspect('language');

Expand Down
8 changes: 4 additions & 4 deletions Classes/Evaluation/LonLat.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

class LonLat
{
function returnFieldJS()
public function returnFieldJS(): string
{
return ("return value;");
return "return value;";
}

function evaluateFieldValue($value, $is_in, &$set)
public function evaluateFieldValue($value, $is_in, &$set): string
{
return (sprintf('%01.6f', $value));
return sprintf('%01.6f', $value);
}
}
64 changes: 32 additions & 32 deletions Classes/Provider/Leaflet.php
Original file line number Diff line number Diff line change
Expand Up @@ -316,40 +316,40 @@ protected function getMarker($item, $table)
}

foreach ($jsElementVarsForPopup as $jsElementVar) {
// is there a properties attribute from geoJSON? If so, we will show the given properties
$popupJsCode = '';
if ($item['properties'] ?? null) {
$geojsonProperties = json_encode(explode(', ', $item['properties']));
$popupJsCode = "
function (layer) {
var osm_popup = '" . ($item['popup'] ?? '') . "';
var feature = layer.feature,
props = feature.properties,
ll = Object.keys(props),
attribute, value = '';
var osm_filter = " . $geojsonProperties . ";
osm_filter.forEach((osm_prop) => {
if (typeof props[osm_prop] !== 'undefined') {
value += '<dt>' + osm_prop + '</dt> <dd>' + props[osm_prop] + '</dd>';
}
});
return osm_popup + '<dl>' + value + '</dl>';
}
";
} else if ($item['popup'] ?? null) {
$popupJsCode = json_encode($item['popup'] ?? '');
}
if ($this->config['show_popups'] == 1) {
$jsMarker .= $jsElementVar . '.bindPopup(' . $popupJsCode . '); ' . "\n";
if ($item['initial_popup'] ?? null) {
$jsMarker .= $jsElementVar . ".openPopup();\n";
// is there a properties attribute from geoJSON? If so, we will show the given properties
$popupJsCode = '';
if ($item['properties'] ?? null) {
$geojsonProperties = json_encode(explode(', ', $item['properties']));
$popupJsCode = "
function (layer) {
var osm_popup = '" . ($item['popup'] ?? '') . "';
var feature = layer.feature,
props = feature.properties,
ll = Object.keys(props),
attribute, value = '';
var osm_filter = " . $geojsonProperties . ";
osm_filter.forEach((osm_prop) => {
if (typeof props[osm_prop] !== 'undefined') {
value += '<dt>' + osm_prop + '</dt> <dd>' + props[osm_prop] + '</dd>';
}
});
return osm_popup + '<dl>' + value + '</dl>';
}
} else if ($this->config['show_popups'] == 2) {
$jsMarker .= $jsElementVar . '.bindTooltip(' . $popupJsCode . ");\n";
";
} else if ($item['popup'] ?? null) {
$popupJsCode = json_encode($item['popup'] ?? '');
}
if ($this->config['show_popups'] == 1) {
$jsMarker .= $jsElementVar . '.bindPopup(' . $popupJsCode . '); ' . "\n";
if ($item['initial_popup'] ?? null) {
$jsMarker .= $jsElementVar . ".openPopup();\n";
}
} else if ($this->config['show_popups'] == 2) {
$jsMarker .= $jsElementVar . '.bindTooltip(' . $popupJsCode . ");\n";
}
}

return $jsMarker;
Expand Down
8 changes: 0 additions & 8 deletions Classes/Provider/Openlayers.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ className: 'ods-osm-mouse-position',
closer.blur();
return false;
};
";
}

Expand Down Expand Up @@ -210,7 +209,6 @@ protected function getLayer($layer, $i, $backpath = '')
$layer['tile_url'] = strtr($this->getTileUrl($layer), ['{s}' => '{' . $layer['subdomains'] . '}']);

if ($layer['overlay'] == 1) {

$jsLayer = $this->config['id'] . "_" . $i . "_overlayLayer =
new ol.layer.Tile({
visible: " . ($layer['visible'] == true ? 'true' : 'false') . ",
Expand Down Expand Up @@ -568,9 +566,7 @@ protected function getMarker($item, $table)

// It's a group of markers
if ($item['group_title'] ?? false) {

if (empty($jsMarkerGroup)) {

$jsMarker .= $markerStyle;

$group_title = ($marker['type'] == 'html' ? $icon : "<img class='marker-icon' src='" . $icon . "' />") . ' ' . $item['group_title'];
Expand All @@ -584,7 +580,6 @@ protected function getMarker($item, $table)
});";

$this->layers[2][$item['group_uid']]['layer'] = $jsMarkerGroup;

}

$popupJsCode = "
Expand Down Expand Up @@ -612,9 +607,7 @@ function (layer) {
});";

$this->layers[2][$item['group_uid']]['jsMarkerFeatures'][] = $jsMarkerFeature;

} else {

$jsMarker .= $markerStyle;
$jsMarker .= "var " . $jsElementVar . " = new ol.layer.Vector({
title: '<img src=\"" .$icon . "\" class=\"marker-icon\" /> " . ($item['group_title'] ?? $item['name']) . "',
Expand All @@ -638,5 +631,4 @@ function (layer) {

return $jsMarker;
}

}
29 changes: 13 additions & 16 deletions Classes/TceMain.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ class TceMain
var $lat = [];

// ['t3lib/class.t3lib_tcemain.php']['processDatamapClass']
function processDatamap_preProcessFieldArray(&$incomingFieldArray, $table, $id, $obj)
public function processDatamap_preProcessFieldArray(&$incomingFieldArray, $table, $id, $obj)
{
}

/**
/**
* Generate a different preview link *
*
* @param string $status status
Expand All @@ -35,8 +35,7 @@ public function processDatamap_afterDatabaseOperations(
array $fieldArray,
DataHandler $parentObject
) {

/**
/*
* The id may be integer already or the temporary NEW id. This depends, how the record was created
*
* case 1:
Expand Down Expand Up @@ -171,7 +170,6 @@ public function processDatamap_afterDatabaseOperations(
->executeStatement();

// handle properties
$properties = [];
$properties = (array)$polygon->getData();
if (empty($properties)) {
// seems to contain multiple polygones
Expand All @@ -180,7 +178,7 @@ public function processDatamap_afterDatabaseOperations(
$properties = (array)$components[0]->getData();
}

if (! empty($properties)) {
if (!empty($properties)) {

$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
->getQueryBuilderForTable($table);
Expand All @@ -197,7 +195,7 @@ public function processDatamap_afterDatabaseOperations(
if ($row = $result->fetch()) {
if ($row['properties_from_file'] && !empty($properties)) {
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
->getQueryBuilderForTable($table);
->getQueryBuilderForTable($table);

$queryBuilder
->update('tx_odsosm_vector')
Expand All @@ -213,14 +211,13 @@ public function processDatamap_afterDatabaseOperations(
}
}
break;
}
}
}

// ['t3lib/class.t3lib_tcemain.php']['processDatamapClass']
function processDatamap_postProcessFieldArray($status, $table, $id, &$fieldArray, $obj)
public function processDatamap_postProcessFieldArray($status, $table, $id, &$fieldArray, $obj)
{
switch ($table) {

case 'tx_odsosm_vector':
if (!empty($fieldArray['data'] ?? false)) {
$this->lon = [];
Expand All @@ -245,7 +242,7 @@ function processDatamap_postProcessFieldArray($status, $table, $id, &$fieldArray
$properties = (array)$components[0]->getData();
}

if (! empty($properties)) {
if (!empty($properties)) {

$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
->getQueryBuilderForTable($table);
Expand Down Expand Up @@ -273,16 +270,16 @@ function processDatamap_postProcessFieldArray($status, $table, $id, &$fieldArray
$fieldArray['max_lon'] = 0;
$fieldArray['max_lat'] = 0;
}
}
}
break;
default:
$tc = Div::getTableConfig($table);
if ($tc['lon'] ?? false) {
if (
(isset($tc['address']) && ($fieldArray[$tc['address']] ?? null)) ||
(isset($tc['street']) && ($fieldArray[$tc['street']] ?? null)) ||
(isset($tc['zip']) && ($fieldArray[$tc['zip']] ?? null)) ||
(isset($tc['city']) && ($fieldArray[$tc['city']] ?? null))
(isset($tc['address']) && ($fieldArray[$tc['address']] ?? null))
|| (isset($tc['street']) && ($fieldArray[$tc['street']] ?? null))
|| (isset($tc['zip']) && ($fieldArray[$tc['zip']] ?? null))
|| (isset($tc['city']) && ($fieldArray[$tc['city']] ?? null))
) {
$config = Div::getConfig(['autocomplete']);
// Search coordinates
Expand Down
11 changes: 2 additions & 9 deletions Classes/Updates/FileLocationUpdater.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,6 @@ protected function falGetRecordsFromTable($countOnly = false)
protected function falPerformUpdate(): bool
{
$result = true;
$title = "Perform Update";

try {
$storages = GeneralUtility::makeInstance(StorageRepository::class)->findAll();
Expand Down Expand Up @@ -281,8 +280,6 @@ protected function migrateField($table, $row)

// maybe the file was already moved, so check if the original file still exists
if (file_exists($sourcePath)) {
$title = 'Migrate field ' . $sourcePath;

if (!is_dir($targetDirectory)) {
GeneralUtility::mkdir_deep($targetDirectory);
}
Expand Down Expand Up @@ -337,7 +334,7 @@ protected function migrateField($table, $row)
$row['uid'],
$fieldItem
));
return false;
return;
}
}

Expand All @@ -355,9 +352,7 @@ protected function migrateField($table, $row)
];

$queryBuilder = $connectionPool->getQueryBuilderForTable('sys_file_reference');

$result = $queryBuilder
->insert('sys_file_reference')->values($fields)->executeStatement();
$queryBuilder->insert('sys_file_reference')->values($fields)->executeStatement();

++$i;
}
Expand All @@ -374,6 +369,4 @@ protected function migrateField($table, $row)
)->set($this->fieldsToMigrate[$table], $i)->executeStatement();
}
}


}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<div xmlns="http://www.w3.org/1999/xhtml" lang="en"
xmlns:f="http://typo3.org/ns/TYPO3/Fluid/ViewHelpers"
xmlns:f="http://typo3.org/ns/TYPO3/Fluid/ViewHelpers"
>

<f:layout name="Default"/>
<f:section name="Main">
<div class="panel panel-default">
Expand All @@ -14,8 +13,7 @@
<f:translate key="back"/>
</f:link.page>
</f:if>
<f:link.action action="detail" arguments="{index: index}" format="ics" class="btn btn-default">ICS/iCal
</f:link.action>
<f:link.action action="detail" arguments="{index: index}" format="ics" class="btn btn-default">ICS/iCal</f:link.action>
</div>
<div class="map">
<f:cObject typoscriptObjectPath="plugin.tx_odsosm_pi1" />
Expand Down
26 changes: 11 additions & 15 deletions ext_localconf.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
<?php
defined('TYPO3') || die();

use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
use Bobosch\OdsOsm\TceMain;
use Bobosch\OdsOsm\Evaluation\LonLat;
use Bobosch\OdsOsm\Backend\FormDataProvider\FlexFormManipulation;
use TYPO3\CMS\Backend\Form\FormDataProvider\TcaFlexPrepare;
use TYPO3\CMS\Backend\Form\FormDataProvider\TcaFlexProcess;
use Bobosch\OdsOsm\Evaluation\LonLat;
use Bobosch\OdsOsm\TceMain;
use Bobosch\OdsOsm\Updates\FileLocationUpdater;
use Bobosch\OdsOsm\Updates\MigrateSettings;
use Bobosch\OdsOsm\Wizard\CoordinatepickerWizard;
use Bobosch\OdsOsm\Wizard\VectordrawWizard;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Imaging\IconRegistry;
use TYPO3\CMS\Backend\Form\FormDataProvider\TcaFlexPrepare;
use TYPO3\CMS\Backend\Form\FormDataProvider\TcaFlexProcess;
use TYPO3\CMS\Core\Imaging\IconProvider\BitmapIconProvider;
use Bobosch\OdsOsm\Updates\FileLocationUpdater;
use Bobosch\OdsOsm\Updates\MigrateSettings;
use HDNET\Calendarize\Domain\Model\Event;
use TYPO3\CMS\Extbase\Object\Container\Container;
use TYPO3\CMS\Core\Imaging\IconRegistry;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;

ExtensionManagementUtility::addPItoST43(
'ods_osm',
Expand Down Expand Up @@ -86,7 +84,5 @@
}

# add migration wizards
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/install']['update']['odsOsmFileLocationUpdater']
= FileLocationUpdater::class;
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/install']['update']['odsOsmMigrateSettings']
= \Bobosch\OdsOsm\Updates\MigrateSettings::class;
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/install']['update']['odsOsmFileLocationUpdater'] = FileLocationUpdater::class;
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/install']['update']['odsOsmMigrateSettings'] = MigrateSettings::class;

0 comments on commit 4a8b28e

Please sign in to comment.