Initial commit

This commit is contained in:
2019-11-20 07:44:43 +01:00
commit 5bf49c4a81
41188 changed files with 5459177 additions and 0 deletions

View File

@@ -0,0 +1,231 @@
<?php
/**
* 2007-2016 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 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/afl-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 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-2015 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
namespace OnBoarding;
class Configuration
{
private $translator;
public function __construct($translator)
{
$this->translator = $translator;
}
public function getConfiguration()
{
return array(
'templates' => array(
'lost',
'popup',
'tooltip',
),
'steps' => array(
'groups' => array(
array(
'steps' => array(
array(
'type' => 'popup',
'text' => array(
'type' => 'template',
'src' => 'welcome',
),
'options' => array(
'savepoint',
'hideFooter'
),
'page' => 'index.php?controller=AdminDashboard',
),
),
),
array(
'title' => $this->translator->trans('Let\'s create your first product', array(), 'Modules.Welcome.Admin'),
'subtitle' => array(
'1' => $this->translator->trans('What do you want to tell about it? Think about what your customers want to know.', array(), 'Modules.Welcome.Admin'),
'2' => $this->translator->trans('Add clear and attractive information. Don\'t worry, you can edit it later :)', array(), 'Modules.Welcome.Admin'),
),
'steps' => array(
array(
'type' => 'tooltip',
'text' => $this->translator->trans('Give your product a catchy name.', array(), 'Modules.Welcome.Admin'),
'options' => array(
'savepoint',
),
'page' => array(
'index.php/product/new',
'index.php/product/form',
),
'selector' => '#form_step1_name_1',
'position' => 'right',
),
array(
'type' => 'tooltip',
'text' => $this->translator->trans('Fill out the essential details in this tab. The other tabs are for more advanced information.', array(), 'Modules.Welcome.Admin'),
'page' => 'index.php/product/form',
'selector' => '#tab_step1',
'position' => 'right',
),
array(
'type' => 'tooltip',
'text' => $this->translator->trans('Add one or more pictures so your product looks tempting!', array(), 'Modules.Welcome.Admin'),
'page' => 'index.php/product/form',
'selector' => '#product-images-dropzone',
'position' => 'right',
),
array(
'type' => 'tooltip',
'text' => $this->translator->trans('How much do you want to sell it for?', array(), 'Modules.Welcome.Admin'),
'page' => 'index.php/product/form',
'selector' => '.right-column > .row > .col-md-12 > .form-group:nth-child(4) > .row > .col-md-6:first-child > .input-group',
'position' => 'left',
'action' => array(
'selector' => '#product_form_save_go_to_catalog_btn',
'action' => 'click',
),
),
array(
'type' => 'tooltip',
'text' => $this->translator->trans('Yay! You just created your first product. Looks good, right?', array(), 'Modules.Welcome.Admin'),
'page' => 'index.php/product/catalog',
'selector' => '#product_catalog_list table tr:first-child td:nth-child(3)',
'position' => 'left',
),
),
),
array(
'title' => $this->translator->trans('Give your shop its own identity', array(), 'Modules.Welcome.Admin'),
'subtitle' => array(
'1' => $this->translator->trans('How do you want your shop to look? What makes it so special?', array(), 'Modules.Welcome.Admin'),
'2' => $this->translator->trans('Customize your theme or choose the best design from our theme catalog.', array(), 'Modules.Welcome.Admin'),
),
'steps' => array(
array(
'type' => 'tooltip',
'text' => $this->translator->trans('A good way to start is to add your own logo here!', array(), 'Modules.Welcome.Admin'),
'options' => array(
'savepoint',
),
'page' => 'index.php?controller=AdminThemes',
'selector' => '#js_theme_form_container .tab-content.panel .btn:first-child',
'position' => 'right',
),
array(
'type' => 'tooltip',
'text' => $this->translator->trans('If you want something really special, have a look at the theme catalog!', array(), 'Modules.Welcome.Admin'),
'page' => 'index.php?controller=AdminThemesCatalog',
'selector' => '.addons-theme-one:first-child',
'position' => 'right',
),
),
),
array(
'title' => $this->translator->trans('Get your shop ready for payments', array(), 'Modules.Welcome.Admin'),
'subtitle' => array(
'1' => $this->translator->trans('How do you want your customers to pay you?', array(), 'Modules.Welcome.Admin'),
'2' => $this->translator->trans('Adapt your offer to your market: add the most popular payment methods for your customers!', array(), 'Modules.Welcome.Admin'),
),
'steps' => array(
array(
'type' => 'tooltip',
'text' => $this->translator->trans('These payment methods are already available to your customers.', array(), 'Modules.Welcome.Admin'),
'options' => array(
'savepoint',
),
'page' => 'index.php?controller=AdminPayment',
'selector' => '.modules_list_container_tab:first tr:first-child .text-muted',
'position' => 'right',
),
array(
'type' => 'tooltip',
'text' => $this->translator->trans('And you can choose to add other payment methods from here!', array(), 'Modules.Welcome.Admin'),
'page' => 'index.php?controller=AdminPayment',
'selector' => '.panel:eq(1) table tr:eq(0) td:eq(1)',
'position' => 'top',
),
),
),
array(
'title' => $this->translator->trans('Choose your shipping solutions', array(), 'Modules.Welcome.Admin'),
'subtitle' => array(
'1' => $this->translator->trans('How do you want to deliver your products?', array(), 'Modules.Welcome.Admin'),
'2' => $this->translator->trans('Select the shipping solutions the most likely to suit your customers! Create your own carrier or add a ready-made module.', array(), 'Modules.Welcome.Admin'),
),
'steps' => array(
array(
'type' => 'tooltip',
'text' => $this->translator->trans('Here are the shipping methods available on your shop today.', array(), 'Modules.Welcome.Admin'),
'options' => array(
'savepoint',
),
'page' => 'index.php?controller=AdminCarriers',
'selector' => '#table-carrier tr:eq(2) td:eq(3)',
'position' => 'right',
),
array(
'type' => 'tooltip',
'text' => $this->translator->trans('You can offer more delivery options by setting up additional carriers', array(), 'Modules.Welcome.Admin'),
'page' => 'index.php?controller=AdminCarriers',
'selector' => '.modules_list_container_tab tr:eq(0) .text-muted',
'position' => 'right',
),
),
),
array(
'title' => $this->translator->trans('Improve your shop with modules', array(), 'Modules.Welcome.Admin'),
'subtitle' => array(
'1' => $this->translator->trans('Add new features and manage existing ones thanks to modules.', array(), 'Modules.Welcome.Admin'),
'2' => $this->translator->trans('Some modules are already pre-installed, others may be free or paid modules - browse our selection and find out what is available!', array(), 'Modules.Welcome.Admin'),
),
'steps' => array(
array(
'type' => 'tooltip',
'text' => $this->translator->trans('Discover our module selection in the first tab. Manage your modules on the second one and be aware of notifications in the third tab.', array(), 'Modules.Welcome.Admin'),
'options' => array(
'savepoint',
),
'page' => 'index.php/module/catalog',
'selector' => '.page-head-tabs .tab:eq(0)',
'position' => 'right',
),
array(
'type' => 'popup',
'text' => array(
'type' => 'template',
'src' => 'end',
),
'options' => array(
'savepoint',
'hideFooter',
),
'page' => 'index.php/product/catalog',
),
),
),
),
),
);
}
}

View File

@@ -0,0 +1,295 @@
<?php
/**
* 2007-2016 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 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/afl-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 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-2015 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
namespace OnBoarding;
use Module;
use PrestaShopBundle\Service\Routing\Router;
class Configuration
{
/**
* Module Dependency
*/
const MODULE_MBO = 'ps_mbo';
const FAKE_ID = 123456789;
private $translator;
public function __construct($translator)
{
$this->translator = $translator;
}
public function getConfiguration(Router $router)
{
$contextLink = \Context::getContext()->link;
$productFormUrlPattern = $this->generateSfBaseUrl(
$router,
'admin_product_form',
['id' => static::FAKE_ID]
);
$data = [
'templates' => [
'lost',
'popup',
'tooltip',
],
'steps' => [
'groups' => [
[
'steps' => [
[
'type' => 'popup',
'text' => [
'type' => 'template',
'src' => 'welcome',
],
'options' => [
'savepoint',
'hideFooter',
],
'page' => $contextLink->getAdminLink('AdminDashboard'),
],
],
],
[
'title' => $this->translator->trans('Let\'s create your first product', [], 'Modules.Welcome.Admin'),
'subtitle' => [
'1' => $this->translator->trans('What do you want to tell about it? Think about what your customers want to know.', [], 'Modules.Welcome.Admin'),
'2' => $this->translator->trans('Add clear and attractive information. Don\'t worry, you can edit it later :)', [], 'Modules.Welcome.Admin'),
],
'steps' => [
[
'type' => 'tooltip',
'text' => $this->translator->trans('Give your product a catchy name.', [], 'Modules.Welcome.Admin'),
'options' => [
'savepoint',
],
'page' => [
$router->generate('admin_product_new'),
$productFormUrlPattern,
],
'selector' => '#form_step1_name_1',
'position' => 'right',
],
[
'type' => 'tooltip',
'text' => $this->translator->trans('Fill out the essential details in this tab. The other tabs are for more advanced information.', [], 'Modules.Welcome.Admin'),
'page' => $productFormUrlPattern,
'selector' => '#tab_step1',
'position' => 'right',
],
[
'type' => 'tooltip',
'text' => $this->translator->trans('Add one or more pictures so your product looks tempting!', [], 'Modules.Welcome.Admin'),
'page' => $productFormUrlPattern,
'selector' => '#product-images-dropzone',
'position' => 'right',
],
[
'type' => 'tooltip',
'text' => $this->translator->trans('How much do you want to sell it for?', [], 'Modules.Welcome.Admin'),
'page' => $productFormUrlPattern,
'selector' => '.right-column > .row > .col-md-12 > .form-group:nth-child(4) > .row > .col-md-6:first-child > .input-group',
'position' => 'left',
'action' => [
'selector' => '#product_form_save_go_to_catalog_btn',
'action' => 'click',
],
],
[
'type' => 'tooltip',
'text' => $this->translator->trans('Yay! You just created your first product. Looks good, right?', [], 'Modules.Welcome.Admin'),
'page' => $this->generateSfBaseUrl($router, 'admin_product_catalog'),
'selector' => '#product_catalog_list table tr:first-child td:nth-child(3)',
'position' => 'left',
],
],
],
[
'title' => $this->translator->trans('Give your shop its own identity', [], 'Modules.Welcome.Admin'),
'subtitle' => [
'1' => $this->translator->trans('How do you want your shop to look? What makes it so special?', [], 'Modules.Welcome.Admin'),
'2' => $this->translator->trans('Customize your theme or choose the best design from our theme catalog.', [], 'Modules.Welcome.Admin'),
],
'steps' => [
[
'type' => 'tooltip',
'text' => $this->translator->trans('A good way to start is to add your own logo here!', [], 'Modules.Welcome.Admin'),
'options' => [
'savepoint',
],
'page' => $contextLink->getAdminLink('AdminThemes'),
'selector' => '#js_theme_form_container .tab-content.panel .btn:first-child',
'position' => 'right',
],
[
'type' => 'tooltip',
'text' => $this->translator->trans('If you want something really special, have a look at the theme catalog!', [], 'Modules.Welcome.Admin'),
'page' => $contextLink->getAdminLink('AdminThemesCatalog'),
'selector' => '.addons-theme-one:first-child',
'position' => 'right',
],
],
],
],
],
];
$paymentSteps = [
'title' => $this->translator->trans('Get your shop ready for payments', [], 'Modules.Welcome.Admin'),
'subtitle' => [
'1' => $this->translator->trans('How do you want your customers to pay you?', [], 'Modules.Welcome.Admin'),
],
'steps' => [
[
'type' => 'tooltip',
'text' => $this->translator->trans('These payment methods are already available to your customers.', [], 'Modules.Welcome.Admin'),
'options' => [
'savepoint',
],
'page' => $contextLink->getAdminLink('AdminPayment'),
'selector' => '.modules_list_container_tab:first tr:first-child .text-muted, .card:eq(0) .text-muted:eq(0)',
'position' => 'right',
],
],
];
if (Module::isInstalled(self::MODULE_MBO) && Module::isEnabled(self::MODULE_MBO)) {
$paymentSteps['subtitle']['2'] = $this->translator->trans(
'Adapt your offer to your market: add the most popular payment methods for your customers!',
[],
'Modules.Welcome.Admin'
);
$paymentSteps['steps'][] = [
'type' => 'tooltip',
'text' => $this->translator->trans('And you can choose to add other payment methods from here!', [], 'Modules.Welcome.Admin'),
'page' => $contextLink->getAdminLink('AdminPayment'),
'selector' => '.panel:eq(1) table tr:eq(0) td:eq(1), .card:eq(1) .module-item-list div:eq(0) div:eq(1)',
'position' => 'top',
];
}
$data['steps']['groups'][] = $paymentSteps;
$shippingSteps = [
'title' => $this->translator->trans('Choose your shipping solutions', [], 'Modules.Welcome.Admin'),
'subtitle' => [
'1' => $this->translator->trans('How do you want to deliver your products?', [], 'Modules.Welcome.Admin'),
],
'steps' => [
[
'type' => 'tooltip',
'text' => $this->translator->trans('Here are the shipping methods available on your shop today.', [], 'Modules.Welcome.Admin'),
'options' => [
'savepoint',
],
'page' => $contextLink->getAdminLink('AdminCarriers'),
'selector' => '#table-carrier tr:eq(2) td:eq(3)',
'position' => 'right',
],
],
];
if (Module::isInstalled(self::MODULE_MBO) && Module::isEnabled(self::MODULE_MBO)) {
$shippingSteps['subtitle']['2'] = $this->translator->trans(
'Select the shipping solutions the most likely to suit your customers! Create your own carrier or add a ready-made module.',
[],
'Modules.Welcome.Admin'
);
$shippingSteps['steps'][] = [
'type' => 'tooltip',
'text' => $this->translator->trans('You can offer more delivery options by setting up additional carriers', [], 'Modules.Welcome.Admin'),
'page' => $contextLink->getAdminLink('AdminCarriers'),
'selector' => '.modules_list_container_tab tr:eq(0) .text-muted',
'position' => 'right',
];
}
$data['steps']['groups'][] = $shippingSteps;
$moduleSteps = [
'title' => $this->translator->trans('Improve your shop with modules', [], 'Modules.Welcome.Admin'),
'subtitle' => [
'1' => $this->translator->trans('Add new features and manage existing ones thanks to modules.', [], 'Modules.Welcome.Admin'),
'2' => $this->translator->trans('Some modules are already pre-installed, others may be free or paid modules - browse our selection and find out what is available!', [], 'Modules.Welcome.Admin'),
],
'steps' => [
[
'type' => 'tooltip',
'text' => $this->translator->trans('Discover our module selection in the first tab. Manage your modules on the second one and be aware of notifications in the third tab.', [], 'Modules.Welcome.Admin'),
'options' => [
'savepoint',
],
'page' => $router->generate('admin_module_catalog'),
'selector' => '.page-head-tabs .tab:eq(0)',
'position' => 'right',
],
[
'type' => 'popup',
'text' => [
'type' => 'template',
'src' => 'end',
],
'options' => [
'savepoint',
'hideFooter',
],
'page' => $this->generateSfBaseUrl($router, 'admin_module_catalog'),
],
],
];
$data['steps']['groups'][] = $moduleSteps;
return $data;
}
/**
* generate url pattern to recognize the route as the current step url
* here we replace the route specific parameters with wildcard to allow regexp matching
*
* @param \PrestaShopBundle\Service\Routing\Router $router
* @param $controller
* @param array $fakeParameters
*
* @return mixed|string
*/
protected function generateSfBaseUrl(Router $router, $controller, $fakeParameters = [])
{
$url = $router->getGenerator()->generate($controller, $fakeParameters);
$url = substr($url, strlen(basename(__PS_BASE_URI__)) + 1);
$url = str_replace('/' . basename(_PS_ADMIN_DIR_) . '/', '', $url);
$url = str_replace(array_values($fakeParameters), '.+', $url);
return $url;
}
}

