Skip to content

Commit

Permalink
Merge pull request #43 from alexplusde/Type-Hinting
Browse files Browse the repository at this point in the history
Type hinting
  • Loading branch information
alxndr-w authored Nov 24, 2023
2 parents f761ff2 + 76d14a8 commit 05b55ba
Show file tree
Hide file tree
Showing 8 changed files with 120 additions and 94 deletions.
2 changes: 1 addition & 1 deletion lib/country_codes.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
class event_country_codes
{
public static function get()
public static function get(): array
{
return array(
"AF" => "Afghanistan",
Expand Down
6 changes: 3 additions & 3 deletions lib/cronjob_events_ics_import.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

class rex_cronjob_events_ics_import extends rex_cronjob
{
public function execute()
public function execute(): void
{
$debug_dump = []; // Debug-Array, das bei enstprechender Option ausgegeben wird

Expand Down Expand Up @@ -220,12 +220,12 @@ public function execute()
}
}

public function getTypeName()
public function getTypeName(): string
{
return rex_i18n::msg('events_ics_import_cronjob_name');
}

public function getParamFields()
public function getParamFields(): array
{
// ICS-Datei als Demo vorschlagen
$default_url = 'https://www.schulferien.org/deutschland/ical/download/?lid=81&j='.date("Y").'&t=2';
Expand Down
20 changes: 10 additions & 10 deletions lib/event_category.php
Original file line number Diff line number Diff line change
@@ -1,47 +1,47 @@
<?php
class event_category extends \rex_yform_manager_dataset
{
public function getName() :string
public function getName(): string
{
return $this->name;
}
public function getImage() :string
public function getImage(): string
{
return $this->image;
}
public function getMedia()
public function getMedia(): rex_media
{
return rex_media::get($this->image);
}

public function getIcon()
public function getIcon(): string
{
return $this->getValue('icon');
}
public function getPrice()
public function getPrice(): string
{
return $this->getValue('msg_price');
}
public function getUrl()
public function getUrl(): string
{
return rex_getUrl('', '', ['event-category-id' => $this->getId()]);
}

public function getDateWhere($whereRaw = '')
public function getDateWhere($whereRaw = ''): ?rex_yform_manager_collection
{
return event_date::query()->joinRelation('event_category_id', 'c')->where('c.id', $this->getId())->whereRaw($whereRaw)->orderBy('startDate`, `startTime', 'DESC')->find();
}

public function getRelatedDates($whereRaw = '')
public function getRelatedDates($whereRaw = ''): array
{
return $this->getDateWhere($whereRaw);
}

public function getAttributes()
public function getAttributes(): array
{
return explode(",", $this->getValue('msg_form_presets'));
}
public function hasAttribute($needle)
public function hasAttribute($needle): bool
{
return in_array($needle, $this->getAttributes());
}
Expand Down
50 changes: 25 additions & 25 deletions lib/event_date.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,19 @@ public static function generateuuid($id = null) :string
return uuid::uuid3(uuid::NAMESPACE_URL, $id);
}

public function getCategory()
public function getCategory(): ?rex_yform_manager_collection
{
$this->category = event_category::get((int)$this->getValue('event_category_id'));
return $this->category;
}
public function getCategories()

public function getCategories(): array
{
$this->categories = $this->getRelatedCollection('event_category_id');
return $this->categories;
}

public function getIcs()
public function getIcs(): string
{
$UID = $this->getUid();

Expand Down Expand Up @@ -64,35 +65,35 @@ public function getIcs()
// exit($vEvent);
}

public function getLocation()
public function getLocation(): string
{
if ($this->location === null) {
$this->location = $this->getRelatedDataset('location');
}
return $this->location;
}
public function getLocationId()
public function getLocationId(): int
{
return $this->getValue('location');
}

public function getTimezone($lat, $lng)
public function getTimezone(float $lat, float $lng): string
{
$event_timezone = "https://maps.googleapis.com/maps/api/timezone/json?location=" . $lat . "," . $lng . "&timestamp=" . time() . "&sensor=false";
$event_location_time_json = file_get_contents($event_timezone);
return $event_location_time_json;
}

public function getOfferAll()
public function getOfferAll(): array
{
return $this->getRelatedCollection('offer');
}

public function getImage() : ?string
public function getImage(): ?string
{
return $this->image;
}
public function getMedia()
public function getMedia(): rex_media
{
return rex_media::get($this->image);
}
Expand All @@ -101,11 +102,11 @@ public function getDescriptionAsPlaintext() : ?string
{
return strip_tags(html_entity_decode($this->description));
}
public function getIcsStatus()
public function getIcsStatus(): int
{
return strip_tags($this->eventStatus);
}
public function getUid()
public function getUid(): string
{
if ($this->uid === "" && $this->getValue("uid") === "") {
$this->uid = self::generateUuid($this->id);
Expand All @@ -115,19 +116,19 @@ public function getUid()
return $this->uid;
}

public function getJsonLd()
public function getJsonLd(): string
{
$fragment = new rex_fragment();
$fragment->setVar("event_date", $this);
return $fragment->parse('event-date-single.json-ld.php');
}

public static function formatDate($format_date = IntlDateFormatter::FULL, $format_time = IntlDateFormatter::SHORT, $lang = "de")
public static function formatDate(int $format_date = IntlDateFormatter::FULL, int $format_time = IntlDateFormatter::SHORT, string $lang = "de"): IntlDateFormatter
{
return datefmt_create($lang, $format_date, $format_time, null, IntlDateFormatter::GREGORIAN);
}

private function getDateTime($date, $time = "00:00")
private function getDateTime(string $date, string $time = "00:00"): DateTime
{
$time = explode(":", $time);
$dateTime = new DateTime($date);
Expand All @@ -136,22 +137,21 @@ private function getDateTime($date, $time = "00:00")
return $dateTime;
}

public function getFormattedStartDate($format_date = IntlDateFormatter::FULL, $format_time = IntlDateFormatter::NONE)
public function getFormattedStartDate(int $format_date = IntlDateFormatter::FULL, int $format_time = IntlDateFormatter::NONE): string
{
return self::formatDate($format_date, $format_time)->format($this->getDateTime($this->getValue("startDate"), $this->getStartTime()));
}


public function getFormattedEndDate($format_date = IntlDateFormatter::FULL, $format_time = IntlDateFormatter::SHORT)
public function getFormattedEndDate(int $format_date = IntlDateFormatter::FULL, int $format_time = IntlDateFormatter::SHORT): string
{
return self::formatDate($format_date, $format_time)->format($this->getDateTime($this->getValue("endDate"), $this->getEndTime()));
}

public function getFormattedStartTime()
public function getFormattedStartTime(): string
{
return $this->getStartTime();
}
public function getFormattedEndTime()
public function getFormattedEndTime(): string
{
return $this->getEndTime();
}
Expand Down Expand Up @@ -179,7 +179,7 @@ public function geTeaser() : ?string
return $this->getValue("teaser");
}

public function getPrice()
public function getPrice(): string
{
$offer = rex_yform_manager_table::get('rex_event_date_offer')->query()->where("date_id", $this->getValue('id'))->find();

Expand All @@ -188,7 +188,7 @@ public function getPrice()
}
return $this->getCategories()[0]->getPrice();
}
public function getPriceFormatted()
public function getPriceFormatted(): string
{
return $this->getPrice() . " " . rex_config::get('events', 'currency');
}
Expand Down Expand Up @@ -229,7 +229,7 @@ public function isFull() :bool
}
/* Register-URL-Addon */

public static function combineCidDid($cid, $did)
public static function combineCidDid($cid, $did): string
{
return $cid . str_pad($did, 3, '0', STR_PAD_LEFT);
}
Expand Down Expand Up @@ -272,18 +272,18 @@ public function getRegisterBar() :string
'.$this->countRegistrationPerson()."/".$this->getTotalCount().'
</div>';
}
public function getIcon()
public function getIcon(): string
{
if ($category = $this->getCategory()) {
return $category->getIcon();
}
}

public function getRegistrationPerson($status = 0, $operator = ">=")
public function getRegistrationPerson($status = 0, $operator = ">="): ?rex_yform_manager_collection
{
return event_registration_person::query()->where('status', $status, $operator)->where('event_date_id', self::getId())->find();
}
public function countRegistrationPerson($status = 0, $operator = ">=")
public function countRegistrationPerson($status = 0, $operator = ">="): int
{
return count($this->getRegistrationPerson($status, $operator));
}
Expand Down
Loading

0 comments on commit 05b55ba

Please sign in to comment.