Skip to content

Commit

Permalink
fix fuel format, fix emmission format, fix milage format;add attribut…
Browse files Browse the repository at this point in the history
…tes to element class
  • Loading branch information
MDevster committed Feb 6, 2020
1 parent e95e7c5 commit dc6060e
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 40 deletions.
24 changes: 14 additions & 10 deletions src/Elements/ListingElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

namespace Pdir\MobileDeBundle\Elements;

use Contao\System;
use Contao\CoreBundle\Exception\PageNotFoundException;
use Pdir\MobileDeBundle\Module\MobileDeSetup;

Expand Down Expand Up @@ -59,7 +60,7 @@ public function generate()
}

// load language file
$this->lang = \System::loadLanguageFile('tl_mobile_ad');
$this->lang = System::loadLanguageFile('tl_mobile_ad');

// Get reader page model
$this->readerPage = \PageModel::findPublishedByIdOrAlias($this->pdir_md_readerPage)->current()->row();
Expand Down Expand Up @@ -249,31 +250,31 @@ protected function renderAdItem($arrAds)
{
$fuelConsumption[] = [
'label' => $GLOBALS['TL_LANG']['tl_mobile_ad']['emission_fuel_consumption_co2_emission'][0],
'value' => \System::getFormattedNumber($ad['emission_fuel_consumption_co2_emission'], 1),
'value' => System::getFormattedNumber($ad['emission_fuel_consumption_co2_emission'], 1),
];
}

if($ad['emission_fuel_consumption_inner'])
{
$fuelConsumption[] = [
'label' => $GLOBALS['TL_LANG']['tl_mobile_ad']['emission_fuel_consumption_inner'][0],
'value' => \System::getFormattedNumber($ad['emission_fuel_consumption_inner'], 1),
'value' => System::getFormattedNumber($ad['emission_fuel_consumption_inner'], 1),
];
}

if($ad['emission_fuel_consumption_outer'])
{
$fuelConsumption[] = [
'label' => $GLOBALS['TL_LANG']['tl_mobile_ad']['emission_fuel_consumption_outer'][0],
'value' => \System::getFormattedNumber($ad['emission_fuel_consumption_outer'], 1),
'value' => System::getFormattedNumber($ad['emission_fuel_consumption_outer'], 1),
];
}

if($ad['emission_fuel_consumption_combined'])
{
$fuelConsumption[] = [
'label' => $GLOBALS['TL_LANG']['tl_mobile_ad']['emission_fuel_consumption_combined'][0],
'value' => \System::getFormattedNumber($ad['emission_fuel_consumption_combined'], 1),
'value' => System::getFormattedNumber($ad['emission_fuel_consumption_combined'], 1),
];
}

Expand All @@ -289,16 +290,16 @@ protected function renderAdItem($arrAds)
{
$fuelConsumption[] = [
'label' => $GLOBALS['TL_LANG']['tl_mobile_ad']['emission_fuel_consumption_combined_power_consumption'][0],
'value' => \System::getFormattedNumber($ad['emission_fuel_consumption_combined_power_consumption'], 1),
'value' => System::getFormattedNumber($ad['emission_fuel_consumption_combined_power_consumption'], 1),
];
}

$objFilterTemplate->fuelConsumption = $fuelConsumption;

$objFilterTemplate->featured = ('NONE' === $ad['newnessMarker']) ? false : true;
$objFilterTemplate->onlyFilter = $this->pdir_md_only_filter;
$objFilterTemplate->firstRegistration = $this->formatFirstRegistration($ad['specifics_first_registration']);
$objFilterTemplate->mileage = $ad['specifics_mileage'] ? $ad['specifics_mileage'] : 0;
$objFilterTemplate->firstRegistration = $this->formatDate($ad['specifics_first_registration']);
$objFilterTemplate->mileage = $ad['specifics_mileage'] ? System::getFormattedNumber($ad['specifics_mileage'], 0) : 0;
$objFilterTemplate->filterClasses = $this->getFilterClasses($ad);

if (!$this->pdir_md_hidePromotionBox) {
Expand Down Expand Up @@ -394,9 +395,12 @@ protected function getFilterClasses($ad)
return implode(' ', $filter);
}