View File

@@ -0,0 +1,239 @@
<?php
/**
* 2007-2016 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 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/afl-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 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-2015 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
namespace OnBoarding;
use Configuration as LegacyConfiguration;
/**
* OnBoarding main class.
*/
class OnBoarding
{
/** @var array */
private $configuration;
/** @var Translator */
private $translator;
private $smarty;
private $module;
/**
* OnBoarding constructor.
*
* @param Translator $translator Twig environment needed to manage the templates
*/
public function __construct($translator, $smarty, $module)
{
$this->translator = $translator;
$this->smarty = $smarty;
$this->module = $module;
$this->loadConfiguration();
}
/**
* Show the OnBoarding module content.
*/
public function showModuleContent()
{
$templates = array();
foreach ($this->configuration['templates'] as $template) {
$templates[] = array(
'name' => $template,
'content' => str_replace(array("\n", "\r", "\t"), "", $this->getTemplateContent("templates/$template")),
);
}
echo $this->getTemplateContent('content', array(
'currentStep' => $this->getCurrentStep(),
'totalSteps' => $this->getTotalSteps(),
'percent_real' => ($this->getCurrentStep() / $this->getTotalSteps()) * 100,
'percent_rounded' => round(($this->getCurrentStep() / $this->getTotalSteps())*100),
'isShutDown' => $this->isShutDown(),
'steps' => $this->configuration['steps'],
'jsonSteps' => json_encode($this->configuration['steps']),
'templates' => $templates,
));
}
/**
* Show the OnBoarding content for the nav bar.
*/
public function showModuleContentForNavBar($link)
{
echo $this->getTemplateContent('navbar', array(
'currentStep' => $this->getCurrentStep(),
'totalSteps' => $this->getTotalSteps(),
'percent_real' => ($this->getCurrentStep() / $this->getTotalSteps()) * 100,
'percent_rounded' => round(($this->getCurrentStep() / $this->getTotalSteps())*100),
'link' => $link->getAdminLink('AdminWelcome'),
));
}
/**
* Set the current step.
*
* @param int $step Current step ID
*
* @return bool Success of the configuration update
*/
public function setCurrentStep($step)
{
return LegacyConfiguration::updateValue('ONBOARDINGV2_CURRENT_STEP', $step);
}
/**
* Set the shut down status.
*
* @param bool $status Onboarding shut downed or not
*
* @return bool Success of the configuration update
*/
public function setShutDown($status)
{
return LegacyConfiguration::updateValue('ONBOARDINGV2_SHUT_DOWN', $status);
}
/**
* Return true if the OnBoarding is finished.
*
* @return bool True if the OnBoarding is finished
*/
public function isFinished()
{
return $this->getCurrentStep() >= $this->getTotalSteps();
}
/**
* Load all the steps with the localized texts.
*
* @param string $configPath Path where the configuration can be loaded
*/
private function loadConfiguration()
{
$configuration = new Configuration($this->translator);
$configuration = $configuration->getConfiguration();
foreach ($configuration['steps']['groups'] as &$currentGroup) {
if (isset($currentGroup['title'])) {
$currentGroup['title'] = $this->getTextFromSettings($currentGroup['title']);
}
if (isset($currentGroup['subtitle'])) {
foreach ($currentGroup['subtitle'] as &$subtitle) {
$subtitle = $this->getTextFromSettings($subtitle);
}
}
foreach ($currentGroup['steps'] as &$currentStep) {
$currentStep['text'] = $this->getTextFromSettings($currentStep['text']);
}
}
$this->configuration = $configuration;
}
/**
* Return a text from step text configuration.
*
* @param array $text Step text configuration
*
* @return string|null Text if it exists
*/
private function getTextFromSettings($text)
{
if (is_array($text)) {
switch ($text['type']) {
case 'template':
return $this->getTemplateContent('contents/'.$text['src']);
}
}
return $text;
}
/**
* Echoes a template.
*
* @param string $templateName Template name
*/
public function showTemplate($templateName)
{
echo $this->getTemplateContent($templateName);
}
/**
* Return a template.
*
* @param string $templateName Template name
* @param array $additionnalParameters Additionnal parameters to inject on the Twig template
*
* @return string Parsed template
*/
private function getTemplateContent($templateName, $additionnalParameters = array())
{
$this->smarty->assign($additionnalParameters);
return $this->module->fetch(__DIR__.'/../views/'.$templateName.'.tpl');
}
/**
* Return the current step.
*
* @return int Current step
*/
private function getCurrentStep()
{
return (int)LegacyConfiguration::get('ONBOARDINGV2_CURRENT_STEP');
}
/**
* Return the steps count.
*
* @return int Steps count
*/
private function getTotalSteps()
{
$total = 0;
if (null != $this->configuration) {
foreach ($this->configuration['steps']['groups'] as &$group) {
$total += count($group['steps']);
}
}
return $total;
}
/**
* Return the shut down status.
*
* @return bool Shut down status
*/
private function isShutDown()
{
return (int)LegacyConfiguration::get('ONBOARDINGV2_SHUT_DOWN');
}
}

