Skip to content

Commit

Permalink
Načtení členství ze skautIS (#949)
Browse files Browse the repository at this point in the history
* update membership

* fix

* fix cs
  • Loading branch information
jan-stanek committed Apr 5, 2023
1 parent 185d6fb commit cb90ad3
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
33 changes: 33 additions & 0 deletions app/AdminModule/UsersModule/Components/UsersGridControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
use App\Services\QueryBus;
use App\Services\SkautIsEventEducationService;
use App\Services\SkautIsEventGeneralService;
use App\Services\SkautIsService;
use App\Services\SubeventService;
use App\Services\UserService;
use App\Utils\Helpers;
Expand All @@ -46,6 +47,7 @@
use Nette\Localization\Translator;
use Nette\Utils\ArrayHash;
use Nette\Utils\Html;
use Skaut\Skautis\Wsdl\WsdlException;
use Throwable;
use Ublaboo\DataGrid\DataGrid;
use Ublaboo\DataGrid\Exception\DataGridColumnStatusException;
Expand All @@ -72,6 +74,7 @@ public function __construct(
private AclService $aclService,
private ApplicationService $applicationService,
private UserService $userService,
private SkautIsService $skautIsService,
private SkautIsEventEducationService $skautIsEventEducationService,
private SkautIsEventGeneralService $skautIsEventGeneralService,
private SubeventService $subeventService
Expand Down Expand Up @@ -150,6 +153,9 @@ public function createComponentUsersGrid(string $name): DataGrid
$grid->addGroupAction('admin.users.users_group_action_export_schedules')
->onSelect[] = [$this, 'groupExportSchedules'];

$grid->addGroupAction('Načíst členství ze skautIS (admin)')
->onSelect[] = [$this, 'groupUpdateMembership'];

$grid->addColumnText('displayName', 'admin.users.users_name')
->setSortable()
->setFilterText();
Expand Down Expand Up @@ -720,6 +726,33 @@ public function groupExportUsers(array $ids): void
$this->redirect('exportusers');
}

/**
* @param int[] $ids
*/
public function groupUpdateMembership(array $ids): void
{
$users = $this->userRepository->findUsersByIds($ids);
$errors = 0;

foreach ($users as $user) {
try {
$membership = $this->skautIsService->getValidMembership($user->getSkautISPersonId());
$user->setUnit($membership?->RegistrationNumber);
$this->userRepository->save($user);
} catch (WsdlException $e) {
$errors++;
}
}

if ($errors > 0) {
$this->getPresenter()->flashMessage('Členství některých účastníků se nepodařilo načíst (oprávnění).', 'warning');
} else {
$this->getPresenter()->flashMessage('Členství byla úspěšně načtena.', 'success');
}

$this->reload();
}

/**
* Zpracuje export seznamu uživatelů.
*
Expand Down
6 changes: 1 addition & 5 deletions app/Services/Authenticator.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,7 @@ private function updateUserFromSkautIS(User $user, stdClass $skautISUser): void
$user->setMember($skautISUser->HasMembership);

$validMembership = $this->skautIsService->getValidMembership($user->getSkautISPersonId());
if ($validMembership === null) {
$user->setUnit(null);
} else {
$user->setUnit($validMembership->RegistrationNumber);
}
$user->setUnit($validMembership?->RegistrationNumber);

$photoUpdate = new DateTimeImmutable($skautISPerson->PhotoUpdate);
if ($user->getPhotoUpdate() === null || $photoUpdate->diff($user->getPhotoUpdate())->s > 0) {
Expand Down

0 comments on commit cb90ad3

Please sign in to comment.