Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
joshine
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
joshine
Commits
af42297d
Commit
af42297d
authored
Mar 14, 2023
by
halweg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: admin 操作 reviews
parent
a9ab7d14
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
403 additions
and
1 deletions
+403
-1
app/code/Joshine/Review/Block/Images.php
+1
-1
app/code/Joshine/Review/Data/Form/Element/Image.php
+19
-0
app/code/Joshine/Review/Model/Repository/ImagesRepository.php
+140
-0
app/code/Joshine/Review/Plugin/Review/Block/Adminhtml/Edit/Form.php
+115
-0
app/code/Joshine/Review/Plugin/Review/Controller/Adminhtml/Product/Review/Save.php
+43
-0
app/code/Joshine/Review/etc/adminhtml/di.xml
+17
-0
app/code/Joshine/Review/view/adminhtml/templates/images.phtml
+68
-0
No files found.
app/code/Joshine/Review/Block/Images.php
View file @
af42297d
...
...
@@ -108,7 +108,7 @@ class Images extends \Magento\Framework\View\Element\Template
*/
public
function
getResizedImagePath
(
$item
)
:
string
{
return
$this
->
imageHelper
->
resize
(
$item
->
getPath
(),
self
::
REVIEW_COVER_WIDTH
*
2
);
return
$this
->
imageHelper
->
resize
(
$item
->
getPath
(),
self
::
REVIEW_COVER_WIDTH
);
}
/**
...
...
app/code/Joshine/Review/Data/Form/Element/Image.php
0 → 100644
View file @
af42297d
<?php
namespace
Joshine\Review\Data\Form\Element
;
/**
* Class Image - add multiple file upload
*/
class
Image
extends
\Magento\Framework\Data\Form\Element\Image
{
/**
* @return string
*/
public
function
getElementHtml
()
{
$html
=
parent
::
getElementHtml
();
$html
=
str_replace
(
'type="file"'
,
'type="file" multiple accept="image/*" '
,
$html
);
return
$html
;
}
}
app/code/Joshine/Review/Model/Repository/ImagesRepository.php
0 → 100644
View file @
af42297d
<?php
namespace
Joshine\Review\Model\Repository
;
use
Joshine\Review\Block\Images
;
use
Magento\Framework\Api\SearchCriteriaInterface
;
use
Magento\Framework\Exception\NoSuchEntityException
;
use
Magento\Framework\Exception\CouldNotDeleteException
;
use
Magento\Framework\Exception\CouldNotSaveException
;
use
Joshine\Review\Model\ResourceModel
;
use
Joshine\Review\Model\ImagesFactory
;
use
Magento\Framework\Api\Search\FilterGroup
;
use
Magento\Ui\Api\Data\BookmarkSearchResultsInterfaceFactory
;
use
Magento\Framework\Api\SortOrder
;
use
Magento\Framework\Api\SearchCriteriaBuilder
;
use
Magento\Framework\App\Filesystem\DirectoryList
;
use
Joshine\Review\Helper\ImageHelper
;
class
ImagesRepository
{
/**
* @var array
*/
private
$images
=
[];
/**
* @var ResourceModel\Images
*/
private
$imagesResource
;
/**
* @var ImagesFactory
*/
private
$imagesFactory
;
/**
* @var ResourceModel\Images\CollectionFactory
*/
private
$imagesCollectionFactory
;
/**
* @var \Magento\Framework\Filesystem\Io\File
*/
private
$ioFile
;
/**
* @var null|string
*/
private
$folderPath
=
null
;
/**
* @var \Magento\Framework\Filesystem
*/
private
$filesystem
;
public
function
__construct
(
\Joshine\Review\Model\ResourceModel\Images
$imagesResource
,
\Joshine\Review\Model\ImagesFactory
$imagesFactory
,
\Joshine\Review\Model\ResourceModel\Images\CollectionFactory
$imagesCollectionFactory
,
\Magento\Framework\Filesystem
$filesystem
,
\Magento\Framework\Filesystem\Io\File
$ioFile
)
{
$this
->
imagesResource
=
$imagesResource
;
$this
->
imagesFactory
=
$imagesFactory
;
$this
->
imagesCollectionFactory
=
$imagesCollectionFactory
;
$this
->
ioFile
=
$ioFile
;
$this
->
filesystem
=
$filesystem
;
}
/**
* {@inheritdoc}
*/
public
function
get
(
$imageId
)
{
if
(
!
isset
(
$this
->
images
[
$imageId
]))
{
/** @var \Joshine\Review\Model\Images $image */
$image
=
$this
->
imagesFactory
->
create
();
$this
->
imagesResource
->
load
(
$image
,
$imageId
);
if
(
!
$image
->
getImageId
())
{
throw
new
NoSuchEntityException
(
__
(
'Rule with specified ID "%1" not found.'
,
$imageId
));
}
$this
->
images
[
$imageId
]
=
$image
;
}
return
$this
->
images
[
$imageId
];
}
/**
* @return string
*/
private
function
getFolderPath
()
{
if
(
$this
->
folderPath
===
null
)
{
$this
->
folderPath
=
$this
->
filesystem
->
getDirectoryRead
(
DirectoryList
::
MEDIA
)
->
getAbsolutePath
(
ImageHelper
::
IMAGE_PATH
);
}
return
$this
->
folderPath
;
}
/**
* {@inheritdoc}
*/
public
function
delete
(
$image
)
{
try
{
$this
->
ioFile
->
rm
(
$this
->
getFolderPath
()
.
$image
->
getPath
());
$this
->
ioFile
->
rm
(
$this
->
getFolderPath
()
.
'resized/'
.
Images
::
REVIEW_COVER_WIDTH
);
$this
->
imagesResource
->
delete
(
$image
);
unset
(
$this
->
images
[
$image
->
getId
()]);
}
catch
(
\Exception
$e
)
{
if
(
$image
->
getImageId
())
{
throw
new
CouldNotDeleteException
(
__
(
'Unable to remove image with ID %1. Error: %2'
,
[
$image
->
getImageId
(),
$e
->
getMessage
()])
);
}
throw
new
CouldNotDeleteException
(
__
(
'Unable to remove image. Error: %1'
,
$e
->
getMessage
()));
}
return
true
;
}
/**
* {@inheritdoc}
*/
public
function
deleteById
(
$imageId
)
{
$model
=
$this
->
get
(
$imageId
);
$this
->
delete
(
$model
);
return
true
;
}
}
app/code/Joshine/Review/Plugin/Review/Block/Adminhtml/Edit/Form.php
0 → 100644
View file @
af42297d
<?php
namespace
Joshine\Review\Plugin\Review\Block\Adminhtml\Edit
;
use
Joshine\Review\Helper\BlockHelper
as
BlockHelper
;
use
Joshine\Review\Model\Repository\VoteRepository
;
use
Magento\Backend\Block\Widget\Form\Generic
as
MagentoForm
;
class
Form
{
/**
* @var \Magento\Framework\Registry
*/
private
$registry
;
/**
* @var VoteRepository
*/
private
$voteRepository
;
/**
* @var BlockHelper
*/
private
$blockHelper
;
/**
* @var \Magento\Framework\DataObjectFactory
*/
private
$dataObjectFactory
;
public
function
__construct
(
BlockHelper
$blockHelper
,
\Magento\Framework\Registry
$registry
,
VoteRepository
$voteRepository
,
\Magento\Framework\DataObjectFactory
$dataObjectFactory
)
{
$this
->
registry
=
$registry
;
$this
->
voteRepository
=
$voteRepository
;
$this
->
blockHelper
=
$blockHelper
;
$this
->
dataObjectFactory
=
$dataObjectFactory
;
}
/**
* @param MagentoForm $subject
* @param \Magento\Framework\Data\Form $form
* @return array
*/
public
function
beforeSetForm
(
MagentoForm
$subject
,
\Magento\Framework\Data\Form
$form
)
{
$fieldset
=
$form
->
getElement
(
'review_details'
)
?:
$form
->
getElement
(
'add_review_form'
);
$review
=
$this
->
registry
->
registry
(
'review_data'
)
?:
$this
->
dataObjectFactory
->
create
();
$fieldset
->
addField
(
'size_fits'
,
'select'
,
[
'label'
=>
__
(
'Size Fits'
),
'required'
=>
false
,
'values'
=>
[
[
'value'
=>
0
,
'label'
=>
__
(
'---select---'
)],
[
'value'
=>
1
,
'label'
=>
__
(
'Small'
)],
[
'value'
=>
2
,
'label'
=>
__
(
'True to Size'
)],
[
'value'
=>
3
,
'label'
=>
__
(
'Large'
)],
]
,
'name'
=>
'size_fits'
,
'value'
=>
(
int
)
$review
->
getData
(
'size_fits'
)
]
);
$form
->
setData
(
'enctype'
,
'multipart/form-data'
);
$imageHtml
=
trim
(
$this
->
blockHelper
->
getReviewImagesHtml
(
$review
->
getId
(),
8575
));
$addImageTitle
=
__
(
'Customer Images'
);
if
(
$imageHtml
)
{
$fieldset
->
addField
(
'added_images'
,
'note'
,
[
'label'
=>
__
(
'Customer Images'
),
'required'
=>
false
,
'name'
=>
'added_images'
,
'after_element_html'
=>
$imageHtml
]
);
$addImageTitle
=
''
;
}
$fieldset
->
addField
(
'review_images'
,
\Joshine\Review\Data\Form\Element\Image
::
class
,
[
'label'
=>
$addImageTitle
,
'name'
=>
'review_images[]'
,
'before_element_html'
=>
__
(
'Add new images'
)
]
);
return
[
$form
];
}
/**
* @param $review
* @return \Magento\Framework\Phrase
*/
private
function
getReviewHelpfulness
(
$review
)
{
$vote
=
$this
->
voteRepository
->
getVotesCount
(
$review
->
getId
());
return
__
(
'%1 people found this helpful; %2 found this unhelpful.'
,
$vote
[
'plus'
],
$vote
[
'minus'
]);
}
}
app/code/Joshine/Review/Plugin/Review/Controller/Adminhtml/Product/Review/Save.php
0 → 100644
View file @
af42297d
<?php
namespace
Joshine\Review\Plugin\Review\Controller\Adminhtml\Product\Review
;
use
Magento\Review\Controller\Adminhtml\Product\Save
as
MagentoReview
;
class
Save
{
private
$imagesRepository
;
public
function
__construct
(
\Joshine\Review\Model\Repository\ImagesRepository
$imagesRepository
)
{
$this
->
imagesRepository
=
$imagesRepository
;
}
/**
* @param MagentoReview $subject
* @param $result
* @return mixed
*/
public
function
afterExecute
(
MagentoReview
$subject
,
$result
)
{
$this
->
removeImages
(
$subject
);
return
$result
;
}
/**
* @param MagentoReview $subject
*/
private
function
removeImages
(
MagentoReview
$subject
)
{
$images
=
$subject
->
getRequest
()
->
getParam
(
'review_remove_image'
,
[]);
if
(
is_array
(
$images
))
{
foreach
(
$images
as
$id
=>
$image
)
{
$this
->
imagesRepository
->
deleteById
(
$id
);
}
}
}
}
app/code/Joshine/Review/etc/adminhtml/di.xml
0 → 100644
View file @
af42297d
<?xml version="1.0"?>
<config
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation=
"urn:magento:framework:ObjectManager/etc/config.xsd"
>
<type
name=
"Magento\Review\Block\Adminhtml\Edit\Form"
>
<plugin
name=
"Joshine_Review::add-answer-field"
type=
"Joshine\Review\Plugin\Review\Block\Adminhtml\Edit\Form"
/>
</type>
<type
name=
"Magento\Review\Block\Adminhtml\Add\Form"
>
<plugin
name=
"Joshine_Review::add-module-fields"
type=
"Joshine\Review\Plugin\Review\Block\Adminhtml\Edit\Form"
/>
</type>
<type
name=
"Magento\Review\Controller\Adminhtml\Product\Save"
>
<plugin
name=
"Joshine_Review::add-module-fields::remove-image"
type=
"Joshine\Review\Plugin\Review\Controller\Adminhtml\Product\Review\Save"
/>
</type>
</config>
app/code/Joshine/Review/view/adminhtml/templates/images.phtml
0 → 100644
View file @
af42297d
<?php
/** @var \Joshine\Review\Block\Images $block */
$collection
=
$block
->
getCollection
();
// phpcs:ignoreFile
?>
<style>
.review-images
{
display
:
flex
;
flex-wrap
:
wrap
;
}
.review-slider-item
{
position
:
relative
;
flex-shrink
:
0
;
width
:
150px
;
height
:
150px
;
line-height
:
150px
;
overflow
:
hidden
;
margin-right
:
5px
;
margin-bottom
:
0.2em
;
vertical-align
:
middle
;
border
:
1px
solid
#9E9E9E
;
}
.review-slider-item
img
{
width
:
100%
;
height
:
100%
;
object-fit
:
cover
;
}
.review-remove-image
{
line-height
:
normal
;
position
:
absolute
;
top
:
.3rem
;
left
:
.3rem
;
color
:
white
;
font-weight
:
lighter
;
padding
:
.3em
;
background-color
:
rgba
(
0
,
0
,
0
,
0.5
);
}
</style>
<?php
if
(
$collection
->
getSize
())
:
?>
<div
id=
"review-id-
<?=
$block
->
escapeHtmlAttr
(
$block
->
getReviewId
());
?>
"
class=
"review-images"
>
<?php
foreach
(
$collection
as
$item
)
:
?>
<div
class=
"review-slider-item"
data-review-js=
"slider-item"
>
<a
href=
"
<?=
$block
->
getFullImagePath
(
$item
);
?>
"
target=
"_blank"
class=
"review-image-link"
data-review-js=
"review-image"
>
<img
class=
"review-image"
src=
"
<?=
/* @noEscape */
$block
->
getResizedImagePath
(
$item
);
?>
"
title=
"
<?=
$block
->
escapeHtml
(
__
(
'Review image'
));
?>
"
alt=
"
<?=
$block
->
escapeHtml
(
__
(
'Review image'
));
?>
"
/>
</a>
<label
class=
"review-remove-image"
title=
"
<?=
$block
->
escapeHtml
(
__
(
'Remove image'
));
?>
"
>
<input
class=
"review-checkbox"
value=
"1"
type=
"checkbox"
name=
"review_remove_image[
<?=
/* @noEscape */
(
int
)
$item
->
getId
();
?>
]"
style=
"margin-top: 0;"
>
<?=
$block
->
escapeHtml
(
__
(
'Remove'
));
?>
</label>
</div>
<?php
endforeach
;
?>
</div>
<?php
endif
;
?>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment