Exemple #1
0
 /**
  * @return void
  */
 public function execute()
 {
     $ipId = (int) $this->getRequest()->getParam('id');
     if ($ipId) {
         /** @var $ipModel \Rapidmage\Firewall\Model\Ip */
         $ipModel = $this->_ipFactory->create();
         $ipModel->load($ipId);
         // Check this IP exists or not
         if (!$ipModel->getId()) {
             $this->messageManager->addError(__('This IP no longer exists.'));
         } else {
             try {
                 // Delete IP
                 $ipModel->delete();
                 $this->messageManager->addSuccess(__('The IP has been deleted.'));
                 // Redirect to grid page
                 $this->_redirect('*/*/');
                 return;
             } catch (\Exception $e) {
                 $this->messageManager->addError($e->getMessage());
                 $this->_redirect('*/*/edit', ['id' => $ipModel->getId()]);
             }
         }
     }
 }
Exemple #2
0
 /**
  * @return void
  */
 public function execute()
 {
     $ipId = $this->getRequest()->getParam('id');
     /** @var \Rapidmage\Firewall\Model\Ip $model */
     $model = $this->_ipFactory->create();
     if ($ipId) {
         $model->load($ipId);
         if (!$model->getId()) {
             $this->messageManager->addError(__('This Ip no longer exists.'));
             $this->_redirect('*/*/');
             return;
         }
     }
     // Restore previously entered form data from session
     $data = $this->_session->getIpData(true);
     if (!empty($data)) {
         $model->setData($data);
     }
     $this->_coreRegistry->register('firewall_blackip', $model);
     /** @var \Magento\Backend\Model\View\Result\Page $resultPage */
     $resultPage = $this->_resultPageFactory->create();
     $resultPage->setActiveMenu('Rapidmage_Firewall::main_menu');
     $resultPage->getConfig()->getTitle()->prepend(__('Firewall'));
     return $resultPage;
 }
Exemple #3
0
 /**
  * @return void
  */
 public function execute()
 {
     $isPost = $this->getRequest()->getPost();
     if ($isPost) {
         $ipModel = $this->_ipFactory->create();
         $ipId = $this->getRequest()->getParam('id');
         if ($ipId) {
             $ipModel->load($ipId);
         }
         $formData = $this->getRequest()->getParam('ip');
         $ipModel->setData($formData);
         try {
             // Save Ip
             $ipModel->save();
             // Display success message
             $this->messageManager->addSuccess(__('The IP has been saved.'));
             // Check if 'Save and Continue'
             if ($this->getRequest()->getParam('back')) {
                 $this->_redirect('*/*/edit', ['id' => $ipModel->getId(), '_current' => true]);
                 return;
             }
             // Go to grid page
             $this->_redirect('*/*/');
             return;
         } catch (\Exception $e) {
             $this->messageManager->addError($e->getMessage());
         }
         $this->_getSession()->setIpData($formData);
         $this->_redirect('*/*/edit', ['id' => $ipId]);
     }
 }
Exemple #4
0
 public function execute()
 {
     /**
      * When Magento get your model, it will generate a Factory class
      * for your model at var/generaton folder and we can get your
      * model by this way
      */
     $ipModel = $this->_ipFactory->create();
     // Load the item with ID is 1
     $item = $ipModel->load(1);
     var_dump($item->getData());
     // Get Ip collection
     $ipCollection = $ipModel->getCollection();
     // Load all data of collection
     var_dump($ipCollection->getData());
 }
Exemple #5
0
 /**
  * @return void
  */
 public function execute()
 {
     // Get IDs of the selected Ips
     $ipIds = $this->getRequest()->getParam('ip');
     foreach ($ipIds as $ipId) {
         try {
             /** @var $ipModel \Rapidmage\Firewall\Model\IP */
             $ipModel = $this->_ipFactory->create();
             $ipModel->load($ipId)->delete();
         } catch (\Exception $e) {
             $this->messageManager->addError($e->getMessage());
         }
     }
     if (count($ipIds)) {
         $this->messageManager->addSuccess(__('A total of %1 record(s) were deleted.', count($ipIds)));
     }
     $this->_redirect('*/*/index');
 }