Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
kiwi-commerce committed May 31, 2018
1 parent 04cf170 commit fb77b9d
Show file tree
Hide file tree
Showing 75 changed files with 13,217 additions and 0 deletions.
83 changes: 83 additions & 0 deletions Block/Adminhtml/Dashboard/Cronjobs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php
/**
* KiwiCommerce
*
* Do not edit or add to this file if you wish to upgrade to newer versions in the future.
* If you wish to customise this module for your needs.
* Please contact us https://kiwicommerce.co.uk/contacts.
*
* @category KiwiCommerce
* @package KiwiCommerce_CronScheduler
* @copyright Copyright (C) 2018 Kiwi Commerce Ltd (https://kiwicommerce.co.uk/)
* @license https://kiwicommerce.co.uk/magento2-extension-license/
*/

namespace KiwiCommerce\CronScheduler\Block\Adminhtml\Dashboard;

/**
* Class Cronjobs
* @package KiwiCommerce\CronScheduler\Block\Adminhtml\Dashboard
*/
class Cronjobs extends \Magento\Backend\Block\Template
{
/**
* @var \KiwiCommerce\CronScheduler\Model\ResourceModel\Schedule\CollectionFactory
*/
public $scheduleCollectionFactory = null;

/**
* Dashboard enable/disable status
*/
const XML_PATH_DASHBOARD_ENABLE_STATUS = 'cronscheduler/general/cronscheduler_dashboard_enabled';

/**
* Display total records on dashboard
*/
const TOTAL_RECORDS_ON_DASHBOARD = 5;

/**
* Class constructor.
* @param \Magento\Backend\Block\Template\Context $context
* @param \KiwiCommerce\CronScheduler\Model\ResourceModel\Schedule\CollectionFactory $scheduleCollectionFactory
*/
public function __construct(
\Magento\Backend\Block\Template\Context $context,
\KiwiCommerce\CronScheduler\Model\ResourceModel\Schedule\CollectionFactory $scheduleCollectionFactory
) {
$this->scheduleCollectionFactory = $scheduleCollectionFactory;
parent::__construct($context);
}

/**
* Get Top running jobs
*
* @return \KiwiCommerce\CronScheduler\Model\ResourceModel\Schedule\Collection
*/
public function getTopRunningJobs()
{
$collection = $this->scheduleCollectionFactory->create();

$collection->addFieldToFilter('status', \Magento\Cron\Model\Schedule::STATUS_SUCCESS)
->addExpressionFieldToSelect(
'timediff',
'TIME_TO_SEC(TIMEDIFF(`finished_at`, `executed_at`))',
[]
)
->setOrder('TIME_TO_SEC(TIMEDIFF(`finished_at`, `executed_at`))', 'DESC')
->setPageSize(self::TOTAL_RECORDS_ON_DASHBOARD)
->load();

return $collection;
}

/**
* Check store configuration value for dashboard
* @return mixed
*/
public function isDashboardActive()
{
$dashboardEnableStatus = $this->_scopeConfig->getValue(self::XML_PATH_DASHBOARD_ENABLE_STATUS, \Magento\Store\Model\ScopeInterface::SCOPE_STORE);

return $dashboardEnableStatus;
}
}
53 changes: 53 additions & 0 deletions Block/Adminhtml/DefaultBlocks/Setvalues.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

/**
* KiwiCommerce
*
* Do not edit or add to this file if you wish to upgrade to newer versions in the future.
* If you wish to customise this module for your needs.
* Please contact us https://kiwicommerce.co.uk/contacts.
*
* @category KiwiCommerce
* @package KiwiCommerce_CronScheduler
* @copyright Copyright (C) 2018 Kiwi Commerce Ltd (https://kiwicommerce.co.uk/)
* @license https://kiwicommerce.co.uk/magento2-extension-license/
*/
namespace KiwiCommerce\CronScheduler\Block\Adminhtml\DefaultBlocks;

