Browse Source

Merge branch 'feature/V8-5579-mise-en-place-du-nouveau-systme-' into develop

Olivier Massot 1 năm trước cách đây
mục cha
commit
eccd41ea8a

+ 8 - 0
icon.svg

@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools -->
+<svg width="800px" height="800px" viewBox="-2 0 260 260" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" preserveAspectRatio="xMidYMid">
+    <g>
+        <path d="M109.525333,4.05333333 C104.810667,8.08533333 101.461333,12.8 101.461333,26.88 C101.461333,65.1946667 149.824,180.288 182.762667,180.288 C186.462268,180.338187 190.147176,179.812799 193.685333,178.730667 L193.616,178.75 L192.774258,180.100166 C164.346546,225.411559 130.133077,258.650903 109.429541,259.317782 L108.8,259.328 C63.8293333,259.328 0,123.562667 0,63.8293333 C0,54.4213333 2.13333333,47.04 5.376,42.4533333 C20.8426667,23.552 69.2053333,8.74666667 109.525333,4.05333333 Z M172.672,0 C214.314667,0 256,6.72 256,30.2293333 C256,77.9306667 225.749333,135.744 210.304,135.744 C182.762667,135.744 148.437333,59.136 148.437333,20.8213333 C148.437333,3.34933333 155.136,0 172.608,0 L172.672,0 Z" fill="#F49700">
+
</path>
+    </g>
+</svg>

+ 1 - 1
ot_core/Classes/Domain/Repository/DonorRepository.php

@@ -65,7 +65,7 @@ class DonorRepository extends BaseApiRepository
         $donor->setWebsite($record['website']);
         $donor->setWording($record['wording']);
         $donor->setDisplayedOn($record['displayedOn']);
-        $donor->setLogo($record['logo'] ?? null);
+        $donor->setLogo($record['logo'] ? $this->apiService->getApiUri($record['logo'], true) : null);
 
         return $donor;
     }

+ 1 - 1
ot_core/Classes/Domain/Repository/EventRepository.php

@@ -190,7 +190,7 @@ class EventRepository extends BaseApiRepository
         $event->setRoomFloorSize($record['roomFloorSize']);
         $event->setZupId($record['zupId']);
         $event->setDeepLink($record['deepLink']);
-        $event->setImage($record['image']);
+        $event->setImage($record['image'] ? $this->apiService->getApiUri($record['image'], true) : null);
         $event->setPriceMini($record['priceMini']);
         $event->setMeetingSchedule($record['meetingSchedule']);
         $event->setApi($record['api']);

+ 1 - 3
ot_core/Classes/Domain/Repository/FederationStructureRepository.php

@@ -62,9 +62,7 @@ class FederationStructureRepository extends BaseApiRepository
         $federationStructure->setLongitude($record['longitude']);
         $federationStructure->setCountry($record['country']);
         $federationStructure->setCategories($record['categories']);
-        if ($record['logoId']) {
-            $federationStructure->setLogoUri($this->apiService->getApiUri('_internal/secure/files/') . $record['logoId']);
-        }
+        $federationStructure->setLogoUri($record['logoId']);
         $federationStructure->setParentId($record['n1Id']);
         $federationStructure->setParentName($record['n1Name']);
         $federationStructure->setParents($record['parents']);

+ 1 - 1
ot_core/Classes/Domain/Repository/MemberRepository.php

@@ -64,7 +64,7 @@ class MemberRepository extends BaseApiRepository
             $member->setMission($record['mission']);
         }
         $member->setPersonId((int)$record['personId']);
-        $member->setImage($record['image']);
+        $member->setImage($record['image'] ? $this->apiService->getApiUri($record['image'], true) : null);
 
         return $member;
     }

+ 7 - 4
ot_core/Classes/Service/OpentalentApiService.php

@@ -57,11 +57,12 @@ class OpentalentApiService
      * Return the API URI for the current repository
      *
      * @param string $trailing_part
+     * @param bool $public Si vrai, retourne l'url publique et non interne
      * @return string
      */
-    public function getApiUri(string $trailing_part = ""): string
+    public function getApiUri(string $trailing_part = "", bool $public = false): string
     {
-        $uri = OpentalentEnvService::get('API_BASE_URI');
+        $uri = OpentalentEnvService::get($public ? 'PUBLIC_API_BASE_URI' : 'API_BASE_URI');
         return rtrim($uri, '/') . '/' . ltrim($trailing_part, '/');
     }
 
@@ -95,15 +96,17 @@ class OpentalentApiService
      *
      * @param string $uri
      * @param array $params