View File

@@ -0,0 +1,240 @@
<?php
/**
* 2007-2016 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 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/afl-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 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-2015 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
namespace OnBoarding;
use Configuration as LegacyConfiguration;
use PrestaShopBundle\Service\Routing\Router;
/**
* OnBoarding main class.
*/
class OnBoarding
{
/** @var array */
private $configuration;
/** @var Translator */
private $translator;
private $smarty;
private $module;
/**
* OnBoarding constructor.
*
* @param Translator $translator Twig environment needed to manage the templates
*/
public function __construct($translator, $smarty, $module, Router $router)
{
$this->translator = $translator;
$this->smarty = $smarty;
$this->module = $module;
$this->loadConfiguration($router);
}
/**
* Show the OnBoarding module content.
*/
public function showModuleContent()
{
$templates = array();
foreach ($this->configuration['templates'] as $template) {
$templates[] = array(
'name' => $template,
'content' => str_replace(array("\n", "\r", "\t"), "", $this->getTemplateContent("templates/$template")),
);
}
echo $this->getTemplateContent('content', array(
'currentStep' => $this->getCurrentStep(),
'totalSteps' => $this->getTotalSteps(),
'percent_real' => ($this->getCurrentStep() / $this->getTotalSteps()) * 100,
'percent_rounded' => round(($this->getCurrentStep() / $this->getTotalSteps())*100),
'isShutDown' => $this->isShutDown(),
'steps' => $this->configuration['steps'],
'jsonSteps' => json_encode($this->configuration['steps']),
'templates' => $templates,
));
}
/**
* Show the OnBoarding content for the nav bar.
*/
public function showModuleContentForNavBar($link)
{
echo $this->getTemplateContent('navbar', array(
'currentStep' => $this->getCurrentStep(),
'totalSteps' => $this->getTotalSteps(),
'percent_real' => ($this->getCurrentStep() / $this->getTotalSteps()) * 100,
'percent_rounded' => round(($this->getCurrentStep() / $this->getTotalSteps())*100),
'link' => $link->getAdminLink('AdminWelcome'),
));
}
/**
* Set the current step.
*
* @param int $step Current step ID
*
* @return bool Success of the configuration update
*/
public function setCurrentStep($step)
{
return LegacyConfiguration::updateValue('ONBOARDINGV2_CURRENT_STEP', $step);
}
/**
* Set the shut down status.
*
* @param bool $status Onboarding shut downed or not
*
* @return bool Success of the configuration update
*/
public function setShutDown($status)
{
return LegacyConfiguration::updateValue('ONBOARDINGV2_SHUT_DOWN', $status);
}
/**
* Return true if the OnBoarding is finished.
*
* @return bool True if the OnBoarding is finished
*/
public function isFinished()
{
return $this->getCurrentStep() >= $this->getTotalSteps();
}
/**
* Load all the steps with the localized texts.
*
* @param string $configPath Path where the configuration can be loaded
*/
private function loadConfiguration(Router $router)
{
$configuration = new Configuration($this->translator);
$configuration = $configuration->getConfiguration($router);
foreach ($configuration['steps']['groups'] as &$currentGroup) {
if (isset($currentGroup['title'])) {
$currentGroup['title'] = $this->getTextFromSettings($currentGroup['title']);
}
if (isset($currentGroup['subtitle'])) {
foreach ($currentGroup['subtitle'] as &$subtitle) {
$subtitle = $this->getTextFromSettings($subtitle);
}
}
foreach ($currentGroup['steps'] as &$currentStep) {
$currentStep['text'] = $this->getTextFromSettings($currentStep['text']);
}
}
$this->configuration = $configuration;
}
/**
* Return a text from step text configuration.
*
* @param array $text Step text configuration
*
* @return string|null Text if it exists
*/
private function getTextFromSettings($text)
{
if (is_array($text)) {
switch ($text['type']) {
case 'template':
return $this->getTemplateContent('contents/'.$text['src']);
}
}
return $text;
}
/**
* Echoes a template.
*
* @param string $templateName Template name
*/
public function showTemplate($templateName)
{
echo $this->getTemplateContent($templateName);
}
/**
* Return a template.
*
* @param string $templateName Template name
* @param array $additionnalParameters Additionnal parameters to inject on the Twig template
*
* @return string Parsed template
*/
private function getTemplateContent($templateName, $additionnalParameters = array())
{
$this->smarty->assign($additionnalParameters);
return $this->module->fetch(__DIR__.'/../views/'.$templateName.'.tpl');
}
/**
* Return the current step.
*
* @return int Current step
*/
private function getCurrentStep()
{
return (int)LegacyConfiguration::get('ONBOARDINGV2_CURRENT_STEP');
}
/**
* Return the steps count.
*
* @return int Steps count
*/
private function getTotalSteps()
{
$total = 0;
if (null != $this->configuration) {
foreach ($this->configuration['steps']['groups'] as &$group) {
$total += count($group['steps']);
}
}
return $total;
}
/**
* Return the shut down status.
*
* @return bool Shut down status
*/
private function isShutDown()
{
return (int)LegacyConfiguration::get('ONBOARDINGV2_SHUT_DOWN');
}
}