/**
* Class Setvalues
* @package KiwiCommerce\CronScheduler\Block\Adminhtml\DefaultBlocks
*/
class Setvalues extends \Magento\Framework\View\Element\Template
{
/**
* @var \Magento\Framework\App\DeploymentConfig\Reader
*/
public $configReader;

/**
* Class constructor.
* @param \Magento\Framework\View\Element\Template\Context $context
* @param \Magento\Framework\App\DeploymentConfig\Reader $configReader
*/
public function __construct(
\Magento\Framework\View\Element\Template\Context $context,
\Magento\Framework\App\DeploymentConfig\Reader $configReader
) {
$this->configReader = $configReader;
parent::__construct($context);
}

/**
* Get Admin URL
* @return string
* @throws \Exception
* @throws \Magento\Framework\Exception\FileSystemException
*/
public function getAdminBaseUrl()
{
$config = $this->configReader->load();
$adminSuffix = $config['backend']['frontName'];
return $this->getBaseUrl() . $adminSuffix . '/';
}
}
47 changes: 47 additions & 0 deletions Block/Adminhtml/Form/BackButton.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php
/**
* KiwiCommerce
*
* Do not edit or add to this file if you wish to upgrade to newer versions in the future.
* If you wish to customise this module for your needs.
* Please contact us https://kiwicommerce.co.uk/contacts.
*
* @category KiwiCommerce
* @package KiwiCommerce_CronScheduler
* @copyright Copyright (C) 2018 Kiwi Commerce Ltd (https://kiwicommerce.co.uk/)
* @license https://kiwicommerce.co.uk/magento2-extension-license/
*/

namespace KiwiCommerce\CronScheduler\Block\Adminhtml\Form;

use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;

/**
* Class BackButton
* @package KiwiCommerce\CronScheduler\Block\Adminhtml\Form
*/
class BackButton extends GenericButton implements ButtonProviderInterface
{
/**
* @return array
*/
public function getButtonData()
{
return [
'label' => __('Back'),
'on_click' => sprintf("location.href = '%s';", $this->getUrl('cronscheduler/job/listing')),
'class' => 'back',
'sort_order' => 10
];
}

/**
* Get URL for back (reset) button
*
* @return string
*/
public function getBackUrl()
{
return $this->getUrl('*/*/');
}
}
73 changes: 73 additions & 0 deletions Block/Adminhtml/Form/GenericButton.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php
/**
* KiwiCommerce
*
* Do not edit or add to this file if you wish to upgrade to newer versions in the future.
* If you wish to customise this module for your needs.
* Please contact us https://kiwicommerce.co.uk/contacts.
*
* @category KiwiCommerce
* @package KiwiCommerce_CronScheduler
* @copyright Copyright (C) 2018 Kiwi Commerce Ltd (https://kiwicommerce.co.uk/)
* @license https://kiwicommerce.co.uk/magento2-extension-license/
*/

namespace KiwiCommerce\CronScheduler\Block\Adminhtml\Form;

/**
* Class GenericButton
* @package KiwiCommerce\CronScheduler\Block\Adminhtml\Form
*/
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;
}

/**
* 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);
}
}
40 changes: 40 additions & 0 deletions Block/Adminhtml/Form/SaveButton.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php
/**
* KiwiCommerce
*
* Do not edit or add to this file if you wish to upgrade to newer versions in the future.
* If you wish to customise this module for your needs.
* Please contact us https://kiwicommerce.co.uk/contacts.
*
* @category KiwiCommerce
* @package KiwiCommerce_CronScheduler
* @copyright Copyright (C) 2018 Kiwi Commerce Ltd (https://kiwicommerce.co.uk/)
* @license https://kiwicommerce.co.uk/magento2-extension-license/
*/

namespace KiwiCommerce\CronScheduler\Block\Adminhtml\Form;

use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;

/**
* Class SaveButton
* @package KiwiCommerce\CronScheduler\Block\Adminhtml\Form
*/
class SaveButton extends GenericButton implements ButtonProviderInterface
{
/**
* @return array
*/
public function getButtonData()
{
return [
'label' => __('Save'),
'class' => 'save primary',
'data_attribute' => [
'mage-init' => ['button' => ['event' => 'save']],
'form-role' => 'save',
],
'sort_order' => 90,
];
}
}
Loading

0 comments on commit fb77b9d

Please sign in to comment.