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),

Model/ResourceModel/Document/Collection.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,21 @@ protected function _construct(): void
2323
$this->_init(Document::class, DocumentDb::class);
2424
}
2525

26-
public function addDefaultImage(string $alias = 'default_image_file_name'): Collection
26+
public function addDefaultImage(string $alias = 'default_image_file_name'): self
2727
{
2828
if ($this->_fieldsToSelect && in_array($alias, $this->_fieldsToSelect, true)) {
2929
$this->removeFieldFromSelect($alias);
3030
}
31-
$this->join(['mdt' => 'opengento_document_type'], 'main_table.type_id=mdt.entity_id', '');
32-
$this->getSelect()->columns([$alias => 'mdt.default_image_file_name']);
31+
$this->join(['odt' => 'opengento_document_type'], 'main_table.type_id=odt.entity_id', '');
32+
$this->getSelect()->columns([$alias => 'odt.default_image_file_name']);
33+
34+
return $this;
35+
}
36+
37+
public function addVisibilityFilter(array $condition): self
38+
{
39+
$this->join(['odt' => 'opengento_document_type'], 'main_table.type_id=odt.entity_id', '');
40+
$this->addFieldToFilter('odt.visibility', $condition);
3341

3442
return $this;
3543
}

etc/adminhtml/di.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
<item name="entity_id" xsi:type="boolean">true</item>
1515
<item name="code" xsi:type="boolean">true</item>
1616
<item name="scheduled_import" xsi:type="boolean">true</item>
17+
<item name="visibility" xsi:type="boolean">true</item>
1718
<item name="name" xsi:type="boolean">true</item>
1819
<item name="file_source_path" xsi:type="boolean">true</item>
1920
<item name="file_dest_path" xsi:type="boolean">true</item>

etc/db_schema.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<column xsi:type="int" name="entity_id" padding="10" unsigned="true" nullable="false" identity="true" comment="Document Type Entity ID"/>
1111
<column xsi:type="varchar" name="code" nullable="false" length="255" comment="Document Type Identifier"/>
1212
<column xsi:type="boolean" name="scheduled_import" nullable="false" comment="Document Type Schedule Import"/>
13+
<column xsi:type="varchar" name="visibility" nullable="false" length="255" comment="Document Type Visibility"/>
1314
<column xsi:type="text" name="name" nullable="false" comment="Document Type Title"/>
1415
<column xsi:type="text" name="file_source_path" nullable="false" comment="Files Source Path of the Document Type"/>
1516
<column xsi:type="text" name="file_dest_path" nullable="false" comment="Files Destination Path of the Document Type"/>
@@ -28,6 +29,9 @@
2829
<index referenceId="OPENGENTO_DOCUMENT_TYPE_SCHEDULED_IMPORT" indexType="btree">
2930
<column name="scheduled_import"/>
3031
</index>
32+
<index referenceId="OPENGENTO_DOCUMENT_TYPE_VISIBILITY" indexType="btree">
33+
<column name="visibility"/>
34+
</index>
3135
</table>
3236
<table name="opengento_document" resource="default" engine="innodb" comment="opengento_document">
3337
<column xsi:type="int" name="entity_id" padding="10" unsigned="true" nullable="false" identity="true" comment="Document Entity ID"/>

