From c971333b4208185431ec2a75bf54439e2bf1f315 Mon Sep 17 00:00:00 2001 From: Michael Kaplan Date: Tue, 6 Aug 2024 13:56:26 +0200 Subject: [PATCH 1/6] chore: cleanup ununsed bits --- bin/installl.sh | 7 - ci/kissj-pipeline.yaml | 287 -------------------------------- ci/tasks/build-image-task.yaml | 15 -- ci/tasks/codesniffer-task.yaml | 22 --- ci/tasks/helm-lint-task.yaml | 19 --- ci/tasks/helm-package-task.yaml | 23 --- ci/tasks/install-deps-task.yaml | 23 --- ci/tasks/lint-task.yaml | 19 --- ci/tasks/stan-task.yaml | 24 --- ci/tasks/unit-task.yaml | 23 --- 10 files changed, 462 deletions(-) delete mode 100755 bin/installl.sh delete mode 100644 ci/kissj-pipeline.yaml delete mode 100644 ci/tasks/build-image-task.yaml delete mode 100644 ci/tasks/codesniffer-task.yaml delete mode 100644 ci/tasks/helm-lint-task.yaml delete mode 100644 ci/tasks/helm-package-task.yaml delete mode 100644 ci/tasks/install-deps-task.yaml delete mode 100644 ci/tasks/lint-task.yaml delete mode 100644 ci/tasks/stan-task.yaml delete mode 100644 ci/tasks/unit-task.yaml diff --git a/bin/installl.sh b/bin/installl.sh deleted file mode 100755 index 1ddde8e4..00000000 --- a/bin/installl.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env bash - -if [ -f /usr/bin/dnf ]; then dnf install -y php-pecl-xdebug3; fi - -composer install --no-interaction - -composer phinx:migrate --no-interaction diff --git a/ci/kissj-pipeline.yaml b/ci/kissj-pipeline.yaml deleted file mode 100644 index 4d35f50e..00000000 --- a/ci/kissj-pipeline.yaml +++ /dev/null @@ -1,287 +0,0 @@ -resource_types: - -- name: slack-alert - type: registry-image - source: - repository: arbourd/concourse-slack-alert-resource - -- name: helm-deploy - type: registry-image - source: - repository: typositoire/concourse-helm3-resource - tag: v1.20.0 - -resources: -- name: kissj-app - type: git - icon: github - source: - uri: https://github.com/SkautDevs/kissj.git - branch: master - -- name: kissj-php-registry - type: registry-image - icon: docker - source: - repository: quay.io/kissj/php - tag: latest - username: ((kissj-registry.username)) - password: ((kissj-registry.password)) - -- name: kissj-caddy-registry - type: registry-image - icon: docker - source: - repository: quay.io/kissj/caddy - tag: latest - username: ((kissj-registry.username)) - password: ((kissj-registry.password)) - -- name: kissj-aks-cluster - type: helm-deploy - source: - cluster_url: ((concourse-ci.cluster_url)) - cluster_ca: ((concourse-ci.cluster_ca)) - token: ((concourse-ci.token)) - namespace: kissj-prod - release: kissj - -- name: slack-notify - type: slack-alert - source: - url: ((slack-webhook.webhook)) - -jobs: -- name: tests - - on_success: - put: slack-notify - params: - alert_type: sucess - on_failure: - put: slack-notify - params: - alert_type: failed - on_error: - put: slack-notify - params: - alert_type: errored - - plan: - - in_parallel: - - - get: kissj-app - trigger: true - - - task: install-dependencies - file: kissj-app/ci/tasks/install-deps-task.yaml - output_mapping: - kissj-app: kissj-app - - - try: - in_parallel: - - task: lint-code - file: kissj-app/ci/tasks/lint-task.yaml - - task: stan - file: kissj-app/ci/tasks/stan-task.yaml - - task: unit-test - file: kissj-app/ci/tasks/unit-task.yaml - - task: lint-helm-chart - file: kissj-app/ci/tasks/helm-lint-task.yaml - - - -#Build and push container images -- name: build-and-push - - on_success: - put: slack-notify - params: - alert_type: sucess - on_failure: - put: slack-notify - params: - alert_type: failed - on_error: - put: slack-notify - params: - alert_type: errored - - plan: - - in_parallel: - - get: kissj-app - trigger: true - passed: [tests] - - - in_parallel: - - - do: - - task: build-php-image - file: kissj-app/ci/tasks/build-image-task.yaml - privileged: true - output_mapping: - image: php-image - - params: - DOCKERFILE: kissj-app/deploy/container_images/php/Containerfile - - - put: kissj-php-registry - attempts: 10 - params: - image: php-image/image.tar - additional_tags: kissj-app/.git/short_ref - - - do: - - task: build-caddy-image - file: kissj-app/ci/tasks/build-image-task.yaml - privileged: true - output_mapping: - image: caddy-image - - params: - DOCKERFILE: kissj-app/deploy/container_images/caddy/Containerfile - - - put: kissj-caddy-registry - attempts: 10 - params: - image: caddy-image/image.tar - additional_tags: kissj-app/.git/short_ref - - - -#Deploy prod to k8s -- name: deploy-prod - - on_success: - put: slack-notify - params: - alert_type: sucess - on_failure: - put: slack-notify - params: - alert_type: failed - on_error: - put: slack-notify - params: - alert_type: errored - - plan: - - in_parallel: - - get: kissj-app - trigger: true - passed: [build-and-push] - - - get: kissj-caddy-registry - trigger: true - passed: [build-and-push] - - - get: kissj-php-registry - trigger: true - passed: [build-and-push] - - - get: kissj-aks-cluster - - - put: kissj-aks-cluster - params: - chart: kissj-app/deploy/helm/charts/kissj - namespace: kissj-prod - release: kissj - check_is_ready: true - override_values: -#postgres values - - key: postgres.incluster - value: false - type: boolean - - - key: postgres.username - value: ((postgres.username)) - type: string - hide: true - - - key: postgres.password - value: ((postgres.password)) - type: string - hide: true - - - key: postgres.dbname - value: ((postgres.dbname)) - type: string - hide: true - - - key: postgres.host - value: ((postgres.host)) - type: string - hide: true -#caddy values - - key: caddy.image.name - value: quay.io/kissj/caddy - type: string - - - key: caddy.image.tag - path: kissj-app/.git/short_ref - type: string -#php values - - key: php.image.name - value: quay.io/kissj/php - type: string - - - key: php.image.tag - path: kissj-app/.git/short_ref - type: string -#app values - - key: app.url - value: kissj.net - - - key: app.adminer.username - value: ((adminer.username)) - hide: true - - - key: app.adminer.password - value: ((adminer.password)) - hide: true - - - key: app.s3.key - value: ((s3.key)) - hide: true - - - key: app.s3.secret - value: ((s3.secret)) - hide: true - - - key: app.s3.region - value: ((s3.region)) - hide: true - - - key: app.s3.endpoint - value: ((s3.endpoint)) - hide: true - - - key: app.s3.bucket - value: ((s3.bucket)) - hide: true - - - key: app.mail.server - value: ((mail.server)) - hide: true - - - key: app.mail.port - value: ((mail.port)) - - - key: app.mail.encryption - value: tls - - - key: app.mail.username - value: ((mail.username)) - hide: true - - - key: app.mail.password - value: ((mail.password)) - hide: true - - - key: app.sentry.dsn - value: ((sentry.dsn)) - hide: true - - - key: app.mail.dsn - value: ((mail.dsn)) - hide: true diff --git a/ci/tasks/build-image-task.yaml b/ci/tasks/build-image-task.yaml deleted file mode 100644 index 5419b046..00000000 --- a/ci/tasks/build-image-task.yaml +++ /dev/null @@ -1,15 +0,0 @@ ---- -platform: linux - -image_resource: - type: registry-image - source: - repository: concourse/oci-build-task - -inputs: - - name: kissj-app -outputs: - - name: image - -run: - path: build diff --git a/ci/tasks/codesniffer-task.yaml b/ci/tasks/codesniffer-task.yaml deleted file mode 100644 index 037e9961..00000000 --- a/ci/tasks/codesniffer-task.yaml +++ /dev/null @@ -1,22 +0,0 @@ ---- -platform: linux - -image_resource: - type: registry-image - source: - repository: quay.io/kissj/php - tag: latest - - -inputs: - - name: kissj-app - -run: - path: composer - args: - - cs - - --working-dir=kissj-app - - --no-interaction - - - diff --git a/ci/tasks/helm-lint-task.yaml b/ci/tasks/helm-lint-task.yaml deleted file mode 100644 index 5b77b71b..00000000 --- a/ci/tasks/helm-lint-task.yaml +++ /dev/null @@ -1,19 +0,0 @@ ---- -platform: linux - -image_resource: - type: registry-image - source: - repository: alpine/helm - tag: latest - - -inputs: - - name: kissj-app - -run: - path: helm - args: - - lint - - kissj-app/deploy/helm/charts/kissj - diff --git a/ci/tasks/helm-package-task.yaml b/ci/tasks/helm-package-task.yaml deleted file mode 100644 index 7c813464..00000000 --- a/ci/tasks/helm-package-task.yaml +++ /dev/null @@ -1,23 +0,0 @@ ---- -platform: linux - -image_resource: - type: registry-image - source: - repository: alpine/helm - tag: latest - - -inputs: - - name: kissj-app -outputs: - - name: helm-chart - -run: - path: helm - args: - - package - - kissj-app/deploy/helm/charts/kissj - - --destination=helm-chart - - diff --git a/ci/tasks/install-deps-task.yaml b/ci/tasks/install-deps-task.yaml deleted file mode 100644 index 683ea3d2..00000000 --- a/ci/tasks/install-deps-task.yaml +++ /dev/null @@ -1,23 +0,0 @@ ---- -platform: linux - -image_resource: - type: registry-image - source: - repository: quay.io/kissj/php - tag: latest - - - -inputs: - - name: kissj-app -outputs: - - name: kissj-app -params: - COMPOSER_MEMORY_LIMIT: "256M" -run: - path: composer - args: - - install - - --working-dir=kissj-app - - --no-interaction diff --git a/ci/tasks/lint-task.yaml b/ci/tasks/lint-task.yaml deleted file mode 100644 index 1adf8199..00000000 --- a/ci/tasks/lint-task.yaml +++ /dev/null @@ -1,19 +0,0 @@ ---- -platform: linux - -image_resource: - type: registry-image - source: - repository: overtrue/phplint - #tag: 8.0 - - -inputs: - - name: kissj-app - -run: - path: /root/.composer/vendor/bin/phplint - args: - - kissj-app - - --exclude=vendor - - --warning \ No newline at end of file diff --git a/ci/tasks/stan-task.yaml b/ci/tasks/stan-task.yaml deleted file mode 100644 index 12004e0b..00000000 --- a/ci/tasks/stan-task.yaml +++ /dev/null @@ -1,24 +0,0 @@ ---- -platform: linux - -image_resource: - type: registry-image - source: - repository: quay.io/kissj/php - tag: latest - -inputs: - - name: kissj-app - -params: - COMPOSER_MEMORY_LIMIT: "512M" - -run: - path: composer - args: - - stan - - --working-dir=kissj-app - - --no-interaction - - - diff --git a/ci/tasks/unit-task.yaml b/ci/tasks/unit-task.yaml deleted file mode 100644 index dc122bcd..00000000 --- a/ci/tasks/unit-task.yaml +++ /dev/null @@ -1,23 +0,0 @@ ---- -platform: linux - -image_resource: - type: registry-image - source: - repository: quay.io/kissj/php - tag: latest - - -inputs: - - name: kissj-app - -params: - COMPOSER_MEMORY_LIMIT: "512M" - -run: - path: composer - args: - - test - - --working-dir=kissj-app - - --no-interaction - From 6df785c2a036bbce50856b06cd25ecfa307ba6ba Mon Sep 17 00:00:00 2001 From: Michael Kaplan Date: Tue, 6 Aug 2024 15:15:33 +0200 Subject: [PATCH 2/6] chore: cleanup dev setup --- .gitignore | 8 ++- Makefile | 57 ++++++++++++++++--- deploy/dev/.gitignore | 1 + deploy/{dev-postgres => dev}/Caddyfile | 2 +- deploy/dev/compose.env.example | 26 +++++++++ .../{dev-postgres => dev}/docker-compose.yml | 20 ++++--- 6 files changed, 94 insertions(+), 20 deletions(-) create mode 100644 deploy/dev/.gitignore rename deploy/{dev-postgres => dev}/Caddyfile (94%) create mode 100644 deploy/dev/compose.env.example rename deploy/{dev-postgres => dev}/docker-compose.yml (78%) diff --git a/.gitignore b/.gitignore index 488c43de..9ca97ac2 100755 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ -/.idea/* /.composer/cache/* /attachments/* /backups/* @@ -18,3 +17,10 @@ !db_init.sqlite /backup/* /uploads/* + +# editor and IDE paraphernalia +.idea +.vscode +*.swp +*.swo +*~ diff --git a/Makefile b/Makefile index c4fd1ca7..0b944107 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,48 @@ -.PHONY: local-dev-postgresql -local-dev-postgresql: - docker-compose --file deploy/dev-postgres/docker-compose.yml up --build -d - sleep 5 - docker exec -it $$(docker ps | grep php-fpm | awk '{print $$1}') bash -c "./bin/installl.sh" - -.PHONY: down-local-dev-postgresql -down-local-dev-postgresql: - docker-compose --file deploy/dev-postgres/docker-compose.yml down +# Check for docker/podman +DOCKER := $(shell command -v podman 2> /dev/null || command -v docker 2> /dev/null) + +# Check for docker-compose/podman-compose +DOCKER_COMPOSE := $(shell command -v podman-compose 2> /dev/null || command -v docker-compose 2> /dev/null) + +.PHONY: info +info: +ifeq ($(DOCKER),) + @echo "Neither docker nor podman is installed." + exit 1 +else + @echo "Using $(DOCKER)" +endif + +ifeq ($(DOCKER_COMPOSE),) + @echo "Neither docker-compose nor podman-compose is installed." + exit 1 +else + @echo "Using $(DOCKER_COMPOSE)" +endif + +# Start the containers +.PHONY: compose-up +compose-up: + $(DOCKER_COMPOSE) --file deploy/dev/docker-compose.yml up -d + +# Stop the containers +.PHONY: compose-down +compose-down: + $(DOCKER_COMPOSE) --file deploy/dev/docker-compose.yml down + +# Get container ID +.PHONY: $(FPM_ID) +FPM_ID = $(shell $(DOCKER) ps | grep 'quay.io/kissj/php-ubi' | awk '{print $$1}') + +.PHONY: composer-install +composer-install: + $(DOCKER) exec -it -u root $(FPM_ID) sh -c "COMPOSER_ALLOW_SUPERUSER=1 composer install --no-interaction" + +.PHONY: migrate +migrate: + $(DOCKER) exec -it -u root $(FPM_ID) sh -c "COMPOSER_ALLOW_SUPERUSER=1 composer phinx:migrate --no-interaction" + + +dev-up: info compose-up composer-install migrate +dev-down: info compose-down + diff --git a/deploy/dev/.gitignore b/deploy/dev/.gitignore new file mode 100644 index 00000000..4f509e52 --- /dev/null +++ b/deploy/dev/.gitignore @@ -0,0 +1 @@ +*.env \ No newline at end of file diff --git a/deploy/dev-postgres/Caddyfile b/deploy/dev/Caddyfile similarity index 94% rename from deploy/dev-postgres/Caddyfile rename to deploy/dev/Caddyfile index fcc2d008..c3fa4be5 100644 --- a/deploy/dev-postgres/Caddyfile +++ b/deploy/dev/Caddyfile @@ -1,4 +1,4 @@ -:80 { +:8080 { root * /var/www/html/public file_server php_fastcgi {env.PHPFPM_HOST}:9000 diff --git a/deploy/dev/compose.env.example b/deploy/dev/compose.env.example new file mode 100644 index 00000000..8f99a531 --- /dev/null +++ b/deploy/dev/compose.env.example @@ -0,0 +1,26 @@ +BASEPATH="" # app subfolder with leading slash only, eg. "/registration/kissj" - use "" if running on domain root +DEBUG=true +TEMPLATE_CACHE=true +DEFAULT_LOCALE="cs" +GIT_HASH="default" + +LOGGER_TARGET="file" # "file" or "stdout" # TODO implement +LOGGER_FILENAME="app.log" +LOGGER_LEVEL='DEBUG' # values defined in RFC 5424 (fe. DEBUG, INFO, ERROR) + +MAIL_DSN="smtp://mailhog:1025" # be careful on the encoding of the special symbols - https://symfony.com/doc/current/mailer.html#transport-setup +MAIL_SEND_MAIL_TO_MAIN_RECIPIENT=true # keep true for sending emails + +FILE_HANDLER_TYPE="local" # "local" for saving into local filesystem, "s3bucket" for s3bucket +S3_BUCKET="" +S3_KEY="" +S3_SECRET="" +S3_REGION="" +S3_ENDPOINT="" + +SENTRY_DSN="" +SENTRY_PROFILING_RATE="0.5" # from 0 to 1 + +SKAUTIS_APP_ID="kissj" +SKAUTIS_USE_TEST="true" + diff --git a/deploy/dev-postgres/docker-compose.yml b/deploy/dev/docker-compose.yml similarity index 78% rename from deploy/dev-postgres/docker-compose.yml rename to deploy/dev/docker-compose.yml index 06ebbf3b..d1e1dad0 100644 --- a/deploy/dev-postgres/docker-compose.yml +++ b/deploy/dev/docker-compose.yml @@ -1,14 +1,12 @@ -version: "3.3" +name: kissj-app services: - #database postgresql: - image: postgres:14-alpine + image: postgres:16-alpine volumes: - db-data:/var/lib/postgresql/data ports: - "5432:5432" - environment: - POSTGRES_USER=user - POSTGRES_PASSWORD=password @@ -28,6 +26,10 @@ services: - POSTGRES_DB=kissj - DATABASE_HOST=postgresql - DB_TYPE=postgresql + - REDIS_HOST=dragonfly + - REDIS_PASSWORD=dragonfly + - REDIS_PORT=6379 + env_file: "compose.env" volumes: - ../../:/var/www/html @@ -35,7 +37,7 @@ services: caddy: image: quay.io/kissj/caddy-ubi ports: - - 80:80 + - 8080:8080 depends_on: - php-fpm links: @@ -44,18 +46,18 @@ services: environment: - PHPFPM_HOST=php-fpm - WEB_HOST=localhost + env_file: "compose.env" volumes: - ./Caddyfile:/etc/caddy/Caddyfile - ../../:/var/www/html #session storage - redis: - image: redis/redis-stack-server + dragonfly: + image: docker.dragonflydb.io/dragonflydb/dragonfly ports: - "6379:6379" environment: - - REDIS_HOST="redis" - - REDIS_HOST_PASSWORD="redis" + - DFLY_requirepass=dragonfly # debug mail server mailhog: From 6ffc9683842732412916f78068a990d45cee1a7b Mon Sep 17 00:00:00 2001 From: Michael Kaplan Date: Tue, 6 Aug 2024 19:35:34 +0200 Subject: [PATCH 3/6] chore: fix readme --- README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index b6578ead..bfa55635 100755 --- a/README.md +++ b/README.md @@ -40,10 +40,11 @@ kissj is scouts **registration system for national and international Scout Jambo ### Setup 1. Clone this repository: `git clone https://github.com/SkautDevs/kissj.git` -2. Setup environment (dotenv) `cp .env.example .env` -3. Run the make target, so you don't have to do install manually: `make local-dev-postgresql` -4. add line `127.0.0.1 kissj.local` to your `/etc/hosts` file +2. Copy `deploy/dev/compose.env.example` to `deploy/dev/compose.env` and fill in the values +3. Run the make target dev-up, so you don't have to do it manually: `make dev-up` +4. add line `127.0.0.1 kissj.local` to your `/etc/hosts` file(optional) 5. Open `http://kissj.local/v2/event/test-event-slug/` in your browser and you are good to go! +6. To stop the containers and remove them, run `make dev-down`(data should be preserved) ### Devstack From 6d6e1bd44b29775743c835eb8a4086e59c8c919d Mon Sep 17 00:00:00 2001 From: Lung Date: Tue, 6 Aug 2024 22:25:59 +0200 Subject: [PATCH 4/6] reformat admin dashboard --- .../translatable/admin/dashboard-admin.twig | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/Templates/translatable/admin/dashboard-admin.twig b/src/Templates/translatable/admin/dashboard-admin.twig index f8536a27..b9e80659 100755 --- a/src/Templates/translatable/admin/dashboard-admin.twig +++ b/src/Templates/translatable/admin/dashboard-admin.twig @@ -38,13 +38,6 @@

