Showing preview only (382K chars total). Download the full file or copy to clipboard to get everything.
Repository: tzyganu/Magento2SampleModule
Branch: master
Commit: 1047ae6ab3b5
Files: 101
Total size: 353.3 KB
Directory structure:
gitextract_3yank7zg/
├── Api/
│ ├── AuthorRepositoryInterface.php
│ └── Data/
│ ├── AuthorInterface.php
│ └── AuthorSearchResultsInterface.php
├── Block/
│ ├── Adminhtml/
│ │ └── Author/
│ │ └── Edit/
│ │ └── Buttons/
│ │ ├── Back.php
│ │ ├── Delete.php
│ │ ├── Generic.php
│ │ ├── Reset.php
│ │ ├── Save.php
│ │ └── SaveAndContinue.php
│ ├── Author/
│ │ ├── ListAuthor/
│ │ │ ├── Rss/
│ │ │ │ └── Link.php
│ │ │ └── Rss.php
│ │ ├── ListAuthor.php
│ │ └── ViewAuthor.php
│ ├── Image.php
│ └── ImageBuilder.php
├── Controller/
│ ├── Adminhtml/
│ │ ├── Author/
│ │ │ ├── Delete.php
│ │ │ ├── Edit.php
│ │ │ ├── File/
│ │ │ │ └── Upload.php
│ │ │ ├── Image/
│ │ │ │ └── Upload.php
│ │ │ ├── Index.php
│ │ │ ├── InlineEdit.php
│ │ │ ├── MassAction.php
│ │ │ ├── MassDelete.php
│ │ │ ├── MassDisable.php
│ │ │ ├── MassEnable.php
│ │ │ ├── NewAction.php
│ │ │ ├── Save.php
│ │ │ └── Upload.php
│ │ └── Author.php
│ ├── Author/
│ │ ├── Index.php
│ │ ├── Rss.php
│ │ └── View.php
│ ├── RegistryConstants.php
│ └── Router.php
├── Helper/
│ └── Image.php
├── LICENSE
├── Model/
│ ├── Author/
│ │ ├── DataProvider.php
│ │ ├── Rss.php
│ │ └── Url.php
│ ├── Author.php
│ ├── AuthorFactory.php
│ ├── AuthorRepository.php
│ ├── FactoryInterface.php
│ ├── Image.php
│ ├── Output.php
│ ├── ResourceModel/
│ │ ├── Author/
│ │ │ ├── Collection.php
│ │ │ └── Grid/
│ │ │ ├── Collection.php
│ │ │ └── ServiceCollection.php
│ │ └── Author.php
│ ├── Routing/
│ │ ├── Entity.php
│ │ └── RoutableInterface.php
│ ├── Source/
│ │ ├── AbstractSource.php
│ │ ├── Country.php
│ │ └── Options.php
│ ├── Uploader.php
│ └── UploaderPool.php
├── Plugin/
│ └── Block/
│ └── Topmenu.php
├── README.md
├── Setup/
│ ├── InstallSchema.php
│ └── Uninstall.php
├── Test/
│ └── Unit/
│ ├── Model/
│ │ ├── Author/
│ │ │ ├── DataProviderTest.php
│ │ │ ├── RssTest.php
│ │ │ └── UrlTest.php
│ │ ├── AuthorTest.php
│ │ ├── Source/
│ │ │ └── CountryTest.php
│ │ ├── UploaderPoolTest.php
│ │ └── UploaderTest.php
│ └── Ui/
│ ├── Component/
│ │ └── Listing/
│ │ └── Column/
│ │ ├── AuthorActionsTest.php
│ │ ├── AvatarTest.php
│ │ └── Store/
│ │ └── OptionsTest.php
│ └── DataProvider/
│ └── Author/
│ └── Form/
│ └── Modifier/
│ └── AuthorDataTest.php
├── Ui/
│ ├── Component/
│ │ └── Listing/
│ │ └── Column/
│ │ ├── AuthorActions.php
│ │ ├── Avatar.php
│ │ └── Store/
│ │ └── Options.php
│ └── DataProvider/
│ └── Author/
│ └── Form/
│ └── Modifier/
│ └── AuthorData.php
├── composer.json
├── etc/
│ ├── acl.xml
│ ├── adminhtml/
│ │ ├── di.xml
│ │ ├── menu.xml
│ │ ├── routes.xml
│ │ └── system.xml
│ ├── config.xml
│ ├── di.xml
│ ├── frontend/
│ │ ├── di.xml
│ │ └── routes.xml
│ └── module.xml
├── i18l/
│ └── en_US.csv
├── registration.php
└── view/
├── adminhtml/
│ ├── layout/
│ │ ├── sample_news_author_edit.xml
│ │ └── sample_news_author_index.xml
│ ├── ui_component/
│ │ ├── sample_news_author_form.xml
│ │ └── sample_news_author_listing.xml
│ └── web/
│ └── template/
│ ├── file-preview.html
│ └── image-preview.html
└── frontend/
├── layout/
│ ├── sample_news_author_index.xml
│ └── sample_news_author_view.xml
└── templates/
├── author/
│ ├── list.phtml
│ └── view.phtml
├── image.phtml
├── image_with_borders.phtml
└── rss/
└── link.phtml
================================================
FILE CONTENTS
================================================
================================================
FILE: Api/AuthorRepositoryInterface.php
================================================
<?php
/**
* Sample_News extension
*
* NOTICE OF LICENSE
*
* This source file is subject to the MIT License
* that is bundled with this package in the file LICENSE
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/mit-license.php
*
* @category Sample
* @package Sample_News
* @copyright 2016 Marius Strajeru
* @license http://opensource.org/licenses/mit-license.php MIT License
* @author Marius Strajeru
*/
namespace Sample\News\Api;
use Magento\Framework\Api\SearchCriteriaInterface;
use Sample\News\Api\Data\AuthorInterface;
/**
* @api
*/
interface AuthorRepositoryInterface
{
/**
* Save page.
*
* @param AuthorInterface $author
* @return AuthorInterface
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function save(AuthorInterface $author);
/**
* Retrieve Author.
*
* @param int $authorId
* @return AuthorInterface
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function getById($authorId);
/**
* Retrieve pages matching the specified criteria.
*
* @param SearchCriteriaInterface $searchCriteria
* @return \Sample\News\Api\Data\AuthorSearchResultsInterface
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function getList(SearchCriteriaInterface $searchCriteria);
/**
* Delete author.
*
* @param AuthorInterface $author
* @return bool true on success
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function delete(AuthorInterface $author);
/**
* Delete author by ID.
*
* @param int $authorId
* @return bool true on success
* @throws \Magento\Framework\Exception\NoSuchEntityException
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function deleteById($authorId);
}
================================================
FILE: Api/Data/AuthorInterface.php
================================================
<?php
/**
* Sample_News extension
*
* NOTICE OF LICENSE
*
* This source file is subject to the MIT License
* that is bundled with this package in the file LICENSE
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/mit-license.php
*
* @category Sample
* @package Sample_News
* @copyright 2016 Marius Strajeru
* @license http://opensource.org/licenses/mit-license.php MIT License
* @author Marius Strajeru
*/
namespace Sample\News\Api\Data;
/**
* @api
*/
interface AuthorInterface
{
/**
* Constants for keys of data array. Identical to the name of the getter in snake case
*/
const AUTHOR_ID = 'author_id';
const NAME = 'name';
const URL_KEY = 'url_key';
const IS_ACTIVE = 'is_active';
const IN_RSS = 'in_rss';
const BIOGRAPHY = 'biography';
const DOB = 'dob';
const TYPE = 'type';
const AWARDS = 'awards';
const AVATAR = 'avatar';
const RESUME = 'resume';
const COUNTRY = 'country';
const CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at';
const META_TITLE = 'meta_title';
const META_DESCRIPTION = 'meta_description';
const META_KEYWORDS = 'meta_keywords';
const STORE_ID = 'store_id';
/**
* Get ID
*
* @return int|null
*/
public function getId();
/**
* Get name
*
* @return string
*/
public function getName();
/**
* Get url key
*
* @return string
*/
public function getUrlKey();
/**
* Get is active
*
* @return bool|int
*/
public function getIsActive();
/**
* Get in rss
*
* @return bool|int
*/
public function getInRss();
/**
* Get biography
*
* @return string
*/
public function getBiography();
/**
* @return string
*/
public function getProcessedBiography();
/**
* Get DOB
*
* @return string
*/
public function getDob();
/**
* Get type
*
* @return int
*/
public function getType();
/**
* Get awards
*
* @return string
*/
public function getAwards();
/**
* Get avatar
*
* @return string
*/
public function getAvatar();
/**
* Get resume
*
* @return string
*/
public function getResume();
/**
* Get country
*
* @return string
*/
public function getCountry();
/**
* set id
*
* @param $id
* @return AuthorInterface
*/
public function setId($id);
/**
* set name
*
* @param $name
* @return AuthorInterface
*/
public function setName($name);
/**
* set url key
*
* @param $urlKey
* @return AuthorInterface
*/
public function setUrlKey($urlKey);
/**
* Set is active
*
* @param $isActive
* @return AuthorInterface
*/
public function setIsActive($isActive);
/**
* Set in rss
*
* @param $inRss
* @return AuthorInterface
*/
public function setInRss($inRss);
/**
* Set biography
*
* @param $biography
* @return AuthorInterface
*/
public function setBiography($biography);
/**
* Set DOB
*
* @param $dob
* @return AuthorInterface
*/
public function setDob($dob);
/**
* set type
*
* @param $type
* @return AuthorInterface
*/
public function setType($type);
/**
* set awards
*
* @param $awards
* @return AuthorInterface
*/
public function setAwards($awards);
/**
* set avatar
*
* @param $avatar
* @return AuthorInterface
*/
public function setAvatar($avatar);
/**
* set resume
*
* @param $resume
* @return AuthorInterface
*/
public function setResume($resume);
/**
* Set country
*
* @param $country
* @return AuthorInterface
*/
public function setCountry($country);
/**
* Get created at
*
* @return string
*/
public function getCreatedAt();
/**
* set created at
*
* @param $createdAt
* @return AuthorInterface
*/
public function setCreatedAt($createdAt);
/**
* Get updated at
*
* @return string
*/
public function getUpdatedAt();
/**
* set updated at
*
* @param $updatedAt
* @return AuthorInterface
*/
public function setUpdatedAt($updatedAt);
/**
* @param $storeId
* @return AuthorInterface
*/
public function setStoreId($storeId);
/**
* @return int[]
*/
public function getStoreId();
/**
* @return string
*/
public function getMetaTitle();
/**
* @param $metaTitle
* @return AuthorInterface
*/
public function setMetaTitle($metaTitle);
/**
* @return string
*/
public function getMetaDescription();
/**
* @param $metaDescription
* @return AuthorInterface
*/
public function setMetaDescription($metaDescription);
/**
* @return string
*/
public function getMetaKeywords();
/**
* @param $metaKeywords
* @return AuthorInterface
*/
public function setMetaKeywords($metaKeywords);
}
================================================
FILE: Api/Data/AuthorSearchResultsInterface.php
================================================
<?php
/**
* Sample_News extension
*
* NOTICE OF LICENSE
*
* This source file is subject to the MIT License
* that is bundled with this package in the file LICENSE
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/mit-license.php
*
* @category Sample
* @package Sample_News
* @copyright 2016 Marius Strajeru
* @license http://opensource.org/licenses/mit-license.php MIT License
* @author Marius Strajeru
*/
namespace Sample\News\Api\Data;
use Magento\Framework\Api\SearchResultsInterface;
/**
* @api
*/
interface AuthorSearchResultsInterface extends SearchResultsInterface
{
/**
* Get author list.
*
* @return \Sample\News\Api\Data\AuthorInterface[]
*/
public function getItems();
/**
* Set authors list.
*
* @param \Sample\News\Api\Data\AuthorInterface[] $items
* @return $this
*/
public function setItems(array $items);
}
================================================
FILE: Block/Adminhtml/Author/Edit/Buttons/Back.php
================================================
<?php
/**
* Sample_News extension
*
* NOTICE OF LICENSE
*
* This source file is subject to the MIT License
* that is bundled with this package in the file LICENSE
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/mit-license.php
*
* @category Sample
* @package Sample_News
* @copyright 2016 Marius Strajeru
* @license http://opensource.org/licenses/mit-license.php MIT License
* @author Marius Strajeru
*/
namespace Sample\News\Block\Adminhtml\Author\Edit\Buttons;
use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
class Back extends Generic implements ButtonProviderInterface
{
/**
* get button data
*
* @return array
*/
public function getButtonData()
{
return [
'label' => __('Back'),
'on_click' => sprintf("location.href = '%s';", $this->getBackUrl()),
'class' => 'back',
'sort_order' => 10
];
}
/**
* Get URL for back (reset) button
*
* @return string
*/
public function getBackUrl()
{
return $this->getUrl('*/*/');
}
}
================================================
FILE: Block/Adminhtml/Author/Edit/Buttons/Delete.php
================================================
<?php
/**
* Sample_News extension
*
* NOTICE OF LICENSE
*
* This source file is subject to the MIT License
* that is bundled with this package in the file LICENSE
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/mit-license.php
*
* @category Sample
* @package Sample_News
* @copyright 2016 Marius Strajeru
* @license http://opensource.org/licenses/mit-license.php MIT License
* @author Marius Strajeru
*/
namespace Sample\News\Block\Adminhtml\Author\Edit\Buttons;
use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
class Delete extends Generic implements ButtonProviderInterface
{
/**
* get button data
*
* @return array
*/
public function getButtonData()
{
$data = [];
if ($this->getAuthorId()) {
$data = [
'label' => __('Delete Author'),
'class' => 'delete',
'on_click' => 'deleteConfirm(\'' . __(
'Are you sure you want to do this?'
) . '\', \'' . $this->getDeleteUrl() . '\')',
'sort_order' => 20,
];
}
return $data;
}
/**
* @return string
*/
public function getDeleteUrl()
{
return $this->getUrl('*/*/delete', ['author_id' => $this->getAuthorId()]);
}
}
================================================
FILE: Block/Adminhtml/Author/Edit/Buttons/Generic.php
================================================
<?php
/**
* Sample_News extension
*
* NOTICE OF LICENSE
*
* This source file is subject to the MIT License
* that is bundled with this package in the file LICENSE
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/mit-license.php
*
* @category Sample
* @package Sample_News
* @copyright 2016 Marius Strajeru
* @license http://opensource.org/licenses/mit-license.php MIT License
* @author Marius Strajeru
*/
namespace Sample\News\Block\Adminhtml\Author\Edit\Buttons;
use Magento\Backend\Block\Widget\Context;
use Sample\News\Api\AuthorRepositoryInterface;
use Magento\Framework\Exception\NoSuchEntityException;
class Generic
{
/**
* @var Context
*/
protected $context;
/**
* @var AuthorRepositoryInterface
*/
protected $authorRepository;
/**
* @param Context $context
* @param AuthorRepositoryInterface $authorRepository
*/
public function __construct(
Context $context,
AuthorRepositoryInterface $authorRepository
) {
$this->context = $context;
$this->authorRepository = $authorRepository;
}
/**
* Return Author page ID
*
* @return int|null
*/
public function getAuthorId()
{
try {
return $this->authorRepository->getById(
$this->context->getRequest()->getParam('author_id')
)->getId();
} catch (NoSuchEntityException $e) {
return null;
}
}
/**
* Generate url by route and parameters
*
* @param string $route
* @param array $params
* @return string
*/
public function getUrl($route = '', $params = [])
{
return $this->context->getUrlBuilder()->getUrl($route, $params);
}
}
================================================
FILE: Block/Adminhtml/Author/Edit/Buttons/Reset.php
================================================
<?php
/**
* Sample_News extension
*
* NOTICE OF LICENSE
*
* This source file is subject to the MIT License
* that is bundled with this package in the file LICENSE
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/mit-license.php
*
* @category Sample
* @package Sample_News
* @copyright 2016 Marius Strajeru
* @license http://opensource.org/licenses/mit-license.php MIT License
* @author Marius Strajeru
*/
namespace Sample\News\Block\Adminhtml\Author\Edit\Buttons;
use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
class Reset implements ButtonProviderInterface
{
/**
* get button data
*
* @return array
*/
public function getButtonData()
{
return [
'label' => __('Reset'),
'class' => 'reset',
'on_click' => 'location.reload();',
'sort_order' => 30
];
}
}
================================================
FILE: Block/Adminhtml/Author/Edit/Buttons/Save.php
================================================
<?php
/**
* Sample_News extension
*
* NOTICE OF LICENSE
*
* This source file is subject to the MIT License
* that is bundled with this package in the file LICENSE
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/mit-license.php
*
* @category Sample
* @package Sample_News
* @copyright 2016 Marius Strajeru
* @license http://opensource.org/licenses/mit-license.php MIT License
* @author Marius Strajeru
*/
namespace Sample\News\Block\Adminhtml\Author\Edit\Buttons;
use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
class Save extends Generic implements ButtonProviderInterface
{
/**
* get button data
*
* @return array
*/
public function getButtonData()
{
return [
'label' => __('Save Author'),
'class' => 'save primary',
'data_attribute' => [
'mage-init' => ['button' => ['event' => 'save']],
'form-role' => 'save',
],
'sort_order' => 90,
];
}
}
================================================
FILE: Block/Adminhtml/Author/Edit/Buttons/SaveAndContinue.php
================================================
<?php
/**
* Sample_News extension
*
* NOTICE OF LICENSE
*
* This source file is subject to the MIT License
* that is bundled with this package in the file LICENSE
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/mit-license.php
*
* @category Sample
* @package Sample_News
* @copyright 2016 Marius Strajeru
* @license http://opensource.org/licenses/mit-license.php MIT License
* @author Marius Strajeru
*/
namespace Sample\News\Block\Adminhtml\Author\Edit\Buttons;
use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
class SaveAndContinue extends Generic implements ButtonProviderInterface
{
/**
* get button data
*
* @return array
*/
public function getButtonData()
{
return [
'label' => __('Save and Continue Edit'),
'class' => 'save',
'data_attribute' => [
'mage-init' => [
'button' => ['event' => 'saveAndContinueEdit'],
],
],
'sort_order' => 80,
];
}
}
================================================
FILE: Block/Author/ListAuthor/Rss/Link.php
================================================
<?php
/**
* Sample_News extension
*
* NOTICE OF LICENSE
*
* This source file is subject to the MIT License
* that is bundled with this package in the file LICENSE
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/mit-license.php
*
* @category Sample
* @package Sample_News
* @copyright 2016 Marius Strajeru
* @license http://opensource.org/licenses/mit-license.php MIT License
* @author Marius Strajeru
*/
namespace Sample\News\Block\Author\ListAuthor\Rss;
use Magento\Framework\View\Element\Template;
use Magento\Framework\View\Element\Template\Context;
use Sample\News\Model\Author\Rss as RssModel;
class Link extends Template
{
/**
* @var RssModel
*/
protected $rssModel;
/**
* @param RssModel $rssModel
* @param Context $context
* @param array $data
*/
public function __construct(
Context $context,
RssModel $rssModel,
array $data = []
) {
$this->rssModel = $rssModel;
parent::__construct($context, $data);
}
/**
* @return string
*/
public function isRssEnabled()
{
return $this->rssModel->isRssEnabled();
}
/**
* @return string
*/
public function getLabel()
{
return __('Subscribe to RSS Feed');
}
/**
* @return string
*/
public function getLink()
{
return $this->rssModel->getRssLink();
}
}
================================================
FILE: Block/Author/ListAuthor/Rss.php
================================================
<?php
/**
* Sample_News extension
*
* NOTICE OF LICENSE
*
* This source file is subject to the MIT License
* that is bundled with this package in the file LICENSE
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/mit-license.php
*
* @category Sample
* @package Sample_News
* @copyright 2016 Marius Strajeru
* @license http://opensource.org/licenses/mit-license.php MIT License
* @author Marius Strajeru
*/
namespace Sample\News\Block\Author\ListAuthor;
use Magento\Framework\App\Rss\DataProviderInterface;
use Magento\Framework\View\Element\AbstractBlock;
use Magento\Framework\View\Element\Context;
use Magento\Store\Model\ScopeInterface;
use Magento\Store\Model\StoreManagerInterface;
use Sample\News\Model\Author;
use Sample\News\Model\Author\Rss as RssModel;
use Sample\News\Model\Author\Url;
use Sample\News\Model\ResourceModel\Author\CollectionFactory;
class Rss extends AbstractBlock implements DataProviderInterface
{
/**
* @var string
*/
const CACHE_LIFETIME_CONFIG_PATH = 'sample_news/author/rss_cache';
/**
* @var \Sample\News\Model\Author\Rss
*/
protected $rssModel;
/**
* @var \Sample\News\Model\Author\Url
*/
protected $urlModel;
/**
* @var \Sample\News\Model\ResourceModel\Author\CollectionFactory
*/
protected $authorCollectionFactory;
/**
* @var \Magento\Store\Model\StoreManagerInterface
*/
protected $storeManager;
/**
* @param Context $context
* @param RssModel $rssModel
* @param Url $urlModel
* @param CollectionFactory $authorCollectionFactory
* @param StoreManagerInterface $storeManager
* @param array $data
*/
public function __construct(
Context $context,
RssModel $rssModel,
Url $urlModel,
CollectionFactory $authorCollectionFactory,
StoreManagerInterface $storeManager,
array $data = []
) {
$this->rssModel = $rssModel;
$this->urlModel = $urlModel;
$this->authorCollectionFactory = $authorCollectionFactory;
$this->storeManager = $storeManager;
parent::__construct($context, $data);
}
/**
* @return int
*/
protected function getStoreId()
{
$storeId = (int)$this->getRequest()->getParam('store_id');
if ($storeId == null) {
$storeId = $this->storeManager->getStore()->getId();
}
return $storeId;
}
/**
* @return array
*/
public function getRssData()
{
$url = $this->urlModel->getListUrl();
$data = [
'title' => __('Authors'),
'description' => __('Authors'),
'link' => $url,
'charset' => 'UTF-8'
];
$collection = $this->authorCollectionFactory->create();
$collection->addStoreFilter($this->getStoreId());
$collection->addFieldToFilter('is_active', Author::STATUS_ENABLED);
$collection->addFieldToFilter('in_rss', 1);
foreach ($collection as $item) {
/** @var \Sample\News\Model\Author $item */
$description = '<table><tr><td><a href="%s">%s</a></td></tr></table>';
$description = sprintf($description, $item->getAuthorUrl(), $item->getName());
$data['entries'][] = [
'title' => $item->getName(),
'link' => $item->getAuthorUrl(),
'description' => $description,
];
}
return $data;
}
/**
* Check if RSS feed allowed
*
* @return mixed
*/
public function isAllowed()
{
return $this->rssModel->isRssEnabled();
}
/**
* Get information about all feeds this Data Provider is responsible for
*
* @return array
*/
public function getFeeds()
{
$feeds = [];
$feeds[] = [
'label' => __('Authors'),
'link' => $this->rssModel->getRssLink(),
];
$result = ['group' => __('News'), 'feeds' => $feeds];
return $result;
}
/**
* @return bool
*/
public function isAuthRequired()
{
return false;
}
/**
* @return int
*/
public function getCacheLifetime()
{
$lifetime = $this->_scopeConfig->getValue(
self::CACHE_LIFETIME_CONFIG_PATH,
ScopeInterface::SCOPE_STORE
);
return $lifetime ?: null;
}
}
================================================
FILE: Block/Author/ListAuthor.php
================================================
<?php
/**
* Sample_News extension
*
* NOTICE OF LICENSE
*
* This source file is subject to the MIT License
* that is bundled with this package in the file LICENSE
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/mit-license.php
*
* @category Sample
* @package Sample_News
* @copyright 2016 Marius Strajeru
* @license http://opensource.org/licenses/mit-license.php MIT License
* @author Marius Strajeru
*/
namespace Sample\News\Block\Author;
use Magento\Framework\UrlFactory;
use Magento\Framework\View\Element\Template;
use Magento\Framework\View\Element\Template\Context;
use Magento\Theme\Block\Html\Pager;
use Sample\News\Model\Author;
use Sample\News\Model\ResourceModel\Author\CollectionFactory as AuthorCollectionFactory;
class ListAuthor extends Template
{
/**
* @var AuthorCollectionFactory
*/
protected $authorCollectionFactory;
/**
* @var UrlFactory
*/
protected $urlFactory;
/**
* @var \Sample\News\Model\ResourceModel\Author\Collection
*/
protected $authors;
/**
* @param Context $context
* @param AuthorCollectionFactory $authorCollectionFactory
* @param UrlFactory $urlFactory
* @param array $data
*/
public function __construct(
Context $context,
AuthorCollectionFactory $authorCollectionFactory,
UrlFactory $urlFactory,
array $data = []
) {
$this->authorCollectionFactory = $authorCollectionFactory;
$this->urlFactory = $urlFactory;
parent::__construct($context, $data);
}
/**
* @return \Sample\News\Model\ResourceModel\Author\Collection
*/
public function getAuthors()
{
if (is_null($this->authors)) {
$this->authors = $this->authorCollectionFactory->create()
->addFieldToSelect('*')
->addFieldToFilter('is_active', Author::STATUS_ENABLED)
->addStoreFilter($this->_storeManager->getStore()->getId())
->setOrder('name', 'ASC');
}
return $this->authors;
}
/**
* @return $this
*/
protected function _prepareLayout()
{
parent::_prepareLayout();
/** @var \Magento\Theme\Block\Html\Pager $pager */
$pager = $this->getLayout()->createBlock(Pager::class, 'sample_news.author.list.pager');
$pager->setCollection($this->getAuthors());
$this->setChild('pager', $pager);
$this->getAuthors()->load();
return $this;
}
/**
* @return string
*/
public function getPagerHtml()
{
return $this->getChildHtml('pager');
}
}
================================================
FILE: Block/Author/ViewAuthor.php
================================================
<?php
/**
* Sample_News extension
*
* NOTICE OF LICENSE
*
* This source file is subject to the MIT License
* that is bundled with this package in the file LICENSE
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/mit-license.php
*
* @category Sample
* @package Sample_News
* @copyright 2016 Marius Strajeru
* @license http://opensource.org/licenses/mit-license.php MIT License
* @author Marius Strajeru
*/
namespace Sample\News\Block\Author;
use Magento\Framework\Registry;
use Magento\Framework\View\Element\Template;
use Magento\Framework\View\Element\Template\Context;
use Sample\News\Block\ImageBuilder;
class ViewAuthor extends Template
{
/**
* @var Registry
*/
protected $coreRegistry;
/**
* @var ImageBuilder
*/
protected $imageBuilder;
/**
* @param Context $context
* @param Registry $registry
* @param $imageBuilder
* @param array $data
*/
public function __construct(
Context $context,
Registry $registry,
ImageBuilder $imageBuilder,
array $data = []
) {
$this->coreRegistry = $registry;
$this->imageBuilder = $imageBuilder;
parent::__construct($context, $data);
}
/**
* get current author
*
* @return \Sample\News\Model\Author
*/
public function getCurrentAuthor()
{
return $this->coreRegistry->registry('current_author');
}
/**
* @param $entity
* @param $imageId
* @param array $attributes
* @return \Sample\News\Block\Image
*/
public function getImage($entity, $imageId, $attributes = [])
{
return $this->imageBuilder->setEntity($entity)
->setImageId($imageId)
->setAttributes($attributes)
->create();
}
}
================================================
FILE: Block/Image.php
================================================
<?php
/**
* Sample_News extension
*
* NOTICE OF LICENSE
*
* This source file is subject to the MIT License
* that is bundled with this package in the file LICENSE
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/mit-license.php
*
* @category Sample
* @package Sample_News
* @copyright 2016 Marius Strajeru
* @license http://opensource.org/licenses/mit-license.php MIT License
* @author Marius Strajeru
*/
namespace Sample\News\Block;
use Magento\Framework\View\Element\Template\Context;
use Magento\Framework\View\Element\Template;
/**
* @method string getImageUrl()
* @method string getWidth()
* @method string getHeight()
* @method string getLabel()
* @method mixed getResizedImageWidth()
* @method mixed getResizedImageHeight()
* @method float getRatio()
* @method string getCustomAttributes()
*/
class Image extends Template
{
/**
* @var \Magento\Framework\Model\AbstractModel
*/
protected $entity;
/**
* @var array
*/
protected $attributes = [];
/**
* @param Context $context
* @param array $data
*/
public function __construct(
Context $context,
array $data = []
) {
if (isset($data['template'])) {
$this->setTemplate($data['template']);
unset($data['template']);
}
parent::__construct($context, $data);
}
}
================================================
FILE: Block/ImageBuilder.php
================================================
<?php
/**
* Sample_News extension
*
* NOTICE OF LICENSE
*
* This source file is subject to the MIT License
* that is bundled with this package in the file LICENSE
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/mit-license.php
*
* @category Sample
* @package Sample_News
* @copyright 2016 Marius Strajeru
* @license http://opensource.org/licenses/mit-license.php MIT License
* @author Marius Strajeru
*/
namespace Sample\News\Block;
use Magento\Framework\Model\AbstractModel;
use Sample\News\Helper\Image as ImageHelper;
use Sample\News\Helper\ImageFactory as HelperFactory;
class ImageBuilder
{
/**
* @var ImageFactory
*/
protected $imageFactory;
/**
* @var HelperFactory
*/
protected $helperFactory;
/**
* @var \Magento\Framework\Model\AbstractModel
*/
protected $entity;
/**
* @var string
*/
protected $imageId;
/**
* @var array
*/
protected $attributes = [];
/**
* @var string
*/
protected $entityCode;
/**
* @param HelperFactory $helperFactory
* @param ImageFactory $imageFactory
* @param $entityCode
*/
public function __construct(
HelperFactory $helperFactory,
ImageFactory $imageFactory,
$entityCode
) {
$this->helperFactory = $helperFactory;
$this->imageFactory = $imageFactory;
$this->entityCode = $entityCode;
}
/**
* @param \Magento\Framework\Model\AbstractModel $entity
* @return $this
*/
public function setEntity(AbstractModel $entity)
{
$this->entity = $entity;
return $this;
}
/**
* Set image ID
*
* @param string $imageId
* @return $this
*/
public function setImageId($imageId)
{
$this->imageId = $imageId;
return $this;
}
/**
* Set custom attributes
*
* @param array $attributes
* @return $this
*/
public function setAttributes(array $attributes)
{
if ($attributes) {
$this->attributes = $attributes;
}
return $this;
}
/**
* Retrieve image custom attributes for HTML element
*
* @return string
*/
protected function getCustomAttributes()
{
$result = [];
foreach ($this->attributes as $name => $value) {
$result[] = $name . '="' . $value . '"';
}
return !empty($result) ? implode(' ', $result) : '';
}
/**
* Calculate image ratio
*
* @param ImageHelper $helper
* @return float|int
*/
protected function getRatio(ImageHelper $helper)
{
$width = $helper->getWidth();
$height = $helper->getHeight();
if ($width && $height) {
return $height / $width;
}
return 1;
}
/**
* Create image block
*
* @return \Sample\News\Block\Image
*/
public function create()
{
/** @var ImageHelper $helper */
$helper = $this->helperFactory
->create([
'entityCode' => $this->entityCode
])
->init(
$this->entity,
$this->imageId,
$this->attributes
);
$template = $helper->getFrame()
? 'Sample_News::image.phtml'
: 'Sample_News::image_with_borders.phtml';
$imagesize = $helper->getResizedImageInfo();
$data = [
'data' => [
'template' => $template,
'image_url' => $helper->getUrl(),
'width' => $helper->getWidth(),
'height' => $helper->getHeight(),
'label' => $helper->getLabel(),
'ratio' => $this->getRatio($helper),
'custom_attributes' => $this->getCustomAttributes(),
'resized_image_width' => !empty($imagesize[0]) ? $imagesize[0] : $helper->getWidth(),
'resized_image_height' => !empty($imagesize[1]) ? $imagesize[1] : $helper->getHeight(),
],
];
return $this->imageFactory->create($data);
}
}
================================================
FILE: Controller/Adminhtml/Author/Delete.php
================================================
<?php
/**
* Sample_News extension
*
* NOTICE OF LICENSE
*
* This source file is subject to the MIT License
* that is bundled with this package in the file LICENSE
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/mit-license.php
*
* @category Sample
* @package Sample_News
* @copyright 2016 Marius Strajeru
* @license http://opensource.org/licenses/mit-license.php MIT License
* @author Marius Strajeru
*/
namespace Sample\News\Controller\Adminhtml\Author;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Exception\NoSuchEntityException;
use Sample\News\Controller\Adminhtml\Author;
class Delete extends Author
{
/**
* @return \Magento\Backend\Model\View\Result\Redirect
*/
public function execute()
{
$resultRedirect = $this->resultRedirectFactory->create();
$id = $this->getRequest()->getParam('author_id');
if ($id) {
try {
$this->authorRepository->deleteById($id);
$this->messageManager->addSuccessMessage(__('The author has been deleted.'));
$resultRedirect->setPath('sample_news/*/');
return $resultRedirect;
} catch (NoSuchEntityException $e) {
$this->messageManager->addErrorMessage(__('The author no longer exists.'));
return $resultRedirect->setPath('sample_news/*/');
} catch (LocalizedException $e) {
$this->messageManager->addErrorMessage($e->getMessage());
return $resultRedirect->setPath('sample_news/author/edit', ['author_id' => $id]);
} catch (\Exception $e) {
$this->messageManager->addErrorMessage(__('There was a problem deleting the author'));
return $resultRedirect->setPath('sample_news/author/edit', ['author_id' => $id]);
}
}
$this->messageManager->addErrorMessage(__('We can\'t find a author to delete.'));
$resultRedirect->setPath('sample_news/*/');
return $resultRedirect;
}
}
================================================
FILE: Controller/Adminhtml/Author/Edit.php
================================================
<?php
/**
* Sample_News extension
*
* NOTICE OF LICENSE
*
* This source file is subject to the MIT License
* that is bundled with this package in the file LICENSE
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/mit-license.php
*
* @category Sample
* @package Sample_News
* @copyright 2016 Marius Strajeru
* @license http://opensource.org/licenses/mit-license.php MIT License
* @author Marius Strajeru
*/
namespace Sample\News\Controller\Adminhtml\Author;
use Sample\News\Controller\Adminhtml\Author;
use Sample\News\Controller\RegistryConstants;
class Edit extends Author
{
/**
* Initialize current author and set it in the registry.
*
* @return int
*/
protected function _initAuthor()
{
$authorId = $this->getRequest()->getParam('author_id');
$this->coreRegistry->register(RegistryConstants::CURRENT_AUTHOR_ID, $authorId);
return $authorId;
}
/**
* Edit or create author
*
* @return \Magento\Backend\Model\View\Result\Page
*/
public function execute()
{
$authorId = $this->_initAuthor();
/** @var \Magento\Backend\Model\View\Result\Page $resultPage */
$resultPage = $this->resultPageFactory->create();
$resultPage->setActiveMenu('Sample_News::author');
$resultPage->getConfig()->getTitle()->prepend(__('Authors'));
$resultPage->addBreadcrumb(__('News'), __('News'));
$resultPage->addBreadcrumb(__('Authors'), __('Authors'), $this->getUrl('sample_news/author'));
if ($authorId === null) {
$resultPage->addBreadcrumb(__('New Author'), __('New Author'));
$resultPage->getConfig()->getTitle()->prepend(__('New Author'));
} else {
$resultPage->addBreadcrumb(__('Edit Author'), __('Edit Author'));
$resultPage->getConfig()->getTitle()->prepend(
$this->authorRepository->getById($authorId)->getName()
);
}
return $resultPage;
}
}
================================================
FILE: Controller/Adminhtml/Author/File/Upload.php
================================================
<?php
/**
* Sample_News extension
*
* NOTICE OF LICENSE
*
* This source file is subject to the MIT License
* that is bundled with this package in the file LICENSE
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/mit-license.php
*
* @category Sample
* @package Sample_News
* @copyright 2016 Marius Strajeru
* @license http://opensource.org/licenses/mit-license.php MIT License
* @author Marius Strajeru
*/
namespace Sample\News\Controller\Adminhtml\Author\File;
use Sample\News\Controller\Adminhtml\Author\Upload as GenericUpload;
class Upload extends GenericUpload
{
}
================================================
FILE: Controller/Adminhtml/Author/Image/Upload.php
================================================
<?php
/**
* Sample_News extension
*
* NOTICE OF LICENSE
*
* This source file is subject to the MIT License
* that is bundled with this package in the file LICENSE
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/mit-license.php
*
* @category Sample
* @package Sample_News
* @copyright 2016 Marius Strajeru
* @license http://opensource.org/licenses/mit-license.php MIT License
* @author Marius Strajeru
*/
namespace Sample\News\Controller\Adminhtml\Author\Image;
use Sample\News\Controller\Adminhtml\Author\Upload as GenericUpload;
class Upload extends GenericUpload
{
}
================================================
FILE: Controller/Adminhtml/Author/Index.php
================================================
<?php
/**
* Sample_News extension
*
* NOTICE OF LICENSE
*
* This source file is subject to the MIT License
* that is bundled with this package in the file LICENSE
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/mit-license.php
*
* @category Sample
* @package Sample_News
* @copyright 2016 Marius Strajeru
* @license http://opensource.org/licenses/mit-license.php MIT License
* @author Marius Strajeru
*/
namespace Sample\News\Controller\Adminhtml\Author;
use \Sample\News\Controller\Adminhtml\Author as AuthorController;
class Index extends AuthorController
{
/**
* Authors list.
*
* @return \Magento\Backend\Model\View\Result\Page
*/
public function execute()
{
/** @var \Magento\Backend\Model\View\Result\Page $resultPage */
$resultPage = $this->resultPageFactory->create();
$resultPage->setActiveMenu('Sample_News::author');
$resultPage->getConfig()->getTitle()->prepend(__('Authors'));
$resultPage->addBreadcrumb(__('News'), __('News'));
$resultPage->addBreadcrumb(__('Authors'), __('Authors'));
return $resultPage;
}
}
================================================
FILE: Controller/Adminhtml/Author/InlineEdit.php
================================================
<?php
/**
* Sample_News extension
*
* NOTICE OF LICENSE
*
* This source file is subject to the MIT License
* that is bundled with this package in the file LICENSE
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/mit-license.php
*
* @category Sample
* @package Sample_News
* @copyright 2016 Marius Strajeru
* @license http://opensource.org/licenses/mit-license.php MIT License
* @author Marius Strajeru
*/
namespace Sample\News\Controller\Adminhtml\Author;
use Magento\Backend\App\Action\Context;
use Magento\Backend\Model\Session;
use Magento\Framework\Api\DataObjectHelper;
use Magento\Framework\Controller\Result\JsonFactory;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Reflection\DataObjectProcessor;
use Magento\Framework\Registry;
use Magento\Framework\Stdlib\DateTime\Filter\Date;
use Magento\Framework\View\Result\PageFactory;
use Sample\News\Api\AuthorRepositoryInterface;
use Sample\News\Api\Data\AuthorInterface;
use Sample\News\Api\Data\AuthorInterfaceFactory;
use Sample\News\Controller\Adminhtml\Author as AuthorController;
use Sample\News\Model\Author;
use Sample\News\Model\ResourceModel\Author as AuthorResourceModel;
class InlineEdit extends AuthorController
{
/**
* @var DataObjectHelper
*/
protected $dataObjectHelper;
/**
* @var DataObjectProcessor
*/
protected $dataObjectProcessor;
/**
* @var JsonFactory
*/
protected $jsonFactory;
/**
* @var AuthorResourceModel
*/
protected $authorResourceModel;
/**
* @param Registry $registry
* @param AuthorRepositoryInterface $authorRepository
* @param PageFactory $resultPageFactory
* @param Date $dateFilter
* @param Context $context
* @param DataObjectProcessor $dataObjectProcessor
* @param DataObjectHelper $dataObjectHelper
* @param JsonFactory $jsonFactory
* @param AuthorResourceModel $authorResourceModel
*/
public function __construct(
Registry $registry,
AuthorRepositoryInterface $authorRepository,
PageFactory $resultPageFactory,
Date $dateFilter,
Context $context,
DataObjectProcessor $dataObjectProcessor,
DataObjectHelper $dataObjectHelper,
JsonFactory $jsonFactory,
AuthorResourceModel $authorResourceModel
)
{
$this->dataObjectProcessor = $dataObjectProcessor;
$this->dataObjectHelper = $dataObjectHelper;
$this->jsonFactory = $jsonFactory;
$this->authorResourceModel = $authorResourceModel;
parent::__construct($registry, $authorRepository, $resultPageFactory, $dateFilter, $context);
}
/**
* @return \Magento\Framework\Controller\ResultInterface
*/
public function execute()
{
/** @var \Magento\Framework\Controller\Result\Json $resultJson */
$resultJson = $this->jsonFactory->create();
$error = false;
$messages = [];
$postItems = $this->getRequest()->getParam('items', []);
if (!($this->getRequest()->getParam('isAjax') && count($postItems))) {
return $resultJson->setData([
'messages' => [__('Please correct the data sent.')],
'error' => true,
]);
}
foreach (array_keys($postItems) as $authorId) {
/** @var \Sample\News\Model\Author|AuthorInterface $author */
$author = $this->authorRepository->getById((int)$authorId);
try {
$authorData = $this->filterData($postItems[$authorId]);
$this->dataObjectHelper->populateWithArray($author, $authorData , AuthorInterface::class);
$this->authorResourceModel->saveAttribute($author, array_keys($authorData));
} catch (LocalizedException $e) {
$messages[] = $this->getErrorWithAuthorId($author, $e->getMessage());
$error = true;
} catch (\RuntimeException $e) {
$messages[] = $this->getErrorWithAuthorId($author, $e->getMessage());
$error = true;
} catch (\Exception $e) {
$messages[] = $this->getErrorWithAuthorId(
$author,
__('Something went wrong while saving the author.')
);
$error = true;
}
}
return $resultJson->setData([
'messages' => $messages,
'error' => $error
]);
}
/**
* Add author id to error message
*
* @param Author $author
* @param string $errorText
* @return string
*/
protected function getErrorWithAuthorId(Author $author, $errorText)
{
return '[Author ID: ' . $author->getId() . '] ' . $errorText;
}
}
================================================
FILE: Controller/Adminhtml/Author/MassAction.php
================================================
<?php
/**
* Sample_News extension
*
* NOTICE OF LICENSE
*
* This source file is subject to the MIT License
* that is bundled with this package in the file LICENSE
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/mit-license.php
*
* @category Sample
* @package Sample_News
* @copyright 2016 Marius Strajeru
* @license http://opensource.org/licenses/mit-license.php MIT License
* @author Marius Strajeru
*/
namespace Sample\News\Controller\Adminhtml\Author;
use Magento\Backend\App\Action;
use Magento\Backend\App\Action\Context;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Registry;
use Magento\Framework\Stdlib\DateTime\Filter\Date;
use Magento\Framework\View\Result\PageFactory;
use Magento\Ui\Component\MassAction\Filter;
use Sample\News\Api\AuthorRepositoryInterface;
use Sample\News\Controller\Adminhtml\Author;
use Sample\News\Model\Author as AuthorModel;
use Sample\News\Model\ResourceModel\Author\CollectionFactory;
abstract class MassAction extends Author
{
/**
* @var Filter
*/
protected $filter;
/**
* @var CollectionFactory
*/
protected $collectionFactory;
/**
* @var string
*/
protected $successMessage;
/**
* @var string
*/
protected $errorMessage;
/**
* @param Registry $registry
* @param AuthorRepositoryInterface $authorRepository
* @param PageFactory $resultPageFactory
* @param Date $dateFilter
* @param Context $context
* @param Filter $filter
* @param CollectionFactory $collectionFactory
* @param $successMessage
* @param $errorMessage
*/
public function __construct(
Registry $registry,
AuthorRepositoryInterface $authorRepository,
PageFactory $resultPageFactory,
Date $dateFilter,
Context $context,
Filter $filter,
CollectionFactory $collectionFactory,
$successMessage,
$errorMessage
) {
$this->filter = $filter;
$this->collectionFactory = $collectionFactory;
$this->successMessage = $successMessage;
$this->errorMessage = $errorMessage;
parent::__construct($registry, $authorRepository, $resultPageFactory, $dateFilter, $context);
}
/**
* @param AuthorModel $author
* @return mixed
*/
protected abstract function massAction(AuthorModel $author);
/**
* execute action
*
* @return \Magento\Backend\Model\View\Result\Redirect
*/
public function execute()
{
try {
$collection = $this->filter->getCollection($this->collectionFactory->create());
$collectionSize = $collection->getSize();
foreach ($collection as $author) {
$this->massAction($author);
}
$this->messageManager->addSuccessMessage(__($this->successMessage, $collectionSize));
} catch (LocalizedException $e) {
$this->messageManager->addErrorMessage($e->getMessage());
} catch (\Exception $e) {
$this->messageManager->addExceptionMessage($e, __($this->errorMessage));
}
$redirectResult = $this->resultRedirectFactory->create();
$redirectResult->setPath('sample_news/*/index');
return $redirectResult;
}
}
================================================
FILE: Controller/Adminhtml/Author/MassDelete.php
================================================
<?php
/**
* Sample_News extension
*
* NOTICE OF LICENSE
*
* This source file is subject to the MIT License
* that is bundled with this package in the file LICENSE
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/mit-license.php
*
* @category Sample
* @package Sample_News
* @copyright 2016 Marius Strajeru
* @license http://opensource.org/licenses/mit-license.php MIT License
* @author Marius Strajeru
*/
namespace Sample\News\Controller\Adminhtml\Author;
use Sample\News\Model\Author;
class MassDelete extends MassAction
{
/**
* @param Author $author
* @return $this
*/
protected function massAction(Author $author)
{
$this->authorRepository->delete($author);
return $this;
}
}
================================================
FILE: Controller/Adminhtml/Author/MassDisable.php
================================================
<?php
/**
* Sample_News extension
*
* NOTICE OF LICENSE
*
* This source file is subject to the MIT License
* that is bundled with this package in the file LICENSE
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/mit-license.php
*
* @category Sample
* @package Sample_News
* @copyright 2016 Marius Strajeru
* @license http://opensource.org/licenses/mit-license.php MIT License
* @author Marius Strajeru
*/
namespace Sample\News\Controller\Adminhtml\Author;
use Sample\News\Model\Author;
class MassDisable extends MassAction
{
/**
* @var bool
*/
protected $isActive = false;
/**
* @param Author $author
* @return $this
*/
protected function massAction(Author $author)
{
$author->setIsActive($this->isActive);
$this->authorRepository->save($author);
return $this;
}
}
================================================
FILE: Controller/Adminhtml/Author/MassEnable.php
================================================
<?php
/**
* Sample_News extension
*
* NOTICE OF LICENSE
*
* This source file is subject to the MIT License
* that is bundled with this package in the file LICENSE
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/mit-license.php
*
* @category Sample
* @package Sample_News
* @copyright 2016 Marius Strajeru
* @license http://opensource.org/licenses/mit-license.php MIT License
* @author Marius Strajeru
*/
namespace Sample\News\Controller\Adminhtml\Author;
class MassEnable extends MassDisable
{
/**
* @var bool
*/
protected $isActive = true;
}
================================================
FILE: Controller/Adminhtml/Author/NewAction.php
================================================
<?php
/**
* Sample_News extension
*
* NOTICE OF LICENSE
*
* This source file is subject to the MIT License
* that is bundled with this package in the file LICENSE
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/mit-license.php
*
* @category Sample
* @package Sample_News
* @copyright 2016 Marius Strajeru
* @license http://opensource.org/licenses/mit-license.php MIT License
* @author Marius Strajeru
*/
namespace Sample\News\Controller\Adminhtml\Author;
use Magento\Backend\App\Action;
use Magento\Backend\App\Action\Context;
use Magento\Backend\Model\View\Result\ForwardFactory;
class NewAction extends Action
{
/**
* @var string
*/
const ACTION_RESOURCE = 'Sample_News::author';
/**
* @var ForwardFactory
*/
protected $resultForwardFactory;
/**
* constructor
*
* @param Context $context
* @param ForwardFactory $resultForwardFactory
*/
public function __construct(
Context $context,
ForwardFactory $resultForwardFactory
) {
$this->resultForwardFactory = $resultForwardFactory;
parent::__construct($context);
}
/**
* forward to edit
*
* @return \Magento\Backend\Model\View\Result\Forward
*/
public function execute()
{
$resultForward = $this->resultForwardFactory->create();
$resultForward->forward('edit');
return $resultForward;
}
}
================================================
FILE: Controller/Adminhtml/Author/Save.php
================================================
<?php
/**
* Sample_News extension
*
* NOTICE OF LICENSE
*
* This source file is subject to the MIT License
* that is bundled with this package in the file LICENSE
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/mit-license.php
*
* @category Sample
* @package Sample_News
* @copyright 2016 Marius Strajeru
* @license http://opensource.org/licenses/mit-license.php MIT License
* @author Marius Strajeru
*/
namespace Sample\News\Controller\Adminhtml\Author;
use Magento\Backend\Model\Session;
use Magento\Backend\App\Action\Context;
use Magento\Framework\Api\DataObjectHelper;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Reflection\DataObjectProcessor;
use Magento\Framework\Registry;
use Magento\Framework\Stdlib\DateTime\Filter\Date;
use Magento\Framework\View\Result\PageFactory;
use Sample\News\Api\AuthorRepositoryInterface;
use Sample\News\Api\Data\AuthorInterface;
use Sample\News\Api\Data\AuthorInterfaceFactory;
use Sample\News\Controller\Adminhtml\Author;
use Sample\News\Model\Uploader;
use Sample\News\Model\UploaderPool;
class Save extends Author
{
/**
* @var DataObjectProcessor
*/
protected $dataObjectProcessor;
/**
* @var DataObjectHelper
*/
protected $dataObjectHelper;
/**
* @var UploaderPool
*/
protected $uploaderPool;
/**
* @param Registry $registry
* @param AuthorRepositoryInterface $authorRepository
* @param PageFactory $resultPageFactory
* @param Date $dateFilter
* @param Context $context
* @param AuthorInterfaceFactory $authorFactory
* @param DataObjectProcessor $dataObjectProcessor
* @param DataObjectHelper $dataObjectHelper
* @param UploaderPool $uploaderPool
*/
public function __construct(
Registry $registry,
AuthorRepositoryInterface $authorRepository,
PageFactory $resultPageFactory,
Date $dateFilter,
Context $context,
AuthorInterfaceFactory $authorFactory,
DataObjectProcessor $dataObjectProcessor,
DataObjectHelper $dataObjectHelper,
UploaderPool $uploaderPool
)
{
$this->authorFactory = $authorFactory;
$this->dataObjectProcessor = $dataObjectProcessor;
$this->dataObjectHelper = $dataObjectHelper;
$this->uploaderPool = $uploaderPool;
parent::__construct($registry, $authorRepository, $resultPageFactory, $dateFilter, $context);
}
/**
* run the action
*
* @return \Magento\Backend\Model\View\Result\Redirect
*/
public function execute()
{
/** @var \Sample\News\Api\Data\AuthorInterface $author */
$author = null;
$data = $this->getRequest()->getPostValue();
$id = !empty($data['author_id']) ? $data['author_id'] : null;
$resultRedirect = $this->resultRedirectFactory->create();
try {
if ($id) {
$author = $this->authorRepository->getById((int)$id);
} else {
unset($data['author_id']);
$author = $this->authorFactory->create();
}
$avatar = $this->getUploader('image')->uploadFileAndGetName('avatar', $data);
$data['avatar'] = $avatar;
$resume = $this->getUploader('file')->uploadFileAndGetName('resume', $data);
$data['resume'] = $resume;
$this->dataObjectHelper->populateWithArray($author, $data, AuthorInterface::class);
$this->authorRepository->save($author);
$this->messageManager->addSuccessMessage(__('You saved the author'));
if ($this->getRequest()->getParam('back')) {
$resultRedirect->setPath('sample_news/author/edit', ['author_id' => $author->getId()]);
} else {
$resultRedirect->setPath('sample_news/author');
}
} catch (LocalizedException $e) {
$this->messageManager->addErrorMessage($e->getMessage());
if ($author != null) {
$this->storeAuthorDataToSession(
$this->dataObjectProcessor->buildOutputDataArray(
$author,
AuthorInterface::class
)
);
}
$resultRedirect->setPath('sample_news/author/edit', ['author_id' => $id]);
} catch (\Exception $e) {
$this->messageManager->addErrorMessage(__('There was a problem saving the author'));
if ($author != null) {
$this->storeAuthorDataToSession(
$this->dataObjectProcessor->buildOutputDataArray(
$author,
AuthorInterface::class
)
);
}
$resultRedirect->setPath('sample_news/author/edit', ['author_id' => $id]);
}
return $resultRedirect;
}
/**
* @param $type
* @return Uploader
* @throws \Exception
*/
protected function getUploader($type)
{
return $this->uploaderPool->getUploader($type);
}
/**
* @param $authorData
*/
protected function storeAuthorDataToSession($authorData)
{
$this->_getSession()->setSampleNewsAuthorData($authorData);
}
}
================================================
FILE: Controller/Adminhtml/Author/Upload.php
================================================
<?php
/**
* Sample_News extension
*
* NOTICE OF LICENSE
*
* This source file is subject to the MIT License
* that is bundled with this package in the file LICENSE
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/mit-license.php
*
* @category Sample
* @package Sample_News
* @copyright 2016 Marius Strajeru
* @license http://opensource.org/licenses/mit-license.php MIT License
* @author Marius Strajeru
*/
namespace Sample\News\Controller\Adminhtml\Author;
use Magento\Backend\App\Action;
use Magento\Backend\App\Action\Context;
use Magento\Framework\Controller\ResultFactory;
use Sample\News\Model\Uploader;
class Upload extends Action
{
/**
* @var string
*/
const ACTION_RESOURCE = 'Sample_News::author';
/**
* uploader
*
* @var Uploader
*/
protected $uploader;
/**
* @param Context $context
* @param Uploader $uploader
*/
public function __construct(
Context $context,
Uploader $uploader
) {
parent::__construct($context);
$this->uploader = $uploader;
}
/**
* Upload file controller action
*
* @return \Magento\Framework\Controller\ResultInterface
*/
public function execute()
{
try {
$result = $this->uploader->saveFileToTmpDir($this->getFieldName());
$result['cookie'] = [
'name' => $this->_getSession()->getName(),
'value' => $this->_getSession()->getSessionId(),
'lifetime' => $this->_getSession()->getCookieLifetime(),
'path' => $this->_getSession()->getCookiePath(),
'domain' => $this->_getSession()->getCookieDomain(),
];
} catch (\Exception $e) {
$result = ['error' => $e->getMessage(), 'errorcode' => $e->getCode()];
}
return $this->resultFactory->create(ResultFactory::TYPE_JSON)->setData($result);
}
/**
* @return string
*/
protected function getFieldName()
{
return $this->_request->getParam('field');
}
}
================================================
FILE: Controller/Adminhtml/Author.php
================================================
<?php
/**
* Sample_News extension
*
* NOTICE OF LICENSE
*
* This source file is subject to the MIT License
* that is bundled with this package in the file LICENSE
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/mit-license.php
*
* @category Sample
* @package Sample_News
* @copyright 2016 Marius Strajeru
* @license http://opensource.org/licenses/mit-license.php MIT License
* @author Marius Strajeru
*/
namespace Sample\News\Controller\Adminhtml;
use Magento\Backend\App\Action;
use Magento\Backend\App\Action\Context;
use Magento\Framework\Registry;
use Magento\Framework\Stdlib\DateTime\Filter\Date;
use Magento\Framework\View\Result\PageFactory;
use Sample\News\Api\AuthorRepositoryInterface;
abstract class Author extends Action
{
/**
* @var string
*/
const ACTION_RESOURCE = 'Sample_News::author';
/**
* author factory
*
* @var AuthorRepositoryInterface
*/
protected $authorRepository;
/**
* Core registry
*
* @var Registry
*/
protected $coreRegistry;
/**
* date filter
*
* @var \Magento\Framework\Stdlib\DateTime\Filter\Date
*/
protected $dateFilter;
/**
* @var PageFactory
*/
protected $resultPageFactory;
/**
* @param Registry $registry
* @param AuthorRepositoryInterface $authorRepository
* @param PageFactory $resultPageFactory
* @param Date $dateFilter
* @param Context $context
*/
public function __construct(
Registry $registry,
AuthorRepositoryInterface $authorRepository,
PageFactory $resultPageFactory,
Date $dateFilter,
Context $context
) {
$this->coreRegistry = $registry;
$this->authorRepository = $authorRepository;
$this->resultPageFactory = $resultPageFactory;
$this->dateFilter = $dateFilter;
parent::__construct($context);
}
/**
* filter dates
*
* @param array $data
* @return array
*/
public function filterData($data)
{
$inputFilter = new \Zend_Filter_Input(
['dob' => $this->dateFilter],
[],
$data
);
$data = $inputFilter->getUnescaped();
if (isset($data['awards'])) {
if (is_array($data['awards'])) {
$data['awards'] = implode(',', $data['awards']);
}
}
return $data;
}
}
================================================
FILE: Controller/Author/Index.php
================================================
<?php
/**
* Sample_News extension
*
* NOTICE OF LICENSE
*
* This source file is subject to the MIT License
* that is bundled with this package in the file LICENSE
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/mit-license.php
*
* @category Sample
* @package Sample_News
* @copyright 2016 Marius Strajeru
* @license http://opensource.org/licenses/mit-license.php MIT License
* @author Marius Strajeru
*/
namespace Sample\News\Controller\Author;
use Magento\Framework\App\Action\Action;
use Magento\Framework\App\Action\Context;
use Magento\Framework\View\Result\PageFactory;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Store\Model\ScopeInterface;
class Index extends Action
{
/**
* @var string
*/
const META_DESCRIPTION_CONFIG_PATH = 'sample_news/author/meta_description';
/**
* @var string
*/
const META_KEYWORDS_CONFIG_PATH = 'sample_news/author/meta_keywords';
/**
* @var string
*/
const META_TITLE_CONFIG_PATH = 'sample_news/author/meta_title';
/**
* @var string
*/
const BREADCRUMBS_CONFIG_PATH = 'sample_news/author/breadcrumbs';
/**
* @var \Magento\Framework\App\Config\ScopeConfigInterface
*/
protected $scopeConfig;
/**
* @param Context $context
* @param PageFactory $resultPageFactory
* @param ScopeConfigInterface $scopeConfig
*/
public function __construct(
Context $context,
PageFactory $resultPageFactory,
ScopeConfigInterface $scopeConfig
) {
parent::__construct($context);
$this->resultPageFactory = $resultPageFactory;
$this->scopeConfig = $scopeConfig;
}
/**
* @return \Magento\Framework\View\Result\Page
*/
public function execute()
{
$resultPage = $this->resultPageFactory->create();
$resultPage->getConfig()->getTitle()->set(
$this->scopeConfig->getValue(self::META_TITLE_CONFIG_PATH, ScopeInterface::SCOPE_STORE)
);
$resultPage->getConfig()->setDescription(
$this->scopeConfig->getValue(self::META_DESCRIPTION_CONFIG_PATH, ScopeInterface::SCOPE_STORE)
);
$resultPage->getConfig()->setKeywords(
$this->scopeConfig->getValue(self::META_KEYWORDS_CONFIG_PATH, ScopeInterface::SCOPE_STORE)
);
if ($this->scopeConfig->isSetFlag(self::BREADCRUMBS_CONFIG_PATH, ScopeInterface::SCOPE_STORE)) {
/** @var \Magento\Theme\Block\Html\Breadcrumbs $breadcrumbsBlock */
$breadcrumbsBlock = $resultPage->getLayout()->getBlock('breadcrumbs');
if ($breadcrumbsBlock) {
$breadcrumbsBlock->addCrumb(
'home',
[
'label' => __('Home'),
'link' => $this->_url->getUrl('')
]
);
$breadcrumbsBlock->addCrumb(
'authors',
[
'label' => __('Authors'),
]
);
}
}
return $resultPage;
}
}
================================================
FILE: Controller/Author/Rss.php
================================================
<?php
/**
* Sample_News extension
*
* NOTICE OF LICENSE
*
* This source file is subject to the MIT License
* that is bundled with this package in the file LICENSE
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/mit-license.php
*
* @category Sample
* @package Sample_News
* @copyright 2016 Marius Strajeru
* @license http://opensource.org/licenses/mit-license.php MIT License
* @author Marius Strajeru
*/
namespace Sample\News\Controller\Author;
use Magento\Customer\Api\AccountManagementInterface;
use Magento\Customer\Model\Session;
class Rss extends \Magento\Rss\Controller\Feed\Index
{
/**
* @return void
*/
public function execute()
{
$this->getRequest()->setParam('type', 'authors');
parent::execute();
}
}
================================================
FILE: Controller/Author/View.php
================================================
<?php
/**
* Sample_News extension
*
* NOTICE OF LICENSE
*
* This source file is subject to the MIT License
* that is bundled with this package in the file LICENSE
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/mit-license.php
*
* @category Sample
* @package Sample_News
* @copyright 2016 Marius Strajeru
* @license http://opensource.org/licenses/mit-license.php MIT License
* @author Marius Strajeru
*/
namespace Sample\News\Controller\Author;
use Magento\Framework\App\Action\Action;
use Magento\Framework\App\Action\Context;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\Controller\Result\ForwardFactory;
use Magento\Framework\Registry;
use Magento\Framework\View\Result\PageFactory;
use Magento\Store\Model\ScopeInterface;
use Sample\News\Api\AuthorRepositoryInterface;
use Sample\News\Model\Author\Url as UrlModel;
class View extends Action
{
/**
* @var string
*/
const BREADCRUMBS_CONFIG_PATH = 'sample_news/author/breadcrumbs';
/**
* @var \Sample\News\Api\AuthorRepositoryInterface
*/
protected $authorRepository;
/**
* @var \Magento\Framework\Controller\Result\ForwardFactory
*/
protected $resultForwardFactory;
/**
* @var \Magento\Framework\View\Result\PageFactory
*/
protected $resultPageFactory;
/**
* @var \Magento\Framework\Registry
*/
protected $coreRegistry;
/**
* @var \Sample\News\Model\Author\Url
*/
protected $urlModel;
/**
* @var \Magento\Framework\App\Config\ScopeConfigInterface
*/
protected $scopeConfig;
/**
* @param Context $context
* @param AuthorRepositoryInterface $authorRepository
* @param ForwardFactory $resultForwardFactory
* @param PageFactory $resultPageFactory
* @param Registry $coreRegistry
* @param UrlModel $urlModel
* @param ScopeConfigInterface $scopeConfig
*/
public function __construct(
Context $context,
AuthorRepositoryInterface $authorRepository,
ForwardFactory $resultForwardFactory,
PageFactory $resultPageFactory,
Registry $coreRegistry,
UrlModel $urlModel,
ScopeConfigInterface $scopeConfig
) {
$this->resultForwardFactory = $resultForwardFactory;
$this->authorRepository = $authorRepository;
$this->resultPageFactory = $resultPageFactory;
$this->coreRegistry = $coreRegistry;
$this->urlModel = $urlModel;
$this->scopeConfig = $scopeConfig;
parent::__construct($context);
}
/**
* @return \Magento\Framework\Controller\Result\Forward|\Magento\Framework\View\Result\Page
*/
public function execute()
{
try {
$authorId = (int)$this->getRequest()->getParam('id');
$author = $this->authorRepository->getById($authorId);
if (!$author->getIsActive()) {
throw new \Exception();
}
} catch (\Exception $e){
$resultForward = $this->resultForwardFactory->create();
$resultForward->forward('noroute');
return $resultForward;
}
$this->coreRegistry->register('current_author', $author);
$resultPage = $this->resultPageFactory->create();
//$title = ($author->getMetaTitle()) ?: $author->getName();
$resultPage->getConfig()->getTitle()->set($author->getName());
$resultPage->getConfig()->setDescription($author->getMetaDescription());
$resultPage->getConfig()->setKeywords($author->getMetaKeywords());
if ($this->scopeConfig->isSetFlag(self::BREADCRUMBS_CONFIG_PATH, ScopeInterface::SCOPE_STORE)) {
/** @var \Magento\Theme\Block\Html\Breadcrumbs $breadcrumbsBlock */
$breadcrumbsBlock = $resultPage->getLayout()->getBlock('breadcrumbs');
if ($breadcrumbsBlock) {
$breadcrumbsBlock->addCrumb(
'home',
[
'label' => __('Home'),
'link' => $this->_url->getUrl('')
]
);
$breadcrumbsBlock->addCrumb(
'authors',
[
'label' => __('Authors'),
'link' => $this->urlModel->getListUrl()
]
);
$breadcrumbsBlock->addCrumb(
'author-'.$author->getId(),
[
'label' => $author->getName()
]
);
}
}
return $resultPage;
}
}
================================================
FILE: Controller/RegistryConstants.php
================================================
<?php
/**
* Sample_News extension
*
* NOTICE OF LICENSE
*
* This source file is subject to the MIT License
* that is bundled with this package in the file LICENSE
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/mit-license.php
*
* @category Sample
* @package Sample_News
* @copyright 2016 Marius Strajeru
* @license http://opensource.org/licenses/mit-license.php MIT License
* @author Marius Strajeru
*/
namespace Sample\News\Controller;
class RegistryConstants
{
/**
* Registry key where current author ID is stored
*/
const CURRENT_AUTHOR_ID = 'current_author_id';
}
================================================
FILE: Controller/Router.php
================================================
<?php
/**
* Sample_News extension
*
* NOTICE OF LICENSE
*
* This source file is subject to the MIT License
* that is bundled with this package in the file LICENSE
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/mit-license.php
*
* @category Sample
* @package Sample_News
* @copyright 2016 Marius Strajeru
* @license http://opensource.org/licenses/mit-license.php MIT License
* @author Marius Strajeru
*/
namespace Sample\News\Controller;
use Magento\Framework\App\ActionFactory;
use Magento\Framework\App\Action\Forward;
use Magento\Framework\App\Action\Redirect;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\App\RequestInterface;
use Magento\Framework\App\ResponseInterface;
use Magento\Framework\App\RouterInterface;
use Magento\Framework\App\State;
use Magento\Framework\DataObject;
use Magento\Framework\Event\ManagerInterface;
use Magento\Framework\Url;
use Magento\Framework\UrlInterface;
use Magento\Store\Model\ScopeInterface;
use Magento\Store\Model\StoreManagerInterface;
use Sample\News\Model\Routing\Entity;
class Router implements RouterInterface
{
/**
* @var \Magento\Framework\App\ActionFactory
*/
protected $actionFactory;
/**
* Event manager
* @var \Magento\Framework\Event\ManagerInterface
*/
protected $eventManager;
/**
* Store manager
* @var \Magento\Store\Model\StoreManagerInterface
*/
protected $storeManager;
/**
* Author factory
* @var \Sample\News\Model\AuthorFactory
*/
protected $authorFactory;
/**
* Config primary
* @var \Magento\Framework\App\State
*/
protected $appState;
/**
* Url
* @var \Magento\Framework\UrlInterface
*/
protected $url;
/**
* Response
* @var \Magento\Framework\App\ResponseInterface|\Magento\Framework\App\Response\Http
*/
protected $response;
/**
* @var \Magento\Framework\App\Config\ScopeConfigInterface
*/
protected $scopeConfig;
/**
* @var bool
*/
protected $dispatched;
/**
* @var \Sample\News\Model\Routing\Entity[]
*/
protected $routingEntities;
/**
* @param ActionFactory $actionFactory
* @param ManagerInterface $eventManager
* @param UrlInterface $url
* @param State $appState
* @param StoreManagerInterface $storeManager
* @param ResponseInterface $response
* @param ScopeConfigInterface $scopeConfig
* @param array $routingEntities
*/
public function __construct(
ActionFactory $actionFactory,
ManagerInterface $eventManager,
UrlInterface $url,
State $appState,
StoreManagerInterface $storeManager,
ResponseInterface $response,
ScopeConfigInterface $scopeConfig,
array $routingEntities
) {
$this->actionFactory = $actionFactory;
$this->eventManager = $eventManager;
$this->url = $url;
$this->appState = $appState;
$this->storeManager = $storeManager;
$this->response = $response;
$this->scopeConfig = $scopeConfig;
$this->routingEntities = $routingEntities;
}
/**
* Validate and Match News Author and modify request
*
* @param \Magento\Framework\App\RequestInterface|\Magento\Framework\HTTP\PhpEnvironment\Request $request
* @return bool
*/
public function match(RequestInterface $request)
{
if (!$this->dispatched) {
$urlKey = trim($request->getPathInfo(), '/');
$origUrlKey = $urlKey;
/** @var Object $condition */
$condition = new DataObject(['url_key' => $urlKey, 'continue' => true]);
$this->eventManager->dispatch(
'sample_news_controller_router_match_before',
['router' => $this, 'condition' => $condition]
);
$urlKey = $condition->getUrlKey();
if ($condition->getRedirectUrl()) {
$this->response->setRedirect($condition->getRedirectUrl());
$request->setDispatched(true);
return $this->actionFactory->create(Redirect::class);
}
if (!$condition->getContinue()) {
return null;
}
foreach ($this->routingEntities as $entityKey => $entity) {
$match = $this->matchRoute($request, $entity, $urlKey, $origUrlKey);
if ($match === false) {
continue;
}
return $match;
}
}
return null;
}
/**
* @param RequestInterface|\Magento\Framework\HTTP\PhpEnvironment\Request $request
* @param Entity $entity
* @param $urlKey
* @param $origUrlKey
* @return bool|\Magento\Framework\App\ActionInterface|null
*/
protected function matchRoute(RequestInterface $request, Entity $entity, $urlKey, $origUrlKey)
{
$listKey = $this->scopeConfig->getValue($entity->getListKeyConfigPath(), ScopeInterface::SCOPE_STORE);
if ($listKey) {
if ($urlKey == $listKey) {
$request->setModuleName('sample_news');
$request->setControllerName($entity->getController());
$request->setActionName($entity->getListAction());
$request->setAlias(Url::REWRITE_REQUEST_PATH_ALIAS, $urlKey);
$this->dispatched = true;
return $this->actionFactory->create(Forward::class);
}
}
$prefix = $this->scopeConfig->getValue($entity->getPrefixConfigPath(), ScopeInterface::SCOPE_STORE);
if ($prefix) {
$parts = explode('/', $urlKey);
if ($parts[0] != $prefix || count($parts) != 2) {
return false;
}
$urlKey = $parts[1];
}
$configSuffix = $this->scopeConfig->getValue($entity->getSuffixConfigPath(), ScopeInterface::SCOPE_STORE);
if ($configSuffix) {
$suffix = substr($urlKey, -strlen($configSuffix) - 1);
if ($suffix != '.'.$configSuffix) {
return false;
}
$urlKey = substr($urlKey, 0, -strlen($configSuffix) - 1);
}
$instance = $entity->getFactory()->create();
$id = $instance->checkUrlKey($urlKey, $this->storeManager->getStore()->getId());
if (!$id) {
return null;
}
$request->setModuleName('sample_news');
$request->setControllerName($entity->getController());
$request->setActionName($entity->getViewAction());
$request->setParam($entity->getParam(), $id);
$request->setAlias(Url::REWRITE_REQUEST_PATH_ALIAS, $origUrlKey);
$request->setDispatched(true);
$this->dispatched = true;
return $this->actionFactory->create(Forward::class);
}
}
================================================
FILE: Helper/Image.php
================================================
<?php
/**
* Sample_News extension
*
* NOTICE OF LICENSE
*
* This source file is subject to the MIT License
* that is bundled with this package in the file LICENSE
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/mit-license.php
*
* @category Sample
* @package Sample_News
* @copyright 2016 Marius Strajeru
* @license http://opensource.org/licenses/mit-license.php MIT License
* @author Marius Strajeru
*/
namespace Sample\News\Helper;
use Magento\Framework\App\Area;
use Magento\Framework\App\Helper\AbstractHelper;
use Magento\Framework\App\Helper\Context;
use Magento\Framework\View\Asset\Repository;
use Magento\Framework\View\ConfigInterface;
use Magento\Store\Model\ScopeInterface;
use Sample\News\Model\ImageFactory;
/**
* @SuppressWarnings(PHPMD.TooManyFields)
*/
class Image extends AbstractHelper
{
/**
* Media config node
*/
const MEDIA_TYPE_CONFIG_NODE = 'images';
/**
* Current model
*
* @var \Sample\News\Model\Image
*/
protected $model;
/**
* Scheduled for resize image
*
* @var bool
*/
protected $scheduleResize = true;
/**
* Scheduled for rotate image
*
* @var bool
*/
protected $scheduleRotate = false;
/**
* Angle
*
* @var int
*/
protected $angle;
/**
* Watermark file name
*
* @var string
*/
protected $watermark;
/**
* Watermark Position
*
* @var string
*/
protected $watermarkPosition;
/**
* Watermark Size
*
* @var string
*/
protected $watermarkSize;
/**
* Watermark Image opacity
*
* @var int
*/
protected $watermarkImageOpacity;
/**
* Current Product
*
* @var \Magento\Framework\Model\AbstractModel
*/
protected $entity;
/**
* Image File
*
* @var string
*/
protected $imageFile;
/**
* Image Placeholder
*
* @var string
*/
protected $placeholder;
/**
* @var \Magento\Framework\View\Asset\Repository
*/
protected $assetRepo;
/**
* image factory
*
* @var \Sample\News\Model\ImageFactory
*/
protected $imageFactory;
/**
* @var \Magento\Framework\View\ConfigInterface
*/
protected $viewConfig;
/**
* @var \Magento\Framework\Config\View
*/
protected $configView;
/**
* Image configuration attributes
*
* @var array
*/
protected $attributes = [];
/**
* @var string
*/
protected $entityCode;
/**
* @param Context $context
* @param ImageFactory $imageFactory
* @param Repository $assetRepo
* @param ConfigInterface $viewConfig
* @param $entityCode
*/
public function __construct(
Context $context,
ImageFactory $imageFactory,
Repository $assetRepo,
ConfigInterface $viewConfig,
$entityCode
) {
$this->imageFactory = $imageFactory;
$this->assetRepo = $assetRepo;
$this->viewConfig = $viewConfig;
$this->entityCode = $entityCode;
parent::__construct($context);
}
/**
* Reset all previous data
*
* @return $this
*/
protected function _reset()
{
$this->model = null;
$this->scheduleRotate = false;
$this->angle = null;
$this->watermark = null;
$this->watermarkPosition = null;
$this->watermarkSize = null;
$this->watermarkImageOpacity = null;
$this->entity = null;
$this->imageFile = null;
$this->attributes = [];
return $this;
}
/**
* Initialize Helper to work with Image
*
* @param \Magento\Framework\Model\AbstractModel $entity
* @param string $imageId
* @param array $attributes
* @return $this
*/
public function init($entity, $imageId, $attributes = [])
{
$this->_reset();
$this->attributes = array_merge(
$this->getConfigView()->getMediaAttributes('Sample_News', self::MEDIA_TYPE_CONFIG_NODE, $imageId),
$attributes
);
$this->setEntity($entity);
$this->setImageProperties();
$this->setWatermarkProperties();
return $this;
}
/**
* Set image properties
*
* @return $this
*/
protected function setImageProperties()
{
$this->getModel()->setDestinationSubdir($this->getType());
$this->getModel()->setWidth($this->getWidth());
$this->getModel()->setHeight($this->getHeight());
// Set 'keep frame' flag
$frame = $this->getFrame();
if (!empty($frame)) {
$this->getModel()->setKeepFrame($frame);
}
// Set 'constrain only' flag
$constrain = $this->getAttribute('constrain');
if (!empty($constrain)) {
$this->getModel()->setConstrainOnly($constrain);
}
// Set 'keep aspect ratio' flag
$aspectRatio = $this->getAttribute('aspect_ratio');
if (!empty($aspectRatio)) {
$this->getModel()->setKeepAspectRatio($aspectRatio);
}
// Set 'transparency' flag
$transparency = $this->getAttribute('transparency');
if (!empty($transparency)) {
$this->getModel()->setKeepTransparency($transparency);
}
// Set background color
$background = $this->getAttribute('background');
if (!empty($background)) {
$this->getModel()->setBackgroundColor($background);
}
return $this;
}
/**
* Set watermark properties
* @return $this
*/
protected function setWatermarkProperties()
{
// @codingStandardsIgnoreStart
//TODO: set proper watermarks paths
// @codingStandardsIgnoreEnd
$this->setWatermark(
$this->scopeConfig->getValue(
"design/watermark/{$this->getModel()->getDestinationSubdir()}_image",
ScopeInterface::SCOPE_STORE
)
);
$this->setWatermarkImageOpacity(
$this->scopeConfig->getValue(
"design/watermark/{$this->getModel()->getDestinationSubdir()}_imageOpacity",
ScopeInterface::SCOPE_STORE
)
);
$this->setWatermarkPosition(
$this->scopeConfig->getValue(
"design/watermark/{$this->getModel()->getDestinationSubdir()}_position",
ScopeInterface::SCOPE_STORE
)
);
$this->setWatermarkSize(
$this->scopeConfig->getValue(
"design/watermark/{$this->getModel()->getDestinationSubdir()}_size",
ScopeInterface::SCOPE_STORE
)
);
return $this;
}
/**
* Schedule resize of the image
* $width *or* $height can be null - in this case, lacking dimension will be calculated.
*
* @see \Sample\News\Model\Image
* @param int $width
* @param int $height
* @return $this
*/
public function resize($width, $height = null)
{
$this->getModel()->setWidth($width)->setHeight($height);
$this->scheduleResize = true;
return $this;
}
/**
* Set image quality, values in percentage from 0 to 100
*
* @param int $quality
* @return $this
*/
public function setQuality($quality)
{
$this->getModel()->setQuality($quality);
return $this;
}
/**
* Guarantee, that image picture width/height will not be distorted.
* Applicable before calling resize()
* It is true by default.
*
* @see \Sample\News\Model\Image
* @param bool $flag
* @return $this
*/
public function keepAspectRatio($flag)
{
$this->getModel()->setKeepAspectRatio($flag);
return $this;
}
/**
* Guarantee, that image will have dimensions, set in $width/$height
* Applicable before calling resize()
* Not applicable, if keepAspectRatio(false)
*
* @see \Sample\News\Model\Image
* @param bool $flag
* @return $this
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function keepFrame($flag)
{
$this->getModel()->setKeepFrame($flag);
return $this;
}
/**
* Guarantee, that image will not lose transparency if any.
* Applicable before calling resize()
* It is true by default.
*
* @see \Sample\News\Model\Image
* @param bool $flag
* @return $this
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function keepTransparency($flag)
{
$this->getModel()->setKeepTransparency($flag);
return $this;
}
/**
* Guarantee, that image picture will not be bigger, than it was.
* Applicable before calling resize()
* It is false by default
*
* @param bool $flag
* @return $this
*/
public function constrainOnly($flag)
{
$this->getModel()->setConstrainOnly($flag);
return $this;
}
/**
* Set color to fill image frame with.
* Applicable before calling resize()
* The keepTransparency(true) overrides this (if image has transparent color)
* It is white by default.
*
* @see \Sample\News\Model\Image\Image
* @param array $colorRGB
* @return $this
*/
public function backgroundColor($colorRGB)
{
// assume that 3 params were given instead of array
if (!is_array($colorRGB)) {
$colorRGB = func_get_args();
}
$this->getModel()->setBackgroundColor($colorRGB);
return $this;
}
/**
* Rotate image into specified angle
*
* @param int $angle
* @return $this
*/
public function rotate($angle)
{
$this->setAngle($angle);
$this->getModel()->setAngle($angle);
$this->scheduleRotate = true;
return $this;
}
/**
* Add watermark to image
* size param in format 100x200
*
* @param string $fileName
* @param string $position
* @param string $size
* @param int $imageOpacity
* @return $this
*/
public function watermark($fileName, $position, $size = null, $imageOpacity = null)
{
$this->setWatermark($fileName)
->setWatermarkPosition($position)
->setWatermarkSize($size)
->setWatermarkImageOpacity($imageOpacity);
return $this;
}
/**
* Set placeholder
*
* @param string $fileName
* @return void
*/
public function placeholder($fileName)
{
$this->placeholder = $fileName;
}
/**
* Get Placeholder
*
* @param null|string $placeholder
* @return string
*/
public function getPlaceholder($placeholder = null)
{
if ($placeholder) {
$placeholderFullPath = 'Sample_News::images/'.$this->entityCode.'/placeholder/' . $placeholder . '.jpg';
} else {
$placeholderFullPath = $this->placeholder
?: 'Sample_News::images/'.$this->entityCode.'/placeholder/' . $this->getModel()->getDestinationSubdir() . '.jpg';
}
return $placeholderFullPath;
}
/**
* Apply scheduled actions
*
* @return $this
* @throws \Exception
*/
protected function applyScheduledActions()
{
$this->initBaseFile();
if ($this->isScheduledActionsAllowed()) {
$model = $this->getModel();
if ($this->scheduleRotate) {
$model->rotate($this->getAngle());
}
if ($this->scheduleResize) {
$model->resize();
}
if ($this->getWatermark()) {
$model->setWatermark($this->getWatermark());
}
$model->saveFile();
}
return $this;
}
/**
* Initialize base image file
*
* @return $this
*/
protected function initBaseFile()
{
$model = $this->getModel();
$baseFile = $model->getBaseFile();
if (!$baseFile) {
if ($this->getImageFile()) {
$model->setBaseFile($this->getImageFile());
} else {
$model->setBaseFile($this->getEntity()->getData($model->getDestinationSubdir()));
}
}
return $this;
}
/**
* Check if scheduled actions is allowed
*
* @return bool
*/
protected function isScheduledActionsAllowed()
{
$model = $this->getModel();
if ($model->isBaseFilePlaceholder()
&& $model->getNewFile() === true
|| $model->isCached()
) {
return false;
}
return true;
}
/**
* Retrieve image URL
*
* @return string
*/
public function getUrl()
{
try {
$this->applyScheduledActions();
return $this->getModel()->getUrl();
} catch (\Exception $e) {
return $this->getDefaultPlaceholderUrl();
}
}
/**
* @return $this
*/
public function save()
{
$this->applyScheduledActions();
return $this;
}
/**
* Return resized image information
*
* @return array
*/
public function getResizedImageInfo()
{
$this->applyScheduledActions();
return $this->getModel()->getResizedImageInfo();
}
/**
* @param null|string $placeholder
* @return string
*/
public function getDefaultPlaceholderUrl($placeholder = null)
{
try {
$url = $this->assetRepo->getUrl($this->getPlaceholder($placeholder));
} catch (\Exception $e) {
$this->_logger->critical($e);
$url = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAMAAABEpIrGAAAAnFBMVEUAAAAAAAAAAAAAAAC0tLS4uLi0tLT6+vrx8fHo6Ojj4OC+mpq7UE2wXlqzOTGtHwza2dnGaWeiJxDV0dGNJhari4uqeHi/W1edTkevSkWWNCOLEQiXEgbExMXbiorTgH+NT0a4RD+XIxTPFwm7BQHYAwHJAwDLd3aWcXDKV03JODOjNyunLCS6JQ6nCQO/q6viqKjFREOYQTrQIiHNANNfAAAAB3RSTlMCPiYZ3uvFTohbPwAAAURJREFUOMuVk9dygzAQRW3jeGUhikQvDtUl7uX//y0b4bGMCDPJAV64Z+5Ko9HkLxizEYynMCW/A9OXsETI8xkRSPeNNpDnOyZo5dChCe8pAUJ04Qd65bzYXilIaSiYrPhEisoEiS5YvOCVbdt8G1kDATGjbWV5QC7HiDNzKFCb2/J3wqKIVcuBEDImi60vxo5JEvYEQCFmB0/mt5sdHhNLF+CQHGS+3+Ok2k8HQprVAPf944E51JkuAMRZdrk7m7WDuZfncV9Awiz3uxzlcx5qAgHq5067kXkgzj7VBCSoz63YYX/stCKAQQNAKdrmJITTbERJJErojMA/Net1c/IDPBxK6cJ424WE7so0LXcuoauV585nk5fQh5AVgDvvBqgGBRaA+yFztcheAfWoytUIJbhd/3iDykcWuZhpl3eqYUz+wTdj6SFVkjRnJQAAAABJRU5ErkJggg==';
}
return $url;
}
/**
* Get current Image model
*
* @return \Sample\News\Model\Image
*/
protected function getModel()
{
if (!$this->model) {
$this->model = $this->imageFactory->create(['entityCode' => 'author']);
}
return $this->model;
}
/**
* Set Rotation Angle
*
* @param int $angle
* @return $this
*/
protected function setAngle($angle)
{
$this->angle = $angle;
return $this;
}
/**
* Get Rotation Angle
*
* @return int
*/
protected function getAngle()
{
return $this->angle;
}
/**
* Set watermark file name
*
* @param string $watermark
* @return $this
*/
protected function setWatermark($watermark)
{
$this->watermark = $watermark;
$this->getModel()->setWatermarkFile($watermark);
return $this;
}
/**
* Get watermark file name
*
* @return string
*/
protected function getWatermark()
{
return $this->watermark;
}
/**
* Set watermark position
*
* @param string $position
* @return $this
*/
protected function setWatermarkPosition($position)
{
$this->watermarkPosition = $position;
$this->getModel()->setWatermarkPosition($position);
return $this;
}
/**
* Get watermark position
*
* @return string
*/
protected function getWatermarkPosition()
{
return $this->watermarkPosition;
}
/**
* Set watermark size
* param size in format 100x200
*
* @param string $size
* @return $this
*/
public function setWatermarkSize($size)
{
$this->watermarkSize = $size;
$this->getModel()->setWatermarkSize($this->parseSize($size));
return $this;
}
/**
* Get watermark size
*
* @return string
*/
protected function getWatermarkSize()
{
return $this->watermarkSize;
}
/**
* Set watermark image opacity
*
* @param int $imageOpacity
* @return $this
*/
public function setWatermarkImageOpacity($imageOpacity)
{
$this->watermarkImageOpacity = $imageOpacity;
$this->getModel()->setWatermarkImageOpacity($imageOpacity);
return $this;
}
/**
* Get watermark image opacity
*
* @return int
*/
protected function getWatermarkImageOpacity()
{
if ($this->watermarkImageOpacity) {
return $this->watermarkImageOpacity;
}
return $this->getModel()->getWatermarkImageOpacity();
}
/**
* Set current Entity
*
* @param \Magento\Framework\Model\AbstractModel
* @return $this
*/
protected function setEntity($entity)
{
$this->entity = $entity;
return $this;
}
/**
* Get current Product
*
* @return \Magento\Framework\Model\AbstractModel
*/
protected function getEntity()
{
return $this->entity;
}
/**
* Set Image file
*
* @param string $file
* @return $this
*/
public function setImageFile($file)
{
$this->imageFile = $file;
return $this;
}
/**
* Get Image file
*
* @return string
*/
protected function getImageFile()
{
return $this->imageFile;
}
/**
* Retrieve size from string
*
* @param string $string
* @return array|bool
*/
protected function parseSize($string)
{
$size = explode('x', strtolower($string));
if (sizeof($size) == 2) {
return [
'width' => $size[0] > 0 ? $size[0] : null,
'height' => $size[1] > 0 ? $size[1] : null
];
}
return false;
}
/**
* Retrieve original image width
*
* @return int|null
*/
public function getOriginalWidth()
{
return $this->getModel()->getImageProcessor()->getOriginalWidth();
}
/**
* Retrieve original image height
*
* @return int|null
*/
public function getOriginalHeight()
{
return $this->getModel()->getImageProcessor()->getOriginalHeight();
}
/**
* Retrieve Original image size as array
* 0 - width, 1 - height
*
* @return int[]
*/
public function getOriginalSizeArray()
{
return [$this->getOriginalWidth(), $this->getOriginalHeight()];
}
/**
* Retrieve config view
*
* @return \Magento\Framework\Config\View
*/
protected function getConfigView()
{
if (!$this->configView) {
$this->configView = $this->viewConfig->getViewConfig();
}
return $this->configView;
}
/**
* Retrieve image type
*
* @return string
*/
public function getType()
{
return $this->getAttribute('type');
}
/**
* Retrieve image width
*
* @return string
*/
public function getWidth()
{
return $this->getAttribute('width');
}
/**
* Retrieve image height
*
* @return string
*/
public function getHeight()
{
return $this->getAttribute('height') ?: $this->getAttribute('width');
}
/**
* Retrieve image frame flag
*
* @return false|string
*/
public function getFrame()
{
$frame = $this->getAttribute('frame');
if (empty($frame)) {
$frame = $this->getConfigView()->getVarValue('Sample_News', 'image_white_borders');
}
return $frame;
}
/**
* Retrieve image attribute
*
* @param string $name
* @return string
*/
protected function getAttribute($name)
{
return isset($this->attributes[$name]) ? $this->attributes[$name] : null;
}
/**
* Return image label
*
* @return string
*/
public function getLabel()
{
return $this->entity->getData('name');
}
}
================================================
FILE: LICENSE
================================================
The MIT License (MIT)
Copyright (c) 2016 Marius
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
================================================
FILE: Model/Author/DataProvider.php
================================================
<?php
/**
* Sample_News extension
*
* NOTICE OF LICENSE
*
* This source file is subject to the MIT License
* that is bundled with this package in the file LICENSE
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/mit-license.php
*
* @category Sample
* @package Sample_News
* @copyright 2016 Marius Strajeru
* @license http://opensource.org/licenses/mit-license.php MIT License
* @author Marius Strajeru
*/
namespace Sample\News\Model\Author;
use Magento\Ui\DataProvider\AbstractDataProvider;
use Magento\Ui\DataProvider\Modifier\ModifierInterface;
use Magento\Ui\DataProvider\Modifier\PoolInterface;
use Sample\News\Model\ResourceModel\Author\CollectionFactory;
class DataProvider extends AbstractDataProvider
{
/**
* @var array
*/
protected $loadedData;
/**
* @var PoolInterface
*/
protected $pool;
/**
* @param string $name
* @param string $primaryFieldName
* @param string $requestFieldName
* @param CollectionFactory $authorCollectionFactory
* @param PoolInterface $pool
* @param array $meta
* @param array $data
*/
public function __construct(
$name,
$primaryFieldName,
$requestFieldName,
CollectionFactory $authorCollectionFactory,
PoolInterface $pool,
array $meta = [],
array $data = []
) {
$this->collection = $authorCollectionFactory->create();
$this->pool = $pool;
parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data);
$this->meta = $this->prepareMeta($this->meta);
}
/**
* Prepares Meta
*
* @param array $meta
* @return array
*/
public function prepareMeta(array $meta)
{
$meta = parent::getMeta();
/** @var ModifierInterface $modifier */
foreach ($this->pool->getModifiersInstances() as $modifier) {
$meta = $modifier->modifyMeta($meta);
}
return $meta;
}
/**
* Get data
*
* @return array
*/
public function getData()
{
/** @var ModifierInterface $modifier */
foreach ($this->pool->getModifiersInstances() as $modifier) {
$this->data = $modifier->modifyData($this->data);
}
return $this->data;
}
}
================================================
FILE: Model/Author/Rss.php
================================================
<?php
/**
* Sample_News extension
*
* NOTICE OF LICENSE
*
* This source file is subject to the MIT License
* that is bundled with this package in the file LICENSE
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/mit-license.php
*
* @category Sample
* @package Sample_News
* @copyright 2016 Marius Strajeru
* @license http://opensource.org/licenses/mit-license.php MIT License
* @author Marius Strajeru
*/
namespace Sample\News\Model\Author;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\UrlInterface;
use Magento\Store\Model\ScopeInterface;
use Magento\Store\Model\StoreManagerInterface;
class Rss
{
/**
* @var string
*/
const RSS_PAGE_URL = 'sample_news/author/rss';
/**
* @var string
*/
const AUTHOR_RSS_ACTIVE_CONFIG_PATH = 'sample_news/author/rss';
/**
* @var string
*/
const GLOBAL_RSS_ACTIVE_CONFIG_PATH = 'rss/config/active';
/**
* @var ScopeConfigInterface
*/
protected $scopeConfig;
/**
* @var UrlInterface
*/
protected $urlBuilder;
/**
* @var StoreManagerInterface
*/
protected $storeManager;
/**
* @param UrlInterface $urlBuilder
* @param ScopeConfigInterface $scopeConfig
* @param StoreManagerInterface $storeManager
*/
public function __construct(
UrlInterface $urlBuilder,
ScopeConfigInterface $scopeConfig,
StoreManagerInterface $storeManager
) {
$this->urlBuilder = $urlBuilder;
$this->scopeConfig = $scopeConfig;
$this->storeManager = $storeManager;
}
/**
* @return bool
*/
public function isRssEnabled()
{
return
$this->scopeConfig->getValue(self::GLOBAL_RSS_ACTIVE_CONFIG_PATH, ScopeInterface::SCOPE_STORE) &&
$this->scopeConfig->getValue(self::AUTHOR_RSS_ACTIVE_CONFIG_PATH, ScopeInterface::SCOPE_STORE);
}
/**
* @return string
*/
public function getRssLink()
{
return $this->urlBuilder->getUrl(
self::RSS_PAGE_URL,
['store' => $this->storeManager->getStore()->getId()]
);
}
}
================================================
FILE: Model/Author/Url.php
================================================
<?php
/**
* Sample_News extension
*
* NOTICE OF LICENSE
*
* This source file is subject to the MIT License
* that is bundled with this package in the file LICENSE
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/mit-license.php
*
* @category Sample
* @package Sample_News
* @copyright 2016 Marius Strajeru
* @license http://opensource.org/licenses/mit-license.php MIT License
* @author Marius Strajeru
*/
namespace Sample\News\Model\Author;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\UrlInterface;
use Magento\Store\Model\ScopeInterface;
use Sample\News\Model\Author;
class Url
{
/**
* @var string
*/
const LIST_URL_CONFIG_PATH = 'sample_news/author/list_url';
/**
* @var string
*/
const URL_PREFIX_CONFIG_PATH = 'sample_news/author/url_prefix';
/**
* @var string
*/
const URL_SUFFIX_CONFIG_PATH = 'sample_news/author/url_suffix';
/**
* url builder
*
* @var \Magento\Framework\UrlInterface
*/
protected $urlBuilder;
/**
* @var ScopeConfigInterface
*/
protected $scopeConfig;
/**
* @param UrlInterface $urlBuilder
* @param ScopeConfigInterface $scopeConfig
*/
public function __construct(
UrlInterface $urlBuilder,
ScopeConfigInterface $scopeConfig
) {
$this->urlBuilder = $urlBuilder;
$this->scopeConfig = $scopeConfig;
}
/**
* @return string
*/
public function getListUrl()
{
$sefUrl = $this->scopeConfig->getValue(self::LIST_URL_CONFIG_PATH, ScopeInterface::SCOPE_STORE);
if ($sefUrl) {
return $this->urlBuilder->getUrl('', ['_direct' => $sefUrl]);
}
return $this->urlBuilder->getUrl('sample_news/author/index');
}
/**
* @param Author $author
* @return string
*/
public function getAuthorUrl(Author $author)
{
if ($urlKey = $author->getUrlKey()) {
$prefix = $this->scopeConfig->getValue(
self::URL_PREFIX_CONFIG_PATH,
ScopeInterface::SCOPE_STORE
);
$suffix = $this->scopeConfig->getValue(
self::URL_SUFFIX_CONFIG_PATH,
ScopeInterface::SCOPE_STORE
);
$path = (($prefix) ? $prefix . '/' : '').
$urlKey .
(($suffix) ? '.'. $suffix : '');
return $this->urlBuilder->getUrl('', ['_direct'=>$path]);
}
return $this->urlBuilder->getUrl('sample_news/author/view', ['id' => $author->getId()]);
}
}
================================================
FILE: Model/Author.php
================================================
<?php
/**
* Sample_News extension
*
* NOTICE OF LICENSE
*
* This source file is subject to the MIT License
* that is bundled with this package in the file LICENSE
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/mit-license.php
*
* @category Sample
* @package Sample_News
* @copyright 2016 Marius Strajeru
* @license http://opensource.org/licenses/mit-license.php MIT License
* @author Marius Strajeru
*/
namespace Sample\News\Model;
use Magento\Framework\Data\Collection\AbstractDb;
use Magento\Framework\Data\Collection\Db;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Filter\FilterManager;
use Magento\Framework\Model\AbstractModel;
use Magento\Framework\Model\Context;
use Magento\Framework\Model\ResourceModel\AbstractResource;
use Magento\Framework\Registry;
use Sample\News\Api\Data\AuthorInterface;
use Sample\News\Model\Author\Url;
use Sample\News\Model\ResourceModel\Author as AuthorResourceModel;
use Sample\News\Model\Routing\RoutableInterface;
use Sample\News\Model\Source\AbstractSource;
/**
* @method AuthorResourceModel _getResource()
* @method AuthorResourceModel getResource()
*/
class Author extends AbstractModel implements AuthorInterface, RoutableInterface
{
/**
* @var int
*/
const STATUS_ENABLED = 1;
/**
* @var int
*/
const STATUS_DISABLED = 0;
/**
* @var Url
*/
protected $urlModel;
/**
* cache tag
*
* @var string
*/
const CACHE_TAG = 'sample_news_author';
/**
* cache tag
*
* @var string
*/
protected $_cacheTag = 'sample_news_author';
/**
* Prefix of model events names
*
* @var string
*/
protected $_eventPrefix = 'sample_news_author';
/**
* filter model
*
* @var \Magento\Framework\Filter\FilterManager
*/
protected $filter;
/**
* @var UploaderPool
*/
protected $uploaderPool;
/**
* @var \Sample\News\Model\Output
*/
protected $outputProcessor;
/**
* @var AbstractSource[]
*/
protected $optionProviders;
/**
* @param Context $context
* @param Registry $registry
* @param Output $outputProcessor
* @param UploaderPool $uploaderPool
* @param FilterManager $filter
* @param Url $urlModel
* @param array $optionProviders
* @param array $data
* @param AbstractResource|null $resource
* @param AbstractDb|null $resourceCollection
*/
public function __construct(
Context $context,
Registry $registry,
Output $outputProcessor,
UploaderPool $uploaderPool,
FilterManager $filter,
Url $urlModel,
array $optionProviders = [],
array $data = [],
AbstractResource $resource = null,
AbstractDb $resourceCollection = null
)
{
$this->outputProcessor = $outputProcessor;
$this->uploaderPool = $uploaderPool;
$this->filter = $filter;
$this->urlModel = $urlModel;
$this->optionProviders = $optionProviders;
parent::__construct($context, $registry, $resource, $resourceCollection, $data);
}
/**
* Initialize resource model
*
* @return void
*/
protected function _construct()
{
$this->_init(AuthorResourceModel::class);
}
/**
* Get in rss
*
* @return bool|int
*/
public function getInRss()
{
return $this->getData(AuthorInterface::IN_RSS);
}
/**
* Get type
*
* @return int
*/
public function getType()
{
return $this->getData(AuthorInterface::TYPE);
}
/**
* Get awards
*
* @return string
*/
public function getAwards()
{
return $this->getData(AuthorInterface::AWARDS);
}
/**
* Get country
*
* @return string
*/
public function getCountry()
{
return $this->getData(AuthorInterface::COUNTRY);
}
/**
* set name
*
* @param $name
* @return AuthorInterface
*/
public function setName($name)
{
return $this->setData(AuthorInterface::NAME, $name);
}
/**
* Set in rss
*
* @param $inRss
* @return AuthorInterface
*/
public function setInRss($inRss)
{
return $this->setData(AuthorInterface::IN_RSS, $inRss);
}
/**
* Set biography
*
* @param $biography
* @return AuthorInterface
*/
public function setBiography($biography)
{
return $this->setData(AuthorInterface::BIOGRAPHY, $biography);
}
/**
* Set DOB
*
* @param $dob
* @return AuthorInterface
*/
public function setDob($dob)
{
return $this->setData(AuthorInterface::DOB, $dob);
}
/**
* set type
*
* @param $type
* @return AuthorInterface
*/
public function setType($type)
{
return $this->setData(AuthorInterface::TYPE, $type);
}
/**
* set awards
*
* @param $awards
* @return AuthorInterface
*/
public function setAwards($awards)
{
return $this->setData(AuthorInterface::AWARDS, $awards);
}
/**
* Set country
*
* @param $country
* @return AuthorInterface
*/
public function setCountry($country)
{
return $this->setData(AuthorInterface::COUNTRY, $country);
}
/**
* Get name
*
* @return string
*/
public function getName()
{
return $this->getData(AuthorInterface::NAME);
}
/**
* Get url key
*
* @return string
*/
public function getUrlKey()
{
return $this->getData(AuthorInterface::URL_KEY);
}
/**
* Get is active
*
* @return bool|int
*/
public function getIsActive()
{
return $this->getData(AuthorInterface::IS_ACTIVE);
}
/**
* Get biography
*
* @return string
*/
public function getBiography()
{
return $this->getData(AuthorInterface::BIOGRAPHY);
}
/**
* @return mixed
*/
public function getProcessedBiography()
{
return $this->outputProcessor->filterOutput($this->getBiography());
}
/**
* Get DOB
*
* @return string
*/
public function getDob()
{
return $this->getData(AuthorInterface::DOB);
}
/**
* Get avatar
*
* @return string
*/
public function getAvatar()
{
return $this->getData(AuthorInterface::AVATAR);
}
/**
* @return bool|string
* @throws LocalizedException
*/
public function getAvatarUrl()
{
$url = false;
$avatar = $this->getAvatar();
if ($avatar) {
if (is_string($avatar)) {
$uploader = $this->uploaderPool->getUploader('image');
$url = $uploader->getBaseUrl().$uploader->getBasePath().$avatar;
} else {
throw new LocalizedException(
__('Something went wrong while getting the avatar url.')
);
}
}
return $url;
}
/**
* @return bool|string
* @throws LocalizedException
*/
public function getResumeUrl()
{
$url = false;
$resume = $this->getResume();
if ($resume) {
if (is_string($resume)) {
$uploader = $this->uploaderPool->getUploader('file');
$url = $uploader->getBaseUrl().$uploader->getBasePath().$resume;
} else {
throw new LocalizedException(
__('Something went wrong while getting the resume url.')
);
}
}
return $url;
}
/**
* Get resume
*
* @return string
*/
public function getResume()
{
return $this->getData(AuthorInterface::RESUME);
}
/**
* Get created at
*
* @return string
*/
public function getCreatedAt()
{
return $this->getData(AuthorInterface::CREATED_AT);
}
/**
* Get updated at
*
* @return string
*/
public function getUpdatedAt()
{
return $this->getData(AuthorInterface::UPDATED_AT);
}
/**
* set url key
*
* @param $urlKey
* @return AuthorInterface
*/
public function setUrlKey($urlKey)
{
return $this->setData(AuthorInterface::URL_KEY, $urlKey);
}
/**
* Set is active
*
* @param $isActive
* @return AuthorInterface
*/
public function setIsActive($isActive)
{
return $this->setData(AuthorInterface::IS_ACTIVE, $isActive);
}
/**
* set avatar
*
* @param $avatar
* @return AuthorInterface
*/
public function setAvatar($avatar)
{
return $this->setData(AuthorInterface::AVATAR, $avatar);
}
/**
* set resume
*
* @param $resume
* @return AuthorInterface
*/
public function setResume($resume)
{
return $this->setData(AuthorInterface::RESUME, $resume);
}
/**
* set created at
*
* @param $createdAt
* @return AuthorInterface
*/
public function setCreatedAt($createdAt)
{
return $this->setData(AuthorInterface::CREATED_AT, $createdAt);
}
/**
* set updated at
*
* @param $updatedAt
* @return AuthorInterface
*/
public function setUpdatedAt($updatedAt)
{
return $this->setData(AuthorInterface::UPDATED_AT, $updatedAt);
}
/**
* Check if author url key exists
* return author id if author exists
*
* @param string $urlKey
* @param int $storeId
* @return int
*/
public function checkUrlKey($urlKey, $storeId)
{
return $this->_getResource()->checkUrlKey($urlKey, $storeId);
}
/**
* Get identities
*
* @return array
*/
public function getIdentities()
{
return [self::CACHE_TAG . '_' . $this->getId()];
}
/**
* @param $storeId
* @return AuthorInterface
*/
public function setStoreId($storeId)
{
$this->setData(AuthorInterface::STORE_ID, $storeId);
return $this;
}
/**
* @return array
*/
public function getStoreId()
{
return $this->getData(AuthorInterface::STORE_ID);
}
/**
* @return string
*/
public function getMetaTitle()
{
return $this->getData(AuthorInterface::META_TITLE);
}
/**
* @param $metaTitle
* @return AuthorInterface
*/
public function setMetaTitle($metaTitle)
{
$this->setData(AuthorInterface::META_TITLE, $metaTitle);
return $this;
}
/**
* @return string
*/
public function getMetaDescription()
{
return $this->getData(AuthorInterface::META_DESCRIPTION);
}
/**
* @param $metaDescription
* @return AuthorInterface
*/
public function setMetaDescription($metaDescription)
{
$this->setData(AuthorInterface::META_DESCRIPTION, $metaDescription);
return $this;
}
/**
* @return string
*/
public function getMetaKeywords()
{
return $this->getData(AuthorInterface::META_KEYWORDS);
}
/**
* @param $metaKeywords
* @return AuthorInterface
*/
public function setMetaKeywords($metaKeywords)
{
$this->setData(AuthorInterface::META_KEYWORDS, $metaKeywords);
return $this;
}
/**
* sanitize the url key
*
* @param $string
* @return string
*/
public function formatUrlKey($string)
{
return $this->filter->translitUrl($string);
}
/**
* @return mixed
*/
public function getAuthorUrl()
{
return $this->urlModel->getAuthorUrl($this);
}
/**
* @return bool
*/
public function isActive()
{
return (bool)$this->getIsActive();
}
/**
* @param $attribute
* @return string
*/
public function getAttributeText($attribute)
{
if (!isset($this->optionProviders[$attribute])) {
return '';
}
if (!($this->optionProviders[$attribute] instanceof AbstractSource)) {
return '';
}
return $this->optionProviders[$attribute]->getOptionText($this->getData($attribute));
}
}
================================================
FILE: Model/AuthorFactory.php
================================================
<?php
/**
* Sample_News extension
*
* NOTICE OF LICENSE
*
* This source file is subject to the MIT License
* that is bundled with this package in the file LICENSE
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/mit-license.php
*
* @category Sample
* @package Sample_News
* @copyright 2016 Marius Strajeru
* @license http://opensource.org/licenses/mit-license.php MIT License
* @author Marius Strajeru
*/
namespace Sample\News\Model;
use Magento\Framework\ObjectManagerInterface;
use Sample\News\Model\Routing\RoutableInterface;
class AuthorFactory implements FactoryInterface
{
/**
* Object Manager instance
*
* @var ObjectManagerInterface
*/
protected $_objectManager = null;
/**
* Instance name to create
*
* @var string
*/
protected $_instanceName = null;
/**
* Factory constructor
*
* @param ObjectManagerInterface $objectManager
* @param string $instanceName
*/
public function __construct(ObjectManagerInterface $objectManager, $instanceName = Author::class)
{
$this->_objectManager = $objectManager;
$this->_instanceName = $instanceName;
}
/**
* Create class instance with specified parameters
*
* @param array $data
* @return RoutableInterface|\Sample\News\Model\Author
*/
public function create(array $data = array())
{
return $this->_objectManager->create($this->_instanceName, $data);
}
}
================================================
FILE: Model/AuthorRepository.php
================================================
<?php
/**
* Sample_News extension
*
* NOTICE OF LICENSE
*
* This source file is subject to the MIT License
* that is bundled with this package in the file LICENSE
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/mit-license.php
*
* @category Sample
* @package Sample_News
* @copyright 2016 Marius Strajeru
* @license http://opensource.org/licenses/mit-license.php MIT License
* @author Marius Strajeru
*/
namespace Sample\News\Model;
use Magento\Framework\Api\DataObjectHelper;
use Magento\Framework\Api\SearchCriteriaInterface;
use Magento\Framework\Api\Search\FilterGroup;
use Magento\Framework\Api\SortOrder;
use Magento\Framework\Exception\CouldNotSaveException;
use Magento\Framework\Exception\StateException;
use Magento\Framework\Exception\ValidatorException;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Store\Model\StoreManagerInterface;
use Sample\News\Api\AuthorRepositoryInterface;
use Sample\News\Api\Data;
use Sample\News\Api\Data\AuthorInterface;
use Sample\News\Api\Data\AuthorInterfaceFactory;
use Sample\News\Api\Data\AuthorSearchResultsInterfaceFactory;
use Sample\News\Model\ResourceModel\Author as ResourceAuthor;
use Sample\News\Model\ResourceModel\Author\Collection;
use Sample\News\Model\ResourceModel\Author\CollectionFactory as AuthorCollectionFactory;
/**
* Class AuthorRepository
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class AuthorRepository implements AuthorRepositoryInterface
{
/**
* @var array
*/
protected $instances = [];
/**
* @var ResourceAuthor
*/
protected $resource;
/**
* @var StoreManagerInterface
*/
protected $storeManager;
/**
* @var AuthorCollectionFactory
*/
protected $authorCollectionFactory;
/**
* @var AuthorSearchResultsInterfaceFactory
*/
protected $searchResultsFactory;
/**
* @var AuthorInterfaceFactory
*/
protected $authorInterfaceFactory;
/**
* @var DataObjectHelper
*/
protected $dataObjectHelper;
public function __construct(
ResourceAuthor $resource,
StoreManagerInterface $storeManager,
AuthorCollectionFactory $authorCollectionFactory,
AuthorSearchResultsInterfaceFactory $authorSearchResultsInterfaceFactory,
AuthorInterfaceFactory $authorInterfaceFactory,
DataObjectHelper $dataObjectHelper
) {
$this->resource = $resource;
$this->storeManager = $storeManager;
$this->authorCollectionFactory = $authorCollectionFactory;
$this->searchResultsFactory = $authorSearchResultsInterfaceFactory;
$this->authorInterfaceFactory = $authorInterfaceFactory;
$this->dataObjectHelper = $dataObjectHelper;
}
/**
* Save page.
*
* @param \Sample\News\Api\Data\AuthorInterface $author
* @return \Sample\News\Api\Data\AuthorInterface
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function save(AuthorInterface $author)
{
/** @var AuthorInterface|\Magento\Framework\Model\AbstractModel $author */
if (empty($author->getStoreId())) {
$storeId = $this->storeManager->getStore()->getId();
$author->setStoreId($storeId);
}
try {
$this->resource->save($author);
} catch (\Exception $exception) {
throw new CouldNotSaveException(__(
'Could not save the author: %1',
$exception->getMessage()
));
}
return $author;
}
/**
* Retrieve Author.
*
* @param int $authorId
* @return \Sample\News\Api\Data\AuthorInterface
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function getById($authorId)
{
if (!isset($this->instances[$authorId])) {
/** @var \Sample\News\Api\Data\AuthorInterface|\Magento\Framework\Model\AbstractModel $author */
$author = $this->authorInterfaceFactory->create();
$this->resource->load($author, $authorId);
if (!$author->getId()) {
throw new NoSuchEntityException(__('Requested author doesn\'t exist'));
}
$this->instances[$authorId] = $author;
}
return $this->instances[$authorId];
}
/**
* Retrieve pages matching the specified criteria.
*
* @param SearchCriteriaInterface $searchCriteria
* @return \Sample\News\Api\Data\AuthorSearchResultsInterface
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function getList(SearchCriteriaInterface $searchCriteria)
{
/** @var \Sample\News\Api\Data\AuthorSearchResultsInterface $searchResults */
$searchResults = $this->searchResultsFactory->create();
$searchResults->setSearchCriteria($searchCriteria);
/** @var \Sample\News\Model\ResourceModel\Author\Collection $collection */
$collection = $this->authorCollectionFactory->create();
//Add filters from root filter group to the collection
/** @var FilterGroup $group */
foreach ($searchCriteria->getFilterGroups() as $group) {
$this->addFilterGroupToCollection($group, $collection);
}
$sortOrders = $searchCriteria->getSortOrders();
/** @var SortOrder $sortOrder */
if ($sortOrders) {
foreach ($searchCriteria->getSortOrders() as $sortOrder) {
$field = $sortOrder->getField();
$collection->addOrder(
$field,
($sortOrder->getDirection() == SortOrder::SORT_ASC) ? 'ASC' : 'DESC'
);
}
} else {
// set a default sorting order since this method is used constantly in many
// different blocks
$field = 'author_id';
$collection->addOrder($field, 'ASC');
}
$collection->setCurPage($searchCriteria->getCurrentPage());
$collection->setPageSize($searchCriteria->getPageSize());
/** @var \Sample\News\Api\Data\AuthorInterface[] $authors */
$authors = [];
/** @var \Sample\News\Model\Author $author */
foreach ($collection as $author) {
/** @var \Sample\News\Api\Data\AuthorInterface $authorDataObject */
$authorDataObject = $this->authorInterfaceFactory->create();
$this->dataObjectHelper->populateWithArray($authorDataObject, $author->getData(), AuthorInterface::class);
$authors[] = $authorDataObject;
}
$searchResults->setTotalCount($collection->getSize());
return $searchResults->setItems($authors);
}
/**
* Delete author.
*
* @param \Sample\News\Api\Data\AuthorInterface $author
* @return bool true on success
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function delete(AuthorInterface $author)
{
/** @var \Sample\News\Api\Data\AuthorInterface|\Magento\Framework\Model\AbstractModel $author */
$id = $author->getId();
try {
unset($this->instances[$id]);
$this->resource->delete($author);
} catch (ValidatorException $e) {
throw new CouldNotSaveException(__($e->getMessage()));
} catch (\Exception $e) {
throw new StateException(
__('Unable to remove author %1', $id)
);
}
unset($this->instances[$id]);
return true;
}
/**
* Delete author by ID.
*
* @param int $authorId
* @return bool true on success
* @throws \Magento\Framework\Exception\NoSuchEntityException
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function deleteById($authorId)
{
$author = $this->getById($authorId);
return $this->delete($author);
}
/**
* Helper function that adds a FilterGroup to the collection.
*
* @param FilterGroup $filterGroup
* @param Collection $collection
* @return $this
* @throws \Magento\Framework\Exception\InputException
*/
protected function addFilterGroupToCollection(FilterGroup $filterGroup, Collection $collection)
{
$fields = [];
$conditions = [];
foreach ($filterGroup->getFilters() as $filter) {
$condition = $filter->getConditionType() ? $filter->getConditionType() : 'eq';
$fields[] = $filter->getField();
$conditions[] = [$condition => $filter->getValue()];
}
if ($fields) {
$collection->addFieldToFilter($fields, $conditions);
}
return $this;
}
}
================================================
FILE: Model/FactoryInterface.php
================================================
<?php
/**
* Sample_News extension
*
* NOTICE OF LICENSE
*
* This source file is subject to the MIT License
* that is bundled with this package in the file LICENSE
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/mit-license.php
*
* @category Sample
* @package Sample_News
* @copyright 2016 Marius Strajeru
* @license http://opensource.org/licenses/mit-license.php MIT License
* @author Marius Strajeru
*/
namespace Sample\News\Model;
use Sample\News\Model\Routing\RoutableInterface;
interface FactoryInterface
{
/**
* @return RoutableInterface
*/
public function create();
}
================================================
FILE: Model/Image.php
================================================
<?php
/**
* Sample_News extension
*
* NOTICE OF LICENSE
*
* This source file is subject to the MIT License
* that is bundled with this package in the file LICENSE
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/mit-license.php
*
* @category Sample
* @package Sample_News
* @copyright 2016 Marius Strajeru
* @license http://opensource.org/licenses/mit-license.php MIT License
* @author Marius Strajeru
*/
namespace Sample\News\Model;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\Data\Collection\AbstractDb;
use Magento\Framework\Filesystem;
use Magento\Framework\Image as MagentoImage;
use Magento\Framework\Image\Factory as MagentoImageFactory;
use Magento\Framework\Model\AbstractModel;
use Magento\Framework\Model\Context;
use Magento\Framework\Model\ResourceModel\AbstractResource;
use Magento\Framework\Registry;
use Magento\Framework\UrlInterface;
use Magento\Framework\View\Asset\Repository;
use Magento\Framework\View\FileSystem as ViewFileSystem;
use Magento\MediaStorage\Helper\File\Storage\Database;
use Magento\Store\Model\Store;
use Magento\Store\Model\StoreManagerInterface;
/**
* @SuppressWarnings(PHPMD.TooManyFields)
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @method string getFile()
* @method string getLabel()
* @method string getPosition()
*/
class Image extends AbstractModel
{
/**
* @var int
*/
protected $width;
/**
* @var int
*/
protected $height;
/**
* Default quality value (for JPEG images only).
*
* @var int
*/
protected $quality = 80;
/**
* @var bool
*/
protected $keepAspectRatio = true;
/**
* @var bool
*/
protected $keepFrame = true;
/**
* @var bool
*/
protected $keepTransparency = true;
/**
* @var bool
*/
protected $constrainOnly = true;
/**
* @var int[]
*/
protected $backgroundColor = [255, 255, 255];
/**
* @var string
*/
protected $baseFile;
/**
* @var bool
*/
protected $isBaseFilePlaceholder;
/**
* @var string|bool
*/
protected $newFile;
/**
* @var MagentoImage
*/
protected $processor;
/**
* @var string
*/
protected $destinationSubdir;
/**
* @var int
*/
protected $angle;
/**
* @var string
*/
protected $watermarkFile;
/**
* @var int
*/
protected $watermarkPosition;
/**
* @var int
*/
protected $watermarkWidth;
/**
* @var int
*/
protected $watermarkHeight;
/**
* @var int
*/
protected $watermarkImageOpacity = 70;
/**
* @var \Magento\Framework\Filesystem\Directory\WriteInterface
*/
protected $mediaDirectory;
/**
* @var \Magento\Framework\Image\Factory
*/
protected $imageFactory;
/**
* @var \Magento\Framework\View\Asset\Repository
*/
protected $assetRepo;
/**
* @var \Magento\Framework\View\FileSystem
*/
protected $viewFileSystem;
/**
* Core file storage database
*
* @var \Magento\MediaStorage\Helper\File\Storage\Database
*/
protected $coreFileStorageDatabase = null;
/**
* Core store config
*
* @var \Magento\Framework\App\Config\ScopeConfigInterface
*/
protected $scopeConfig;
/**
* @var Uploader
*/
protected $uploader;
/**
* Store manager
*
* @var \Magento\Store\Model\StoreManagerInterface
*/
protected $storeManager;
/**
* @var string
*/
protected $entityCode;
/**
* @param Context $context
* @param Registry $registry
* @param StoreManagerInterface $storeManager
* @param Uploader $uploader
* @param Database $coreFileStorageDatabase
* @param Filesystem $filesystem
* @param ImageFactory $imageFactory
* @param Repository $assetRepo
* @param ViewFileSystem $viewFileSystem
* @param ScopeConfigInterface $scopeConfig
* @param $entityCode
* @param AbstractResource|null $resource
* @param AbstractDb|null $resourceCollection
* @param array $data
*/
public function __construct(
Context $context,
Registry $registry,
StoreManagerInterface $storeManager,
Uploader $uploader,
Database $coreFileStorageDatabase,
Filesystem $filesystem,
MagentoImageFactory $imageFactory,
Repository $assetRepo,
ViewFileSystem $viewFileSystem,
ScopeConfigInterface $scopeConfig,
$entityCode,
AbstractResource $resource = null,
AbstractDb $resourceCollection = null,
array $data = []
) {
$this->storeManager = $storeManager;
$this->uploader = $uploader;
$this->coreFileStorageDatabase = $coreFileStorageDatabase;
$this->imageFactory = $imageFactory;
$this->assetRepo = $assetRepo;
$this->viewFileSystem = $viewFileSystem;
$this->scopeConfig = $scopeConfig;
$this->entityCode = $entityCode;
parent::__construct($context, $registry, $resource, $resourceCollection, $data);
$this->mediaDirectory = $filesystem->getDirectoryWrite(DirectoryList::MEDIA);
$this->mediaDirectory->create($this->uploader->getBasePath());
}
/**
* @param int $width
* @return $this
*/
public function setWidth($width)
{
$this->width = $width;
return $this;
}
/**
* @return int
*/
public function getWidth()
{
return $this->width;
}
/**
* @param int $height
* @return $this
*/
public function setHeight($height)
{
$this->height = $height;
return $this;
}
/**
* @return int
*/
public function getHeight()
{
return $this->height;
}
/**
* Set image quality, values in percentage from 0 to 100
*
* @param int $quality
* @return $this
*/
public function setQuality($quality)
{
$this->quality = $quality;
return $this;
}
/**
* Get image quality
*
* @return int
*/
public function getQuality()
{
return $this->quality;
}
/**
* @param bool $keep
* @return $this
*/
public function setKeepAspectRatio($keep)
{
$this->keepAspectRatio = (bool)$keep;
return $this;
}
/**
* @param bool $keep
* @return $this
*/
public function setKeepFrame($keep)
{
$this->keepFrame = (bool)$keep;
return $this;
}
/**
* @param bool $keep
* @return $this
*/
public function setKeepTransparency($keep)
{
$this->keepTransparency = (bool)$keep;
return $this;
}
/**
* @param bool $flag
* @return $this
*/
public function setConstrainOnly($flag)
{
$this->constrainOnly = (bool)$flag;
return $this;
}
/**
* @param int[] $rgbArray
* @return $this
*/
public function setBackgroundColor(array $rgbArray)
{
$this->backgroundColor = $rgbArray;
return $this;
}
/**
* @param string $size
* @return $this
*/
public function setSize($size)
{
// determine width and height from string
list($width, $height) = explode('x', strtolower($size), 2);
foreach (['width', 'height'] as $wh) {
${$wh} = (int)${$wh};
if (empty(${$wh})) {
${$wh} = null;
}
}
// set sizes
$this->setWidth($width)->setHeight($height);
return $this;
}
/**
* @param string|null $file
* @return bool
*/
protected function checkMemory($file = null)
{
return $this->getMemoryLimit() > $this->getMemoryUsage() + $this->getNeedMemoryForFile(
$file
)
|| $this->getMemoryLimit() == -1;
}
/**
* @return string
*/
protected function getMemoryLimit()
{
$memoryLimit = trim(strtoupper(ini_get('memory_limit')));
if (!isset($memoryLimit[0])) {
$memoryLimit = "128M";
}
if (substr($memoryLimit, -1) == 'K') {
return substr($memoryLimit, 0, -1) * 1024;
}
if (substr($memoryLimit, -1) == 'M') {
return substr($memoryLimit, 0, -1) * 1024 * 1024;
}
if (substr($memoryLimit, -1) == 'G') {
return substr($memoryLimit, 0, -1) * 1024 * 1024 * 1024;
}
return $memoryLimit;
}
/**
* @return int
*/
protected function getMemoryUsage()
{
if (function_exists('memory_get_usage')) {
return memory_get_usage();
}
return 0;
}
/**
* @param string|null $file
* @return float|int
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
protected function getNeedMemoryForFile($file = null)
{
$file = $file === null ? $this->getBaseFile() : $file;
if (!$file) {
return 0;
}
if (!$this->mediaDirectory->isExist($file)) {
return 0;
}
$imageInfo = getimagesize($this->mediaDirectory->getAbsolutePath($file));
if (!isset($imageInfo[0]) || !isset($imageInfo[1])) {
return 0;
}
if (!isset($imageInfo['channels'])) {
// if there is no info about this parameter lets set it for maximum
$imageInfo['channels'] = 4;
}
if (!isset($imageInfo['bits'])) {
// if there is no info about this parameter lets set it for maximum
$imageInfo['bits'] = 8;
}
return round(
($imageInfo[0] * $imageInfo[1] * $imageInfo['bits'] * $imageInfo['channels'] / 8 + Pow(2, 16)) * 1.65
);
}
/**
* Convert array of 3 items (decimal r, g, b) to string of their hex values
*
* @param int[] $rgbArray
* @return string
*/
protected function rgbToString($rgbArray)
{
$result = [];
foreach ($rgbArray as $value) {
if (null === $value) {
$result[] = 'null';
} else {
$result[] = sprintf('%02s', dechex($value));
}
}
return implode($result);
}
/**
* Set filenames for base file and new file
*
* @param string $file
* @return $this
* @throws \Exception
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
public function setBaseFile($file)
{
$this->isBaseFilePlaceholder = false;
if ($file && 0 !== strpos($file, '/', 0)) {
$file = '/' . $file;
}
$baseDir = $this->uploader->getBasePath();
if ($file) {
if (!$this->fileExists($baseDir . $file) || !$this->checkMemory($baseDir . $file)) {
$file = null;
}
}
if (!$file) {
$this->isBaseFilePlaceholder = true;
$this->newFile = true;
return $this;
}
$baseFile = $baseDir . $file;
if (!$file || !$this->mediaDirectory->isFile($baseFile)) {
throw new \Exception(__('We can\'t find the image file.'));
}
$this->baseFile = $baseFile;
// build new filename (most important params)
$path = [
$this->uploader->getBasePath(),
'cache',
$this->storeManager->getStore()->getId(),
$path[] = $this->getDestinationSubdir(),
];
if (!empty($this->width) || !empty($this->height)) {
$path[] = "{$this->width}x{$this->height}";
}
// add misk params as a hash
$miscParams = [
($this->keepAspectRatio ? '' : 'non') . 'proportional',
($this->keepFrame ? '' : 'no') . 'frame',
($this->keepTransparency ? '' : 'no') . 'transparency',
($this->constrainOnly ? 'do' : 'not') . 'constrainonly',
$this->rgbToString($this->backgroundColor),
'angle' . $this->angle,
'quality' . $this->quality,
];
// if has watermark add watermark params to hash
if ($this->getWatermarkFile()) {
$miscParams[] = $this->getWatermarkFile();
$miscParams[] = $this->getWatermarkImageOpacity();
$miscParams[] = $this->getWatermarkPosition();
$miscParams[] = $this->getWatermarkWidth();
$miscParams[] = $this->getWatermarkHeight();
}
$path[] = md5(implode('_', $miscParams));
// append prepared filename
$this->newFile = implode('/', $path) . $file;
// the $file contains heading slash
return $this;
}
/**
* @return string
*/
public function getBaseFile()
{
return $this->baseFile;
}
/**
* @return bool|string
*/
public function getNewFile()
{
return $this->newFile;
}
/**
* Retrieve 'true' if image is a base file placeholder
*
* @return bool
*/
public function isBaseFilePlaceholder()
{
return (bool)$this->isBaseFilePlaceholder;
}
/**
* @param MagentoImage $processor
* @return $this
*/
public function setImageProcessor($processor)
{
$this->processor = $processor;
return $this;
}
/**
* @return MagentoImage
*/
public function getImageProcessor()
{
if (!$this->processor) {
$filename = $this->getBaseFile() ? $this->mediaDirectory->getAbsolutePath($this->getBaseFile()) : null;
$this->processor = $this->imageFactory->create($filename);
}
$this->processor->keepAspectRatio($this->keepAspectRatio);
$this->processor->keepFrame($this->keepFrame);
$this->processor->keepTransparency($this->keepTransparency);
$this->processor->constrainOnly($this->constrainOnly);
$this->processor->backgroundColor($this->backgroundColor);
$this->processor->quality($this->quality);
return $this->processor;
}
/**
* @see \Magento\Framework\Image\Adapter\AbstractAdapter
* @return $this
*/
public function resize()
{
if ($this->getWidth() === null && $this->getHeight() === null) {
return $this;
}
$this->getImageProcessor()->resize($this->width, $this->height);
return $this;
}
/**
* @param int $angle
* @return $this
*/
public function rotate($angle)
{
$angle = intval($angle);
$this->getImageProcessor()->rotate($angle);
return $this;
}
/**
* Set angle for rotating
*
* This func actually affects only the cache filename.
*
* @param int $angle
* @return $this
*/
public function setAngle($angle)
{
$this->angle = $angle;
return $this;
}
/**
* Add watermark to image
* size param in format 100x200
*
* @param string $file
* @param string $position
* @param array $size ['width' => int, 'height' => int]
* @param int $width
* @param int $height
* @param int $opacity
* @return $this
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
public function setWatermark(
$file,
$position = null,
$size = null,
$width = null,
$height = null,
$opacity = null
) {
if ($this->isBaseFilePlaceholder) {
return $this;
}
if ($file) {
$this->setWatermarkFile($file);
} else {
return $this;
}
if ($position) {
$this->setWatermarkPosition($position);
}
if ($size) {
$this->setWatermarkSize($size);
}
if ($width) {
$this->setWatermarkWidth($width);
}
if ($height) {
$this->setWatermarkHeight($height);
}
if ($opacity) {
$this->setWatermarkImageOpacity($opacity);
}
$filePath = $this->getWatermarkFilePath();
if ($filePath) {
$imagePreprocessor = $this->getImageProcessor();
$imagePreprocessor->setWatermarkPosition($this->getWatermarkPosition());
$imagePreprocessor->setWatermarkImageOpacity($this->getWatermarkImageOpacity());
$imagePreprocessor->setWatermarkWidth($this->getWatermarkWidth());
$imagePreprocessor->setWatermarkHeight($this->getWatermarkHeight());
$imagePreprocessor->watermark($filePath);
}
return $this;
}
/**
* @return $this
*/
public function saveFile()
{
if ($this->isBaseFilePlaceholder && $this->newFile === true) {
return $this;
}
$filename = $this->mediaDirectory->getAbsolutePath($this->getNewFile());
$this->getImageProcessor()->save($filename);
$this->coreFileStorageDatabase->saveFile($filename);
return $this;
}
/**
* @return string
*/
public function getUrl()
{
if ($this->newFile === true) {
$url = $this->assetRepo->getUrl(
"Sample_News::images/".$this->entityCode."/placeholder/{$this->getDestinationSubdir()}.jpg"
);
} else {
$url = $this->storeManager->getStore()->getBaseUrl(
UrlInterface::URL_TYPE_MEDIA
) . $this->newFile;
}
return $url;
}
/**
* @param string $dir
* @return $this
*/
public function setDestinationSubdir($dir)
{
$this->destinationSubdir = $dir;
return $this;
}
/**
* @return string
*/
public function getDestinationSubdir()
{
return $this->destinationSubdir;
}
/**
* @return bool|void
*/
public function isCached()
{
if (is_string($this->newFile)) {
return $this->fileExists($this->newFile);
}
return false;
}
/**
* Set watermark file name
*
* @param string $file
* @return $this
*/
public function setWatermarkFile($file)
{
$this->watermarkFile = $file;
return $this;
}
/**
* Get watermark file name
*
* @return string
*/
public function getWatermarkFile()
{
return $this->watermarkFile;
}
/**
* Get relative watermark file path
* or false if file not found
*
* @return string | bool
*/
protected function getWatermarkFilePath()
{
$filePath = false;
if (!($file = $this->getWatermarkFile())) {
return $filePath;
}
$baseDir = $this->uploader->getBasePath();
$candidates = [
$baseDir . '/watermark/stores/' . $this->storeManager->getStore()->getId() . $file,
$baseDir . '/watermark/websites/' . $this->storeManager->getWebsite()->getId() . $file,
$baseDir . '/watermark/default/' . $file,
$baseDir . '/watermark/' . $file,
];
foreach ($candidates as $candidate) {
if ($this->mediaDirectory->isExist($candidate)) {
$filePath = $this->mediaDirectory->getAbsolutePath($candidate);
break;
}
}
if (!$filePath) {
$filePath = $this->viewFileSystem->getStaticFileName($file);
}
return $filePath;
}
/**
* Set watermark position
*
* @param string $position
* @return $this
*/
public function setWatermarkPosition($position)
{
$this->watermarkPosition = $position;
return $this;
}
/**
* Get watermark position
*
* @return string
*/
public function getWatermarkPosition()
{
return $this->watermarkPosition;
}
/**
* Set watermark image opacity
*
* @param int $imageOpacity
* @return $this
*/
public function setWatermarkImageOpacity($imageOpacity)
{
$this->watermarkImageOpacity = $imageOpacity;
return $this;
}
/**
* Get watermark image opacity
*
* @return int
*/
public function getWatermarkImageOpacity()
{
return $this->watermarkImageOpacity;
}
/**
* Set watermark size
*
* @param array $size
* @return $this
*/
public function setWatermarkSize($size)
{
if (is_array($size)) {
$this->setWatermarkWidth($size['width'])->setWatermarkHeight($size['height']);
}
return $this;
}
/**
* Set watermark width
*
* @param int $width
* @return $this
*/
public function setWatermarkWidth($width)
{
$this->watermarkWidth = $width;
return $this;
}
/**
* Get watermark width
*
* @return int
*/
public function getWatermarkWidth()
{
return $this->watermarkWidth;
}
/**
* Set watermark height
*
* @param int $height
* @return $this
*/
public function setWatermarkHeight($height)
{
$this->watermarkHeight = $height;
return $this;
}
/**
* Get watermark height
*
* @return string
*/
public function getWatermarkHeight()
{
return $this->watermarkHeight;
}
/**
* @return void
*/
public function clearCache()
{
$directory = $this->uploader->getBasePath() . '/cache';
$this->mediaDirectory->delete($directory);
$this->coreFileStorageDatabase->deleteFolder($this->mediaDirectory->getAbsolutePath($directory));
}
/**
* First check this file on FS
* If it doesn't exist - try to download it from DB
*
* @param string $filename
* @return bool
*/
protected function fileExists($filename)
{
if ($this->mediaDirectory->isFile($filename)) {
return true;
} else {
return $this->coreFileStorageDatabase->saveFileToFilesystem(
$this->mediaDirectory->getAbsolutePath($filename)
);
}
}
/**
* Return resized image information
*
* @return array
*/
public function getResizedImageInfo()
{
$fileInfo = null;
if ($this->newFile === true) {
$asset = $this->assetRepo->createAsset(
"Sample_News::images/".$this->entityCode."/placeholder/{$this->getDestinationSubdir()}.jpg"
);
$img = $asset->getSourceFile();
$fileInfo = getimagesize($img);
} else {
if ($this->mediaDirectory->isFile($this->mediaDirectory->getAbsolutePath($this->newFile))) {
$fileInfo = getimagesize($this->mediaDirectory->getAbsolutePath($this->newFile));
}
}
return $fileInfo;
}
}
================================================
FILE: Model/Output.php
================================================
<?php
/**
* Sample_News extension
*
* NOTICE OF LICENSE
*
* This source file is subject to the MIT License
* that is bundled with this package in the file LICENSE
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/mit-license.php
*
* @category Sample
* @package Sample_News
* @copyright 2016 Marius Strajeru
* @license http://opensource.org/licenses/mit-license.php MIT License
* @author Marius Strajeru
*/
namespace Sample\News\Model;
class Output
{
/**
* @var \Zend_Filter_Interface
*/
protected $templateProcessor;
/**
* @param \Zend_Filter_Interface $templateProcessor
*/
public function __construct(
\Zend_Filter_Interface $templateProcessor
) {
$this->templateProcessor = $templateProcessor;
}
/**
* @param $string
* @return string
*/
public function filterOutput($string)
{
return $this->templateProcessor->filter($string);
}
}
================================================
FILE: Model/ResourceModel/Author/Collection.php
================================================
<?php
/**
* Sample_News extension
*
* NOTICE OF LICENSE
*
* This source file is subject to the MIT License
* that is bundled with this package in the file LICENSE
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/mit-license.php
*
* @category Sample
* @package Sample_News
* @copyright 2016 Marius Strajeru
* @license http://opensource.org/licenses/mit-license.php MIT License
* @author Marius Strajeru
*/
namespace Sample\News\Model\ResourceModel\Author;
use Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection;
use Magento\Framework\Data\Collection\Db\FetchStrategyInterface;
use Magento\Framework\Data\Collection\EntityFactoryInterface;
use Magento\Framework\Event\ManagerInterface;
use Magento\Framework\Model\ResourceModel\Db\AbstractDb;
use Magento\Store\Model\Store;
use Magento\Store\Model\StoreManagerInterface;
use Psr\Log\LoggerInterface;
use Sample\News\Model\Author;
use Sample\News\Model\ResourceModel\Author as AuthorResourceModel;
class Collection extends AbstractCollection
{
/**
* @var string
*/
protected $_idFieldName = 'author_id';
/**
* Event prefix
*
* @var string
*/
protected $_eventPrefix = 'sample_news_author_collection';
/**
* Event object
*
* @var string
*/
protected $_eventObject = 'author_collection';
/**
* Store manager
*
* @var \Magento\Store\Model\StoreManagerInterface
*/
protected $storeManager;
/**
* @var array
*/
protected $_joinedFields = [];
/**
* constructor
*
* @param EntityFactoryInterface $entityFactory
* @param LoggerInterface $logger
* @param FetchStrategyInterface $fetchStrategy
* @param ManagerInterface $eventManager
* @param StoreManagerInterface $storeManager
* @param null $connection
* @param AbstractDb $resource
*/
public function __construct(
EntityFactoryInterface $entityFactory,
LoggerInterface $logger,
FetchStrategyInterface $fetchStrategy,
ManagerInterface $eventManager,
StoreManagerInterface $storeManager,
$connection = null,
AbstractDb $resource = null
) {
$this->storeManager = $storeManager;
parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager, $connection, $resource);
}
/**
* Define resource model
*
* @return void
*/
protected function _construct()
{
$this->_init(Author::class, AuthorResourceModel::class);
$this->_map['fields']['author_id'] = 'main_table.author_id';
$this->_map['fields']['store_id'] = 'store_table.store_id';
}
/**
* after collection load
*
* @return $this
*/
protected function _afterLoad()
{
$this->performAfterLoad('sample_news_author_store', 'author_id');
foreach ($this->getItems() as $item) {
/** @var \Sample\News\Model\Author $item */
$awards = $item->getAwards();
if ($awards && !is_array($awards)) {
$item->setAwards(explode(',', $awards));
}
}
return parent::_afterLoad();
}
public function addFieldToFilter($field, $condition = null)
{
if ($field === 'store_id') {
return $this->addStoreFilter($condition, false);
}
return parent::addFieldToFilter($field, $condition);
}
/**
* Add filter by store
*
* @param int|\Magento\Store\Model\Store $store
* @param bool $withAdmin
* @return $this
*/
public function addStoreFilter($store, $withAdmin = true)
{
if (!$this->getFlag('store_filter_added')) {
if ($store instanceof Store) {
$store = [$store->getId()];
}
if (!is_array($store)) {
$store = [$store];
}
if ($withAdmin) {
$store[] = Store::DEFAULT_STORE_ID;
}
$this->addFilter('store_id', ['in' => $store], 'public');
}
return $this;
}
/**
* Join store relation table if there is store filter
*
* @return void
* @SuppressWarnings(PHPMD.Ecg.Sql.SlowQuery)
*/
protected function _renderFiltersBefore()
{
if ($this->getFilter('store_id')) {
$this->getSelect()->join(
['store_table' => $this->getTable('sample_news_author_store')],
'main_table.author_id = store_table.author_id',
[]
)
// @codingStandardsIgnoreStart
->group('main_table.author_id');
// @codingStandardsIgnoreEnd
}
parent::_renderFiltersBefore();
}
/**
* Get SQL for get record count.
* Extra GROUP BY strip added.
*
* @return \Magento\Framework\DB\Select
*/
public function getSelectCountSql()
{
$countSelect = parent::getSelectCountSql();
$countSelect->reset(\Zend_Db_Select::GROUP);
return $countSelect;
}
/**
* @param $tableName
* @param $linkField
*/
protected function performAfterLoad($tableName, $linkField)
{
$linkedIds = $this->getColumnValues($linkField);
if (count($linkedIds)) {
$connection = $this->getConnection();
$select = $connection->select()->from(['sample_news_author_store' => $this->getTable($tableName)])
->where('sample_news_author_store.' . $linkField . ' IN (?)', $linkedIds);
// @codingStandardsIgnoreStart
$result = $connection->fetchAll($select);
// @codingStandardsIgnoreEnd
if ($result) {
$storesData = [];
foreach ($result as $storeData) {
$storesData[$storeData[$linkField]][] = $storeData['store_id'];
}
foreach ($this as $item) {
$linkedId = $item->getData($linkField);
if (!isset($storesData[$linkedId])) {
continue;
}
$storeIdKey = array_search(Store::DEFAULT_STORE_ID, $storesData[$linkedId], true);
if ($storeIdKey !== false) {
$stores = $this->storeManager->getStores(false, true);
$storeId = current($stores)->getId();
$storeCode = key($stores);
} else {
$storeId = current($storesData[$linkedId]);
$storeCode = $this->storeManager->getStore($storeId)->getCode();
}
$item->setData('store_id', $storesData[$linkedId]);
}
}
}
}
}
================================================
FILE: Model/ResourceModel/Author/Grid/Collection.php
================================================
<?php
/**
* Sample_News extension
*
* NOTICE OF LICENSE
*
* This source file is subject to the MIT License
* that is bundled with this package in the file LICENSE
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/mit-license.php
*
* @category Sample
* @package Sample_News
* @copyright 2016 Marius Strajeru
* @license http://opensource.org/licenses/mit-license.php MIT License
* @author Marius Strajeru
*/
namespace Sample\News\Model\ResourceModel\Author\Grid;
use Magento\Framework\Api\Search\SearchResultInterface;
use Magento\Framework\Api\Search\AggregationInterface;
use Magento\Framework\Api\SearchCriteriaInterface;
use Magento\Framework\Data\Collection\EntityFactoryInterface;
use Magento\Framework\Data\Collection\Db\FetchStrategyInterface;
use Magento\Framework\Event\ManagerInterface;
use Magento\Framework\Model\ResourceModel\Db\AbstractDb;
use Magento\Framework\View\Element\UiComponent\DataProvider\Document;
use Magento\Store\Model\StoreManagerInterface;
use Psr\Log\LoggerInterface;
use Sample\News\Model\ResourceModel\Author\Collection as AuthorCollection;
class Collection extends AuthorCollection implements SearchResultInterface
{
/**
* @var AggregationInterface
*/
protected $aggregations;
/**
* @param EntityFactoryInterface $entityFactory
* @param LoggerInterface $logger
* @param FetchStrategyInterface $fetchStrategy
* @param ManagerInterface $eventManager
* @param StoreManagerInterface $storeManager
* @param null $mainTable
* @param AbstractDb $eventPrefix
* @param $eventObject
* @param $resourceModel
* @param string $model
* @param null $connection
* @param AbstractDb|null $resource
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function __construct(
EntityFactoryInterface $entityFactory,
LoggerInterface $logger,
FetchStrategyInterface $fetchStrategy,
ManagerInterface $eventManager,
StoreManagerInterface $storeManager,
$mainTable,
$eventPrefix,
$eventObject,
$resourceModel,
$model = Document::class,
$connection = null,
AbstractDb $resource = null
) {
parent::__construct(
$entityFactory,
$logger,
$fetchStrategy,
$eventManager,
$storeManager,
$connection,
$resource
);
$this->_eventPrefix = $eventPrefix;
$this->_eventObject = $eventObject;
$this->_init($model, $resourceModel);
$this->setMainTable($mainTable);
}
/**
* @return AggregationInterface
*/
public function getAggregations()
{
return $this->aggregations;
}
/**
* @param AggregationInterface $aggregations
* @return $this
*/
public function setAggregations($aggregations)
{
$this->aggregations = $aggregations;
}
/**
* Get search criteria.
*
* @return \Magento\Framework\Api\SearchCriteriaInterface|null
*/
public function getSearchCriteria()
{
return null;
}
/**
* Set search criteria.
*
* @param \Magento\Framework\Api\SearchCriteriaInterface $searchCriteria
* @return $this
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function setSearchCriteria(SearchCriteriaInterface $searchCriteria = null)
{
return $this;
}
/**
* Get total count.
*
* @return int
*/
public function getTotalCount()
{
return $this->getSize();
}
/**
* Set total count.
*
* @param int $totalCount
* @return $this
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function setTotalCount($totalCount)
{
return $this;
}
/**
* Set items list.
*
* @param \Magento\Framework\Api\ExtensibleDataInterface[] $items
* @return $this
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function setItems(array $items = null)
{
return $this;
}
}
================================================
FILE: Model/ResourceModel/Author/Grid/ServiceCollection.php
================================================
<?php
/**
* Sample_News extension
*
* NOTICE OF LICENSE
*
* This source file is subject to the MIT License
* that is bundled with this package in the file LICENSE
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/mit-license.php
*
* @category Sample
* @package Sample_News
* @copyright 2016 Marius Strajeru
* @license http://opensource.org/licenses/mit-license.php MIT License
* @author Marius Strajeru
*/
// @codingStandardsIgnoreFile
namespace Sample\News\Model\ResourceModel\Author\Grid;
use Magento\Framework\Api\AbstractServiceCollection;
use Magento\Framework\Api\FilterBuilder;
use Magento\Framework\Api\SearchCriteriaBuilder;
use Magento\Framework\Api\SimpleDataObjectConverter;
use Magento\Framework\Api\SortOrderBuilder;
use Magento\Framework\Data\Collection\EntityFactory;
use Magento\Framework\DataObject;
use Sample\News\Api\AuthorRepositoryInterface;
use Sample\News\Api\Data\AuthorInterface;
/**
* Author collection backed by services
*/
class ServiceCollection extends AbstractServiceCollection
{
/**
* @var AuthorRepositoryInterface
*/
protected $authorRepository;
/**
* @var SimpleDataObjectConverter
*/
protected $simpleDataObjectConverter;
/**
* @param EntityFactory $entityFactory
* @param FilterBuilder $filterBuilder
* @param SearchCriteriaBuilder $searchCriteriaBuilder
* @param SortOrderBuilder $sortOrderBuilder
* @param AuthorRepositoryInterface $authorRepository
* @param SimpleDataObjectConverter $simpleDataObjectConverter
*/
public function __construct(
EntityFactory $entityFactory,
FilterBuilder $filterBuilder,
SearchCriteriaBuilder $searchCriteriaBuilder,
SortOrderBuilder $sortOrderBuilder,
AuthorRepositoryInterface $authorRepository,
SimpleDataObjectConverter $simpleDataObjectConverter
) {
$this->authorRepository = $authorRepository;
$this->simpleDataObjectConverter = $simpleDataObjectConverter;
parent::__construct($entityFactory, $filterBuilder, $searchCriteriaBuilder, $sortOrderBuilder);
}
/**
* Load customer group collection data from service
*
* @param bool $printQuery
* @param bool $logQuery
* @return $this
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function loadData($printQuery = false, $logQuery = false)
{
if (!$this->isLoaded()) {
$searchCriteria = $this->getSearchCriteria();
$searchResults = $this->authorRepository->getList($searchCriteria);
$this->_totalRecords = $searchResults->getTotalCount();
/** @var AuthorInterface[] $authors */
$authors = $searchResults->getItems();
foreach ($authors as $author) {
$authorItem = new DataObject();
$authorItem->addData(
$this->simpleDataObjectConverter->toFlatArray($author, AuthorInterface::class)
);
$this->_addItem($authorItem);
}
$this->_setIsLoaded();
}
return $this;
}
}
================================================
FILE: Model/ResourceModel/Author.php
================================================
<?php
/**
* Sample_News extension
*
* NOTICE OF LICENSE
*
* This source file is subject to the MIT License
* that is bundled with this package in the file LICENSE
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/mit-license.php
*
* @category Sample
* @package Sample_News
* @copyright 2016 Marius Strajeru
* @license http://opensource.org/licenses/mit-license.php MIT License
* @author Marius Strajeru
*/
namespace Sample\News\Model\ResourceModel;
use Magento\Framework\Model\ResourceModel\Db\AbstractDb;
use Magento\Framework\Model\ResourceModel\Db\Context;
use Magento\Framework\Stdlib\DateTime\DateTime;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Framework\Stdlib\DateTime as LibDateTime;
use Magento\Framework\Model\AbstractModel;
use Magento\Store\Model\Store;
use Sample\News\Model\Author as AuthorModel;
use Magento\Framework\Event\ManagerInterface;
class Author extends AbstractDb
{
/**
* Store model
*
* @var \Magento\Store\Model\Store
*/
protected $store = null;
/**
* @var \Magento\Framework\Stdlib\DateTime\DateTime
*/
protected $date;
/**
* Store manager
*
* @var \Magento\Store\Model\StoreManagerInterface
*/
protected $storeManager;
/**
* @var \Magento\Framework\Stdlib\DateTime
*/
protected $dateTime;
/**
* @var \Magento\Framework\Event\ManagerInterface
*/
protected $eventManager;
/**
* @param Context $context
* @param DateTime $date
* @param StoreManagerInterface $storeManager
* @param LibDateTime $dateTime
* @param ManagerInterface $eventManager
*/
public function __construct(
Context $context,
DateTime $date,
StoreManagerInterface $storeManager,
LibDateTime $dateTime,
ManagerInterface $eventManager
) {
$this->date = $date;
$this->storeManager = $storeManager;
$this->dateTime = $dateTime;
$this->eventManager = $eventManager;
parent::__construct($context);
}
/**
* Initialize resource model
*
* @return void
*/
protected function _construct()
{
$this->_init('sample_news_author', 'author_id');
}
/**
* Process author data before deleting
*
* @param \Magento\Framework\Model\AbstractModel $object
* @return $this
*/
protected function _beforeDelete(AbstractModel $object)
{
$condition = ['author_id = ?' => (int)$object->getId()];
$this->getConnection()->delete($this->getTable('sample_news_author_store'), $condition);
return parent::_beforeDelete($object);
}
/**
* before save callback
*
* @param AbstractModel|\Sample\News\Model\Author $object
* @return $this
*/
protected function _beforeSave(AbstractModel $object)
{
foreach (['dob'] as $field) {
$value = !$object->getData($field) ? null : $object->getData($field);
$object->setData($field, $this->dateTime->formatDate($value));
}
foreach (['awards'] as $field) {
if (is_array($object->getData($field))) {
$object->setData($field, implode(',', $object->getData($field)));
}
}
$object->setUpdatedAt($this->date->gmtDate());
if ($object->isObjectNew()) {
$object->setCreatedAt($this->date->gmtDate());
}
$urlKey = $object->getData('url_key');
if ($urlKey == '') {
$urlKey = $object->getName();
}
$urlKey = $object->formatUrlKey($urlKey);
$object->setUrlKey($urlKey);
$validKey = false;
while (!$validKey) {
if ($this->getIsUniqueAuthorToStores($object)) {
$validKey = true;
} else {
$urlKey = $this->generateNewUrlKey($urlKey);
$object->setData('url_key', $urlKey);
}
}
return parent::_beforeSave($object);
}
/**
* @param $urlKey
* @return string
*/
protected function generateNewUrlKey($urlKey)
{
$parts = explode('-', $urlKey);
$last = $parts[count($parts) - 1];
if (!is_numeric($last)) {
$urlKey = $urlKey.'-1';
} else {
$suffix = '-'.($last + 1);
unset($parts[count($parts) - 1]);
$urlKey = implode('-', $parts).$suffix;
}
return $urlKey;
}
/**
* Assign author to store views
*
* @param AbstractModel|\Sample\News\Model\Author $object
* @return $this
*/
protected function _afterSave(AbstractModel $object)
{
$this->saveStoreRelation($object);
return parent::_afterSave($object);
}
/**
* Perform operations after object load
*
* @param AbstractModel $object
* @return $this
*/
protected function _afterLoad(AbstractModel $object)
{
if ($object->getId()) {
$stores = $this->lookupStoreIds($object->getId());
$object->setData('store_id', $stores);
}
$awards = $object->getData('awards');
if (!is_array($awards)) {
$awards = explode(',', $awards);
$object->setData('awards', $awards);
}
return parent::_afterLoad($object);
}
/**
* Retrieve select object for load object data
*
* @param string $field
* @param mixed $value
* @param \Sample\News\Model\Author $object
* @return \Zend_Db_Select
*/
protected function _getLoadSelect($field, $value, $object)
{
$select = parent::_getLoadSelect($field, $value, $object);
if ($object->getStoreId()) {
$storeIds = [
Store::DEFAULT_STORE_ID,
(int)$object->getStoreId()
];
$select->join(
[
'sample_news_author_store' => $this->getTable('sample_news_author_store')
],
$this->getMainTable() . '.author_id = sample_news_author_store.author_id',
[]
)
->where(
'sample_news_author_store.store_id IN (?)',
$storeIds
)
->order('sample_news_author_store.store_id DESC')
->limit(1);
}
return $select;
}
/**
* Retrieve load select with filter by url_key, store and activity
*
* @param string $urlKey
* @param int|array $store
* @param int $isActive
* @return \Magento\Framework\DB\Select
*/
protected function getLoadByUrlKeySelect($urlKey, $store, $isActive = null)
{
$select = $this->getConnection()
->select()
->from(['author' => $this->getMainTable()])
->join(
['author_store' => $this->getTable('sample_news_author_store')],
'author.author_id = author_store.author_id',
[]
)
->where(
'author.url_key = ?',
$urlKey
)
->where(
'author_store.store_id IN (?)',
$store
);
if (!is_null($isActive)) {
$select->where('author.is_active = ?', $isActive);
}
return $select;
}
/**
* Check if author url_key exist
* return author id if author exists
*
* @param string $urlKey
* @param int $storeId
* @return int
*/
public function checkUrlKey($urlKey, $storeId)
{
$stores = [Store::DEFAULT_STORE_ID, $storeId];
$select = $this->getLoadByUrlKeySelect($urlKey, $stores, 1);
$select->reset(\Zend_Db_Select::COLUMNS)
->columns('author.author_id')
->order('author_store.store_id DESC')
->limit(1);
return $this->getConnection()->fetchOne($select);
}
/**
* Get store ids to which specified item is assigned
*
* @param int $authorId
* @return array
*/
public function lookupStoreIds($authorId)
{
$adapter = $this->getConnection();
$select = $adapter->select()->from(
$this->getTable('sample_news_author_store'),
'store_id'
)->where(
'author_id = ?',
(int)$authorId
);
return $adapter->fetchCol($select);
}
/**
* Set store model
*
* @param Store $store
* @return $this
*/
public function setStore(Store $store)
{
$this->store = $store;
return $this;
}
/**
* Retrieve store model
*
* @return Store
*/
public function getStore()
{
return $this->storeManager->getStore($this->store);
}
/**
* check if url key is unique
*
* @param AbstractModel|\Sample\News\Model\Author $object
* @return bool
*/
public function getIsUniqueAuthorToStores(AbstractModel $object)
{
if ($this->storeManager->hasSingleStore() || !$object->hasStores()) {
$stores = [Store::DEFAULT_STORE_ID];
} else {
$stores = (array)$object->getData('stores');
}
$select = $this->getLoadByUrlKeySelect($object->getData('url_key'), $stores);
if ($object->getId()) {
$select->where('author_store.author_id <> ?', $object->getId());
}
if ($this->getConnection()->fetchRow($select)) {
return false;
}
return true;
}
/**
* @param AuthorModel $author
* @return $this
*/
protected function saveStoreRelation(AuthorModel $author)
{
$oldStores = $this->lookupStoreIds($author->getId());
$newStores = (array)$author->getStoreId();
if (empty($newStores)) {
$newStores = (array)$author->getStoreId();
}
$table = $this->getTable('sample_news_author_store');
$insert = array_diff($newStores, $oldStores);
$delete = array_diff($oldStores, $newStores);
if ($delete) {
$where = [
'author_id = ?' => (int)$author->getId(),
'store_id IN (?)' => $delete
];
$this->getConnection()->delete($table, $where);
}
if ($insert) {
$data = [];
foreach ($insert as $storeId) {
$data[] = [
'author_id' => (int)$author->getId(),
'store_id' => (int)$storeId
];
}
$this->getConnection()->insertMultiple($table, $data);
}
return $this;
}
/**
* @param AbstractModel $object
* @param $attribute
* @return $this
* @throws \Exception
*/
public function saveAttribute(AbstractModel $object, $attribute)
{
if (is_string($attribute)) {
$attributes = [$attribute];
} else {
$attributes = $attribute;
}
if (is_array($attributes) && !empty($attributes)) {
$this->getConnection()->beginTransaction();
$data = array_intersect_key($object->getData(), array_flip($attributes));
try {
$this->beforeSaveAttribute($object, $attributes);
if ($object->getId() && !empty($data)) {
$this->getConnection()->update(
$object->getResource()->getMainTable(),
$data,
[$object->getResource()->getIdFieldName() . '= ?' => (int)$object->getId()]
);
$object->addData($data);
}
$this->afterSaveAttribute($object, $attributes);
$this->getConnection()->commit();
} catch (\Exception $e) {
$this->getConnection()->rollBack();
throw $e;
}
}
return $this;
}
/**
* @param AbstractModel $object
* @param $attribute
* @return $this
*/
protected function beforeSaveAttribute(AbstractModel $object, $attribute)
{
if ($object->getEventObject() && $object->getEventPrefix()) {
$this->eventManager->dispatch(
$object->getEventPrefix() . '_save_attribute_before',
[
$object->getEventObject() => $this,
'object' => $object,
'attribute' => $attribute
]
);
}
return $this;
}
/**
* After save object attribute
*
* @param AbstractModel $object
* @param string $attribute
* @return \Magento\Sales\Model\ResourceModel\Attribute
*/
protected function afterSaveAttribute(AbstractModel $object, $attribute)
{
if ($object->getEventObject() && $object->getEventPrefix()) {
$this->eventManager->dispatch(
$object->getEventPrefix() . '_save_attribute_after',
[
$object->getEventObject() => $this,
'object' => $object,
'attribute' => $attribute
]
);
}
return $this;
}
}
================================================
FILE: Model/Routing/Entity.php
================================================
<?php
namespace Sample\News\Model\Routing;
use Sample\News\Model\FactoryInterface;
class Entity
{
/**
* @var string
*/
protected $prefixConfigPath;
/**
* @var string
*/
protected $suffixConfigPath;
/**
* @var string
*/
protected $listKeyConfigPath;
/**
* @var string
*/
protected $listAction;
/**
* @var FactoryInterface
*/
protected $factory;
/**
* @var string
*/
protected $controller;
/**
* @var string
*/
protected $viewAction;
/**
* @var string
*/
protected $param;
/**
* @param $prefixConfigPath
* @param $suffixConfigPath
* @param $listKeyConfigPath
* @param FactoryInterface $factory
* @param $controller
* @param string $listAction
* @param string $viewAction
* @param string $param
*/
public function __construct(
$prefixConfigPath,
$suffixConfigPath,
$listKeyConfigPath,
FactoryInterface $factory,
$controller,
$listAction = 'index',
$viewAction = 'view',
$param = 'id'
) {
$this->prefixConfigPath = $prefixConfigPath;
$this->suffixConfigPath = $suffixConfigPath;
$this->listKeyConfigPath = $listKeyConfigPath;
$this->factory = $factory;
$this->controller = $controller;
$this->listAction = $listAction;
$this->viewAction = $viewAction;
$this->param = $param;
}
/**
* @return string
*/
public function getPrefixConfigPath()
{
return $this->prefixConfigPath;
}
/**
* @return string
*/
public function getSuffixConfigPath()
{
return $this->suffixConfigPath;
}
/**
* @return string
*/
public function getListKeyConfigPath()
{
return $this->listKeyConfigPath;
}
/**
* @return string
*/
public function getListAction()
{
return $this->listAction;
}
/**
* @return FactoryInterface
*/
public function getFactory()
{
return $this->factory;
}
/**
* @return mixed
*/
public function getController()
{
return $this->controller;
}
/**
* @return string
*/
public function getViewAction()
{
return $this->viewAction;
}
/**
* @return string
*/
public function getParam()
{
return $this->param;
}
}
================================================
FILE: Model/Routing/RoutableInterface.php
================================================
<?php
namespace Sample\News\Model\Routing;
interface RoutableInterface
{
/**
* @param $urlKey
* @param $storeId
* @return int|null
*/
public function checkUrlKey($urlKey, $storeId);
}
================================================
FILE: Model/Source/AbstractSource.php
================================================
<?php
/**
* Sample_News extension
*
* NOTICE OF LICENSE
*
* This source file is subject to the MIT License
* that is bundled with this package in the file LICENSE
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/mit-license.php
*
* @category Sample
* @package Sample_News
* @copyright 2016 Marius Strajeru
* @license http://opensource.org/licenses/mit-license.php MIT License
* @author Marius Strajeru
*/
namespace Sample\News\Model\Source;
use Magento\Framework\Option\ArrayInterface;
abstract class AbstractSource implements ArrayInterface
{
/**
* @var array
*/
protected $options;
/**
* @param array $options
*/
public function __construct(
array $options = []
) {
$this->options = $options;
}
/**
* @return array
*/
abstract public function toOptionArray();
/**
* @param $value
* @return string
*/
public function getOptionText($value)
{
$options = $this->getOptions();
if (!is_array($value)) {
$value = explode(',', $value);
}
$texts = [];
foreach ($value as $v) {
if (isset($options[$v])) {
$texts[] = $options[$v];
}
}
return implode(', ', $texts);
}
/**
* get options as key value pair
*
* @return array
*/
public function getOptions()
{
$options = [];
foreach ($this->toOptionArray() as $values) {
$options[$values['value']] = __($values['label']);
}
return $options;
}
}
================================================
FILE: Model/Source/Country.php
================================================
<?php
/**
* Sample_News extension
*
* NOTICE OF LICENSE
*
* This source file is subject to the MIT License
* that is bundled with this package in the file LICENSE
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/mit-license.php
*
* @category Sample
* @package Sample_News
* @copyright 2016 Marius Strajeru
* @license http://opensource.org/licenses/mit-license.php MIT License
* @author Marius Strajeru
*/
namespace Sample\News\Model\Source;
use Magento\Directory\Model\ResourceModel\Country\CollectionFactory as CountryCollectionFactory;
use Magento\Framework\Option\ArrayInterface;
class Country extends AbstractSource implements ArrayInterface
{
/**
* @var \Sample\News\Model\Author
*/
protected $countryCollectionFactory;
/**
* @param CountryCollectionFactory $countryCollectionFactory
* @param array $options
*/
public function __construct(
CountryCollectionFactory $countryCollectionFactory,
array $options = []
)
{
$this->countryCollectionFactory = $countryCollectionFactory;
parent::__construct($options);
}
/**
* get options as key value pair
*
* @return array
*/
public function toOptionArray()
{
if (count($this->options) == 0) {
$this->options = $this->countryCollectionFactory->create()->toOptionArray(' ');
}
return $this->options;
}
}
================================================
FILE: Model/Source/Options.php
================================================
<?php
/**
* Sample_News extension
*
* NOTICE OF LICENSE
*
* This source file is subject to the MIT License
* that is bundled with this package in the file LICENSE
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/mit-license.php
*
* @category Sample
* @package Sample_News
* @copyright 2016 Marius Strajeru
* @license http://opensource.org/licenses/mit-license.php MIT License
* @author Marius Strajeru
*/
namespace Sample\News\Model\Source;
use Magento\Framework\Option\ArrayInterface;
class Options extends AbstractSource implements ArrayInterface
{
/**
* get options
*
* @return array
*/
public function toOptionArray()
{
$options = [];
foreach ($this->options as $values) {
$options[] = [
'value' => $values['value'],
'label' => __($values['label'])
];
}
return $options;
}
}
================================================
FILE: Model/Uploader.php
================================================
<?php
/**
* Sample_News extension
*
* NOTICE OF LICENSE
*
* This source file is subject to the MIT License
* that is bundled with this package in the file LICENSE
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/mit-license.php
*
* @category Sample
* @package Sample_News
* @copyright 2016 Marius Strajeru
* @license http://opensource.org/licenses/mit-license.php MIT License
* @author Marius Strajeru
*/
namespace Sample\News\Model;
use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Filesystem;
use Magento\Framework\UrlInterface;
use Magento\MediaStorage\Helper\File\Storage\Database;
use Magento\MediaStorage\Model\File\UploaderFactory;
use Magento\Store\Model\StoreManagerInterface;
use Psr\Log\LoggerInterface;
class Uploader
{
/**
* @var string
*/
const IMAGE_TMP_PATH = 'sample_news/tmp/author/image';
/**
* @var string
*/
const IMAGE_PATH = 'sample_news/author/image';
/**
* @var string
*/
const FILE_TMP_PATH = 'sample_news/tmp/author/file';
/**
* @var string
*/
const FILE_PATH = 'sample_news/author/file';
/**
* Core file storage database
*
* @var \Magento\MediaStorage\Helper\File\Storage\Database
*/
protected $coreFileStorageDatabase;
/**
* Media directory object (writable).
*
* @var \Magento\Framework\Filesystem\Directory\WriteInterface
*/
protected $mediaDirectory;
/**
* Uploader factory
*
* @var \Magento\MediaStorage\Model\File\UploaderFactory
*/
private $uploaderFactory;
/**
* Store manager
*
* @var \Magento\Store\Model\StoreManagerInterface
*/
protected $storeManager;
/**
* @var \Psr\Log\LoggerInterface
*/
protected $logger;
/**
* Base tmp path
*
* @var string
*/
protected $baseTmpPath;
/**
* Base path
*
* @var string
*/
protected $basePath;
/**
* Allowed extensions
*
* @var string
*/
protected $allowedExtensions;
/**
* @param Database $coreFileStorageDatabase
* @param Filesystem $filesystem
* @param UploaderFactory $uploaderFactory
* @param StoreManagerInterface $storeManager
* @param LoggerInterface $logger
* @param array $allowedExtensions
* @param $baseTmpPath
* @param $basePath
*/
public function __construct(
Database $coreFileStorageDatabase,
Filesystem $filesystem,
UploaderFactory $uploaderFactory,
StoreManagerInterface $storeManager,
LoggerInterface $logger,
$allowedExtensions = [],
$baseTmpPath,
$basePath
) {
$this->coreFileStorageDatabase = $coreFileStorageDatabase;
$this->mediaDirectory = $filesystem->getDirectoryWrite(DirectoryList::MEDIA);
gitextract_3yank7zg/
├── Api/
│ ├── AuthorRepositoryInterface.php
│ └── Data/
│ ├── AuthorInterface.php
│ └── AuthorSearchResultsInterface.php
├── Block/
│ ├── Adminhtml/
│ │ └── Author/
│ │ └── Edit/
│ │ └── Buttons/
│ │ ├── Back.php
│ │ ├── Delete.php
│ │ ├── Generic.php
│ │ ├── Reset.php
│ │ ├── Save.php
│ │ └── SaveAndContinue.php
│ ├── Author/
│ │ ├── ListAuthor/
│ │ │ ├── Rss/
│ │ │ │ └── Link.php
│ │ │ └── Rss.php
│ │ ├── ListAuthor.php
│ │ └── ViewAuthor.php
│ ├── Image.php
│ └── ImageBuilder.php
├── Controller/
│ ├── Adminhtml/
│ │ ├── Author/
│ │ │ ├── Delete.php
│ │ │ ├── Edit.php
│ │ │ ├── File/
│ │ │ │ └── Upload.php
│ │ │ ├── Image/
│ │ │ │ └── Upload.php
│ │ │ ├── Index.php
│ │ │ ├── InlineEdit.php
│ │ │ ├── MassAction.php
│ │ │ ├── MassDelete.php
│ │ │ ├── MassDisable.php
│ │ │ ├── MassEnable.php
│ │ │ ├── NewAction.php
│ │ │ ├── Save.php
│ │ │ └── Upload.php
│ │ └── Author.php
│ ├── Author/
│ │ ├── Index.php
│ │ ├── Rss.php
│ │ └── View.php
│ ├── RegistryConstants.php
│ └── Router.php
├── Helper/
│ └── Image.php
├── LICENSE
├── Model/
│ ├── Author/
│ │ ├── DataProvider.php
│ │ ├── Rss.php
│ │ └── Url.php
│ ├── Author.php
│ ├── AuthorFactory.php
│ ├── AuthorRepository.php
│ ├── FactoryInterface.php
│ ├── Image.php
│ ├── Output.php
│ ├── ResourceModel/
│ │ ├── Author/
│ │ │ ├── Collection.php
│ │ │ └── Grid/
│ │ │ ├── Collection.php
│ │ │ └── ServiceCollection.php
│ │ └── Author.php
│ ├── Routing/
│ │ ├── Entity.php
│ │ └── RoutableInterface.php
│ ├── Source/
│ │ ├── AbstractSource.php
│ │ ├── Country.php
│ │ └── Options.php
│ ├── Uploader.php
│ └── UploaderPool.php
├── Plugin/
│ └── Block/
│ └── Topmenu.php
├── README.md
├── Setup/
│ ├── InstallSchema.php
│ └── Uninstall.php
├── Test/
│ └── Unit/
│ ├── Model/
│ │ ├── Author/
│ │ │ ├── DataProviderTest.php
│ │ │ ├── RssTest.php
│ │ │ └── UrlTest.php
│ │ ├── AuthorTest.php
│ │ ├── Source/
│ │ │ └── CountryTest.php
│ │ ├── UploaderPoolTest.php
│ │ └── UploaderTest.php
│ └── Ui/
│ ├── Component/
│ │ └── Listing/
│ │ └── Column/
│ │ ├── AuthorActionsTest.php
│ │ ├── AvatarTest.php
│ │ └── Store/
│ │ └── OptionsTest.php
│ └── DataProvider/
│ └── Author/
│ └── Form/
│ └── Modifier/
│ └── AuthorDataTest.php
├── Ui/
│ ├── Component/
│ │ └── Listing/
│ │ └── Column/
│ │ ├── AuthorActions.php
│ │ ├── Avatar.php
│ │ └── Store/
│ │ └── Options.php
│ └── DataProvider/
│ └── Author/
│ └── Form/
│ └── Modifier/
│ └── AuthorData.php
├── composer.json
├── etc/
│ ├── acl.xml
│ ├── adminhtml/
│ │ ├── di.xml
│ │ ├── menu.xml
│ │ ├── routes.xml
│ │ └── system.xml
│ ├── config.xml
│ ├── di.xml
│ ├── frontend/
│ │ ├── di.xml
│ │ └── routes.xml
│ └── module.xml
├── i18l/
│ └── en_US.csv
├── registration.php
└── view/
├── adminhtml/
│ ├── layout/
│ │ ├── sample_news_author_edit.xml
│ │ └── sample_news_author_index.xml
│ ├── ui_component/
│ │ ├── sample_news_author_form.xml
│ │ └── sample_news_author_listing.xml
│ └── web/
│ └── template/
│ ├── file-preview.html
│ └── image-preview.html
└── frontend/
├── layout/
│ ├── sample_news_author_index.xml
│ └── sample_news_author_view.xml
└── templates/
├── author/
│ ├── list.phtml
│ └── view.phtml
├── image.phtml
├── image_with_borders.phtml
└── rss/
└── link.phtml
SYMBOL INDEX (483 symbols across 73 files)
FILE: Api/AuthorRepositoryInterface.php
type AuthorRepositoryInterface (line 26) | interface AuthorRepositoryInterface
method save (line 35) | public function save(AuthorInterface $author);
method getById (line 44) | public function getById($authorId);
method getList (line 53) | public function getList(SearchCriteriaInterface $searchCriteria);
method delete (line 62) | public function delete(AuthorInterface $author);
method deleteById (line 72) | public function deleteById($authorId);
FILE: Api/Data/AuthorInterface.php
type AuthorInterface (line 23) | interface AuthorInterface
method getId (line 53) | public function getId();
method getName (line 60) | public function getName();
method getUrlKey (line 67) | public function getUrlKey();
method getIsActive (line 74) | public function getIsActive();
method getInRss (line 81) | public function getInRss();
method getBiography (line 88) | public function getBiography();
method getProcessedBiography (line 93) | public function getProcessedBiography();
method getDob (line 100) | public function getDob();
method getType (line 107) | public function getType();
method getAwards (line 114) | public function getAwards();
method getAvatar (line 121) | public function getAvatar();
method getResume (line 128) | public function getResume();
method getCountry (line 135) | public function getCountry();
method setId (line 143) | public function setId($id);
method setName (line 151) | public function setName($name);
method setUrlKey (line 159) | public function setUrlKey($urlKey);
method setIsActive (line 167) | public function setIsActive($isActive);
method setInRss (line 175) | public function setInRss($inRss);
method setBiography (line 183) | public function setBiography($biography);
method setDob (line 191) | public function setDob($dob);
method setType (line 199) | public function setType($type);
method setAwards (line 207) | public function setAwards($awards);
method setAvatar (line 215) | public function setAvatar($avatar);
method setResume (line 223) | public function setResume($resume);
method setCountry (line 231) | public function setCountry($country);
method getCreatedAt (line 238) | public function getCreatedAt();
method setCreatedAt (line 246) | public function setCreatedAt($createdAt);
method getUpdatedAt (line 253) | public function getUpdatedAt();
method setUpdatedAt (line 261) | public function setUpdatedAt($updatedAt);
method setStoreId (line 267) | public function setStoreId($storeId);
method getStoreId (line 272) | public function getStoreId();
method getMetaTitle (line 277) | public function getMetaTitle();
method setMetaTitle (line 283) | public function setMetaTitle($metaTitle);
method getMetaDescription (line 288) | public function getMetaDescription();
method setMetaDescription (line 294) | public function setMetaDescription($metaDescription);
method getMetaKeywords (line 299) | public function getMetaKeywords();
method setMetaKeywords (line 305) | public function setMetaKeywords($metaKeywords);
FILE: Api/Data/AuthorSearchResultsInterface.php
type AuthorSearchResultsInterface (line 25) | interface AuthorSearchResultsInterface extends SearchResultsInterface
method getItems (line 32) | public function getItems();
method setItems (line 40) | public function setItems(array $items);
FILE: Block/Adminhtml/Author/Edit/Buttons/Back.php
class Back (line 22) | class Back extends Generic implements ButtonProviderInterface
method getButtonData (line 29) | public function getButtonData()
method getBackUrl (line 44) | public function getBackUrl()
FILE: Block/Adminhtml/Author/Edit/Buttons/Delete.php
class Delete (line 22) | class Delete extends Generic implements ButtonProviderInterface
method getButtonData (line 29) | public function getButtonData()
method getDeleteUrl (line 48) | public function getDeleteUrl()
FILE: Block/Adminhtml/Author/Edit/Buttons/Generic.php
class Generic (line 24) | class Generic
method __construct (line 40) | public function __construct(
method getAuthorId (line 53) | public function getAuthorId()
method getUrl (line 71) | public function getUrl($route = '', $params = [])
FILE: Block/Adminhtml/Author/Edit/Buttons/Reset.php
class Reset (line 22) | class Reset implements ButtonProviderInterface
method getButtonData (line 29) | public function getButtonData()
FILE: Block/Adminhtml/Author/Edit/Buttons/Save.php
class Save (line 22) | class Save extends Generic implements ButtonProviderInterface
method getButtonData (line 29) | public function getButtonData()
FILE: Block/Adminhtml/Author/Edit/Buttons/SaveAndContinue.php
class SaveAndContinue (line 22) | class SaveAndContinue extends Generic implements ButtonProviderInterface
method getButtonData (line 30) | public function getButtonData()
FILE: Block/Author/ListAuthor.php
class ListAuthor (line 27) | class ListAuthor extends Template
method __construct (line 49) | public function __construct(
method getAuthors (line 63) | public function getAuthors()
method _prepareLayout (line 78) | protected function _prepareLayout()
method getPagerHtml (line 92) | public function getPagerHtml()
FILE: Block/Author/ListAuthor/Rss.php
class Rss (line 30) | class Rss extends AbstractBlock implements DataProviderInterface
method __construct (line 65) | public function __construct(
method getStoreId (line 83) | protected function getStoreId()
method getRssData (line 95) | public function getRssData()
method isAllowed (line 126) | public function isAllowed()
method getFeeds (line 136) | public function getFeeds()
method isAuthRequired (line 150) | public function isAuthRequired()
method getCacheLifetime (line 158) | public function getCacheLifetime()
FILE: Block/Author/ListAuthor/Rss/Link.php
class Link (line 24) | class Link extends Template
method __construct (line 36) | public function __construct(
method isRssEnabled (line 48) | public function isRssEnabled()
method getLabel (line 56) | public function getLabel()
method getLink (line 63) | public function getLink()
FILE: Block/Author/ViewAuthor.php
class ViewAuthor (line 25) | class ViewAuthor extends Template
method __construct (line 43) | public function __construct(
method getCurrentAuthor (line 59) | public function getCurrentAuthor()
method getImage (line 70) | public function getImage($entity, $imageId, $attributes = [])
FILE: Block/Image.php
class Image (line 32) | class Image extends Template
method __construct (line 48) | public function __construct(
FILE: Block/ImageBuilder.php
class ImageBuilder (line 24) | class ImageBuilder
method __construct (line 61) | public function __construct(
method setEntity (line 75) | public function setEntity(AbstractModel $entity)
method setImageId (line 87) | public function setImageId($imageId)
method setAttributes (line 99) | public function setAttributes(array $attributes)
method getCustomAttributes (line 112) | protected function getCustomAttributes()
method getRatio (line 127) | protected function getRatio(ImageHelper $helper)
method create (line 142) | public function create()
FILE: Controller/Adminhtml/Author.php
class Author (line 27) | abstract class Author extends Action
method __construct (line 66) | public function __construct(
method filterData (line 87) | public function filterData($data)
FILE: Controller/Adminhtml/Author/Delete.php
class Delete (line 24) | class Delete extends Author
method execute (line 29) | public function execute()
FILE: Controller/Adminhtml/Author/Edit.php
class Edit (line 23) | class Edit extends Author
method _initAuthor (line 30) | protected function _initAuthor()
method execute (line 43) | public function execute()
FILE: Controller/Adminhtml/Author/File/Upload.php
class Upload (line 22) | class Upload extends GenericUpload
FILE: Controller/Adminhtml/Author/Image/Upload.php
class Upload (line 22) | class Upload extends GenericUpload
FILE: Controller/Adminhtml/Author/Index.php
class Index (line 22) | class Index extends AuthorController
method execute (line 29) | public function execute()
FILE: Controller/Adminhtml/Author/InlineEdit.php
class InlineEdit (line 36) | class InlineEdit extends AuthorController
method __construct (line 66) | public function __construct(
method execute (line 88) | public function execute()
method getErrorWithAuthorId (line 138) | protected function getErrorWithAuthorId(Author $author, $errorText)
FILE: Controller/Adminhtml/Author/MassAction.php
class MassAction (line 32) | abstract class MassAction extends Author
method __construct (line 62) | public function __construct(
method massAction (line 84) | protected abstract function massAction(AuthorModel $author);
method execute (line 91) | public function execute()
FILE: Controller/Adminhtml/Author/MassDelete.php
class MassDelete (line 22) | class MassDelete extends MassAction
method massAction (line 28) | protected function massAction(Author $author)
FILE: Controller/Adminhtml/Author/MassDisable.php
class MassDisable (line 22) | class MassDisable extends MassAction
method massAction (line 33) | protected function massAction(Author $author)
FILE: Controller/Adminhtml/Author/MassEnable.php
class MassEnable (line 20) | class MassEnable extends MassDisable
FILE: Controller/Adminhtml/Author/NewAction.php
class NewAction (line 24) | class NewAction extends Action
method __construct (line 41) | public function __construct(
method execute (line 55) | public function execute()
FILE: Controller/Adminhtml/Author/Save.php
class Save (line 35) | class Save extends Author
method __construct (line 63) | public function __construct(
method execute (line 87) | public function execute()
method getUploader (line 144) | protected function getUploader($type)
method storeAuthorDataToSession (line 152) | protected function storeAuthorDataToSession($authorData)
FILE: Controller/Adminhtml/Author/Upload.php
class Upload (line 26) | class Upload extends Action
method __construct (line 43) | public function __construct(
method execute (line 56) | public function execute()
method getFieldName (line 77) | protected function getFieldName()
FILE: Controller/Author/Index.php
class Index (line 26) | class Index extends Action
method __construct (line 55) | public function __construct(
method execute (line 68) | public function execute()
FILE: Controller/Author/Rss.php
class Rss (line 23) | class Rss extends \Magento\Rss\Controller\Feed\Index
method execute (line 28) | public function execute()
FILE: Controller/Author/View.php
class View (line 30) | class View extends Action
method __construct (line 75) | public function __construct(
method execute (line 96) | public function execute()
FILE: Controller/RegistryConstants.php
class RegistryConstants (line 20) | class RegistryConstants
FILE: Controller/Router.php
class Router (line 36) | class Router implements RouterInterface
method __construct (line 103) | public function __construct(
method match (line 129) | public function match(RequestInterface $request)
method matchRoute (line 167) | protected function matchRoute(RequestInterface $request, Entity $entit...
FILE: Helper/Image.php
class Image (line 31) | class Image extends AbstractHelper
method __construct (line 156) | public function __construct(
method _reset (line 175) | protected function _reset()
method init (line 198) | public function init($entity, $imageId, $attributes = [])
method setImageProperties (line 219) | protected function setImageProperties()
method setWatermarkProperties (line 263) | protected function setWatermarkProperties()
method resize (line 304) | public function resize($width, $height = null)
method setQuality (line 317) | public function setQuality($quality)
method keepAspectRatio (line 332) | public function keepAspectRatio($flag)
method keepFrame (line 348) | public function keepFrame($flag)
method keepTransparency (line 364) | public function keepTransparency($flag)
method constrainOnly (line 378) | public function constrainOnly($flag)
method backgroundColor (line 394) | public function backgroundColor($colorRGB)
method rotate (line 410) | public function rotate($angle)
method watermark (line 428) | public function watermark($fileName, $position, $size = null, $imageOp...
method placeholder (line 443) | public function placeholder($fileName)
method getPlaceholder (line 454) | public function getPlaceholder($placeholder = null)
method applyScheduledActions (line 471) | protected function applyScheduledActions()
method initBaseFile (line 495) | protected function initBaseFile()
method isScheduledActionsAllowed (line 514) | protected function isScheduledActionsAllowed()
method getUrl (line 531) | public function getUrl()
method save (line 544) | public function save()
method getResizedImageInfo (line 555) | public function getResizedImageInfo()
method getDefaultPlaceholderUrl (line 565) | public function getDefaultPlaceholderUrl($placeholder = null)
method getModel (line 581) | protected function getModel()
method setAngle (line 595) | protected function setAngle($angle)
method getAngle (line 606) | protected function getAngle()
method setWatermark (line 617) | protected function setWatermark($watermark)
method getWatermark (line 629) | protected function getWatermark()
method setWatermarkPosition (line 640) | protected function setWatermarkPosition($position)
method getWatermarkPosition (line 652) | protected function getWatermarkPosition()
method setWatermarkSize (line 664) | public function setWatermarkSize($size)
method getWatermarkSize (line 676) | protected function getWatermarkSize()
method setWatermarkImageOpacity (line 687) | public function setWatermarkImageOpacity($imageOpacity)
method getWatermarkImageOpacity (line 699) | protected function getWatermarkImageOpacity()
method setEntity (line 714) | protected function setEntity($entity)
method getEntity (line 725) | protected function getEntity()
method setImageFile (line 736) | public function setImageFile($file)
method getImageFile (line 747) | protected function getImageFile()
method parseSize (line 758) | protected function parseSize($string)
method getOriginalWidth (line 775) | public function getOriginalWidth()
method getOriginalHeight (line 785) | public function getOriginalHeight()
method getOriginalSizeArray (line 796) | public function getOriginalSizeArray()
method getConfigView (line 806) | protected function getConfigView()
method getType (line 819) | public function getType()
method getWidth (line 829) | public function getWidth()
method getHeight (line 839) | public function getHeight()
method getFrame (line 849) | public function getFrame()
method getAttribute (line 864) | protected function getAttribute($name)
method getLabel (line 874) | public function getLabel()
FILE: Model/Author.php
class Author (line 39) | class Author extends AbstractModel implements AuthorInterface, RoutableI...
method __construct (line 108) | public function __construct(
method _construct (line 134) | protected function _construct()
method getInRss (line 144) | public function getInRss()
method getType (line 154) | public function getType()
method getAwards (line 164) | public function getAwards()
method getCountry (line 174) | public function getCountry()
method setName (line 185) | public function setName($name)
method setInRss (line 196) | public function setInRss($inRss)
method setBiography (line 207) | public function setBiography($biography)
method setDob (line 218) | public function setDob($dob)
method setType (line 229) | public function setType($type)
method setAwards (line 240) | public function setAwards($awards)
method setCountry (line 251) | public function setCountry($country)
method getName (line 261) | public function getName()
method getUrlKey (line 271) | public function getUrlKey()
method getIsActive (line 281) | public function getIsActive()
method getBiography (line 291) | public function getBiography()
method getProcessedBiography (line 299) | public function getProcessedBiography()
method getDob (line 309) | public function getDob()
method getAvatar (line 319) | public function getAvatar()
method getAvatarUrl (line 328) | public function getAvatarUrl()
method getResumeUrl (line 349) | public function getResumeUrl()
method getResume (line 371) | public function getResume()
method getCreatedAt (line 381) | public function getCreatedAt()
method getUpdatedAt (line 391) | public function getUpdatedAt()
method setUrlKey (line 402) | public function setUrlKey($urlKey)
method setIsActive (line 413) | public function setIsActive($isActive)
method setAvatar (line 424) | public function setAvatar($avatar)
method setResume (line 435) | public function setResume($resume)
method setCreatedAt (line 446) | public function setCreatedAt($createdAt)
method setUpdatedAt (line 457) | public function setUpdatedAt($updatedAt)
method checkUrlKey (line 471) | public function checkUrlKey($urlKey, $storeId)
method getIdentities (line 481) | public function getIdentities()
method setStoreId (line 490) | public function setStoreId($storeId)
method getStoreId (line 499) | public function getStoreId()
method getMetaTitle (line 507) | public function getMetaTitle()
method setMetaTitle (line 516) | public function setMetaTitle($metaTitle)
method getMetaDescription (line 525) | public function getMetaDescription()
method setMetaDescription (line 534) | public function setMetaDescription($metaDescription)
method getMetaKeywords (line 543) | public function getMetaKeywords()
method setMetaKeywords (line 552) | public function setMetaKeywords($metaKeywords)
method formatUrlKey (line 565) | public function formatUrlKey($string)
method getAuthorUrl (line 573) | public function getAuthorUrl()
method isActive (line 581) | public function isActive()
method getAttributeText (line 590) | public function getAttributeText($attribute)
FILE: Model/Author/DataProvider.php
class DataProvider (line 25) | class DataProvider extends AbstractDataProvider
method __construct (line 46) | public function __construct(
method prepareMeta (line 67) | public function prepareMeta(array $meta)
method getData (line 83) | public function getData()
FILE: Model/Author/Rss.php
class Rss (line 25) | class Rss
method __construct (line 57) | public function __construct(
method isRssEnabled (line 70) | public function isRssEnabled()
method getRssLink (line 80) | public function getRssLink()
FILE: Model/Author/Url.php
class Url (line 25) | class Url
method __construct (line 55) | public function __construct(
method getListUrl (line 66) | public function getListUrl()
method getAuthorUrl (line 79) | public function getAuthorUrl(Author $author)
FILE: Model/AuthorFactory.php
class AuthorFactory (line 23) | class AuthorFactory implements FactoryInterface
method __construct (line 45) | public function __construct(ObjectManagerInterface $objectManager, $in...
method create (line 57) | public function create(array $data = array())
FILE: Model/AuthorRepository.php
class AuthorRepository (line 42) | class AuthorRepository implements AuthorRepositoryInterface
method __construct (line 73) | public function __construct(
method save (line 95) | public function save(AuthorInterface $author)
method getById (line 120) | public function getById($authorId)
method getList (line 141) | public function getList(SearchCriteriaInterface $searchCriteria)
method delete (line 194) | public function delete(AuthorInterface $author)
method deleteById (line 220) | public function deleteById($authorId)
method addFilterGroupToCollection (line 234) | protected function addFilterGroupToCollection(FilterGroup $filterGroup...
FILE: Model/FactoryInterface.php
type FactoryInterface (line 22) | interface FactoryInterface
method create (line 27) | public function create();
FILE: Model/Image.php
class Image (line 46) | class Image extends AbstractModel
method __construct (line 212) | public function __construct(
method setWidth (line 248) | public function setWidth($width)
method getWidth (line 257) | public function getWidth()
method setHeight (line 266) | public function setHeight($height)
method getHeight (line 275) | public function getHeight()
method setQuality (line 286) | public function setQuality($quality)
method getQuality (line 297) | public function getQuality()
method setKeepAspectRatio (line 306) | public function setKeepAspectRatio($keep)
method setKeepFrame (line 316) | public function setKeepFrame($keep)
method setKeepTransparency (line 326) | public function setKeepTransparency($keep)
method setConstrainOnly (line 336) | public function setConstrainOnly($flag)
method setBackgroundColor (line 346) | public function setBackgroundColor(array $rgbArray)
method setSize (line 356) | public function setSize($size)
method checkMemory (line 377) | protected function checkMemory($file = null)
method getMemoryLimit (line 388) | protected function getMemoryLimit()
method getMemoryUsage (line 411) | protected function getMemoryUsage()
method getNeedMemoryForFile (line 424) | protected function getNeedMemoryForFile($file = null)
method rgbToString (line 459) | protected function rgbToString($rgbArray)
method setBaseFile (line 481) | public function setBaseFile($file)
method getBaseFile (line 552) | public function getBaseFile()
method getNewFile (line 560) | public function getNewFile()
method isBaseFilePlaceholder (line 570) | public function isBaseFilePlaceholder()
method setImageProcessor (line 579) | public function setImageProcessor($processor)
method getImageProcessor (line 588) | public function getImageProcessor()
method resize (line 607) | public function resize()
method rotate (line 620) | public function rotate($angle)
method setAngle (line 635) | public function setAngle($angle)
method setWatermark (line 654) | public function setWatermark(
method saveFile (line 704) | public function saveFile()
method getUrl (line 718) | public function getUrl()
method setDestinationSubdir (line 737) | public function setDestinationSubdir($dir)
method getDestinationSubdir (line 746) | public function getDestinationSubdir()
method isCached (line 754) | public function isCached()
method setWatermarkFile (line 768) | public function setWatermarkFile($file)
method getWatermarkFile (line 779) | public function getWatermarkFile()
method getWatermarkFilePath (line 790) | protected function getWatermarkFilePath()
method setWatermarkPosition (line 824) | public function setWatermarkPosition($position)
method getWatermarkPosition (line 835) | public function getWatermarkPosition()
method setWatermarkImageOpacity (line 846) | public function setWatermarkImageOpacity($imageOpacity)
method getWatermarkImageOpacity (line 857) | public function getWatermarkImageOpacity()
method setWatermarkSize (line 868) | public function setWatermarkSize($size)
method setWatermarkWidth (line 882) | public function setWatermarkWidth($width)
method getWatermarkWidth (line 893) | public function getWatermarkWidth()
method setWatermarkHeight (line 904) | public function setWatermarkHeight($height)
method getWatermarkHeight (line 915) | public function getWatermarkHeight()
method clearCache (line 923) | public function clearCache()
method fileExists (line 938) | protected function fileExists($filename)
method getResizedImageInfo (line 954) | public function getResizedImageInfo()
FILE: Model/Output.php
class Output (line 20) | class Output
method __construct (line 30) | public function __construct(
method filterOutput (line 40) | public function filterOutput($string)
FILE: Model/ResourceModel/Author.php
class Author (line 30) | class Author extends AbstractDb
method __construct (line 68) | public function __construct(
method _construct (line 88) | protected function _construct()
method _beforeDelete (line 99) | protected function _beforeDelete(AbstractModel $object)
method _beforeSave (line 112) | protected function _beforeSave(AbstractModel $object)
method generateNewUrlKey (line 149) | protected function generateNewUrlKey($urlKey)
method _afterSave (line 169) | protected function _afterSave(AbstractModel $object)
method _afterLoad (line 181) | protected function _afterLoad(AbstractModel $object)
method _getLoadSelect (line 203) | protected function _getLoadSelect($field, $value, $object)
method getLoadByUrlKeySelect (line 237) | protected function getLoadByUrlKeySelect($urlKey, $store, $isActive = ...
method checkUrlKey (line 270) | public function checkUrlKey($urlKey, $storeId)
method lookupStoreIds (line 287) | public function lookupStoreIds($authorId)
method setStore (line 306) | public function setStore(Store $store)
method getStore (line 317) | public function getStore()
method getIsUniqueAuthorToStores (line 328) | public function getIsUniqueAuthorToStores(AbstractModel $object)
method saveStoreRelation (line 350) | protected function saveStoreRelation(AuthorModel $author)
method saveAttribute (line 387) | public function saveAttribute(AbstractModel $object, $attribute)
method beforeSaveAttribute (line 422) | protected function beforeSaveAttribute(AbstractModel $object, $attribute)
method afterSaveAttribute (line 444) | protected function afterSaveAttribute(AbstractModel $object, $attribute)
FILE: Model/ResourceModel/Author/Collection.php
class Collection (line 31) | class Collection extends AbstractCollection
method __construct (line 74) | public function __construct(
method _construct (line 92) | protected function _construct()
method _afterLoad (line 104) | protected function _afterLoad()
method addFieldToFilter (line 117) | public function addFieldToFilter($field, $condition = null)
method addStoreFilter (line 133) | public function addStoreFilter($store, $withAdmin = true)
method _renderFiltersBefore (line 159) | protected function _renderFiltersBefore()
method getSelectCountSql (line 180) | public function getSelectCountSql()
method performAfterLoad (line 191) | protected function performAfterLoad($tableName, $linkField)
FILE: Model/ResourceModel/Author/Grid/Collection.php
class Collection (line 34) | class Collection extends AuthorCollection implements SearchResultInterface
method __construct (line 56) | public function __construct(
method getAggregations (line 88) | public function getAggregations()
method setAggregations (line 97) | public function setAggregations($aggregations)
method getSearchCriteria (line 107) | public function getSearchCriteria()
method setSearchCriteria (line 119) | public function setSearchCriteria(SearchCriteriaInterface $searchCrite...
method getTotalCount (line 129) | public function getTotalCount()
method setTotalCount (line 141) | public function setTotalCount($totalCount)
method setItems (line 153) | public function setItems(array $items = null)
FILE: Model/ResourceModel/Author/Grid/ServiceCollection.php
class ServiceCollection (line 34) | class ServiceCollection extends AbstractServiceCollection
method __construct (line 54) | public function __construct(
method loadData (line 75) | public function loadData($printQuery = false, $logQuery = false)
FILE: Model/Routing/Entity.php
class Entity (line 6) | class Entity
method __construct (line 51) | public function __construct(
method getPrefixConfigPath (line 74) | public function getPrefixConfigPath()
method getSuffixConfigPath (line 82) | public function getSuffixConfigPath()
method getListKeyConfigPath (line 90) | public function getListKeyConfigPath()
method getListAction (line 98) | public function getListAction()
method getFactory (line 106) | public function getFactory()
method getController (line 114) | public function getController()
method getViewAction (line 122) | public function getViewAction()
method getParam (line 130) | public function getParam()
FILE: Model/Routing/RoutableInterface.php
type RoutableInterface (line 4) | interface RoutableInterface
method checkUrlKey (line 11) | public function checkUrlKey($urlKey, $storeId);
FILE: Model/Source/AbstractSource.php
class AbstractSource (line 22) | abstract class AbstractSource implements ArrayInterface
method __construct (line 32) | public function __construct(
method toOptionArray (line 41) | abstract public function toOptionArray();
method getOptionText (line 47) | public function getOptionText($value)
method getOptions (line 66) | public function getOptions()
FILE: Model/Source/Country.php
class Country (line 23) | class Country extends AbstractSource implements ArrayInterface
method __construct (line 34) | public function __construct(
method toOptionArray (line 48) | public function toOptionArray()
FILE: Model/Source/Options.php
class Options (line 22) | class Options extends AbstractSource implements ArrayInterface
method toOptionArray (line 29) | public function toOptionArray()
FILE: Model/Uploader.php
class Uploader (line 29) | class Uploader
method __construct (line 112) | public function __construct(
method setBaseTmpPath (line 140) | public function setBaseTmpPath($baseTmpPath)
method setBasePath (line 152) | public function setBasePath($basePath)
method setAllowedExtensions (line 164) | public function setAllowedExtensions($allowedExtensions)
method getBaseTmpPath (line 174) | public function getBaseTmpPath()
method getBasePath (line 184) | public function getBasePath()
method getAllowedExtensions (line 194) | public function getAllowedExtensions()
method getFilePath (line 207) | public function getFilePath($path, $name)
method moveFileFromTmp (line 221) | public function moveFileFromTmp($name)
method getBaseUrl (line 247) | public function getBaseUrl()
method saveFileToTmpDir (line 264) | public function saveFileToTmpDir($fileId)
method uploadFileAndGetName (line 307) | public function uploadFileAndGetName($input, $data)
FILE: Model/UploaderPool.php
class UploaderPool (line 22) | class UploaderPool
method __construct (line 37) | public function __construct(
method getUploader (line 50) | public function getUploader($type)
FILE: Plugin/Block/Topmenu.php
class Topmenu (line 25) | class Topmenu
method __construct (line 40) | public function __construct(
method beforeGetHtml (line 56) | public function beforeGetHtml(
method getNodeAsArray (line 75) | protected function getNodeAsArray()
method getActiveHandles (line 89) | protected function getActiveHandles()
FILE: Setup/InstallSchema.php
class InstallSchema (line 27) | class InstallSchema implements InstallSchemaInterface
method install (line 35) | public function install(SchemaSetupInterface $setup, ModuleContextInte...
FILE: Setup/Uninstall.php
class Uninstall (line 31) | class Uninstall implements UninstallInterface
method __construct (line 46) | public function __construct(
method uninstall (line 61) | public function uninstall(SchemaSetupInterface $setup, ModuleContextIn...
method deleteConfig (line 83) | protected function deleteConfig(AbstractModel $config)
FILE: Test/Unit/Model/Author/DataProviderTest.php
class DataProviderTest (line 25) | class DataProviderTest extends \PHPUnit_Framework_TestCase
method setUp (line 36) | protected function setUp()
method getDummyMeta (line 69) | protected function getDummyMeta()
method getDummyData (line 77) | protected function getDummyData()
method testPrepareMeta (line 85) | public function testPrepareMeta()
method testGetData (line 93) | public function testGetData()
FILE: Test/Unit/Model/Author/RssTest.php
class RssTest (line 29) | class RssTest extends \PHPUnit_Framework_TestCase
method setUp (line 52) | protected function setUp()
method testIsRssEnabledGlobalFalseAuthorFalse (line 97) | public function testIsRssEnabledGlobalFalseAuthorFalse()
method testIsRssEnabledGlobalTrueAuthorFalse (line 126) | public function testIsRssEnabledGlobalTrueAuthorFalse()
method testIsRssEnabledGlobalFalseAuthorTrue (line 155) | public function testIsRssEnabledGlobalFalseAuthorTrue()
method testIsRssEnabledGlobalTrueAuthorTrue (line 184) | public function testIsRssEnabledGlobalTrueAuthorTrue()
method testGetRssLink (line 210) | public function testGetRssLink()
FILE: Test/Unit/Model/Author/UrlTest.php
class UrlTest (line 26) | class UrlTest extends \PHPUnit_Framework_TestCase
method setUp (line 56) | public function setUp()
method setUpAuthor (line 123) | protected function setUpAuthor($withUrlKey)
method testGetListUrlWithSef (line 140) | public function testGetListUrlWithSef()
method testGetListUrlWithoutSef (line 153) | public function testGetListUrlWithoutSef()
method testGetAuthorUrlWithoutSef (line 166) | public function testGetAuthorUrlWithoutSef()
method testGetAuthorUrlWithSefNoSuffixNoPrefix (line 178) | public function testGetAuthorUrlWithSefNoSuffixNoPrefix()
method testGetAuthorUrlWithSefNoSuffixWithPrefix (line 206) | public function testGetAuthorUrlWithSefNoSuffixWithPrefix()
method testGetAuthorUrlWithSefWithSuffixNoPrefix (line 235) | public function testGetAuthorUrlWithSefWithSuffixNoPrefix()
method testGetAuthorUrlWithSefWithSuffixWithPrefix (line 264) | public function testGetAuthorUrlWithSefWithSuffixWithPrefix()
FILE: Test/Unit/Model/AuthorTest.php
class AuthorTest (line 30) | class AuthorTest extends \PHPUnit_Framework_TestCase
method setUp (line 44) | protected function setUp()
method getAuthorData (line 102) | protected function getAuthorData()
method testGetters (line 130) | public function testGetters()
method testGetAvatarUrlWithNull (line 157) | public function testGetAvatarUrlWithNull()
method testGetAvatarUrlWithString (line 168) | public function testGetAvatarUrlWithString()
method testGetAvatarUrlWithException (line 179) | public function testGetAvatarUrlWithException()
method testGetResumeUrlWithNull (line 191) | public function testGetResumeUrlWithNull()
method testGetResumeUrlWithString (line 202) | public function testGetResumeUrlWithString()
method testGetResumeUrlWithException (line 213) | public function testGetResumeUrlWithException()
FILE: Test/Unit/Model/Source/CountryTest.php
class CountryTest (line 26) | class CountryTest extends \PHPUnit_Framework_TestCase
method setUp (line 49) | protected function setUp()
method testMemoizedOptionArray (line 67) | public function testMemoizedOptionArray()
FILE: Test/Unit/Model/UploaderPoolTest.php
class UploaderPoolTest (line 26) | class UploaderPoolTest extends \PHPUnit_Framework_TestCase
method setUp (line 37) | protected function setUp()
method testGetUploaderNotFound (line 66) | public function testGetUploaderNotFound()
method testGetUploaderInstantiationNeeded (line 77) | public function testGetUploaderInstantiationNeeded()
method testGetUploaderInstantiationNotNeeded (line 87) | public function testGetUploaderInstantiationNotNeeded()
method testGetUploaderWrongType (line 97) | public function testGetUploaderWrongType()
FILE: Test/Unit/Model/UploaderTest.php
class UploaderTest (line 31) | class UploaderTest extends \PHPUnit_Framework_TestCase
method setUp (line 55) | protected function setUp()
method testGetBaseTmpPath (line 117) | public function testGetBaseTmpPath()
method testGetBasePath (line 125) | public function testGetBasePath()
method testGetAllowedExtensions (line 133) | public function testGetAllowedExtensions()
method testGetFilePath (line 143) | public function testGetFilePath()
method testMoveFileFromTmp (line 154) | public function testMoveFileFromTmp()
method testSaveFileToTmpDir (line 162) | public function testSaveFileToTmpDir()
method testUploadFileAndGetName (line 176) | public function testUploadFileAndGetName()
FILE: Test/Unit/Ui/Component/Listing/Column/AuthorActionsTest.php
class AuthorActionsTest (line 26) | class AuthorActionsTest extends \PHPUnit_Framework_TestCase
method testPrepareDataSource (line 31) | public function testPrepareDataSource()
FILE: Test/Unit/Ui/Component/Listing/Column/AvatarTest.php
class AvatarTest (line 29) | class AvatarTest extends \PHPUnit_Framework_TestCase
method testPrepareDataSource (line 34) | public function testPrepareDataSource()
FILE: Test/Unit/Ui/Component/Listing/Column/Store/OptionsTest.php
class OptionsTest (line 27) | class OptionsTest extends \PHPUnit_Framework_TestCase
method setUp (line 62) | protected function setUp()
method testToOptionArray (line 84) | public function testToOptionArray()
FILE: Test/Unit/Ui/DataProvider/Author/Form/Modifier/AuthorDataTest.php
class AuthorDataTest (line 26) | class AuthorDataTest extends \PHPUnit_Framework_TestCase
method setUp (line 44) | protected function setUp()
method testModifyMeta (line 84) | public function testModifyMeta()
method testModifiyData (line 95) | public function testModifiyData()
method getSampleData (line 123) | protected function getSampleData()
FILE: Ui/Component/Listing/Column/AuthorActions.php
class AuthorActions (line 26) | class AuthorActions extends Column
method __construct (line 56) | public function __construct(
method prepareDataSource (line 75) | public function prepareDataSource(array $dataSource)
FILE: Ui/Component/Listing/Column/Avatar.php
class Avatar (line 14) | class Avatar extends Column
method __construct (line 36) | public function __construct(
method prepareDataSource (line 55) | public function prepareDataSource(array $dataSource)
method getAlt (line 82) | protected function getAlt($row)
FILE: Ui/Component/Listing/Column/Store/Options.php
class Options (line 22) | class Options extends StoreOptions
method toOptionArray (line 34) | public function toOptionArray()
FILE: Ui/DataProvider/Author/Form/Modifier/AuthorData.php
class AuthorData (line 24) | class AuthorData implements ModifierInterface
method __construct (line 34) | public function __construct(
method modifyMeta (line 44) | public function modifyMeta(array $meta)
method modifyData (line 54) | public function modifyData(array $data)
Condensed preview — 101 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (386K chars).
[
{
"path": "Api/AuthorRepositoryInterface.php",
"chars": 1943,
"preview": "<?php\n/**\n * Sample_News extension\n *\n * NOTICE OF LICENSE\n *\n * This source file is subject to the MIT License\n * that "
},
{
"path": "Api/Data/AuthorInterface.php",
"chars": 5565,
"preview": "<?php\n/**\n * Sample_News extension\n *\n * NOTICE OF LICENSE\n *\n * This source file is subject to the MIT License\n * that "
},
{
"path": "Api/Data/AuthorSearchResultsInterface.php",
"chars": 958,
"preview": "<?php\n/**\n * Sample_News extension\n *\n * NOTICE OF LICENSE\n *\n * This source file is subject to the MIT License\n * that "
},
{
"path": "Block/Adminhtml/Author/Edit/Buttons/Back.php",
"chars": 1171,
"preview": "<?php\n/**\n * Sample_News extension\n *\n * NOTICE OF LICENSE\n *\n * This source file is subject to the MIT License\n * that "
},
{
"path": "Block/Adminhtml/Author/Edit/Buttons/Delete.php",
"chars": 1387,
"preview": "<?php\n/**\n * Sample_News extension\n *\n * NOTICE OF LICENSE\n *\n * This source file is subject to the MIT License\n * that "
},
{
"path": "Block/Adminhtml/Author/Edit/Buttons/Generic.php",
"chars": 1817,
"preview": "<?php\n/**\n * Sample_News extension\n *\n * NOTICE OF LICENSE\n *\n * This source file is subject to the MIT License\n * that "
},
{
"path": "Block/Adminhtml/Author/Edit/Buttons/Reset.php",
"chars": 957,
"preview": "<?php\n/**\n * Sample_News extension\n *\n * NOTICE OF LICENSE\n *\n * This source file is subject to the MIT License\n * that "
},
{
"path": "Block/Adminhtml/Author/Edit/Buttons/Save.php",
"chars": 1092,
"preview": "<?php\n/**\n * Sample_News extension\n *\n * NOTICE OF LICENSE\n *\n * This source file is subject to the MIT License\n * that "
},
{
"path": "Block/Adminhtml/Author/Edit/Buttons/SaveAndContinue.php",
"chars": 1122,
"preview": "<?php\n/**\n * Sample_News extension\n *\n * NOTICE OF LICENSE\n *\n * This source file is subject to the MIT License\n * that "
},
{
"path": "Block/Author/ListAuthor/Rss/Link.php",
"chars": 1468,
"preview": "<?php\n/**\n * Sample_News extension\n *\n * NOTICE OF LICENSE\n *\n * This source file is subject to the MIT License\n * that "
},
{
"path": "Block/Author/ListAuthor/Rss.php",
"chars": 4491,
"preview": "<?php\n/**\n * Sample_News extension\n *\n * NOTICE OF LICENSE\n *\n * This source file is subject to the MIT License\n * that "
},
{
"path": "Block/Author/ListAuthor.php",
"chars": 2689,
"preview": "<?php\n/**\n * Sample_News extension\n *\n * NOTICE OF LICENSE\n *\n * This source file is subject to the MIT License\n * that "
},
{
"path": "Block/Author/ViewAuthor.php",
"chars": 1856,
"preview": "<?php\n/**\n * Sample_News extension\n *\n * NOTICE OF LICENSE\n *\n * This source file is subject to the MIT License\n * that "
},
{
"path": "Block/Image.php",
"chars": 1427,
"preview": "<?php\n/**\n * Sample_News extension\n *\n * NOTICE OF LICENSE\n *\n * This source file is subject to the MIT License\n * that "
},
{
"path": "Block/ImageBuilder.php",
"chars": 4317,
"preview": "<?php\n/**\n * Sample_News extension\n *\n * NOTICE OF LICENSE\n *\n * This source file is subject to the MIT License\n * that "
},
{
"path": "Controller/Adminhtml/Author/Delete.php",
"chars": 2105,
"preview": "<?php\n/**\n * Sample_News extension\n *\n * NOTICE OF LICENSE\n *\n * This source file is subject to the MIT License\n * that "
},
{
"path": "Controller/Adminhtml/Author/Edit.php",
"chars": 2061,
"preview": "<?php\n/**\n * Sample_News extension\n *\n * NOTICE OF LICENSE\n *\n * This source file is subject to the MIT License\n * that "
},
{
"path": "Controller/Adminhtml/Author/File/Upload.php",
"chars": 642,
"preview": "<?php\n/**\n * Sample_News extension\n *\n * NOTICE OF LICENSE\n *\n * This source file is subject to the MIT License\n * that "
},
{
"path": "Controller/Adminhtml/Author/Image/Upload.php",
"chars": 643,
"preview": "<?php\n/**\n * Sample_News extension\n *\n * NOTICE OF LICENSE\n *\n * This source file is subject to the MIT License\n * that "
},
{
"path": "Controller/Adminhtml/Author/Index.php",
"chars": 1189,
"preview": "<?php\n/**\n * Sample_News extension\n *\n * NOTICE OF LICENSE\n *\n * This source file is subject to the MIT License\n * that "
},
{
"path": "Controller/Adminhtml/Author/InlineEdit.php",
"chars": 4853,
"preview": "<?php\n/**\n * Sample_News extension\n *\n * NOTICE OF LICENSE\n *\n * This source file is subject to the MIT License\n * that "
},
{
"path": "Controller/Adminhtml/Author/MassAction.php",
"chars": 3374,
"preview": "<?php\n/**\n * Sample_News extension\n *\n * NOTICE OF LICENSE\n *\n * This source file is subject to the MIT License\n * that "
},
{
"path": "Controller/Adminhtml/Author/MassDelete.php",
"chars": 798,
"preview": "<?php\n/**\n * Sample_News extension\n *\n * NOTICE OF LICENSE\n *\n * This source file is subject to the MIT License\n * that "
},
{
"path": "Controller/Adminhtml/Author/MassDisable.php",
"chars": 911,
"preview": "<?php\n/**\n * Sample_News extension\n *\n * NOTICE OF LICENSE\n *\n * This source file is subject to the MIT License\n * that "
},
{
"path": "Controller/Adminhtml/Author/MassEnable.php",
"chars": 633,
"preview": "<?php\n/**\n * Sample_News extension\n *\n * NOTICE OF LICENSE\n *\n * This source file is subject to the MIT License\n * that "
},
{
"path": "Controller/Adminhtml/Author/NewAction.php",
"chars": 1482,
"preview": "<?php\n/**\n * Sample_News extension\n *\n * NOTICE OF LICENSE\n *\n * This source file is subject to the MIT License\n * that "
},
{
"path": "Controller/Adminhtml/Author/Save.php",
"chars": 5350,
"preview": "<?php\n/**\n * Sample_News extension\n *\n * NOTICE OF LICENSE\n *\n * This source file is subject to the MIT License\n * that "
},
{
"path": "Controller/Adminhtml/Author/Upload.php",
"chars": 2136,
"preview": "<?php\n/**\n * Sample_News extension\n *\n * NOTICE OF LICENSE\n *\n * This source file is subject to the MIT License\n * that "
},
{
"path": "Controller/Adminhtml/Author.php",
"chars": 2505,
"preview": "<?php\n/**\n * Sample_News extension\n *\n * NOTICE OF LICENSE\n *\n * This source file is subject to the MIT License\n * that "
},
{
"path": "Controller/Author/Index.php",
"chars": 3202,
"preview": "<?php\n/**\n * Sample_News extension\n *\n * NOTICE OF LICENSE\n *\n * This source file is subject to the MIT License\n * that "
},
{
"path": "Controller/Author/Rss.php",
"chars": 827,
"preview": "<?php\n/**\n * Sample_News extension\n *\n * NOTICE OF LICENSE\n *\n * This source file is subject to the MIT License\n * that "
},
{
"path": "Controller/Author/View.php",
"chars": 4747,
"preview": "<?php\n/**\n * Sample_News extension\n *\n * NOTICE OF LICENSE\n *\n * This source file is subject to the MIT License\n * that "
},
{
"path": "Controller/RegistryConstants.php",
"chars": 659,
"preview": "<?php\n/**\n * Sample_News extension\n *\n * NOTICE OF LICENSE\n *\n * This source file is subject to the MIT License\n * that "
},
{
"path": "Controller/Router.php",
"chars": 6985,
"preview": "<?php\n/**\n * Sample_News extension\n *\n * NOTICE OF LICENSE\n *\n * This source file is subject to the MIT License\n * that "
},
{
"path": "Helper/Image.php",
"chars": 21031,
"preview": "<?php\n/**\n * Sample_News extension\n *\n * NOTICE OF LICENSE\n *\n * This source file is subject to the MIT License\n * that "
},
{
"path": "LICENSE",
"chars": 1094,
"preview": "The MIT License (MIT)\r\n\r\nCopyright (c) 2016 Marius\r\n\r\nPermission is hereby granted, free of charge, to any person obtain"
},
{
"path": "Model/Author/DataProvider.php",
"chars": 2375,
"preview": "<?php\n/**\n * Sample_News extension\n *\n * NOTICE OF LICENSE\n *\n * This source file is subject to the MIT License\n * that "
},
{
"path": "Model/Author/Rss.php",
"chars": 2236,
"preview": "<?php\n/**\n * Sample_News extension\n *\n * NOTICE OF LICENSE\n *\n * This source file is subject to the MIT License\n * that "
},
{
"path": "Model/Author/Url.php",
"chars": 2667,
"preview": "<?php\n/**\n * Sample_News extension\n *\n * NOTICE OF LICENSE\n *\n * This source file is subject to the MIT License\n * that "
},
{
"path": "Model/Author.php",
"chars": 12614,
"preview": "<?php\n/**\n * Sample_News extension\n *\n * NOTICE OF LICENSE\n *\n * This source file is subject to the MIT License\n * that "
},
{
"path": "Model/AuthorFactory.php",
"chars": 1539,
"preview": "<?php\n/**\n * Sample_News extension\n *\n * NOTICE OF LICENSE\n *\n * This source file is subject to the MIT License\n * that "
},
{
"path": "Model/AuthorRepository.php",
"chars": 8805,
"preview": "<?php\n/**\n * Sample_News extension\n *\n * NOTICE OF LICENSE\n *\n * This source file is subject to the MIT License\n * that "
},
{
"path": "Model/FactoryInterface.php",
"chars": 665,
"preview": "<?php\n/**\n * Sample_News extension\n *\n * NOTICE OF LICENSE\n *\n * This source file is subject to the MIT License\n * that "
},
{
"path": "Model/Image.php",
"chars": 23420,
"preview": "<?php\n/**\n * Sample_News extension\n *\n * NOTICE OF LICENSE\n *\n * This source file is subject to the MIT License\n * that "
},
{
"path": "Model/Output.php",
"chars": 1005,
"preview": "<?php\n/**\n * Sample_News extension\n *\n * NOTICE OF LICENSE\n *\n * This source file is subject to the MIT License\n * that "
},
{
"path": "Model/ResourceModel/Author/Collection.php",
"chars": 6865,
"preview": "<?php\n/**\n * Sample_News extension\n *\n * NOTICE OF LICENSE\n *\n * This source file is subject to the MIT License\n * that "
},
{
"path": "Model/ResourceModel/Author/Grid/Collection.php",
"chars": 4182,
"preview": "<?php\n/**\n * Sample_News extension\n *\n * NOTICE OF LICENSE\n *\n * This source file is subject to the MIT License\n * that "
},
{
"path": "Model/ResourceModel/Author/Grid/ServiceCollection.php",
"chars": 3193,
"preview": "<?php\n/**\n * Sample_News extension\n *\n * NOTICE OF LICENSE\n *\n * This source file is subject to the MIT License\n * that "
},
{
"path": "Model/ResourceModel/Author.php",
"chars": 13380,
"preview": "<?php\n/**\n * Sample_News extension\n *\n * NOTICE OF LICENSE\n *\n * This source file is subject to the MIT License\n * that "
},
{
"path": "Model/Routing/Entity.php",
"chars": 2580,
"preview": "<?php\nnamespace Sample\\News\\Model\\Routing;\n\nuse Sample\\News\\Model\\FactoryInterface;\n\nclass Entity\n{\n /**\n * @var "
},
{
"path": "Model/Routing/RoutableInterface.php",
"chars": 213,
"preview": "<?php\nnamespace Sample\\News\\Model\\Routing;\n\ninterface RoutableInterface\n{\n /**\n * @param $urlKey\n * @param $s"
},
{
"path": "Model/Source/AbstractSource.php",
"chars": 1653,
"preview": "<?php\n/**\n * Sample_News extension\n *\n * NOTICE OF LICENSE\n *\n * This source file is subject to the MIT License\n * that "
},
{
"path": "Model/Source/Country.php",
"chars": 1480,
"preview": "<?php\n/**\n * Sample_News extension\n *\n * NOTICE OF LICENSE\n *\n * This source file is subject to the MIT License\n * that "
},
{
"path": "Model/Source/Options.php",
"chars": 978,
"preview": "<?php\n/**\n * Sample_News extension\n *\n * NOTICE OF LICENSE\n *\n * This source file is subject to the MIT License\n * that "
},
{
"path": "Model/Uploader.php",
"chars": 8262,
"preview": "<?php\n/**\n * Sample_News extension\n *\n * NOTICE OF LICENSE\n *\n * This source file is subject to the MIT License\n * that "
},
{
"path": "Model/UploaderPool.php",
"chars": 1679,
"preview": "<?php\n/**\n * Sample_News extension\n *\n * NOTICE OF LICENSE\n *\n * This source file is subject to the MIT License\n * that "
},
{
"path": "Plugin/Block/Topmenu.php",
"chars": 2257,
"preview": "<?php\n/**\n * Sample_News extension\n *\n * NOTICE OF LICENSE\n *\n * This source file is subject to the MIT License\n * that "
},
{
"path": "README.md",
"chars": 3811,
"preview": "Magento 2.0 Sample Module\n====================\n\nLast tested on Magento2 version 2.1\n\n\n have be"
},
{
"path": "registration.php",
"chars": 629,
"preview": "<?php\n/**\n * Sample_News extension\n *\n * NOTICE OF LICENSE\n *\n * This source file is subject to the MIT License\n * that "
},
{
"path": "view/adminhtml/layout/sample_news_author_edit.xml",
"chars": 934,
"preview": "<?xml version=\"1.0\"?>\n<!--\n/**\n * Sample_News extension\n *\n * NOTICE OF LICENSE\n *\n * This source file is subject to the"
},
{
"path": "view/adminhtml/layout/sample_news_author_index.xml",
"chars": 1277,
"preview": "<?xml version=\"1.0\"?>\n<!--\n/**\n * Sample_News extension\n *\n * NOTICE OF LICENSE\n *\n * This source file is subject to the"
},
{
"path": "view/adminhtml/ui_component/sample_news_author_form.xml",
"chars": 16910,
"preview": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<form xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchema"
},
{
"path": "view/adminhtml/ui_component/sample_news_author_listing.xml",
"chars": 23787,
"preview": "<?xml version=\"1.0\"?>\n<!--\n/**\n * Sample_News extension\n * NOTICE OF LICENSE\n * \n * This source file is subject to the M"
},
{
"path": "view/adminhtml/web/template/file-preview.html",
"chars": 495,
"preview": "<div class=\"file-uploader-summary\">\n <a attr=\"href: $parent.getFilePreview($file)\" target=\"_blank\" text=\"$file.name\">"
},
{
"path": "view/adminhtml/web/template/image-preview.html",
"chars": 994,
"preview": "<div class=\"file-uploader-summary\">\n <div class=\"file-uploader-preview\">\n <a attr=\"href: $parent.getFilePrevie"
},
{
"path": "view/frontend/layout/sample_news_author_index.xml",
"chars": 1133,
"preview": "<?xml version=\"1.0\"?>\r\n<!--\r\n/**\r\n * Sample_News extension\r\n *\r\n * NOTICE OF LICENSE\r\n *\r\n * This source file is subject"
},
{
"path": "view/frontend/layout/sample_news_author_view.xml",
"chars": 940,
"preview": "<?xml version=\"1.0\"?>\r\n<!--\r\n/**\r\n * Sample_News extension\r\n *\r\n * NOTICE OF LICENSE\r\n *\r\n * This source file is subject"
},
{
"path": "view/frontend/templates/author/list.phtml",
"chars": 1552,
"preview": "<?php\r\n/**\r\n * Sample_News extension\r\n *\r\n * NOTICE OF LICENSE\r\n *\r\n * This source file is subject to the MIT License\r\n "
},
{
"path": "view/frontend/templates/author/view.phtml",
"chars": 2543,
"preview": "<?php\n/**\n * Sample_News extension\n *\n * NOTICE OF LICENSE\n *\n * This source file is subject to the MIT License\n * that "
},
{
"path": "view/frontend/templates/image.phtml",
"chars": 955,
"preview": "<?php\n/**\n * Sample_News extension\n *\n * NOTICE OF LICENSE\n *\n * This source file is subject to the MIT License\n * that "
},
{
"path": "view/frontend/templates/image_with_borders.phtml",
"chars": 1288,
"preview": "<?php\n/**\n * Sample_News extension\n *\n * NOTICE OF LICENSE\n *\n * This source file is subject to the MIT License\n * that "
},
{
"path": "view/frontend/templates/rss/link.phtml",
"chars": 799,
"preview": "<?php\n/**\n * Sample_News extension\n *\n * NOTICE OF LICENSE\n *\n * This source file is subject to the MIT License\n * that "
}
]
About this extraction
This page contains the full source code of the tzyganu/Magento2SampleModule GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 101 files (353.3 KB), approximately 86.9k tokens, and a symbol index with 483 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.