Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
phoenix128 committed Mar 2, 2018
1 parent 60b1c3c commit 551ff92
Show file tree
Hide file tree
Showing 72 changed files with 3,932 additions and 0 deletions.
16 changes: 16 additions & 0 deletions COPYING.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* MageSpecialist
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to info@magespecialist.it so we can send you a copy immediately.
*
* @copyright Copyright (c) 2018 Skeeller srl (http://www.magespecialist.it)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
65 changes: 65 additions & 0 deletions Command/SendMessage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php
/**
* Copyright © MageSpecialist - Skeeller srl. All rights reserved.
* See COPYING.txt for license details.
*/

declare(strict_types=1);

namespace MSP\Notifier\Command;

use MSP\NotifierApi\Api\SendMessageInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class SendMessage extends Command
{
/**
* @var SendMessageInterface
*/
private $sendMessage;

/**
* SendMessage constructor.
* @param SendMessageInterface $cleanMessage
*/
public function __construct(
SendMessageInterface $cleanMessage
) {
$this->sendMessage = $cleanMessage;

parent::__construct();
}

/**
* @inheritdoc
*/
protected function configure()
{
$this->setName('msp:notifier:send');
$this->setDescription('Send a notification message');

$this->addArgument('channel', InputArgument::REQUIRED, 'Channel');
$this->addArgument('message', InputArgument::REQUIRED, 'Message');

parent::configure();
}

/**
* @inheritdoc
* @SuppressWarnings("PHPMD.UnusedFormalParameter")
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$channel = $input->getArgument('channel');
$message = $input->getArgument('message');

if ($this->sendMessage->execute($channel, $message)) {
$output->writeln('Message sent');
} else {
$output->writeln('Could not send message');
}
}
}
61 changes: 61 additions & 0 deletions Controller/Adminhtml/Channel/Delete.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php
/**
* Copyright © MageSpecialist - Skeeller srl. All rights reserved.
* See COPYING.txt for license details.
*/

declare(strict_types=1);

namespace MSP\Notifier\Controller\Adminhtml\Channel;

use Magento\Backend\App\Action;
use Magento\Framework\Controller\ResultInterface;
use MSP\NotifierApi\Api\ChannelRepositoryInterface;
use MSP\NotifierApi\Api\Data\ChannelInterface;

class Delete extends Action
{
/**
* @see _isAllowed()
*/
const ADMIN_RESOURCE = 'MSP_Notifier::channel';

/**
* @var ChannelRepositoryInterface
*/
private $channelRepository;

/**
* Delete constructor.
* @param Action\Context $context
* @param ChannelRepositoryInterface $channelRepository
*/
public function __construct(
Action\Context $context,
ChannelRepositoryInterface $channelRepository
) {
parent::__construct($context);
$this->channelRepository = $channelRepository;
}

/**
* @inheritdoc
*/
public function execute(): ResultInterface
{
$channelId = (int) $this->getRequest()->getParam(ChannelInterface::ID);

try {
$channel = $this->channelRepository->get($channelId);
$this->channelRepository->deleteById($channel->getId());
$this->messageManager->addSuccessMessage(__('Channel "%1" deleted.', $channel->getName()));
} catch (\Exception $e) {
$this->messageManager->addErrorMessage(__('Could not delete channel: %1.', $e->getMessage()));
}

$result = $this->resultRedirectFactory->create();
$result->setPath('*/*/index');

return $result;
}
}
69 changes: 69 additions & 0 deletions Controller/Adminhtml/Channel/Edit.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php
/**
* Copyright © MageSpecialist - Skeeller srl. All rights reserved.
* See COPYING.txt for license details.
*/

declare(strict_types=1);

namespace MSP\Notifier\Controller\Adminhtml\Channel;

use Magento\Backend\App\Action;
use Magento\Framework\Controller\ResultFactory;
use Magento\Framework\Controller\ResultInterface;
use Magento\Framework\Exception\NoSuchEntityException;
use MSP\NotifierApi\Api\ChannelRepositoryInterface;
use MSP\NotifierApi\Api\Data\ChannelInterface;

class Edit extends Action
{
/**
* @see _isAllowed()
*/
const ADMIN_RESOURCE = 'MSP_Notifier::channel';

/**
* @var ChannelRepositoryInterface
*/
private $channelRepository;

/**
* Edit constructor.
* @param Action\Context $context
* @param ChannelRepositoryInterface $channelRepository
*/
public function __construct(
Action\Context $context,
ChannelRepositoryInterface $channelRepository
) {
parent::__construct($context);
$this->channelRepository = $channelRepository;
}

/**
* @inheritdoc
*/
public function execute(): ResultInterface
{
$channelId = (int) $this->getRequest()->getParam(ChannelInterface::ID);
try {
$channel = $this->channelRepository->get($channelId);
$result = $this->resultFactory->create(ResultFactory::TYPE_PAGE);
$result
->setActiveMenu('MSP_Notifier::channel')
->addBreadcrumb(__('Edit Channel'), __('Edit Channel'));

$result->getConfig()
->getTitle()
->prepend(__('Edit Channel: %name', ['name' => $channel->getName()]));
} catch (NoSuchEntityException $e) {
$result = $this->resultRedirectFactory->create();
$this->messageManager->addErrorMessage(
__('Channel with id "%value" does not exist.', ['value' => $channelId])
);
$result->setPath('*/*');
}

return $result;
}
}
40 changes: 40 additions & 0 deletions Controller/Adminhtml/Channel/Index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php
/**
* Copyright © MageSpecialist - Skeeller srl. All rights reserved.
* See COPYING.txt for license details.
*/

declare(strict_types=1);

namespace MSP\Notifier\Controller\Adminhtml\Channel;

use Magento\Backend\App\Action;
use Magento\Backend\Model\View\Result\Page;
use Magento\Framework\Controller\ResultFactory;
use Magento\Framework\Controller\ResultInterface;

/**
* Index Controller
*/
class Index extends Action
{
/**
* @see _isAllowed()
*/
const ADMIN_RESOURCE = 'MSP_Notifier::channel';

/**
* @inheritdoc
*/
public function execute(): ResultInterface
{
/** @var Page $resultPage */
$resultPage = $this->resultFactory->create(ResultFactory::TYPE_PAGE);
$resultPage
->setActiveMenu('MSP_Notifier::channel')
->addBreadcrumb(__('Channels'), __('List'));
$resultPage->getConfig()->getTitle()->prepend(__('Manage Channels'));

return $resultPage;
}
}
38 changes: 38 additions & 0 deletions Controller/Adminhtml/Channel/NewAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php
/**
* Copyright © MageSpecialist - Skeeller srl. All rights reserved.
* See COPYING.txt for license details.
*/

declare(strict_types=1);

namespace MSP\Notifier\Controller\Adminhtml\Channel;

use Magento\Backend\App\Action;
use Magento\Backend\Model\View\Result\Page;
use Magento\Framework\Controller\ResultFactory;
use Magento\Framework\Controller\ResultInterface;

/**
* NewAction Controller
*/
class NewAction extends Action
{
/**
* @see _isAllowed()
*/
const ADMIN_RESOURCE = 'MSP_Notifier::channel';

/**
* @inheritdoc
*/
public function execute(): ResultInterface
{
/** @var Page $resultPage */
$resultPage = $this->resultFactory->create(ResultFactory::TYPE_PAGE);
$resultPage->setActiveMenu('MSP_Notifier::channel');
$resultPage->getConfig()->getTitle()->prepend(__('New channel'));

return $resultPage;
}
}
Loading

0 comments on commit 551ff92

Please sign in to comment.