function formatFirstRegistration($str) {
public function formatDate($str) {
if(strlen($str) == 7)
return $str;
{
$date = explode('-', $str);
return $date[1] . '.' . $date[0];
}

$res = ($str) ? date($GLOBALS['TL_CONFIG']['dateFormat'], $str) : $GLOBALS['TL_LANG']['pdirMobileDe']['field_keys']['first-registration-no-value'];

Expand Down
44 changes: 28 additions & 16 deletions src/Elements/ReaderElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
namespace Pdir\MobileDeBundle\Elements;

use Contao\CoreBundle\Exception\PageNotFoundException;
use Contao\System;
use Pdir\MobileDeBundle\Module\MobileDeSetup;

class ReaderElement extends \ContentElement
Expand Down Expand Up @@ -110,37 +111,48 @@ protected function compile()
continue;
}

if($specific != "exhaust_inspection" && $specific != "general_inspection" && $specific != "construction_date" && $specific != "first_registration" && $specific != "delivery_date" && $specific != "first_models_production_date") {
if($specific != "exhaust_inspection" && $specific != "general_inspection" && $specific != "construction_date" && $specific != "first_registration" && $specific != "delivery_date" && $specific != "first_models_production_date" && $specific != "mileage") {
$newSpecifics[] = [
'key' => $specific,
'label' => $GLOBALS['TL_LANG']['tl_mobile_ad']['specifics_'.$specific][0],
'value' => $GLOBALS['TL_LANG']['tl_mobile_ad']['specifics_'.$specific]['options'][$this->ad['specifics_'.$specific]] ?: $this->ad['specifics_'.$specific],
'plainValue' => $this->ad['specifics_'.$specific],
'label' => $GLOBALS['TL_LANG']['tl_mobile_ad']['specifics_' . $specific][0],
'value' => $GLOBALS['TL_LANG']['tl_mobile_ad']['specifics_' . $specific]['options'][$this->ad['specifics_' . $specific]] ?: $this->ad['specifics_' . $specific],
'plainValue' => $this->ad['specifics_' . $specific],
];
} elseif($specific == "mileage") {
$newSpecifics[] = [
'key' => $specific,
'label' => $GLOBALS['TL_LANG']['tl_mobile_ad']['specifics_' . $specific][0],
'value' => $this->ad['specifics_' . $specific] ? System::getFormattedNumber($this->ad['specifics_' . $specific], 0) : 0,
'plainValue' => $this->ad['specifics_' . $specific],
];

} else {
$newSpecifics[] = [
'key' => $specific,
'label' => $GLOBALS['TL_LANG']['tl_mobile_ad']['specifics_'.$specific][0],
'value' => $GLOBALS['TL_LANG']['tl_mobile_ad']['specifics_'.$specific]['options'][$this->ad['specifics_'.$specific]] ?: date($GLOBALS['TL_CONFIG']['dateFormat'], $this->ad['specifics_'.$specific]),
'value' => $GLOBALS['TL_LANG']['tl_mobile_ad']['specifics_'.$specific]['options'][$this->ad['specifics_'.$specific]] ?: ListingElement::formatDate($this->ad['specifics_'.$specific]),
'plainValue' => $this->ad['specifics_'.$specific],
];
}

}
$this->ad['specifics'] = $newSpecifics;

if($this->ad['specifics_general_inspection']) $this->ad['specifics_general_inspection'] = date($GLOBALS['TL_CONFIG']['dateFormat'], $this->ad['specifics_general_inspection']);
if($this->ad['specifics_general_inspection']) $this->ad['specifics_general_inspection'] = ListingElement::formatDate($this->ad['specifics_general_inspection']);

if($this->ad['specifics_exhaust_inspection']) $this->ad['specifics_exhaust_inspection'] = date($GLOBALS['TL_CONFIG']['dateFormat'], $this->ad['specifics_exhaust_inspection']);
if($this->ad['specifics_exhaust_inspection']) $this->ad['specifics_exhaust_inspection'] = ListingElement::formatDate($this->ad['specifics_exhaust_inspection']);

if($this->ad['specifics_delivery_date']) $this->ad['specifics_delivery_date'] = date($GLOBALS['TL_CONFIG']['dateFormat'], $this->ad['specifics_delivery_date']);
if($this->ad['specifics_delivery_date']) $this->ad['specifics_delivery_date'] = ListingElement::formatDate($this->ad['specifics_delivery_date']);

if($this->ad['specifics_first_registration']) $this->ad['specifics_first_registration'] = date($GLOBALS['TL_CONFIG']['dateFormat'], $this->ad['specifics_first_registration']);
if($this->ad['specifics_first_registration']) $this->ad['specifics_first_registration'] = ListingElement::formatDate($this->ad['specifics_first_registration']);

if($this->ad['specifics_construction_date']) $this->ad['specifics_construction_date'] = date($GLOBALS['TL_CONFIG']['dateFormat'], $this->ad['specifics_construction_date']);
if($this->ad['specifics_construction_date']) $this->ad['specifics_construction_date'] = ListingElement::formatDate($this->ad['specifics_construction_date']);

if($this->ad['specifics_first_models_production_date']) $this->ad['specifics_first_models_production_date'] = date($GLOBALS['TL_CONFIG']['dateFormat'], $this->ad['specifics_first_models_production_date']);

if($this->ad['specifics_power']) $this->ad['specifics_power'] ? $this->ad['specifics_power'].' kW ('.System::getFormattedNumber(($this->ad['specifics_power'] * 1.35962), 0).' PS)' : 'Keine Angabe';


// images
$newGallery = [];
if ('man' === $this->ad['type']) {
Expand Down Expand Up @@ -169,47 +181,47 @@ protected function compile()
{
$fuelConsumption[] = [
'label' => $GLOBALS['TL_LANG']['tl_mobile_ad']['emission_fuel_consumption_co2_emission'][0],
'value' => $this->ad['emission_fuel_consumption_co2_emission'],
'value' => System::getFormattedNumber($this->ad['emission_fuel_consumption_co2_emission'], 1),
];
}

if($this->ad['emission_fuel_consumption_inner'])
{
$fuelConsumption[] = [
'label' => $GLOBALS['TL_LANG']['tl_mobile_ad']['emission_fuel_consumption_inner'][0],
'value' => $this->ad['emission_fuel_consumption_inner'],
'value' => System::getFormattedNumber($this->ad['emission_fuel_consumption_inner'], 1),
];
}

if($this->ad['emission_fuel_consumption_outer'])
{
$fuelConsumption[] = [
'label' => $GLOBALS['TL_LANG']['tl_mobile_ad']['emission_fuel_consumption_outer'][0],
'value' => $this->ad['emission_fuel_consumption_outer'],
'value' => System::getFormattedNumber($this->ad['emission_fuel_consumption_outer'], 1),
];
}

if($this->ad['emission_fuel_consumption_combined'])
{
$fuelConsumption[] = [
'label' => $GLOBALS['TL_LANG']['tl_mobile_ad']['emission_fuel_consumption_combined'][0],
'value' => $this->ad['emission_fuel_consumption_combined'],
'value' => System::getFormattedNumber($this->ad['emission_fuel_consumption_combined'], 1),
];
}

if($this->ad['emission_fuel_consumption_petrol_type'])
{
$fuelConsumption[] = [
'label' => $GLOBALS['TL_LANG']['tl_mobile_ad']['emission_fuel_consumption_petrol_type'][0],
'value' => $this->ad['emission_fuel_consumption_petrol_type'],
'value' => $GLOBALS['TL_LANG']['tl_mobile_ad']['emission_fuel_consumption_petrol_type_options'][$this->ad['emission_fuel_consumption_petrol_type']],
];
}

if($this->ad['emission_fuel_consumption_combined_power_consumption'])
{
$fuelConsumption[] = [
'label' => $GLOBALS['TL_LANG']['tl_mobile_ad']['emission_fuel_consumption_combined_power_consumption'][0],
'value' => $this->ad['emission_fuel_consumption_combined_power_consumption'],
'value' => System::getFormattedNumber($this->ad['emission_fuel_consumption_combined_power_consumption'], 1),
];
}

Expand Down
4 changes: 2 additions & 2 deletions src/Resources/contao/languages/de/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@
$GLOBALS['TL_LANG']['pdirMobileDe']['field_keys']['load-capacity'] = 'Ladekapazität';
$GLOBALS['TL_LANG']['pdirMobileDe']['field_keys']['loading-space'] = 'Laderaum';
$GLOBALS['TL_LANG']['pdirMobileDe']['field_keys']['make'] = 'Marke';
$GLOBALS['TL_LANG']['pdirMobileDe']['field_keys']['mileage'] = 'Kilometerstand';
$GLOBALS['TL_LANG']['pdirMobileDe']['field_keys']['mileage'] = 'Kilometerstand (km)';
$GLOBALS['TL_LANG']['pdirMobileDe']['field_keys']['number-of-bunks'] = 'Anzahl der Schlafräume';
$GLOBALS['TL_LANG']['pdirMobileDe']['field_keys']['number-of-previous-owners'] = 'Anzahl der Vorbesitzer';
$GLOBALS['TL_LANG']['pdirMobileDe']['field_keys']['num-seats'] = 'Anzahl Sitzplätze';
$GLOBALS['TL_LANG']['pdirMobileDe']['field_keys']['operating-hours'] = 'Betriebsstunden';
$GLOBALS['TL_LANG']['pdirMobileDe']['field_keys']['parking-assistants'] = 'Parkassistent';
$GLOBALS['TL_LANG']['pdirMobileDe']['field_keys']['power'] = 'Leistung';
$GLOBALS['TL_LANG']['pdirMobileDe']['field_keys']['power'] = 'Leistung (kW)';
$GLOBALS['TL_LANG']['pdirMobileDe']['field_keys']['radio'] = 'Radio';
$GLOBALS['TL_LANG']['pdirMobileDe']['field_keys']['schwacke-code'] = 'Schwacke-Code';
$GLOBALS['TL_LANG']['pdirMobileDe']['field_keys']['seller-since'] = 'Verkäufer seit';
Expand Down
Loading

0 comments on commit dc6060e

Please sign in to comment.