Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
JaJuMa committed Nov 27, 2023
0 parents commit 18326c2
Show file tree
Hide file tree
Showing 304 changed files with 11,298 additions and 0 deletions.
63 changes: 63 additions & 0 deletions Api/BookMarkRepositoryInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php
/**
* @author JaJuMa GmbH <[email protected]>
* @copyright Copyright (c) 2023-present JaJuMa GmbH <https://www.jajuma.de>. All rights reserved.
* @license http://opensource.org/licenses/mit-license.php MIT License
*/
declare(strict_types=1);

namespace Jajuma\PowerToys\Api;

use Magento\Framework\Api\SearchCriteriaInterface;

interface BookMarkRepositoryInterface
{

/**
* Save BookMark
* @param \Jajuma\PowerToys\Api\Data\BookMarkInterface $bookMark
* @return \Jajuma\PowerToys\Api\Data\BookMarkInterface
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function save(
\Jajuma\PowerToys\Api\Data\BookMarkInterface $bookMark
);

/**
* Retrieve BookMark
* @param string $bookmarkId
* @return \Jajuma\PowerToys\Api\Data\BookMarkInterface
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function get($bookmarkId);

/**
* Retrieve BookMark matching the specified criteria.
* @param \Magento\Framework\Api\SearchCriteriaInterface $searchCriteria
* @return \Jajuma\PowerToys\Api\Data\BookMarkSearchResultsInterface
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function getList(
\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria
);

/**
* Delete BookMark
* @param \Jajuma\PowerToys\Api\Data\BookMarkInterface $bookMark
* @return bool true on success
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function delete(
\Jajuma\PowerToys\Api\Data\BookMarkInterface $bookMark
);

/**
* Delete BookMark by ID
* @param string $bookmarkId
* @return bool true on success
* @throws \Magento\Framework\Exception\NoSuchEntityException
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function deleteById($bookmarkId);
}

86 changes: 86 additions & 0 deletions Api/Data/BookMarkInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?php
/**
* @author JaJuMa GmbH <[email protected]>
* @copyright Copyright (c) 2023-present JaJuMa GmbH <https://www.jajuma.de>. All rights reserved.
* @license http://opensource.org/licenses/mit-license.php MIT License
*/
declare(strict_types=1);

namespace Jajuma\PowerToys\Api\Data;

interface BookMarkInterface
{

const URL = 'url';
const NAME = 'name';
const BOOKMARK_ID = 'bookmark_id';
const POSITION = 'position';
const ICONSVG = 'icon_svg';

/**
* Get bookmark_id
* @return string|null
*/
public function getBookmarkId();

/**
* Set bookmark_id
* @param string $bookmarkId
* @return \Jajuma\PowerToys\BookMark\Api\Data\BookMarkInterface
*/
public function setBookmarkId($bookmarkId);


/**
* Get name
* @return string|null
*/
public function getName();

/**
* Set name
* @param string $name
* @return \Jajuma\PowerToys\BookMark\Api\Data\BookMarkInterface
*/
public function setName($name);

/**
* Get url
* @return string|null
*/
public function getUrl();

/**
* Set url
* @param string $url
* @return \Jajuma\PowerToys\BookMark\Api\Data\BookMarkInterface
*/
public function setUrl($url);

/**
* Set iconsvg
* @param string $iconsvg
* @return \Jajuma\PowerToys\BookMark\Api\Data\BookMarkInterface
*/
public function setIconSvg($iconsvg);

/**
* Get iconsvg
* @return string|null
*/
public function getIconSvg();

/**
* Get position
* @return string|null
*/
public function getPosition();

/**
* Set position
* @param string $position
* @return \Jajuma\PowerToys\BookMark\Api\Data\BookMarkInterface
*/
public function setPosition($position);
}

27 changes: 27 additions & 0 deletions Api/Data/BookMarkSearchResultsInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
/**
* @author JaJuMa GmbH <[email protected]>
* @copyright Copyright (c) 2023-present JaJuMa GmbH <https://www.jajuma.de>. All rights reserved.
* @license http://opensource.org/licenses/mit-license.php MIT License
*/
declare(strict_types=1);

namespace Jajuma\PowerToys\Api\Data;

interface BookMarkSearchResultsInterface extends \Magento\Framework\Api\SearchResultsInterface
{

/**
* Get BookMark list.
* @return \Jajuma\PowerToys\Api\Data\BookMarkInterface[]
*/
public function getItems();

/**
* Set status list.
* @param \Jajuma\PowerToys\Api\Data\BookMarkInterface[] $items
* @return $this
*/
public function setItems(array $items);
}

13 changes: 13 additions & 0 deletions Block/BookmarkBar.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
/**
* @author JaJuMa GmbH <[email protected]>
* @copyright Copyright (c) 2023 JaJuMa GmbH <https://www.jajuma.de>. All rights reserved.
* @license http://opensource.org/licenses/mit-license.php MIT License
*/

namespace Jajuma\PowerToys\Block;

class BookmarkBar extends PowerToys
{

}
180 changes: 180 additions & 0 deletions Block/PowerToys.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
<?php
/**
* @author JaJuMa GmbH <[email protected]>
* @copyright Copyright (c) 2023 JaJuMa GmbH <https://www.jajuma.de>. All rights reserved.
* @license http://opensource.org/licenses/mit-license.php MIT License
*/

namespace Jajuma\PowerToys\Block;

use Jajuma\PowerToys\Model\Config;
use Magento\Framework\Data\Form\FormKey;
use Magento\Framework\Url;
use Magento\Framework\View\Element\Template;
use Jajuma\PowerToys\Model\ResourceModel\BookMark\CollectionFactory as BookMarkCollectionFactory;
use Magento\Framework\UrlInterface;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Backend\Model\Url as BackendUrl;
use Jajuma\PowerToys\Helper\Data;
use Jajuma\PowerToys\Model\System\Config\Backend\Icon;
use \Magento\Backend\Setup\ConfigOptionsList as BackendConfigOptionsList;
use Magento\Framework\App\DeploymentConfig;

class PowerToys extends Template
{
private $powerToyConfig;

protected $formKey;

private $bookMarkCollectionFactory;

protected $storeManager;

protected $backendUrlManager;

protected $helper;

protected $url;

protected $backendSuffix = '';

private $_state;

public function __construct(
Config $powerToyConfig,
FormKey $formKey,
Template\Context $context,
BookMarkCollectionFactory $bookMarkCollectionFactory,
StoreManagerInterface $storeManager,
BackendUrl $backendUrlManager,
Data $helper,
Url $url,
DeploymentConfig $deploymentConfig,
\Magento\Framework\App\State $state,
array $data = []
) {
parent::__construct($context, $data);
$this->powerToyConfig = $powerToyConfig;
$this->formKey = $formKey;
$this->bookMarkCollectionFactory = $bookMarkCollectionFactory;
$this->storeManager = $storeManager;
$this->backendUrlManager = $backendUrlManager;
$this->helper = $helper;
$this->backendSuffix = $deploymentConfig->get(BackendConfigOptionsList::CONFIG_PATH_BACKEND_FRONTNAME);
$this->url = $url;
$this->_state = $state;
}

public function getBlocks($type) {
$blockArr = [];
$blockConfigArr = $this->powerToyConfig->getWidget($type);
$sortOrderConfig = $this->helper->loadComponentSortOrderConfig($type) ?? [];
if ($sortOrderConfig) {
$sortOrderConfig = json_decode($sortOrderConfig, true);
}
foreach ($blockConfigArr as $block_id => $blockConfig) {
$block = $this->getLayout()->getBlock($block_id);
if ($block) {
if ($block->isEnable()) {
if (array_key_exists($block_id, $sortOrderConfig)) {
$block->setData('sort_order', $sortOrderConfig[$block_id]);
}
$blockArr[] = $block;
}
}
}
usort($blockArr, function ($item1, $item2) {
return (intval($item1['sort_order'] ?? '0') - intval($item2['sort_order'] ?? '0'));
});
return $blockArr;
}

public function getFormKey()
{
return $this->formKey->getFormKey();
}

public function getBackendSuffix()
{
return $this->backendSuffix;
}

public function getBookMarkCollection()
{
$bookMarkCollectionFactory = $this->bookMarkCollectionFactory->create();
$bookMarkCollectionFactory->setOrder('position','ASC');
return $bookMarkCollectionFactory;
}

public function getBaseUrlMedia()
{
return $this->storeManager->getStore()->getBaseUrl(
UrlInterface::URL_TYPE_MEDIA
);
}

public function getUrlMediaIcon($icon)
{
if (strpos($icon, 'wysiwyg/') !== false) {
return $this->getBaseUrlMedia() . $icon;
}
return $this->getBaseUrlMedia() . 'jajuma_powertoys/bookmark/icon/' . $icon;
}

public function getBookMarkUrl($path, $params = [])
{
if (strpos($path, $this->getBackendSuffix()) !== false) {
$path = preg_replace('/' . $this->getBackendSuffix() . '\//', '', $path, 1);
return $this->generateUrlAdmin($path, $params);
} else {
return $this->storeManager->getStore()->getBaseUrl() . $path;
}
}

public function generateUrlAdmin($path, $params = [])
{
return $this->backendUrlManager->getUrl($path, ['redirectFromBookmark' => true]);
}

public function getDefaultIcon()
{
$iconConfig = $this->helper->getDefaultIcon();
if ($iconConfig) {
return $this->getBaseUrlMedia() . Icon::UPLOAD_DIR . '/' . $iconConfig;
}
return $this->getViewFileUrl('Jajuma_PowerToys::images/jajuma_develop.png');
}

public function isEnabledQuickAction()
{
return $this->helper->isEnabledQuickAction();
}

public function isEnabledWidget()
{
return $this->helper->isEnabledWidget();
}

public function isEnabledBookMark()
{
return $this->helper->isEnabledBookMark();
}

public function getStoreUrl($routePath, $routeParams = [])
{
return $this->url->getUrl($routePath, $routeParams);
}

public function toHtml()
{
if ($this->helper->isAllowedPowerToys()){
return parent::toHtml();
}
return '';
}

public function isAdmin() {
$areaCode = $this->_state->getAreaCode();
return $areaCode == \Magento\Framework\App\Area::AREA_ADMINHTML;
}
}
Loading

0 comments on commit 18326c2

Please sign in to comment.