Skip to content

Commit

Permalink
Remove slug on image, add code on item image
Browse files Browse the repository at this point in the history
  • Loading branch information
lopes-vincent committed May 16, 2021
1 parent 8fbf329 commit 63462fe
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 65 deletions.
2 changes: 1 addition & 1 deletion Config/TheliaMain.sql
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ DROP TABLE IF EXISTS `library_image`;
CREATE TABLE `library_image`
(
`id` INTEGER NOT NULL AUTO_INCREMENT,
`slug` VARCHAR(255),
PRIMARY KEY (`id`)
) ENGINE=InnoDB;

Expand All @@ -28,6 +27,7 @@ CREATE TABLE `library_item_image`
`image_id` INTEGER,
`item_type` VARCHAR(255),
`item_id` INTEGER,
`code` VARCHAR(255),
`visible` TINYINT,
`position` INTEGER,
PRIMARY KEY (`id`),
Expand Down
2 changes: 1 addition & 1 deletion Config/schema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

<table name="library_image" namespace="TheliaLibrary\Model">
<column name="id" primaryKey="true" required="true" type="INTEGER" autoIncrement="true"/>
<column name="slug" type="VARCHAR"/>
<column name="title" type="VARCHAR" />
<column name="file_name" type="VARCHAR" />
<behavior name="i18n">
Expand All @@ -18,6 +17,7 @@
<column name="image_id" type="INTEGER" />
<column name="item_type" type="VARCHAR" />
<column name="item_id" type="INTEGER" />
<column name="code" type="VARCHAR"/>
<column name="visible" type="TINYINT" />
<column name="position" type="INTEGER" />
<foreign-key foreignTable="library_image" name="fk_library_item_image_image_id" onDelete="CASCADE" onUpdate="RESTRICT">
Expand Down
10 changes: 0 additions & 10 deletions Controller/Admin/ImageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ class ImageController extends BaseAdminOpenApiController
* type="string",
* ),
* @OA\Property(
* property="slug",
* type="string",
* ),
* @OA\Property(
* property="locale",
* type="string",
* ),
Expand Down Expand Up @@ -71,7 +67,6 @@ public function createImage(
$image = $libraryImageService->createImage(
$request->files->get('image'),
$request->request->get('title'),
$request->request->get('slug'),
$locale
);

Expand Down Expand Up @@ -105,10 +100,6 @@ public function createImage(
* type="string",
* ),
* @OA\Property(
* property="slug",
* type="string",
* ),
* @OA\Property(
* property="locale",
* type="string",
* ),
Expand Down Expand Up @@ -144,7 +135,6 @@ public function updateImage(
$imageId,
$request->files->get('image'),
$request->request->get('title'),
$request->request->get('slug'),
$locale
);

Expand Down
10 changes: 10 additions & 0 deletions Controller/Admin/ItemImageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ class ItemImageController extends BaseAdminOpenApiController
* type="integer",
* ),
* @OA\Property(
* property="code",
* type="string",
* ),
* @OA\Property(
* property="visible",
* type="boolean",
* )
Expand Down Expand Up @@ -72,6 +76,7 @@ public function createAssociation(
$openApiLibraryItemImage->getImageId(),
$openApiLibraryItemImage->getItemType(),
$openApiLibraryItemImage->getItemId(),
$openApiLibraryItemImage->getCode(),
$openApiLibraryItemImage->isVisible(),
$openApiLibraryItemImage->getPosition()
);
Expand Down Expand Up @@ -101,6 +106,10 @@ public function createAssociation(
* property="visible",
* type="boolean",
* ),
* @OA\Property(
* property="code",
* type="string",
* ),
* @OA\Property(
* property="position",
* type="integer",
Expand Down Expand Up @@ -135,6 +144,7 @@ public function updateAssociation(

$image = $libraryItemImageService->updateImageAssociation(
$itemImageId,
$data['code']?? null,
$data['visible']?? null,
$data['position']?? null,
$data['positionMovement']?? null
Expand Down
11 changes: 0 additions & 11 deletions Controller/Front/ImageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,6 @@ class ImageController extends BaseFrontOpenApiController
* )
* ),
* @OA\Parameter(
* name="slug",
* in="query",
* @OA\Schema(
* type="string"
* )
* ),
* @OA\Parameter(
* name="offset",
* in="query",
* @OA\Schema(
Expand Down Expand Up @@ -96,10 +89,6 @@ public function getImage(
$imageQuery->filterById($id);
}

if (null !== $slug = $request->get('slug')) {
$imageQuery->filterBySlug($slug);
}

if (null !== $limit = $request->get('limit', 20)) {
$imageQuery->limit($limit);
}
Expand Down
19 changes: 14 additions & 5 deletions Controller/Front/ItemImageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ class ItemImageController extends BaseFrontOpenApiController
* )
* ),
* @OA\Parameter(
* name="code",
* in="query",
* @OA\Schema(
* type="string"
* )
* ),
* @OA\Parameter(
* name="offset",
* in="query",
* @OA\Schema(
Expand Down Expand Up @@ -85,6 +92,10 @@ public function getItemImage(
$itemImageQuery->filterByItemId($itemId);
}

if (null !== $code = $request->get('code')) {
$itemImageQuery->filterByCode($code);
}

if (null !== $limit = $request->get('limit', 20)) {
$itemImageQuery->limit($limit);
}
Expand Down Expand Up @@ -125,7 +136,7 @@ function (LibraryItemImage $itemImage) use ($modelFactory, $locale) {
* )
* ),
* @OA\Parameter(
* name="slug",
* name="code",
* in="query",
* @OA\Schema(
* type="string"
Expand Down Expand Up @@ -202,10 +213,8 @@ public function getImage(
$itemImageQuery->filterByItemId($itemId);
}

if (null !== $slug = $request->get('slug')) {
$itemImageQuery->useLibraryImageQuery()
->filterBySlug($slug)
->endUse();
if (null !== $code = $request->get('code')) {
$itemImageQuery->filterByCode($code);
}

if (true === $request->get('onlyVisible', true)) {
Expand Down
28 changes: 0 additions & 28 deletions Model/Api/LibraryImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
use OpenApi\Model\Api\BaseApiModel;
use OpenApi\Constraint as Constraint;
use OpenApi\Model\Api\ModelFactory;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
use Thelia\TaxEngine\TaxEngine;
Expand Down Expand Up @@ -40,14 +38,6 @@ class LibraryImage extends BaseApiModel
*/
protected $title;

/**
* @var string
* @OA\Property(
* type="string",
* )
*/
protected $slug;

/**
* @var string
* @OA\Property(
Expand Down Expand Up @@ -129,24 +119,6 @@ public function setTitle(?string $title): LibraryImage
return $this;
}

/**
* @return string
*/
public function getSlug(): ?string
{
return $this->slug;
}

/**
* @param string $slug
* @return LibraryImage
*/
public function setSlug(?string $slug): LibraryImage
{
$this->slug = $slug;
return $this;
}

/**
* @return string
*/
Expand Down
26 changes: 26 additions & 0 deletions Model/Api/LibraryItemImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ class LibraryItemImage extends BaseApiModel
*/
protected $itemId;

/**
* @var string
* @OA\Property(
* type="string",
* )
*/
protected $code;

/**
* @var boolean
* @OA\Property(
Expand Down Expand Up @@ -165,6 +173,24 @@ public function setItemId(int $itemId): LibraryItemImage
return $this;
}

/**
* @return string
*/
public function getCode(): ?string
{
return $this->code;
}

/**
* @param string|null $code
* @return LibraryItemImage
*/
public function setCode(?string $code): LibraryItemImage
{
$this->code = $code;
return $this;
}

/**
* @return bool
*/
Expand Down
11 changes: 2 additions & 9 deletions Service/LibraryImageService.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,18 @@ public function __construct(
public function createImage(
UploadedFile $file,
string $title = null,
string $slug = null,
string $locale = null
): LibraryImage {
return $this->createOrUpdateImage($file, $title, $slug, $locale);
return $this->createOrUpdateImage($file, $title, $locale);
}

public function updateImage(
$imageId,
UploadedFile $file = null,
string $title = null,
string $slug = null,
string $locale = null
): LibraryImage {
return $this->createOrUpdateImage($file, $title, $slug, $locale, $imageId);
return $this->createOrUpdateImage($file, $title, $locale, $imageId);
}

public function deleteImage(
Expand Down Expand Up @@ -117,7 +115,6 @@ public function getImageFilePublicUrl($imageName = null, $width = null, $height
protected function createOrUpdateImage(
UploadedFile $file = null,
string $title = null,
string $slug = null,
string $locale = null,
int $imageId = null
) {
Expand All @@ -143,10 +140,6 @@ protected function createOrUpdateImage(
$image->setTitle($title);
}

if (null != $slug) {
$image->setSlug($slug);
}

if (null !== $file) {
// Remove old file if already exist for this locale
if (null !== $image->getFileName()) {
Expand Down
4 changes: 4 additions & 0 deletions Service/LibraryItemImageService.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public function associateImage(
$imageId,
$itemType,
$itemId,
$code = null,
$visible = true,
$position = null
): LibraryItemImage
Expand All @@ -38,6 +39,7 @@ public function associateImage(
->setImageId($imageId)
->setItemType($itemType)
->setItemId($itemId)
->setCode($code)
->setVisible($visible);

$itemImage->save();
Expand All @@ -51,6 +53,7 @@ public function associateImage(

public function updateImageAssociation(
$itemImageId,
$code = null,
$visible = true,
$position = null,
$positionMovement = null
Expand All @@ -64,6 +67,7 @@ public function updateImageAssociation(
throw new \Exception(Translator::getInstance()->trans("Can't update an item image that doesn't exist"));
}

$itemImage->setCode($code);
$itemImage->setVisible($visible);
$itemImage->save();

Expand Down

0 comments on commit 63462fe

Please sign in to comment.