Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Comments.php
Go to the documentation of this file.
1 <?php
7 
13 {
18 
23 
28 
34  protected $_entity;
35 
42 
50  public function __construct(
51  \Magento\Framework\View\Element\Template\Context $context,
52  \Magento\Sales\Model\ResourceModel\Order\Invoice\Comment\CollectionFactory $invoiceCollectionFactory,
53  \Magento\Sales\Model\ResourceModel\Order\Creditmemo\Comment\CollectionFactory $memoCollectionFactory,
54  \Magento\Sales\Model\ResourceModel\Order\Shipment\Comment\CollectionFactory $shipmentCollectionFactory,
55  array $data = []
56  ) {
57  parent::__construct($context, $data);
58  $this->_invoiceCollectionFactory = $invoiceCollectionFactory;
59  $this->_memoCollectionFactory = $memoCollectionFactory;
60  $this->_shipmentCollectionFactory = $shipmentCollectionFactory;
61  }
62 
69  public function setEntity($entity)
70  {
71  $this->_entity = $entity;
72  $this->_commentCollection = null;
73  // Changing model and resource model can lead to change of comment collection
74  return $this;
75  }
76 
82  public function getEntity()
83  {
84  return $this->_entity;
85  }
86 
93  public function getComments()
94  {
95  if ($this->_commentCollection === null) {
96  $entity = $this->getEntity();
97  if ($entity instanceof \Magento\Sales\Model\Order\Invoice) {
98  $this->_commentCollection = $this->_invoiceCollectionFactory->create();
99  } elseif ($entity instanceof \Magento\Sales\Model\Order\Creditmemo) {
100  $this->_commentCollection = $this->_memoCollectionFactory->create();
101  } elseif ($entity instanceof \Magento\Sales\Model\Order\Shipment) {
102  $this->_commentCollection = $this->_shipmentCollectionFactory->create();
103  } else {
104  throw new \Magento\Framework\Exception\LocalizedException(__('We found an invalid entity model.'));
105  }
106 
107  $this->_commentCollection->setParentFilter($entity)->setCreatedAtOrder()->addVisibleOnFrontFilter();
108  }
109 
111  }
112 
118  public function hasComments()
119  {
120  return $this->getComments()->count() > 0;
121  }
122 }
__construct(\Magento\Framework\View\Element\Template\Context $context, \Magento\Sales\Model\ResourceModel\Order\Invoice\Comment\CollectionFactory $invoiceCollectionFactory, \Magento\Sales\Model\ResourceModel\Order\Creditmemo\Comment\CollectionFactory $memoCollectionFactory, \Magento\Sales\Model\ResourceModel\Order\Shipment\Comment\CollectionFactory $shipmentCollectionFactory, array $data=[])
Definition: Comments.php:50
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
__()
Definition: __.php:13
$entity
Definition: element.phtml:22