diff --git a/.idea/Easy_solution.iml b/.idea/Easy_solution.iml index 06ed20b..8731bcf 100644 --- a/.idea/Easy_solution.iml +++ b/.idea/Easy_solution.iml @@ -8,6 +8,7 @@ + diff --git a/.idea/php.xml b/.idea/php.xml index f0ca9da..ee12199 100644 --- a/.idea/php.xml +++ b/.idea/php.xml @@ -83,7 +83,6 @@ - @@ -163,6 +162,8 @@ + + diff --git a/composer.json b/composer.json index e55871b..1b37bc3 100644 --- a/composer.json +++ b/composer.json @@ -13,6 +13,7 @@ "doctrine/doctrine-migrations-bundle": "^3.4", "doctrine/orm": "^3.3", "firebase/php-jwt": "^6.11", + "knplabs/knp-time-bundle": "^2.4", "league/oauth2-server-bundle": "^0.11.0", "nelmio/cors-bundle": "^2.5", "phpdocumentor/reflection-docblock": "^5.6", @@ -49,7 +50,6 @@ "symfony/validator": "7.2.*", "symfony/web-link": "7.2.*", "symfony/yaml": "7.2.*", - "twig/extra-bundle": "^2.12|^3.0", "twig/twig": "^2.12|^3.0" }, "config": { diff --git a/composer.lock b/composer.lock index 014e148..b6dfda6 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "ec18ea9254732e2793a2fc5e0e6919aa", + "content-hash": "51f33a9cb3451faf4b58c6984f46bb5d", "packages": [ { "name": "composer/semver", @@ -1411,6 +1411,81 @@ }, "time": "2025-04-09T20:32:01+00:00" }, + { + "name": "knplabs/knp-time-bundle", + "version": "v2.4.0", + "source": { + "type": "git", + "url": "https://github.com/KnpLabs/KnpTimeBundle.git", + "reference": "93e9528415b28a19872d74b28e816045c0fd217b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/KnpLabs/KnpTimeBundle/zipball/93e9528415b28a19872d74b28e816045c0fd217b", + "reference": "93e9528415b28a19872d74b28e816045c0fd217b", + "shasum": "" + }, + "require": { + "php": ">=8.1", + "symfony/config": "^5.4|^6.0|^7.0", + "symfony/dependency-injection": "^5.4|^6.0|^7.0", + "symfony/translation": "^5.4|^6.0|^7.0" + }, + "conflict": { + "phpunit/phpunit": "<8.0" + }, + "require-dev": { + "phpstan/phpstan": "^1.11", + "phpunit/phpunit": "^9.6", + "symfony/framework-bundle": "^5.4|^6.0|^7.0", + "symfony/phpunit-bridge": "^5.4|^6.0|^7.0", + "symfony/twig-bundle": "^5.4|^6.0|^7.0" + }, + "suggest": { + "symfony/twig-bundle": "to use the Twig `time_diff()` function and `|time_diff`/`|duration` filter" + }, + "type": "symfony-bundle", + "extra": { + "branch-alias": { + "dev-master": "2.x-dev" + } + }, + "autoload": { + "psr-4": { + "Knp\\Bundle\\TimeBundle\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "KnpLabs Team", + "homepage": "https://knplabs.com" + }, + { + "name": "Symfony Community", + "homepage": "https://github.com/KnpLabs/KnpTimeBundle/contributors" + } + ], + "description": "Making your dates and durations look sensible and descriptive", + "homepage": "https://github.com/KnpLabs/KnpTimeBundle", + "keywords": [ + "bundle", + "date", + "descriptive time", + "duration", + "knp", + "knplabs", + "time" + ], + "support": { + "issues": "https://github.com/KnpLabs/KnpTimeBundle/issues", + "source": "https://github.com/KnpLabs/KnpTimeBundle/tree/v2.4.0" + }, + "time": "2024-06-11T09:38:28+00:00" + }, { "name": "lcobucci/clock", "version": "3.3.1", @@ -8841,80 +8916,6 @@ ], "time": "2025-06-03T06:57:06+00:00" }, - { - "name": "twig/extra-bundle", - "version": "v3.21.0", - "source": { - "type": "git", - "url": "https://github.com/twigphp/twig-extra-bundle.git", - "reference": "62d1cf47a1aa009cbd07b21045b97d3d5cb79896" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/twigphp/twig-extra-bundle/zipball/62d1cf47a1aa009cbd07b21045b97d3d5cb79896", - "reference": "62d1cf47a1aa009cbd07b21045b97d3d5cb79896", - "shasum": "" - }, - "require": { - "php": ">=8.1.0", - "symfony/framework-bundle": "^5.4|^6.4|^7.0", - "symfony/twig-bundle": "^5.4|^6.4|^7.0", - "twig/twig": "^3.2|^4.0" - }, - "require-dev": { - "league/commonmark": "^1.0|^2.0", - "symfony/phpunit-bridge": "^6.4|^7.0", - "twig/cache-extra": "^3.0", - "twig/cssinliner-extra": "^3.0", - "twig/html-extra": "^3.0", - "twig/inky-extra": "^3.0", - "twig/intl-extra": "^3.0", - "twig/markdown-extra": "^3.0", - "twig/string-extra": "^3.0" - }, - "type": "symfony-bundle", - "autoload": { - "psr-4": { - "Twig\\Extra\\TwigExtraBundle\\": "" - }, - "exclude-from-classmap": [ - "/Tests/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com", - "homepage": "http://fabien.potencier.org", - "role": "Lead Developer" - } - ], - "description": "A Symfony bundle for extra Twig extensions", - "homepage": "https://twig.symfony.com", - "keywords": [ - "bundle", - "extra", - "twig" - ], - "support": { - "source": "https://github.com/twigphp/twig-extra-bundle/tree/v3.21.0" - }, - "funding": [ - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/twig/twig", - "type": "tidelift" - } - ], - "time": "2025-02-19T14:29:33+00:00" - }, { "name": "twig/twig", "version": "v3.21.1", diff --git a/config/bundles.php b/config/bundles.php index 1f80250..2958f8b 100644 --- a/config/bundles.php +++ b/config/bundles.php @@ -9,7 +9,6 @@ return [ Symfony\Bundle\WebProfilerBundle\WebProfilerBundle::class => ['dev' => true, 'test' => true], Symfony\UX\StimulusBundle\StimulusBundle::class => ['all' => true], Symfony\UX\Turbo\TurboBundle::class => ['all' => true], - Twig\Extra\TwigExtraBundle\TwigExtraBundle::class => ['all' => true], Symfony\Bundle\SecurityBundle\SecurityBundle::class => ['all' => true], Symfony\Bundle\MonologBundle\MonologBundle::class => ['all' => true], Symfony\Bundle\MakerBundle\MakerBundle::class => ['dev' => true], @@ -18,4 +17,5 @@ return [ League\Bundle\OAuth2ServerBundle\LeagueOAuth2ServerBundle::class => ['all' => true], Nelmio\CorsBundle\NelmioCorsBundle::class => ['all' => true], Symfony\Bundle\MercureBundle\MercureBundle::class => ['all' => true], + Knp\Bundle\TimeBundle\KnpTimeBundle::class => ['all' => true], ]; diff --git a/src/Controller/OrganizationController.php b/src/Controller/OrganizationController.php index 4eec39a..c0ee87a 100644 --- a/src/Controller/OrganizationController.php +++ b/src/Controller/OrganizationController.php @@ -5,6 +5,7 @@ namespace App\Controller; use App\Entity\Apps; use App\Entity\Roles; use App\Entity\UsersOrganizations; +use App\Service\ActionService; use App\Service\OrganizationsService; use App\Service\UserOrganizationService; use Doctrine\ORM\EntityManagerInterface; @@ -52,7 +53,7 @@ class OrganizationController extends AbstractController } #[Route(path: '/{id}', name: 'show', methods: ['GET'])] - public function show(int $id): Response + public function show(int $id, ActionService $actionService): Response { if ($this->isGranted('ROLE_ADMIN')) { $user = $this->getUser(); @@ -78,6 +79,15 @@ class OrganizationController extends AbstractController // get all applications $applications = $this->organizationsService->getApplicationsWithAccessStatus($organization); + $actions = $organization->getActions()->toArray(); + $activities = array_map(static function($activity) use ($actionService) { + return [ + 'date' => $activity->getDate(), // or however you access the date + 'actionType' => $activity->getActionType(), + 'users' => $activity->getUsers(), + 'color' => $actionService->getActivityColor($activity->getDate()) + ]; + }, $actions); }else{ throw $this->createNotFoundException(self::ACCESS_DENIED); } @@ -88,6 +98,7 @@ class OrganizationController extends AbstractController 'newUsers' => $newUsers, 'org' => $org[0], 'applications' => $applications, + 'activities' => $activities ]); } diff --git a/src/Service/ActionService.php b/src/Service/ActionService.php new file mode 100644 index 0000000..27825b0 --- /dev/null +++ b/src/Service/ActionService.php @@ -0,0 +1,22 @@ +getTimestamp() - $activityTime->getTimestamp(); + + if ($diffInSeconds < 15 * 60) { // less than 15 minutes + return '#086572'; + } + + if ($diffInSeconds < 60 * 60) { // less than 1 hour + return '#247208'; + } + return '#C76633'; + } +} diff --git a/symfony.lock b/symfony.lock index 781a3e1..bc91fb8 100644 --- a/symfony.lock +++ b/symfony.lock @@ -35,6 +35,9 @@ "migrations/.gitignore" ] }, + "knplabs/knp-time-bundle": { + "version": "v2.4.0" + }, "league/oauth2-server-bundle": { "version": "0.11", "recipe": { @@ -381,8 +384,5 @@ "files": [ "config/packages/messenger.yaml" ] - }, - "twig/extra-bundle": { - "version": "v3.20.0" } } diff --git a/templates/organization/activity.html.twig b/templates/organization/activity.html.twig index 81ea905..1c210d4 100644 --- a/templates/organization/activity.html.twig +++ b/templates/organization/activity.html.twig @@ -6,32 +6,20 @@

{{ title }}

-{# {% if activities|length == 0 %}#} -{#

Aucune activité récente.

#} -{# {% else %}#} + {% if activities|length == 0 %} +

Aucune activité récente.

+ {% else %} + {% set sortedActivities = activities|sort((a, b) => a.date <=> b.date)|reverse %}
    -{# {% for activity in activities %}#} -
  • -

    5 mins ago

    -
  • -
  • -

    5 mins ago

    -
  • -
  • -

    5 mins ago

    -
  • -
  • -

    5 mins ago

    -
  • -
  • -

    5 mins ago

    -
  • -
  • -

    5 mins ago

    -
  • - -{# {% endfor %}#} + {% for activity in sortedActivities%} + {% include 'user/organization/userActivity.html.twig' with { + activityTime: activity.date, + action: activity.actionType, + userName: activity.users.name, + color: activity.color + } %} + {% endfor %}
-{# {% endif %}#} + {% endif %}
{% endblock %} \ No newline at end of file diff --git a/templates/user/organization/userActivity.html.twig b/templates/user/organization/userActivity.html.twig new file mode 100644 index 0000000..aa12274 --- /dev/null +++ b/templates/user/organization/userActivity.html.twig @@ -0,0 +1,17 @@ +{% block body %} + +
+
+
+ +

+ + {{ activityTime|ago }}

+
+
+
+

{{ userName }} - {{ action }}

+
+
+ +{% endblock %} \ No newline at end of file