View.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. /**
  3. * Copyright © 2017 Ihor Vansach (ihor@magefan.com). All rights reserved.
  4. * See LICENSE.txt for license details (http://opensource.org/licenses/osl-3.0.php).
  5. *
  6. * Glory to Ukraine! Glory to the heroes!
  7. */
  8. namespace Magefan\Blog\Controller\Archive;
  9. /**
  10. * Blog archive view
  11. */
  12. class View extends \Magefan\Blog\App\Action\Action
  13. {
  14. /**
  15. * View blog archive action
  16. *
  17. * @return \Magento\Framework\Controller\ResultInterface
  18. */
  19. public function execute()
  20. {
  21. if (!$this->moduleEnabled()) {
  22. return $this->_forwardNoroute();
  23. }
  24. $date = $this->getRequest()->getParam('date');
  25. $date = explode('-', $date);
  26. $date[2] = '01';
  27. $time = strtotime(implode('-', $date));
  28. if (!$time || count($date) != 3) {
  29. return $this->_forwardNoroute();
  30. }
  31. $registry = $this->_objectManager->get('\Magento\Framework\Registry');
  32. $registry->register('current_blog_archive_year', (int)$date[0]);
  33. $registry->register('current_blog_archive_month', (int)$date[1]);
  34. $this->_view->loadLayout();
  35. $this->_view->renderLayout();
  36. }
  37. }