Skip to content

Commit

Permalink
Optimalizace volání skautIS (#1384)
Browse files Browse the repository at this point in the history
* skautis optimization

* cs fix
  • Loading branch information
jan-stanek authored Oct 11, 2024
1 parent e99631b commit db6b25d
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions app/Services/SkautIsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ public function getLogoutUrl(): string
}

/**
* Vrátí stav přihlášení uživatele, každých 5 minut obnoví přihlášení.
* Vrátí stav přihlášení uživatele, každých 15 minut obnoví přihlášení.
*/
public function isLoggedIn(): bool
{
$logoutTime = clone($this->skautIs->getUser()->getLogoutDate());
$hardCheck = $logoutTime->diff(new DateTimeImmutable())->i < 25; // pokud od posledniho obnoveni prihlaseni ubehlo 5 minut
$hardCheck = $logoutTime->diff(new DateTimeImmutable())->i < 15; // pokud od posledniho obnoveni prihlaseni ubehlo 15 minut

return $this->skautIs->getUser()->isLoggedIn($hardCheck);
}
Expand Down Expand Up @@ -203,27 +203,31 @@ public function getUnitId(): int|null
*/
public function getValidMembership(int $personId): stdClass|null
{
$membership = $this->skautIs->org->MembershipAllPerson([
$memberships = $this->skautIs->org->MembershipAllPerson([
'ID_Login' => $this->skautIs->getUser()->getLoginId(),
'ID_Person' => $personId,
'ID_MembershipType' => 'radne',
'IsValid' => true,
]);

if (empty($membership)) {
$membership = $this->skautIs->org->MembershipAllPerson([
'ID_Login' => $this->skautIs->getUser()->getLoginId(),
'ID_Person' => $personId,
'ID_MembershipType' => 'cestne',
'IsValid' => true,
]);
if (empty($memberships)) {
return null;
}

$membershipsArray = $memberships->MembershipAllOutput instanceof stdClass ? [$memberships->MembershipAllOutput] : $memberships->MembershipAllOutput;

foreach ($membershipsArray as $membership) {
if ($membership->ID_MembershipType === 'radne') {
return $membership;
}
}

if (empty($membership)) {
return null;
foreach ($membershipsArray as $membership) {
if ($membership->ID_MembershipType === 'cestne') {
return $membership;
}
}

return $membership->MembershipAllOutput;
return null;
}

/**
Expand Down

0 comments on commit db6b25d

Please sign in to comment.