Skip to content

Commit ff24487

Browse files
author
Zane
committed
Article editor: images gallery
1 parent 1cbda6e commit ff24487

File tree

2 files changed

+31
-10
lines changed

2 files changed

+31
-10
lines changed

‎src/Service/Cms/Article.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -174,15 +174,20 @@ public function getImages() : array
174174

175175
$this->arrImages = [];
176176

177-
foreach( $this->entity->getImages() as $junction ) {
177+
foreach($this->entity->getImages() as $junction) {
178178

179-
$image = $junction->getImage();
180-
$idImage = $image->getId();
181-
$this->arrImages[$idImage] = $this->factory->createImage($image);
179+
$junctionRanking = $junction->getRanking();
180+
181+
$imageEntity= $junction->getImage();
182+
$idImage = $imageEntity->getId();
183+
184+
$this->arrImages[$idImage] =
185+
$this->factory->createImage($imageEntity)
186+
->setTempOrder($junctionRanking);
182187
}
183188

184189
usort($this->arrImages, function(Image $img1, Image $img2) {
185-
return $img2->getEntity()->getCreatedAt() <=> $img1->getEntity()->getCreatedAt();
190+
return $img2->getTempOrder() <=> $img1->getTempOrder();
186191
});
187192
}
188193

‎src/Service/Cms/Image.php

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ class Image extends BaseCmsService
8383
protected ImageEntity $entity;
8484
protected static ?string $buildFileExtension = null;
8585
protected ?string $lastBuiltImageMimeType = null;
86+
protected int $tempOrder = 1;
8687

8788

8889
public function __construct(protected Factory $factory)
@@ -390,15 +391,30 @@ public static function getClientSupportedBestFormat() : string
390391

391392
public static function getNewsletterSpotlightId() : int
392393
{
393-
return
394-
array_rand(array_flip(static::IDS_NEWSLETTER_SPOTLIGHT));
394+
return array_rand(array_flip(static::IDS_NEWSLETTER_SPOTLIGHT));
395395
}
396396

397-
public function getFormat() : ?string { return $this->entity->getFormat(); }
398397

399398
public function getUrl(Article $article, string $size) : string
400-
{ return $this->factory->getImageUrlGenerator()->generateUrl($this, $article, $size); }
399+
{
400+
return $this->factory->getImageUrlGenerator()->generateUrl($this, $article, $size);
401+
}
402+
401403

402404
public function getShortUrl(string $size) : string
403-
{ return $this->factory->getImageUrlGenerator()->generateShortUrl($this, $size); }
405+
{
406+
return $this->factory->getImageUrlGenerator()->generateShortUrl($this, $size);
407+
}
408+
409+
410+
public function getFormat() : ?string { return $this->entity->getFormat(); }
411+
412+
413+
public function getTempOrder() : int { return $this->tempOrder; }
414+
415+
public function setTempOrder(int $tempOrder) : static
416+
{
417+
$this->tempOrder = $tempOrder;
418+
return $this;
419+
}
404420
}

0 commit comments

Comments
 (0)