-
Notifications
You must be signed in to change notification settings - Fork 0
For review advertisement repository #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| <?php | ||
| /* | ||
| * Block to fill eliments of Back button for UiForm in backend | ||
| * @category Salecto | ||
| * @package Salecto_Advertisment | ||
| * @author Salecto | ||
| */ | ||
| namespace Salecto\Advertisment\Block\Adminhtml\Advertisment\Edit; | ||
|
|
||
| use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface; | ||
| use Magento\Catalog\Block\Adminhtml\Category\AbstractCategory; | ||
|
|
||
| class BackButton extends GenericButton implements ButtonProviderInterface | ||
| { | ||
| /** | ||
| * Save button | ||
| * | ||
| * @return array | ||
| */ | ||
| public function getButtonData() | ||
| { | ||
| return [ | ||
| 'label' => __('Back'), | ||
| 'on_click' => sprintf("location.href = '%s';", 'advertisment/adverts'), | ||
| 'class' => 'back', | ||
| 'sort_order' => 10 | ||
| ]; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| <?php | ||
| /** | ||
| * Salecto_Advertisment Add New Row Form Admin Block. | ||
| * @category Salecto | ||
| * @package Salecto_Advertisment | ||
| * @author Salecto | ||
| * | ||
| */ | ||
|
|
||
| namespace Salecto\Advertisment\Block\Adminhtml\Advertisment\Edit; | ||
|
|
||
| use Magento\Search\Controller\RegistryConstants; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. RegistryConstants is not used in class anywhere |
||
|
|
||
| /** | ||
| * Class GenericButton | ||
| */ | ||
| class GenericButton | ||
| { | ||
| /** | ||
| * Url Builder | ||
| * | ||
| * @var \Magento\Framework\UrlInterface | ||
| */ | ||
| protected $urlBuilder; | ||
|
|
||
| /** | ||
| * Registry | ||
| * | ||
| * @var \Magento\Framework\Registry | ||
| */ | ||
| protected $registry; | ||
|
|
||
| /** | ||
| * Constructor | ||
| * | ||
| * @param \Magento\Backend\Block\Widget\Context $context | ||
| * @param \Magento\Framework\Registry $registry | ||
| */ | ||
| public function __construct( | ||
| \Magento\Backend\Block\Widget\Context $context, | ||
| \Magento\Framework\Registry $registry | ||
| ) { | ||
| $this->urlBuilder = $context->getUrlBuilder(); | ||
| $this->registry = $registry; | ||
| } | ||
|
|
||
| /** | ||
| * Return the synonyms group Id. | ||
| * | ||
| * @return int|null | ||
| */ | ||
| public function getId() | ||
| { | ||
| $contact = $this->registry->registry('contact'); | ||
| return $contact ? $contact->getId() : null; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can be modified as $contact = $this->registry->registry('contact') ? $contact->getId() : null; |
||
| } | ||
|
|
||
| /** | ||
| * Generate url by route and parameters | ||
| * | ||
| * @param string $route | ||
| * @param array $params | ||
| * @return string | ||
| */ | ||
| public function getUrl($route = '', $params = []) | ||
| { | ||
| return $this->urlBuilder->getUrl($route, $params); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| <?php | ||
| /** | ||
| * Copyright © Magento, Inc. All rights reserved. | ||
| * See COPYING.txt for license details. | ||
| */ | ||
| namespace Salecto\Advertisment\Block\Adminhtml\Advertisment\Edit; | ||
|
|
||
| use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface; | ||
| use Magento\Catalog\Block\Adminhtml\Category\AbstractCategory; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not used anywere |
||
|
|
||
| /** | ||
| * Class SaveButton | ||
| */ | ||
| //class SaveButton extends AbstractCategory implements ButtonProviderInterface | ||
| class SaveButton extends GenericButton implements ButtonProviderInterface | ||
| { | ||
| /** | ||
| * Save button | ||
| * | ||
| * @return array | ||
| */ | ||
| public function getButtonData() | ||
| { | ||
| return []; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| <?php | ||
| /* | ||
| * Block for fetch Advertisment collection. | ||
| * @category Salecto | ||
| * @package Salecto_Advertisment | ||
| * @author Salecto | ||
| */ | ||
| namespace Salecto\Advertisment\Block; | ||
|
|
||
| use Magento\Framework\View\Element\Template\Context; | ||
| use Salecto\Advertisment\Model\GridModelFactory; | ||
| use Magento\Store\Model\StoreManagerInterface; | ||
| use Magento\Framework\Stdlib\DateTime\DateTime; | ||
|
|
||
| class Adverts extends \Magento\Framework\View\Element\Template | ||
| { | ||
| /** | ||
| * @var \Salecto\Advertisment\Model\GridModelFactory | ||
| */ | ||
| protected $_adverts; | ||
|
|
||
| /** | ||
| * @var \Magento\Store\Model\StoreManagerInterface | ||
| */ | ||
| protected $_storeManager; | ||
|
|
||
| /** | ||
| * @var \Magento\Framework\Stdlib\DateTime\DateTime | ||
| */ | ||
| protected $_DateTime; | ||
|
|
||
| /** | ||
| * Constructor | ||
| * | ||
| * @param \Magento\Backend\Block\Widget\Context $context | ||
| * @param \Salecto\Advertisment\Model\GridModelFactory $adverts | ||
| * @param \Magento\Catalog\Model\ProductFactory $storeManager | ||
| * @param \Magento\Framework\Stdlib\DateTime\DateTime $DateTime | ||
| */ | ||
| public function __construct( | ||
| Context $context, | ||
| GridModelFactory $adverts, | ||
| StoreManagerInterface $storeManager, | ||
| DateTime $DateTime | ||
| ) { | ||
| $this->_adverts = $adverts; | ||
| $this->_storeManager = $storeManager; | ||
| $this->_DateTime = $DateTime; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it should be $this->_dateTime = $dateTime |
||
| parent::__construct($context); | ||
| } | ||
|
|
||
| /** | ||
| * @return void | ||
| */ | ||
| public function _prepareLayout() | ||
| { | ||
| $this->pageConfig->getTitle()->set(__('Advertisments')); | ||
|
|
||
| return parent::_prepareLayout(); | ||
| } | ||
|
|
||
| /** | ||
| * Retrieve collection of 'advertisments', filtered with (from-to date, status and display on pages) | ||
| * @param string $page | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It can be null also |
||
| * @return array | ||
| */ | ||
| public function getAdverts($page = null) | ||
| { | ||
| $currentTime = $this->_DateTime->date(); | ||
| $model = $this->_adverts->create(); | ||
| $collection = $model->getCollection(); | ||
| $collection->addFieldToFilter('from_date', ['lteq' => $currentTime]); | ||
| $collection->addFieldToFilter('to_date', ['gteq' => $currentTime]); | ||
| $collection->addFieldToFilter('ad_status', 1); | ||
| $collection->addFieldToFilter('ad_pages', array('finset' => $page)); | ||
|
|
||
| return $collection; | ||
| } | ||
|
|
||
| /** | ||
| * Creates Media Url + custom folder path + imageName.extension | ||
| * @param string $imgName | ||
| * @return string | ||
| */ | ||
| public function getMediaUrl($imgName) | ||
| { | ||
| $mediaUrl = $this->_storeManager->getStore() | ||
| ->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA).'salecto/advertisment/'.$imgName; | ||
| return $mediaUrl; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| <?php | ||
| /* | ||
| * Console Class for add Advertisment into DB table. | ||
| * @category Salecto | ||
| * @package Salecto_Advertisment | ||
| * @author Salecto | ||
| */ | ||
| namespace Salecto\Advertisment\Console; | ||
|
|
||
| use Symfony\Component\Console\Command\Command; | ||
| use Symfony\Component\Console\Input\InputInterface; | ||
| use Symfony\Component\Console\Input\InputOption; | ||
| use Symfony\Component\Console\Output\OutputInterface; | ||
| use Salecto\Advertisment\Model\GridModelFactory; | ||
| /** | ||
| * Class SomeCommand | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. correct the class name |
||
| */ | ||
| class Adverts extends Command | ||
| { | ||
| /** | ||
| * command input parameter 'title' | ||
| */ | ||
| const TITLE = 'title'; | ||
|
|
||
| /** | ||
| * command input parameter 'status' | ||
| */ | ||
| const STATUS = 'status'; | ||
|
|
||
| /** | ||
| * @var \Salecto\Advertisment\Model\GridModelFactory | ||
| */ | ||
| protected $_model; | ||
|
|
||
| /** | ||
| * Constructor | ||
| * | ||
| * @param \Salecto\Advertisment\Model\GridModelFactory | ||
| */ | ||
| public function __construct( | ||
| GridModelFactory $model | ||
| ) { | ||
|
|
||
| $this->_model = $model; | ||
| parent::__construct(); | ||
| } | ||
|
|
||
|
|
||
| /** | ||
| * @inheritDoc | ||
| */ | ||
| protected function configure() | ||
| { | ||
| $this->setName('add:advert'); | ||
| $this->setDescription('This is my first console command.'); | ||
| $this->addOption( | ||
| self::TITLE, | ||
| null, | ||
| InputOption::VALUE_REQUIRED, | ||
| 'TITLE' | ||
| ); | ||
| $this->addOption( | ||
| self::STATUS, | ||
| null, | ||
| InputOption::VALUE_REQUIRED, | ||
| 'STATUS' | ||
| ); | ||
|
|
||
| parent::configure(); | ||
| } | ||
|
|
||
| /** | ||
| * Execute the command | ||
| * | ||
| * @param InputInterface $input | ||
| * @param OutputInterface $output | ||
| * | ||
| * @return null|int | ||
| */ | ||
| protected function execute(InputInterface $input, OutputInterface $output) | ||
| { | ||
|
|
||
| $title = $input->getOption(self::TITLE); | ||
| $status = $input->getOption(self::STATUS); | ||
| $rowData = $this->_model->create(); | ||
| if (($status) && ($title) && (($status == 0) || ($status == 1))) { | ||
| try{ | ||
| $rowData->setTitle($title); | ||
| $rowData->setAdStatus($status); | ||
| $result = $rowData->save(); | ||
| $output->writeln('<info>Success: New Advertisment added with Id Number- `' . $result->getAdId() . '`</info>'); | ||
|
|
||
| }catch (\Exception $e){ | ||
| $output->writeln('<info>Can not save new advertisment - `' . $e . '`</info>'); | ||
| } | ||
| } else { | ||
| $output->writeln('<info> not Allowed</info>'); | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| <?php | ||
| /* | ||
| * Console Class remove generated folder. | ||
| * @category Salecto | ||
| * @package Salecto_Advertisment | ||
| * @author Salecto | ||
| */ | ||
| namespace Salecto\Advertisment\Console; | ||
|
|
||
| use Symfony\Component\Console\Command\Command; | ||
| use Symfony\Component\Console\Input\InputInterface; | ||
| use Symfony\Component\Console\Output\OutputInterface; | ||
| use Symfony\Component\Console\Input\InputOption; | ||
| use Symfony\Component\Filesystem\Filesystem; | ||
|
|
||
| class RfGen extends Command | ||
| { | ||
|
|
||
| /** | ||
| * @inheritDoc | ||
| */ | ||
| protected function configure() | ||
| { | ||
| $this->setName('rf:gen'); | ||
| $this->setDescription('Remove Generated Folder'); | ||
|
|
||
| parent::configure(); | ||
| } | ||
|
|
||
| /** | ||
| * Execute the command | ||
| * | ||
| * @param InputInterface $input | ||
| * @param OutputInterface $output | ||
| * | ||
| * @return null|int | ||
| */ | ||
| protected function execute(InputInterface $input, OutputInterface $output) | ||
| { | ||
| $fs = new Filesystem(); | ||
| try { | ||
| if($fs->exists('generated')){ | ||
| $fs->remove(array('generated')); | ||
| $output->writeln('<info>Generated Folder Removed!</info>'); | ||
| } | ||
| else { | ||
| $output->writeln('<error>Generated Folder\'s aleady deleted</error>'); | ||
| } | ||
| } catch (IOExceptionInterface $e) { | ||
| echo "An error occurred while deleting your directory at ".$e->getPath(); | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not used anywhere in this class