This commit is contained in:
2026-09-15 10:35:56 +08:00
commit 782f8ea7aa
4086 changed files with 631288 additions and 0 deletions
@@ -0,0 +1,161 @@
<?php
/**
* Mageplaza
*
* NOTICE OF LICENSE
*
* This source file is subject to the mageplaza.com license that is
* available through the world-wide-web at this URL:
* https://www.mageplaza.com/LICENSE.txt
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this extension to newer
* version in the future.
*
* @category Mageplaza
* @package Mageplaza_RewardPoints
* @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/)
* @license https://www.mageplaza.com/LICENSE.txt
*/
namespace Mageplaza\Blog\Block\Adminhtml\Author;
use Exception;
use Magento\Backend\Block\Template\Context;
use Magento\Backend\Block\Widget\Grid;
use Magento\Backend\Block\Widget\Grid\Extended;
use Magento\Backend\Helper\Data;
use Magento\Customer\Model\ResourceModel\Customer\CollectionFactory as CustomerCollectionFactory;
use Magento\Customer\Model\ResourceModel\Group\CollectionFactory;
use Magento\Framework\Registry;
/**
* Class CustomerGrid
* @package Mageplaza\Blog\Block\Adminhtml\Author
*/
class CustomerGrid extends Extended
{
/**
* Core registry
* @var Registry
*/
protected $_coreRegistry = null;
/**
* @var CustomerCollectionFactory
*/
protected $_customerCollectionFactory;
/**
* @var CollectionFactory
*/
protected $customerGroup;
/**
* CustomerGrid constructor.
*
* @param Context $context
* @param Data $backendHelper
* @param CustomerCollectionFactory $customerFactory
* @param CollectionFactory $customerGroup
* @param array $data
*/
public function __construct(
Context $context,
Data $backendHelper,
CustomerCollectionFactory $customerFactory,
CollectionFactory $customerGroup,
array $data = []
) {
$this->_customerCollectionFactory = $customerFactory;
$this->customerGroup = $customerGroup;
parent::__construct($context, $backendHelper, $data);
}
/**
* @return void
*/
protected function _construct()
{
parent::_construct();
$this->setId('customer-grid');
$this->setDefaultSort('entity_id');
$this->setUseAjax(true);
}
/**
* @return Grid
*/
protected function _prepareCollection()
{
$collection = $this->_customerCollectionFactory->create();
$collection->getSelect()->joinLeft(
['author' => $collection->getTable('mageplaza_blog_author')],
'e.entity_id = author.customer_id',
['author.user_id AS user_id']
)->where('author.user_id IS NULL')->getConnection();
$this->setCollection($collection);
return parent::_prepareCollection();
}
/**
* @return Extended
* @throws Exception
*/
protected function _prepareColumns()
{
$this->addColumn('customer_id', [
'header_css_class' => 'a-center',
'type' => 'radio',
'html_name' => 'customer_id',
'align' => 'center',
'index' => 'entity_id',
'filter' => false,
'sortable' => false
]);
$this->addColumn('entity_id', [
'header' => __('ID'),
'sortable' => true,
'index' => 'entity_id'
]);
$this->addColumn('firstname', [
'header' => __('First Name'),
'index' => 'firstname',
'type' => 'text',
'sortable' => true,
]);
$this->addColumn('lastname', [
'header' => __('Last Name'),
'index' => 'lastname',
'type' => 'text',
'sortable' => true,
]);
$this->addColumn('email', [
'header' => __('Email'),
'index' => 'email',
'type' => 'text',
'sortable' => true,
]);
$this->addColumn('group_id', [
'header' => __('Group'),
'index' => 'group_id',
'type' => 'options',
'options' => $this->customerGroup->create()->toOptionHash(),
'sortable' => true,
]);
return parent::_prepareColumns();
}
/**
* @return string
*/
public function getGridUrl()
{
return $this->getUrl('mageplaza_blog/author/customergrid', ['_current' => true]);
}
}
+120
View File
@@ -0,0 +1,120 @@
<?php
/**
* Mageplaza
*
* NOTICE OF LICENSE
*
* This source file is subject to the Mageplaza.com license that is
* available through the world-wide-web at this URL:
* https://www.mageplaza.com/LICENSE.txt
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this extension to newer
* version in the future.
*
* @category Mageplaza
* @package Mageplaza_Blog
* @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/)
* @license https://www.mageplaza.com/LICENSE.txt
*/
namespace Mageplaza\Blog\Block\Adminhtml\Author;
use Magento\Backend\Block\Widget\Context;
use Magento\Backend\Block\Widget\Form\Container;
use Magento\Framework\Registry;
use Mageplaza\Blog\Model\Author;
/**
* Class Edit
* @package Mageplaza\Blog\Block\Adminhtml\Author
*/
class Edit extends Container
{
/**
* @var Registry
*/
public $coreRegistry;
/**
* Edit constructor.
*
* @param Context $context
* @param Registry $coreRegistry
* @param array $data
*/
public function __construct(
Context $context,
Registry $coreRegistry,
array $data = []
) {
$this->coreRegistry = $coreRegistry;
parent::__construct($context, $data);
}
/**
* Initialize Post edit block
*
* @return void
*/
protected function _construct()
{
$this->_objectId = 'user_id';
$this->_blockGroup = 'Mageplaza_Blog';
$this->_controller = 'adminhtml_author';
parent::_construct();
$this->buttonList->add('save-and-continue', [
'label' => __('Save And Continue Edit'),
'data_attribute' => [
'mage-init' => [
'button' => [
'event' => 'saveAndContinueEdit',
'target' => '#edit_form'
]
]
]
], -100);
$this->buttonList->add(
'delete',
[
'label' => __('Delete'),
'class' => 'delete',
'onclick' => "setLocation('{$this->getUrl('mageplaza_blog/author/delete', [
'id' => $this->getCurrentAuthor()->getId(),
'_current' => true,
'back' => 'edit'
])}')",
],
-101
);
}
/**
* Retrieve text for header element depending on loaded Post
*
* @return string
*/
public function getHeaderText()
{
/** @var Author $author */
$author = $this->getCurrentAuthor();
if ($author->getId()) {
return __("Edit Author '%1'", $this->escapeHtml($author->getName()));
}
return __('New Author');
}
/**
* @return Author
*/
public function getCurrentAuthor()
{
return $this->coreRegistry->registry('mageplaza_blog_author');
}
}
@@ -0,0 +1,51 @@
<?php
/**
* Mageplaza
*
* NOTICE OF LICENSE
*
* This source file is subject to the Mageplaza.com license that is
* available through the world-wide-web at this URL:
* https://www.mageplaza.com/LICENSE.txt
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this extension to newer
* version in the future.
*
* @category Mageplaza
* @package Mageplaza_Blog
* @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/)
* @license https://www.mageplaza.com/LICENSE.txt
*/
namespace Mageplaza\Blog\Block\Adminhtml\Author\Edit;
use Magento\Backend\Block\Widget\Form\Generic;
/**
* Class Form
* @package Mageplaza\Blog\Block\Adminhtml\Author\Edit
*/
class Form extends Generic
{
/**
* @inheritdoc
*/
protected function _prepareForm()
{
/** @var \Magento\Framework\Data\Form $form */
$form = $this->_formFactory->create([
'data' => [
'id' => 'edit_form',
'action' => $this->getData('action'),
'method' => 'post',
'enctype' => 'multipart/form-data'
]
]);
$form->setUseContainer(true);
$this->setForm($form);
return parent::_prepareForm();
}
}
@@ -0,0 +1,332 @@
<?php
/**
* Mageplaza
*
* NOTICE OF LICENSE
*
* This source file is subject to the Mageplaza.com license that is
* available through the world-wide-web at this URL:
* https://www.mageplaza.com/LICENSE.txt
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this extension to newer
* version in the future.
*
* @category Mageplaza
* @package Mageplaza_Blog
* @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/)
* @license https://www.mageplaza.com/LICENSE.txt
*/
namespace Mageplaza\Blog\Block\Adminhtml\Author\Edit\Tab;
use Magento\Backend\Block\Template\Context;
use Magento\Backend\Block\Widget\Form\Generic;
use Magento\Backend\Block\Widget\Tab\TabInterface;
use Magento\Cms\Model\Wysiwyg\Config;
use Magento\Customer\Api\CustomerRepositoryInterface;
use Magento\Framework\Data\Form;
use Magento\Framework\Data\FormFactory;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\Registry;
use Magento\Framework\UrlInterface;
use Magento\Store\Model\System\Store;
use Mageplaza\Blog\Block\Adminhtml\Renderer\Image;
use Mageplaza\Blog\Helper\Data;
use Mageplaza\Blog\Helper\Image as ImageHelper;
use Mageplaza\Blog\Model\Config\Source\AuthorStatus;
/**
* Class Author
* @package Mageplaza\Blog\Block\Adminhtml\Author\Edit\Tab
*/
class Author extends Generic implements TabInterface
{
/**
* @var Store
*/
public $systemStore;
/**
* @var Config
*/
public $wysiwygConfig;
/**
* @var ImageHelper
*/
protected $imageHelper;
/**
* @var AuthorStatus
*/
protected $authorStatus;
/**
* @var Data
*/
protected $_helperData;
/**
* @var CustomerRepositoryInterface
*/
protected $customerRepository;
/**
* Author constructor.
*
* @param Config $wysiwygConfig
* @param Store $systemStore
* @param Context $context
* @param Registry $registry
* @param FormFactory $formFactory
* @param ImageHelper $imageHelper
* @param AuthorStatus $authorStatus
* @param Data $helperData
* @param CustomerRepositoryInterface $customerRepository
* @param array $data
*/
public function __construct(
Config $wysiwygConfig,
Store $systemStore,
Context $context,
Registry $registry,
FormFactory $formFactory,
ImageHelper $imageHelper,
AuthorStatus $authorStatus,
Data $helperData,
CustomerRepositoryInterface $customerRepository,
array $data = []
) {
$this->wysiwygConfig = $wysiwygConfig;
$this->systemStore = $systemStore;
$this->imageHelper = $imageHelper;
$this->authorStatus = $authorStatus;
$this->_helperData = $helperData;
$this->customerRepository = $customerRepository;
parent::__construct($context, $registry, $formFactory, $data);
}
/**
* @inheritdoc
*/
protected function _prepareForm()
{
/** @var \Mageplaza\Blog\Model\Author $author */
$author = $this->_coreRegistry->registry('mageplaza_blog_author');
/** @var Form $form */
$form = $this->_formFactory->create();
$form->setHtmlIdPrefix('author_');
$form->setFieldNameSuffix('author');
$fieldset = $form->addFieldset('base_fieldset', [
'legend' => __('Author Information'),
'class' => 'fieldset-wide'
]);
if ($author->getId()) {
$fieldset->addField('user_id', 'hidden', ['name' => 'user_id']);
}
if ($this->checkCustomerId($author->getCustomerId())) {
$fieldset->addField('customer_id', 'hidden', [
'name' => 'customer_id',
'value' => $author->getCustomerId()
]);
$customer = $this->customerRepository->getById($author->getCustomerId());
$fieldset->addField('customer', 'label', [
'name' => 'customer',
'label' => __('Customer'),
'title' => __('Customer'),
'value' => $customer->getFirstname() . ' ' . $customer->getLastname()
]);
} else {
$fieldset->addField('customer', 'text', [
'name' => 'customer',
'label' => __('Customer'),
'title' => __('Customer')
])->setAfterElementHtml(
'<div id="customer-grid" style="display:none"></div>
<script type="text/x-magento-init">
{
"#author_customer": {
"Mageplaza_Blog/js/view/author":{
"url": "' . $this->getAjaxUrl() . '"
}
}
}
</script>'
);
$fieldset->addField('customer_id', 'hidden', [
'name' => 'customer_id',
'value' => 0
]);
}
$fieldset->addField('name', 'text', [
'name' => 'name',
'label' => __('Display Name'),
'title' => __('Display Name'),
'required' => true,
'note' => __('This name will be displayed on frontend')
]);
$fieldset->addField('status', 'select', [
'name' => 'status',
'label' => __('Status'),
'title' => __('Status'),
'values' => $this->authorStatus->toArray()
]);
$fieldset->addField('type', 'hidden', [
'name' => 'type',
'value' => 0
]);
$fieldset->addField('short_description', 'editor', [
'name' => 'short_description',
'label' => __('Short Description'),
'title' => __('Short Description'),
'note' => __('Short Description'),
'config' => $this->wysiwygConfig->getConfig([
'add_variables' => false,
'add_widgets' => false,
'add_directives' => true
])
]);
$fieldset->addField('image', Image::class, [
'name' => 'image',
'label' => __('Avatar'),
'title' => __('Avatar'),
'path' => $this->imageHelper->getBaseMediaPath(ImageHelper::TEMPLATE_MEDIA_TYPE_AUTH)
]);
$fieldset->addField('url_key', 'text', [
'name' => 'url_key',
'label' => __('URL Key'),
'title' => __('URL Key')
]);
$authorUrlFormat = $this->_storeManager->getDefaultStoreView()->getBaseUrl(UrlInterface::URL_TYPE_LINK)
. 'blog/author/';
$urlSuffix = $this->_helperData->getUrlSuffix();
$fieldset->addField(
'full_url',
'label',
[
'label' => __('Full URL'),
'value' => $author->getUrlKey() ? $authorUrlFormat . $author->getUrlKey() . $urlSuffix : ''
]
)->setAfterElementHtml(
"<script>
require(['jquery'], function($){
$('#author_url_key').on('keyup', function() {
var url = '" . $authorUrlFormat . "'+$(this).val()+'" . $urlSuffix . "';
if ($(this).val() === ''){
url = '';
}
$('.field-full_url .control-value').html(url);
});
});
</script>"
);
$fieldset->addField('facebook_link', 'text', [
'name' => 'facebook_link',
'label' => __('Facebook'),
'title' => __('Facebook'),
'note' => __('Facebook URL'),
'required' => false,
'class' => 'validate-url'
]);
$fieldset->addField('twitter_link', 'text', [
'name' => 'twitter_link',
'label' => __('Twitter'),
'title' => __('Twitter'),
'note' => __('Twitter URL'),
'required' => false,
'class' => 'validate-url'
]);
$form->addValues($author->getData());
$this->setForm($form);
return parent::_prepareForm();
}
/**
* @param $customerId
*
* @return bool
* @throws LocalizedException
*/
public function checkCustomerId($customerId)
{
try {
if ($this->customerRepository->getById($customerId)) {
return true;
}
} catch (NoSuchEntityException $noSuchEntityException) {
return false;
}
return false;
}
/**
* Prepare label for tab
*
* @return string
*/
public function getTabLabel()
{
return __('Author Info');
}
/**
* Prepare title for tab
*
* @return string
*/
public function getTabTitle()
{
return $this->getTabLabel();
}
/**
* Can show tab in tabs
*
* @return boolean
*/
public function canShowTab()
{
return true;
}
/**
* Tab is hidden
*
* @return boolean
*/
public function isHidden()
{
return false;
}
/**
* Get transaction grid url
* @return string
*/
public function getAjaxUrl()
{
return $this->getUrl('mageplaza_blog/author/customergrid');
}
}
@@ -0,0 +1,217 @@
<?php
/**
* Mageplaza
*
* NOTICE OF LICENSE
*
* This source file is subject to the Mageplaza.com license that is
* available through the world-wide-web at this URL:
* https://www.mageplaza.com/LICENSE.txt
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this extension to newer
* version in the future.
*
* @category Mageplaza
* @package Mageplaza_Blog
* @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/)
* @license https://www.mageplaza.com/LICENSE.txt
*/
namespace Mageplaza\Blog\Block\Adminhtml\Author\Edit\Tab;
use Exception;
use Magento\Backend\Block\Template\Context;
use Magento\Backend\Block\Widget\Grid\Extended;
use Magento\Backend\Block\Widget\Tab\TabInterface;
use Magento\Backend\Helper\Data;
use Magento\Framework\Registry;
use Mageplaza\Blog\Model\PostFactory;
use Mageplaza\Blog\Model\ResourceModel\Post\Collection;
use Mageplaza\Blog\Model\ResourceModel\Post\CollectionFactory;
/**
* Class Post
* @package Mageplaza\Blog\Block\Adminhtml\Tag\Edit\Tab
*/
class Post extends Extended implements TabInterface
{
/**
* Post collection factory
*
* @var CollectionFactory
*/
public $postCollectionFactory;
/**
* Registry
*
* @var Registry
*/
public $coreRegistry;
/**
* Post factory
*
* @var PostFactory
*/
public $postFactory;
/**
* Post constructor.
*
* @param Context $context
* @param Registry $coreRegistry
* @param Data $backendHelper
* @param PostFactory $postFactory
* @param CollectionFactory $postCollectionFactory
* @param array $data
*/
public function __construct(
Context $context,
Registry $coreRegistry,
Data $backendHelper,
PostFactory $postFactory,
CollectionFactory $postCollectionFactory,
array $data = []
) {
$this->coreRegistry = $coreRegistry;
$this->postFactory = $postFactory;
$this->postCollectionFactory = $postCollectionFactory;
parent::__construct($context, $backendHelper, $data);
}
/**
* Set grid params
*/
public function _construct()
{
parent::_construct();
$this->setId('post_grid');
$this->setDefaultSort('position');
$this->setDefaultDir('ASC');
$this->setUseAjax(true);
}
/**
* @inheritdoc
*/
protected function _prepareCollection()
{
/** @var Collection $collection */
$collection = $this->postCollectionFactory->create();
$collection->addFieldToFilter('author_id', $this->getAuthor()->getId());
$this->setCollection($collection);
return parent::_prepareCollection();
}
/**
* @return $this
* @throws Exception
*/
protected function _prepareColumns()
{
$this->addColumn('post_id', [
'header' => __('ID'),
'sortable' => true,
'index' => 'post_id',
'type' => 'number',
'header_css_class' => 'col-id',
'column_css_class' => 'col-id'
]);
$this->addColumn('title', [
'header' => __('Name'),
'index' => 'name',
'header_css_class' => 'col-name',
'column_css_class' => 'col-name'
]);
$this->addColumn('publish_date', [
'header' => __('Published'),
'index' => 'publish_date',
'header_css_class' => 'col-name',
'column_css_class' => 'col-name'
]);
return $this;
}
/**
* @param \Mageplaza\Blog\Model\Post|Object $item
*
* @return string
*/
public function getRowUrl($item)
{
return $this->getUrl('mageplaza_blog/post/edit', ['id' => $item->getId()]);
}
/**
* get grid url
*
* @return string
*/
public function getGridUrl()
{
return $this->getUrl('*/*/postsgrid', ['id' => $this->getAuthor()->getId()]);
}
/**
* @return \Mageplaza\Blog\Model\Author
*/
public function getAuthor()
{
return $this->coreRegistry->registry('mageplaza_blog_author');
}
/**
* @return string
*/
public function getTabLabel()
{
return __('Posts');
}
/**
* @return bool
*/
public function isHidden()
{
return false;
}
/**
* @return string
*/
public function getTabTitle()
{
return $this->getTabLabel();
}
/**
* @return bool
*/
public function canShowTab()
{
return true;
}
/**
* @return string
*/
public function getTabUrl()
{
return $this->getUrl('mageplaza_blog/author/posts', ['_current' => true]);
}
/**
* @return string
*/
public function getTabClass()
{
return 'ajax only';
}
}
@@ -0,0 +1,43 @@
<?php
/**
* Mageplaza
*
* NOTICE OF LICENSE
*
* This source file is subject to the Mageplaza.com license that is
* available through the world-wide-web at this URL:
* https://www.mageplaza.com/LICENSE.txt
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this extension to newer
* version in the future.
*
* @category Mageplaza
* @package Mageplaza_Blog
* @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/)
* @license https://www.mageplaza.com/LICENSE.txt
*/
namespace Mageplaza\Blog\Block\Adminhtml\Author\Edit;
/**
* Class Tabs
* @package Mageplaza\Blog\Block\Adminhtml\Author\Edit
*/
class Tabs extends \Magento\Backend\Block\Widget\Tabs
{
/**
* constructor
*
* @return void
*/
protected function _construct()
{
parent::_construct();
$this->setId('author_tabs');
$this->setDestElementId('edit_form');
$this->setTitle(__('Author Information'));
}
}