etc/di.xml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,27 @@
5151
<argument name="entityRelationComposite" xsi:type="object">Opengento\Document\Model\ResourceModel\Document\RelationComposite</argument>
5252
</arguments>
5353
</type>
54+
<!-- Search Criteria Filter -->
55+
<virtualType name="Opengento\Document\Model\Document\SearchCriteria\CollectionProcessor\FilterProcessor" type="Magento\Framework\Api\SearchCriteria\CollectionProcessor\FilterProcessor">
56+
<arguments>
57+
<argument name="customFilters" xsi:type="array">
58+
<item name="visibility" xsi:type="object">Opengento\Document\Model\Document\SearchCriteria\CollectionProcessor\VisibilityFilter</item>
59+
<item name="defaultImage" xsi:type="object">Opengento\Document\Model\Document\SearchCriteria\CollectionProcessor\DefaultImageFilter</item>
60+
</argument>
61+
</arguments>
62+
</virtualType>
63+
<virtualType name="Opengento\Document\Document\SearchCriteria\CollectionProcessor" type="Magento\Framework\Api\SearchCriteria\CollectionProcessor">
64+
<arguments>
65+
<argument name="processors" xsi:type="array">
66+
<item name="filters" xsi:type="object">Opengento\Document\Model\Document\SearchCriteria\CollectionProcessor\FilterProcessor</item>
67+
</argument>
68+
</arguments>
69+
</virtualType>
70+
<type name="Opengento\Document\Model\DocumentRepository">
71+
<arguments>
72+
<argument name="collectionProcessor" xsi:type="object">Opengento\Document\Document\SearchCriteria\CollectionProcessor</argument>
73+
</arguments>
74+
</type>
5475
<!-- Cache Settings -->
5576
<virtualType name="Opengento\Document\Model\ResourceModel\DocumentType\Collection\FetchStrategy" type="Magento\Framework\Data\Collection\Db\FetchStrategy\Cache">
5677
<arguments>
@@ -100,6 +121,20 @@
100121
</argument>
101122
</arguments>
102123
</type>
124+
<type name="Opengento\Document\Model\Config\Source\Visibility">
125+
<arguments>
126+
<argument name="options" xsi:type="array">
127+
<item name="private" xsi:type="array">
128+
<item name="label" xsi:type="string" translatable="true">Private</item>
129+
<item name="value" xsi:type="const">Opengento\Document\Model\DocumentType\Visibility::VISIBILITY_PRIVATE</item>
130+
</item>
131+
<item name="public" xsi:type="array">
132+
<item name="label" xsi:type="string" translatable="true">Public</item>
133+
<item name="value" xsi:type="const">Opengento\Document\Model\DocumentType\Visibility::VISIBILITY_PUBLIC</item>
134+
</item>
135+
</argument>
136+
</arguments>
137+
</type>
103138
<type name="Opengento\Document\Model\File\Uploader">
104139
<arguments>
105140
<argument name="codeMessages" xsi:type="array">

etc/directory.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © OpenGento, All rights reserved.
5+
* See LICENSE bundled with this library for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_MediaGalleryApi:etc/directory.xsd">
9+
<exclude>
10+
<patterns>
11+
<pattern name="captcha">/^document/</pattern>
12+
</patterns>
13+
</exclude>
14+
</config>

etc/frontend/di.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,11 @@
2222
</argument>
2323
</arguments>
2424
</type>
25+
<virtualType name="Opengento\Document\Model\Document\Collection\FrontendVisibilityModifier" type="Opengento\Document\Model\Document\Collection\VisibilityModifier">
26+
<arguments>
27+
<argument name="visibilities" xsi:type="array">
28+
<item name="public" xsi:type="const">Opengento\Document\Model\DocumentType\Visibility::VISIBILITY_PUBLIC</item>
29+
</argument>
30+
</arguments>
31+
</virtualType>
2532
</config>

etc/resource_document_types.xsd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
<xs:complexType name="documentTypeComplex">
2424
<xs:sequence>
2525
<xs:element type="xs:boolean" name="scheduledImport"/>
26+
<xs:element type="xs:string" name="visibility"/>
2627
<xs:element type="xs:string" name="name"/>
2728
<xs:element type="xs:string" name="fileSourcePath"/>
2829
<xs:element type="xs:string" name="fileDestPath"/>

etc/resource_document_types_merged.xsd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
<xs:complexType name="documentTypeComplex">
1717
<xs:sequence>
1818
<xs:element type="xs:boolean" name="scheduledImport"/>
19+
<xs:element type="xs:string" name="visibility"/>
1920
<xs:element type="xs:string" name="name"/>
2021
<xs:element type="xs:string" name="fileSourcePath"/>
2122
<xs:element type="xs:string" name="fileDestPath"/>

todo.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ see how many available files for a type
33

44
target blank or download
55

6-
visibility: Not visible, Visible in search
6+
visibility => what about serv conf

0 commit comments

Comments
 (0)