{% trans %}dashboard-admin.approvedTp{% endtrans %}: {{ troopParticipants.approvedCount }}

{% trans %}dashboard-admin.paidTp{% endtrans %}: {{ troopParticipants.paidCount }}

{% endif %} -
- {% if event.eventType.showFoodStats() %} -

{% trans %}dashboard-admin.foodCount{% endtrans %}

- {% for food, count in foodStatistic %} -

{{ food|trans }}: {{ count }}

- {% endfor %} - {% endif %}
{% if event.allowIsts %} @@ -65,12 +58,23 @@

{% trans %}dashboard-admin.approvedGuest{% endtrans %}: {{ guests.approvedCount }}

{% trans %}dashboard-admin.paidGuest{% endtrans %}: {{ guests.paidCount }}

{% endif %} -
+
+ +
+

{% trans %}dashboard-admin.entryCount{% endtrans %}

{% trans %}dashboard-admin.entryComing{% endtrans %}: {{ entryStatistic.coming }}

{% trans %}dashboard-admin.entryArrived{% endtrans %}: {{ entryStatistic.arrived }}

{% trans %}dashboard-admin.entryLeave{% endtrans %}: {{ entryStatistic.leave }}

+
+ {% if event.eventType.showFoodStats() %} +

{% trans %}dashboard-admin.foodCount{% endtrans %}

