-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Introducing reusable way to display KPIs blocks in Back Office modern pages #9242
Changes from 6 commits
b1e36ad
77929ae
5d597c3
8f2f542
209832b
24c50b8
443d127
58023a9
d63f347
80c5b7d
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,55 @@ | ||
<?php | ||
/** | ||
* 2007-2018 PrestaShop | ||
* | ||
* 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: | ||
* https://opensource.org/licenses/OSL-3.0 | ||
* 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 license@prestashop.com so we can send you a copy immediately. | ||
* | ||
* DISCLAIMER | ||
* | ||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer | ||
* versions in the future. If you wish to customize PrestaShop for your | ||
* needs please refer to http://www.prestashop.com for more information. | ||
* | ||
* @author PrestaShop SA <contact@prestashop.com> | ||
* @copyright 2007-2018 PrestaShop SA | ||
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) | ||
* International Registered Trademark & Property of PrestaShop SA | ||
*/ | ||
|
||
namespace PrestaShop\PrestaShop\Adapter\Configuration; | ||
|
||
use ConfigurationKPI; | ||
use PrestaShop\PrestaShop\Adapter\Configuration; | ||
|
||
/** | ||
* Class KpiConfiguration provides access to legacy ConfigurationKpi methods | ||
*/ | ||
class KpiConfiguration extends Configuration | ||
{ | ||
/** | ||
* Changes configuration definition before calling it's methods | ||
* | ||
* @param $name | ||
* @param $arguments | ||
* | ||
* @return mixed | ||
*/ | ||
public function __call($name, $arguments) | ||
{ | ||
if (is_callable([$this, $name])) { | ||
ConfigurationKPI::setKpiDefinition(); | ||
$result = call_user_func([$this, $name], $arguments); | ||
ConfigurationKPI::unsetKpiDefinition(); | ||
|
||
return $result; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
<?php | ||
/** | ||
* 2007-2018 PrestaShop | ||
* | ||
* 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: | ||
* https://opensource.org/licenses/OSL-3.0 | ||
* 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 license@prestashop.com so we can send you a copy immediately. | ||
* | ||
* DISCLAIMER | ||
* | ||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer | ||
* versions in the future. If you wish to customize PrestaShop for your | ||
* needs please refer to http://www.prestashop.com for more information. | ||
* | ||
* @author PrestaShop SA <contact@prestashop.com> | ||
* @copyright 2007-2018 PrestaShop SA | ||
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) | ||
* International Registered Trademark & Property of PrestaShop SA | ||
*/ | ||
|
||
namespace PrestaShop\PrestaShop\Adapter\Kpi; | ||
|
||
use HelperKpi; | ||
use PrestaShop\PrestaShop\Adapter\LegacyContext; | ||
use PrestaShop\PrestaShop\Core\ConfigurationInterface; | ||
use PrestaShop\PrestaShop\Core\Kpi\KpiInterface; | ||
use Symfony\Component\Translation\TranslatorInterface; | ||
|
||
/** | ||
* Class EnabledLanguagesKpi is an implementation for enabled languages KPI | ||
*/ | ||
final class EnabledLanguagesKpi implements KpiInterface | ||
{ | ||
/** | ||
* @var TranslatorInterface | ||
*/ | ||
private $translator; | ||
|
||
/** | ||
* @var ConfigurationInterface | ||
*/ | ||
private $configuration; | ||
|
||
/** | ||
* @var LegacyContext | ||
*/ | ||
private $legacyContext; | ||
|
||
/** | ||
* @param LegacyContext $legacyContext | ||
* @param TranslatorInterface $translator | ||
* @param ConfigurationInterface $configuration | ||
*/ | ||
public function __construct( | ||
LegacyContext $legacyContext, | ||
TranslatorInterface $translator, | ||
ConfigurationInterface $configuration | ||
) { | ||
$this->translator = $translator; | ||
$this->configuration = $configuration; | ||
$this->legacyContext = $legacyContext; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function render() | ||
{ | ||
$enabledLanguages = $this->configuration->get('ENABLED_LANGUAGES'); | ||
|
||
$kpi = new HelperKpi(); | ||
$kpi->context->smarty->setTemplateDir(_PS_BO_ALL_THEMES_DIR_.'new-theme/template/'); | ||
$kpi->id = 'box-languages'; | ||
$kpi->icon = 'mic'; | ||
$kpi->color = 'color1'; | ||
$kpi->href = $this->legacyContext->getAdminLink('AdminLanguages'); | ||
$kpi->title = $this->translator->trans('Enabled Languages', [], 'Admin.International.Feature'); | ||
|
||
if (false !== $enabledLanguages) { | ||
$kpi->value = $enabledLanguages; | ||
} | ||
|
||
$params = [ | ||
'ajax' => 1, | ||
'action' => 'getKpi', | ||
'kpi' => 'enabled_languages', | ||
]; | ||
$kpi->source = $this->legacyContext->getAdminLink('AdminStats', true, $params); | ||
$kpi->refresh = $this->configuration->get('ENABLED_LANGUAGES_EXPIRE') < time(); | ||
|
||
return $kpi->generate(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
<?php | ||
/** | ||
* 2007-2018 PrestaShop | ||
* | ||
* 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: | ||
* https://opensource.org/licenses/OSL-3.0 | ||
* 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 license@prestashop.com so we can send you a copy immediately. | ||
* | ||
* DISCLAIMER | ||
* | ||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer | ||
* versions in the future. If you wish to customize PrestaShop for your | ||
* needs please refer to http://www.prestashop.com for more information. | ||
* | ||
* @author PrestaShop SA <contact@prestashop.com> | ||
* @copyright 2007-2018 PrestaShop SA | ||
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) | ||
* International Registered Trademark & Property of PrestaShop SA | ||
*/ | ||
|
||
namespace PrestaShop\PrestaShop\Adapter\Kpi; | ||
|
||
use HelperKpi; | ||
use PrestaShop\PrestaShop\Adapter\LegacyContext; | ||
use PrestaShop\PrestaShop\Core\ConfigurationInterface; | ||
use PrestaShop\PrestaShop\Core\Kpi\KpiInterface; | ||
use Symfony\Component\Translation\TranslatorInterface; | ||
|
||
/** | ||
* Class MainCountryKpi is an implementation for main countries KPI | ||
*/ | ||
final class MainCountryKpi implements KpiInterface | ||
{ | ||
/** | ||
* @var TranslatorInterface | ||
*/ | ||
private $translator; | ||
|
||
/** | ||
* @var ConfigurationInterface | ||
*/ | ||
private $configuration; | ||
|
||
/** | ||
* @var LegacyContext | ||
*/ | ||
private $legacyContext; | ||
|
||
/** | ||
* @param LegacyContext $legacyContext | ||
* @param TranslatorInterface $translator | ||
* @param ConfigurationInterface $configuration | ||
*/ | ||
public function __construct( | ||
LegacyContext $legacyContext, | ||
TranslatorInterface $translator, | ||
ConfigurationInterface $configuration | ||
) { | ||
$this->translator = $translator; | ||
$this->configuration = $configuration; | ||
$this->legacyContext = $legacyContext; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function render() | ||
{ | ||
$mainCountry = $this->configuration->get('MAIN_COUNTRY'); | ||
|
||
$kpi = new HelperKpi(); | ||
$kpi->context->smarty->setTemplateDir(_PS_BO_ALL_THEMES_DIR_.'new-theme/template/'); | ||
$kpi->id = 'box-country'; | ||
$kpi->icon = 'home'; | ||
$kpi->color = 'color2'; | ||
$kpi->title = $this->translator->trans('Main Country', [], 'Admin.International.Feature'); | ||
$kpi->subtitle = $this->translator->trans('30 Days', [], 'Admin.Global'); | ||
|
||
if (false !== $mainCountry) { | ||
$kpi->value = $mainCountry; | ||
} | ||
|
||
$params = [ | ||
'ajax' => 1, | ||
'action' => 'getKpi', | ||
'kpi' => 'main_country', | ||
]; | ||
$kpi->source = $this->legacyContext->getAdminLink('AdminStats', true, $params); | ||
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. if you only need legacy context to render an url, how about making this url an argument of your constructor instead? :) 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. oh yes, good idea :) no need to inject the whole context 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. my 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. hehe now everyone knows! 🙈 |
||
$kpi->refresh = $this->configuration->get('MAIN_COUNTRY_EXPIRE') < time(); | ||
|
||
return $kpi->generate(); | ||
} | ||
} |
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.
Didn't want to increase the scope of this PR so I'm still relying on legacy HelperKpi to render the view, but the overall kpi implementation is not dependent on legacy code.
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.
you're right :) it's the main purpose of using adapters