+     * @param array $options
      * @return string
      * @throws ApiRequestException
      */
     public function getBody(
         string $uri,
-        array $params = []
+        array $params = [],
+        array $options = []
     ): string
     {
-        return (string)$this->get($uri, $params)->getBody();
+        return (string)$this->get($uri, $params, $options)->getBody();
     }
 
     /**

+ 1 - 1
ot_core/Classes/Service/OpentalentEnvService.php

@@ -18,7 +18,7 @@ class OpentalentEnvService
 {
     public static function get($varname) {
         if (!array_key_exists($varname, $GLOBALS['OT'])) {
-            throw new \RuntimeException('Un-existing OT environment variable requested: ' . $varname);
+            throw new \RuntimeException('Non-existing OT environment variable requested: ' . $varname);
         }
         return $GLOBALS['OT'][$varname];
     }

+ 28 - 0
ot_core/Classes/Service/OpentalentImageService.php

@@ -0,0 +1,28 @@
+<?php
+
+namespace Opentalent\OtCore\Service;
+
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+
+class OpentalentImageService
+{
+    public const IMAGE_SM = 'sm';
+    public const IMAGE_MD = 'md';
+    public const IMAGE_LG = 'lg';
+
+    public function __construct(
+        OpentalentApiService $apiService = null
+    )
+    {
+        $this->apiService = $apiService ?? GeneralUtility::makeInstance(OpentalentApiService::class);
+    }
+
+    public function getImageUrl(int $fileId, string $size = self::IMAGE_MD): string {
+        if (!in_array($size, [self::IMAGE_SM, self::IMAGE_MD, self::IMAGE_LG])) {
+            throw new \RuntimeException('Invalid $size : ' . $size);
+        }
+
+        $path = $this->apiService->getBody("api/public/files/$fileId/download/$size", ['relativePath' => true]);
+        return $this->apiService->getApiUri($path, true);
+    }
+}

+ 1 - 1
ot_core/ext_emconf.php

@@ -15,7 +15,7 @@ $EM_CONF[$_EXTKEY] = [
     'author' => 'Olivier Massot',
     'author_email' => 'olivier.massot@2iopenservice.fr',
     'state' => 'stable',
-    'version' => '0.7',
+    'version' => '0.7.1',
     'constraints' => [
         'depends' => [
             'typo3' => '10.4.0-11.5.99',

+ 2 - 0
ot_core/ext_localconf.php

@@ -28,6 +28,7 @@ $GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects'][TYPO3\CMS\Backend\Middleware\Backe
     'className' => Opentalent\OtCore\Middleware\OtBackendUserAuthenticator::class
 ];
 
+
 // ** Opentalent environment variables **
 // An array containing all or part of these variables could have been set before, for example
 // in the AdditionalConfiguration.php file.
@@ -35,6 +36,7 @@ $GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects'][TYPO3\CMS\Backend\Middleware\Backe
 // (/!\ do not forget to clear the cache after any update here)
 $GLOBALS['OT'] = array_merge([
     'API_BASE_URI' => 'http://docker.nginx.opentalent.fr',
+    'PUBLIC_API_BASE_URI' => 'https://local.api.opentalent.fr',
     'DB_HOST' => 'db',
     'DB_USER' => 'dbcloner',
     'DB_PASSWORD' => 'wWZ4hYcrmHLW2mUK',

+ 65 - 0
ot_templating/Classes/ViewHelpers/Image/GetSrcByIdViewHelper.php

@@ -0,0 +1,65 @@
+<?php
+
+namespace Opentalent\OtTemplating\ViewHelpers\Image;
+
+
+use Opentalent\OtCore\Service\OpentalentImageService;
+use Opentalent\OtCore\ViewHelpers\OtAbstractViewHelper;
+
+/**
+ * Returns the url of the requested image
+ *
+ *     {namespace ot=Opentalent\OtTemplating\ViewHelpers}
+ *
+ *     {ot:getImageUrl(fileId: 123, size: 'md')}
+ *
+ * @see ot_core/Classes/Service/OpentalentImageService.php
+ * @package Opentalent\OtTemplating\ViewHelpers
+ */
+class GetSrcByIdViewHelper extends OtAbstractViewHelper
+{
+    public OpentalentImageService $opentalentImageService;
+
+    /**
+     * @param OpentalentImageService $opentalentImageService
+     * @return void
+     */
+    public function injectOpentalentImageService(OpentalentImageService $opentalentImageService)
+    {
+        $this->opentalentImageService = $opentalentImageService;
+    }
+
+    /**
+     * -- This method is expected by Fluid --
+     * Declares the viewhelper's parameters
+     */
+    public function initializeArguments()
+    {
+        $this->registerArgument(
+            'fileId',
+            'int',
+            'The id of the File object',
+            true
+        );
+        $this->registerArgument(
+            'size',
+            'string',
+            'The expected size (sm, md, or lg)',
+            false,
+            'md'
+        );
+    }
+
+    /**
+     * -- This method is expected by Fluid --
+     * Renders the content as html
+     *
+     * @return string Rendered tag
+     */
+    public function render() {
+        $fileId = $this->arguments['fileId'];
+        $size = $this->arguments['size'];
+        return $this->opentalentImageService->getImageUrl($fileId, $size);
+    }
+
+}