+ {% for food, count in foodStatistic %} +

{{ food|trans }}: {{ count }}

+ {% endfor %} + {% endif %} +
{% if event.eventType.showContingentPatrolStats %}

{% trans %}dashboard-admin.contingentPatrolStats{% endtrans %}

From e1c0eb2bc190f5caac5bb4a166b758e82d2ae400 Mon Sep 17 00:00:00 2001 From: paaton Date: Thu, 20 Jun 2024 20:20:48 +0200 Subject: [PATCH 5/6] "All data" and "Only paid" exports now sort participants based on their "patrol leader id", "troop leader id" or "id" in this order. --- src/Export/ExportService.php | 2 ++ src/Participant/ParticipantRepository.php | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/Export/ExportService.php b/src/Export/ExportService.php index fe1ad214..4acc92c3 100755 --- a/src/Export/ExportService.php +++ b/src/Export/ExportService.php @@ -42,6 +42,7 @@ public function healthDataToCSV(Event $event, User $adminUser): array [UserStatus::Paid], $event, $adminUser, + sortedByTroopOrPatrol: true, ); $rows = []; @@ -153,6 +154,7 @@ public function allRegistrationDataToCSV(Event $event, User $adminUser): array [UserStatus::Closed, UserStatus::Approved, UserStatus::Paid], $event, $adminUser, + sortedByTroopOrPatrol: true, ); $rows = [[ diff --git a/src/Participant/ParticipantRepository.php b/src/Participant/ParticipantRepository.php index 03c6d045..9bca08e9 100755 --- a/src/Participant/ParticipantRepository.php +++ b/src/Participant/ParticipantRepository.php @@ -43,6 +43,7 @@ public function getAllParticipantsWithStatus( array $orders = [], bool $filterEmptyParticipants = false, ?int $limit = null, + bool $sortedByTroopOrPatrol = false, ): array { $qb = $this->createFluent(); @@ -91,6 +92,10 @@ public function getAllParticipantsWithStatus( $participants = $this->filterEmptyParticipants($participants); } + if ($sortedByTroopOrPatrol) { + $participants = $this->sortParticipantsBasedOnTroopOrPatrol($participants); + } + return $participants; } @@ -195,6 +200,16 @@ private function filterEmptyParticipants(array $participants): array ); } + /** + * @param Participant[] $participants + * @return Participant[] + */ + private function sortParticipantsBasedOnTroopOrPatrol(array $participants): array{ + usort($participants, + function ($a, $b) { return ($a->troopLeader ?? $a->patrolLeader ?? $a->id) - ($b->troopLeader ?? $b->patrolLeader ?? $b->id); }); + return $participants; + } + /** * @param string[] $contingents * @return StatisticUserValueObject[] From fa0b1e3a1cb8df6cabd635fc84aa1bfaf634ac05 Mon Sep 17 00:00:00 2001 From: Lung Date: Tue, 6 Aug 2024 22:39:25 +0200 Subject: [PATCH 6/6] fixed phpstan --- src/Participant/ParticipantRepository.php | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/Participant/ParticipantRepository.php b/src/Participant/ParticipantRepository.php index 9bca08e9..66818e85 100755 --- a/src/Participant/ParticipantRepository.php +++ b/src/Participant/ParticipantRepository.php @@ -17,6 +17,7 @@ use kissj\Participant\Patrol\PatrolParticipant; use kissj\Participant\Patrol\PatrolsRoster; use kissj\Participant\Patrol\SinglePatrolRoster; +use kissj\Participant\Troop\TroopParticipant; use kissj\User\User; use kissj\User\UserRole; use kissj\User\UserStatus; @@ -204,9 +205,23 @@ private function filterEmptyParticipants(array $participants): array * @param Participant[] $participants * @return Participant[] */ - private function sortParticipantsBasedOnTroopOrPatrol(array $participants): array{ - usort($participants, - function ($a, $b) { return ($a->troopLeader ?? $a->patrolLeader ?? $a->id) - ($b->troopLeader ?? $b->patrolLeader ?? $b->id); }); + private function sortParticipantsBasedOnTroopOrPatrol(array $participants): array + { + usort( + $participants, + function (Participant $a, Participant $b) { + if ($a instanceof PatrolParticipant && $b instanceof PatrolParticipant) { + return $a->patrolLeader->id <=> $b->patrolLeader->id; + } + + if ($a instanceof TroopParticipant && $b instanceof TroopParticipant) { + return ($a->troopLeader->id ?? $a->id) <=> ($b->troopLeader->id ?? $a->id); + } + + return $a->id <=> $b->id; + }, + ); + return $participants; }