init
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Stemcell\Customer\Controller\Adminhtml\Lab;
|
||||
|
||||
use Magento\Backend\App\Action;
|
||||
use Magento\Backend\App\Action\Context;
|
||||
use Magento\Framework\App\Action\HttpPostActionInterface;
|
||||
use Magento\Framework\Controller\Result\Redirect;
|
||||
use Magento\Ui\Component\MassAction\Filter;
|
||||
use Stemcell\Customer\Api\LabRepositoryInterface;
|
||||
use Stemcell\Customer\Model\ResourceModel\Lab\CollectionFactory;
|
||||
|
||||
class MassDelete extends Action implements HttpPostActionInterface
|
||||
{
|
||||
public const ADMIN_RESOURCE = 'Stemcell_Customer::salesperson_index';
|
||||
|
||||
private Filter $filter;
|
||||
|
||||
private CollectionFactory $collectionFactory;
|
||||
|
||||
private LabRepositoryInterface $labRepository;
|
||||
|
||||
public function __construct(
|
||||
Context $context,
|
||||
Filter $filter,
|
||||
CollectionFactory $collectionFactory,
|
||||
LabRepositoryInterface $labRepository
|
||||
) {
|
||||
parent::__construct($context);
|
||||
$this->filter = $filter;
|
||||
$this->collectionFactory = $collectionFactory;
|
||||
$this->labRepository = $labRepository;
|
||||
}
|
||||
|
||||
public function execute(): Redirect
|
||||
{
|
||||
$collection = $this->filter->getCollection($this->collectionFactory->create());
|
||||
$deleted = 0;
|
||||
|
||||
foreach ($collection as $lab) {
|
||||
$this->labRepository->delete($lab);
|
||||
++$deleted;
|
||||
}
|
||||
|
||||
if ($deleted) {
|
||||
$this->messageManager->addSuccessMessage(
|
||||
__('A total of %1 lab record(s) have been deleted.', $deleted)
|
||||
);
|
||||
}
|
||||
|
||||
return $this->resultRedirectFactory->create()->setPath('stemcell_customer/lab/index');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user