+ 59 - 0
ot_templating/Classes/ViewHelpers/Image/GetSrcByPathViewHelper.php

@@ -0,0 +1,59 @@
+<?php
+
+namespace Opentalent\OtTemplating\ViewHelpers\Image;
+
+
+use Opentalent\OtCore\Exception\ApiRequestException;
+use Opentalent\OtCore\Service\OpentalentApiService;
+use Opentalent\OtCore\ViewHelpers\OtAbstractViewHelper;
+
+/**
+ * Returns the absolute url of the requested image
+ *
+ *     {namespace ot=Opentalent\OtTemplating\ViewHelpers}
+ *
+ *     {ot:image.getByUrl(path: "/media/cache/crop_md/organization/123/upload/my_picture.jpg")}
+ *
+ * @see ot_core/Classes/Service/OpentalentImageService.php
+ * @package Opentalent\OtTemplating\ViewHelpers
+ */
+class GetSrcByPathViewHelper extends OtAbstractViewHelper
+{
+    public OpentalentApiService $opentalentApiService;
+
+    /**
+     * @param OpentalentApiService $opentalentApiService
+     * @return void
+     */
+    public function injectOpentalentApiService(OpentalentApiService $opentalentApiService)
+    {
+        $this->opentalentApiService = $opentalentApiService;
+    }
+
+    /**
+     * -- This method is expected by Fluid --
+     * Declares the viewhelper's parameters
+     */
+    public function initializeArguments()
+    {
+        $this->registerArgument(
+            'path',
+            'string',
+            'The path (relative url) of the image in the storage',
+            true
+        );
+    }
+
+    /**
+     * -- This method is expected by Fluid --
+     * Renders the content as html
+     *
+     * @return string
+     * @throws ApiRequestException
+     */
+    public function render()
+    {
+        $path = $this->arguments['path'];
+        return $this->opentalentApiService->getApiUri($path, true);
+    }
+}

+ 1 - 1
ot_templating/Resources/Private/Partials/Classic/EventsIndex.html

@@ -66,7 +66,7 @@
                     <div class="event-poster">
                         <f:if condition="{event.image}">
                             <f:then>
-                                <img src='{event.image}' alt="poster" />
+                                <img src="{event.image}" alt="poster" />
                             </f:then>
                             <f:else>
                                 <f:image src="EXT:ot_templating/Resources/Public/media/event-default.jpg" alt="poster" />

+ 1 - 1
ot_templating/Resources/Private/Partials/Classic/MembersList.html

@@ -12,7 +12,7 @@
                         <p class="ot-member-image">
                             <f:if condition="{member.image}">
                                 <f:then>
-                                    <img src="{member.image}/160x0" alt=""/>
+                                    <img src="{member.image}" alt=""/>
                                 </f:then>
                                 <f:else if="{member.gender}=='MISTER'">
                                     <f:image src="EXT:ot_templating/Resources/Public/media/man-default.jpg"/>

+ 1 - 1
ot_templating/Resources/Private/Partials/Classic/Topbar.html

@@ -6,7 +6,7 @@
     <div class="topbar-logo">
         <f:if condition="{settings.structureLogoId}">
             <a href="{ot:rootPage.getUri()}" title="{settings.structureName}">
-                <img src="{ot:request.getOtEnvVar(argument: 'FILE_STORAGE_URL')}{settings.structureLogoId}" alt="{settings.structureName}"/>
+                <img src="{ot:image.getSrcById(fileId: settings.structureLogoId, size: 'sm')}" alt="{settings.structureName}"/>
             </a>
         </f:if>
     </div>

+ 1 - 1
ot_templating/Resources/Private/Partials/Modern/MembersList.html

@@ -13,7 +13,7 @@
                             <f:if condition="{member.image}">
                                 <f:then>
                                     <f:image class="defer"
-                                             data="{'src':'{member.image}/160x0'}"
+                                             data="{'src':'{member.image}'}"
                                              src="EXT:ot_templating/Resources/Public/media/loading.png"/>
                                 </f:then>
                                 <f:else if="{member.gender}=='MISTER'">

+ 1 - 1
ot_templating/Resources/Private/Partials/Modern/Menu.html

@@ -25,7 +25,7 @@
                                     <f:then>
                                         <a href="{ot:rootPage.getUri()}" title="{settings.structureName}">
                                             <img id="logo_img"
-                                                 src="{ot:request.getOtEnvVar(argument: 'FILE_STORAGE_URL')}{settings.structureLogoId}"
+                                                 src="{ot:image.getSrcById(fileId: settings.structureLogoId, size: 'sm')}"
                                                  alt="{settings.structureName}"/>
                                         </a>
                                     </f:then>