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
5f2d4a02
Commit
5f2d4a02
authored
Mar 20, 2023
by
halweg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bug fix
parent
187e3e9b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
124 additions
and
124 deletions
+124
-124
app/code/Joshine/Review/Block/Images.php
+124
-124
No files found.
app/code/Joshine/Review/Block/Images.php
View file @
5f2d4a02
<?php
namespace
Joshine\Review\Block
;
use
Joshine\Review\Model\ResourceModel\Images\Collection
;
use
Joshine\Review\Helper\ImageHelper
;
use
Magento\Framework\View\Element\Template
;
use
Joshine\Review\Model\ResourceModel\Images\CollectionFactory
;
/**
* Class Images
* @package Amasty\AdvancedReview\Block
*/
class
Images
extends
\Magento\Framework\View\Element\Template
{
//评论缩略图宽度
const
REVIEW_COVER_WIDTH
=
200
;
/**
* @var string
*/
protected
$_template
=
'Joshine_Review::images.phtml'
;
private
$reviewId
;
private
$productId
;
/**
* @var int
*/
/**
* @var \Magento\Framework\Json\EncoderInterface
*/
private
$jsonEncoder
;
/**
* @var CollectionFactory
*/
private
$collectionFactory
;
/**
* @var ImageHelper
*/
private
$imageHelper
;
public
function
__construct
(
Template\Context
$context
,
CollectionFactory
$collectionFactory
,
\Magento\Framework\Json\EncoderInterface
$jsonEncoder
,
ImageHelper
$imageHelper
,
array
$data
=
[]
)
{
parent
::
__construct
(
$context
,
$data
);
$this
->
jsonEncoder
=
$jsonEncoder
;
$this
->
collectionFactory
=
$collectionFactory
;
$this
->
imageHelper
=
$imageHelper
;
}
/**
* @return int
*/
public
function
getReviewId
()
:
int
{
return
$this
->
reviewId
;
}
/**
* @param $reviewId
*
* @return $this
*/
public
function
setReviewId
(
$reviewId
)
:
Images
{
$this
->
reviewId
=
$reviewId
;
return
$this
;
}
public
function
setProductId
(
$productId
)
:
Images
{
$this
->
productId
=
$productId
;
return
$this
;
}
public
function
getProductId
()
{
return
$this
->
productId
;
}
public
function
getCollection
()
{
/** @var Collection $collection */
$collection
=
$this
->
collectionFactory
->
create
()
->
addFieldToSelect
(
'*'
)
->
addFieldToFilter
(
'review_id'
,
$this
->
getReviewId
());
return
$collection
;
}
public
function
getFullImagePath
(
$item
)
:
string
{
return
$this
->
imageHelper
->
getFullPath
(
$item
->
getPath
());
}
/**
* @param $item
* @return string
* @throws \Magento\Framework\Exception\NoSuchEntityException
*/
public
function
getResizedImagePath
(
$item
)
:
string
{
return
$this
->
imageHelper
->
resize
(
$item
->
getPath
(),
self
::
REVIEW_COVER_WIDTH
);
}
/**
* @param $item
* @return string
* @throws \Magento\Framework\Exception\NoSuchEntityException
*/
public
function
getResizedImagePathByLimit
(
$item
,
$width
)
:
string
{
return
$this
->
imageHelper
->
resize
(
$item
->
getPath
(),
$width
);
}
}
<?php
namespace
Joshine\Review\Block
;
use
Joshine\Review\Model\ResourceModel\Images\Collection
;
use
Joshine\Review\Helper\ImageHelper
;
use
Magento\Framework\View\Element\Template
;
use
Joshine\Review\Model\ResourceModel\Images\CollectionFactory
;
/**
* Class Images
* @package Amasty\AdvancedReview\Block
*/
class
Images
extends
\Magento\Framework\View\Element\Template
{
//评论缩略图宽度
const
REVIEW_COVER_WIDTH
=
200
;
/**
* @var string
*/
protected
$_template
=
'Joshine_Review::images.phtml'
;
private
$reviewId
;
private
$productId
;
/**
* @var int
*/
/**
* @var \Magento\Framework\Json\EncoderInterface
*/
private
$jsonEncoder
;
/**
* @var CollectionFactory
*/
private
$collectionFactory
;
/**
* @var ImageHelper
*/
private
$imageHelper
;
public
function
__construct
(
Template\Context
$context
,
CollectionFactory
$collectionFactory
,
\Magento\Framework\Json\EncoderInterface
$jsonEncoder
,
ImageHelper
$imageHelper
,
array
$data
=
[]
)
{
parent
::
__construct
(
$context
,
$data
);
$this
->
jsonEncoder
=
$jsonEncoder
;
$this
->
collectionFactory
=
$collectionFactory
;
$this
->
imageHelper
=
$imageHelper
;
}
/**
* @return int
*/
public
function
getReviewId
()
{
return
$this
->
reviewId
;
}
/**
* @param $reviewId
*
* @return $this
*/
public
function
setReviewId
(
$reviewId
)
{
$this
->
reviewId
=
$reviewId
;
return
$this
;
}
public
function
setProductId
(
$productId
)
{
$this
->
productId
=
$productId
;
return
$this
;
}
public
function
getProductId
()
{
return
$this
->
productId
;
}
public
function
getCollection
()
{
/** @var Collection $collection */
$collection
=
$this
->
collectionFactory
->
create
()
->
addFieldToSelect
(
'*'
)
->
addFieldToFilter
(
'review_id'
,
$this
->
getReviewId
());
return
$collection
;
}
public
function
getFullImagePath
(
$item
)
{
return
$this
->
imageHelper
->
getFullPath
(
$item
->
getPath
());
}
/**
* @param $item
* @return string
* @throws \Magento\Framework\Exception\NoSuchEntityException
*/
public
function
getResizedImagePath
(
$item
)
{
return
$this
->
imageHelper
->
resize
(
$item
->
getPath
(),
self
::
REVIEW_COVER_WIDTH
);
}
/**
* @param $item
* @return string
* @throws \Magento\Framework\Exception\NoSuchEntityException
*/
public
function
getResizedImagePathByLimit
(
$item
,
$width
)
{
return
$this
->
imageHelper
->
resize
(
$item
->
getPath
(),
$width
);
}
}
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