Skip to content

Commit a32ef06

Browse files
committed
implement visibility
1 parent 70ecadb commit a32ef06

File tree

21 files changed

+252
-14
lines changed

21 files changed

+252
-14
lines changed

Api/Data/DocumentTypeInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ public function getCode(): string;
2121

2222
public function getScheduledImport(): bool;
2323

24+
public function getVisibility(): string;
25+
2426
public function getName(): string;
2527

2628
public function getFileSourcePath(): string;

Model/Config/Source/Visibility.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
/**
3+
* Copyright © OpenGento, All rights reserved.
4+
* See LICENSE bundled with this library for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Opengento\Document\Model\Config\Source;
9+
10+
use Magento\Framework\Data\OptionSourceInterface;
11+
12+
final class Visibility implements OptionSourceInterface
13+
{
14+
/**
15+
* @var string[]
16+
*/
17+
private $options;
18+
19+
public function __construct(
20+
array $options
21+
) {
22+
$this->options = $options;
23+
}
24+
25+
public function toOptionArray(): array
26+
{
27+
return $this->options;
28+
}
29+
}

Model/Document/Collection/SelectModifier.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ public function apply(AbstractDb $collection): void
2929
'file_locale',
3030
]);
3131
$collection->join(
32-
['mdt' => 'opengento_document_type'],
33-
'main_table.type_id=mdt.entity_id',
32+
['odt' => 'opengento_document_type'],
33+
'main_table.type_id=odt.entity_id',
3434
[
3535
'type_code' => 'code',
3636
'type_name' => 'name',
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
/**
3+
* Copyright © OpenGento, All rights reserved.
4+
* See LICENSE bundled with this library for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Opengento\Document\Model\Document\Collection;
9+
10+
use Magento\Framework\Data\Collection\AbstractDb;
11+
use Magento\Framework\Data\CollectionModifierInterface;
12+
use Opengento\Document\Model\ResourceModel\Document\Collection;
13+
14+
/**
15+
* @api
16+
*/
17+
final class VisibilityModifier implements CollectionModifierInterface
18+
{
19+
/**
20+
* @var string[]
21+
*/
22+
private $visibilities;
23+
24+
public function __construct(
25+
array $visibilities
26+
) {
27+
$this->visibilities = $visibilities;
28+
}
29+
30+
public function apply(AbstractDb $collection): void
31+
{
32+
/** @var Collection $collection */
33+
$collection->addVisibilityFilter(['in' => $this->visibilities]);
34+
}
35+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
/**
3+
* Copyright © OpenGento, All rights reserved.
4+
* See LICENSE bundled with this library for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Opengento\Document\Model\Document\SearchCriteria\CollectionProcessor;
9+
10+
use Magento\Framework\Api\Filter;
11+
use Magento\Framework\Api\SearchCriteria\CollectionProcessor\FilterProcessor\CustomFilterInterface;
12+
use Magento\Framework\Data\Collection\AbstractDb;
13+
use Opengento\Document\Model\ResourceModel\Document\Collection;
14+
15+
final class DefaultImageFilter implements CustomFilterInterface
16+
{
17+
public function apply(Filter $filter, AbstractDb $collection): bool
18+
{
19+
/** @var Collection $collection */
20+
$collection->addDefaultImage($filter->getField());
21+
22+
return true;
23+
}
24+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
/**
3+
* Copyright © OpenGento, All rights reserved.
4+
* See LICENSE bundled with this library for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Opengento\Document\Model\Document\SearchCriteria\CollectionProcessor;
9+
10+
use Magento\Framework\Api\Filter;
11+
use Magento\Framework\Api\SearchCriteria\CollectionProcessor\FilterProcessor\CustomFilterInterface;
12+
use Magento\Framework\Data\Collection\AbstractDb;
13+
use Opengento\Document\Model\ResourceModel\Document\Collection;
14+
15+
final class VisibilityFilter implements CustomFilterInterface
16+
{
17+
public function apply(Filter $filter, AbstractDb $collection): bool
18+
{
19+
/** @var Collection $collection */
20+
$collection->addVisibilityFilter([$filter->getConditionType() => $filter->getValue()]);
21+
22+
return true;
23+
}
24+
}

Model/DocumentType.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ public function getScheduledImport(): bool
4646
return (bool) $this->_getData('scheduled_import');
4747
}
4848

49+
public function getVisibility(): string
50+
{
51+
return (string) $this->_getData('visibility');
52+
}
53+
4954
public function getName(): string
5055
{
5156
return (string) $this->_getData('name');

Model/DocumentType/Visibility.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
/**
3+
* Copyright © OpenGento, All rights reserved.
4+
* See LICENSE bundled with this library for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Opengento\Document\Model\DocumentType;
9+
10+
final class Visibility
11+
{
12+
public const VISIBILITY_PRIVATE = 'private';
13+
public const VISIBILITY_PUBLIC = 'public';
14+
}

Model/DocumentTypeBuilder.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@ public function setScheduledImport(bool $scheduleImport): self
5555
return $this;
5656
}
5757

58+
public function setVisibility(string $visibility): self
59+
{
60+
$this->data['visibility'] = $visibility;
61+
62+
return $this;
63+
}
64+
5865
public function setName(string $name): self
5966
{
6067
$this->data['name'] = $name;

Model/File/ImageBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ private function createImage(string $filePath, array $settings): Image
132132
$destPath = File::IMAGE_CACHE_PATH . $this->imageId . DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, $path);
133133

134134
$directoryRead = $this->filesystem->getDirectoryRead(DirectoryList::MEDIA);
135-
if (!$directoryRead->isFile($destPath)) {
135+
if ($directoryRead->isFile($filePath) && !$directoryRead->isFile($destPath)) {
136136
$this->createCacheImage(
137137
$directoryRead->getAbsolutePath($filePath),
138138
$directoryRead->getAbsolutePath($destPath),

0 commit comments

Comments
 (0)