View.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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\Author;
  9. /**
  10. * Blog author posts view
  11. */
  12. class View extends \Magefan\Blog\App\Action\Action
  13. {
  14. /**
  15. * View blog author action
  16. *
  17. * @return \Magento\Framework\Controller\ResultInterface
  18. */
  19. public function execute()
  20. {
  21. if (!$this->moduleEnabled()) {
  22. return $this->_forwardNoroute();
  23. }
  24. $enabled = (int) $this->getConfigValue('mfblog/author/enabled');
  25. $pageEnabled = (int) $this->getConfigValue('mfblog/author/page_enabled');
  26. if (!$enabled || !$pageEnabled) {
  27. return $this->_forwardNoroute();
  28. }
  29. $author = $this->_initAuthor();
  30. if (!$author) {
  31. return $this->_forwardNoroute();
  32. }
  33. $this->_objectManager->get('\Magento\Framework\Registry')->register('current_blog_author', $author);
  34. $this->_view->loadLayout();
  35. $this->_view->renderLayout();
  36. }
  37. /**
  38. * Init author
  39. *
  40. * @return \Magefan\Blog\Model\Author || false
  41. */
  42. protected function _initAuthor()
  43. {
  44. $id = $this->getRequest()->getParam('id');
  45. $author = $this->_objectManager->create('Magefan\Blog\Model\Author')->load($id);
  46. if (!$author->getId()) {
  47. return false;
  48. }
  49. return $author;
  50. }
  51. }