// Added Translations KPIs
This commit is contained in:
@@ -216,6 +216,21 @@ class AdminStatsControllerCore extends AdminStatsTabController
|
||||
return array('type' => 'neutral', 'value' => round(100 * $row['neutral'] / $row['total']));
|
||||
}
|
||||
|
||||
public static function getMainCountry($date_from, $date_to)
|
||||
{
|
||||
$total_orders = AdminStatsController::getOrders($date_from, $date_to);
|
||||
if (!$total_orders)
|
||||
return false;
|
||||
$row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
|
||||
SELECT a.id_country, COUNT(*) as orders
|
||||
FROM `'._DB_PREFIX_.'orders` o
|
||||
LEFT JOIN `'._DB_PREFIX_.'address` a ON o.id_address_delivery = a.id_address
|
||||
WHERE `invoice_date` BETWEEN "'.pSQL($date_from).' 00:00:00" AND "'.pSQL($date_to).' 23:59:59"
|
||||
'.Shop::addSqlRestriction(Shop::SHARE_ORDER));
|
||||
$row['orders'] = round(100 * $row['orders'] / $total_orders, 1);
|
||||
return $row;
|
||||
}
|
||||
|
||||
public static function getAverageCustomerAge()
|
||||
{
|
||||
$value = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
|
||||
@@ -408,6 +423,44 @@ class AdminStatsControllerCore extends AdminStatsTabController
|
||||
ConfigurationKPI::updateValue('NEWSLETTER_REGISTRATIONS_EXPIRE', strtotime('+6 hour'));
|
||||
break;
|
||||
|
||||
case 'enabled_languages':
|
||||
$value = Language::countActiveLanguages();
|
||||
ConfigurationKPI::updateValue('ENABLED_LANGUAGES', $value);
|
||||
ConfigurationKPI::updateValue('ENABLED_LANGUAGES_EXPIRE', strtotime('+1 min'));
|
||||
break;
|
||||
|
||||
case 'frontoffice_translations':
|
||||
$themes = Theme::getThemes();
|
||||
$languages = Language::getLanguages();
|
||||
$total = $translated = 0;
|
||||
foreach ($themes as $theme)
|
||||
foreach ($languages as $language)
|
||||
{
|
||||
$kpi_key = substr(strtoupper($theme->name.'_'.$language['iso_code']), 0, 16);
|
||||
$total += ConfigurationKPI::get('TRANSLATE_TOTAL_'.$kpi_key);
|
||||
$translated += ConfigurationKPI::get('TRANSLATE_DONE_'.$kpi_key);
|
||||
}
|
||||
$value = 0;
|
||||
if ($translated)
|
||||
$value = round(100 * $translated / $total, 1);
|
||||
$value .= '%';
|
||||
ConfigurationKPI::updateValue('FRONTOFFICE_TRANSLATIONS', $value);
|
||||
ConfigurationKPI::updateValue('FRONTOFFICE_TRANSLATIONS_EXPIRE', strtotime('+2 min'));
|
||||
break;
|
||||
|
||||
case 'main_country':
|
||||
if (!($row = AdminStatsController::getMainCountry(date('Y-m-d', strtotime('-30 day')), date('Y-m-d'))))
|
||||
$value = $this->l('No orders');
|
||||
else
|
||||
{
|
||||
$country = new Country($row['id_country'], $this->context->language->id);
|
||||
$value = sprintf($this->l('%.1f%% %s'), $row['orders'], $country->name);
|
||||
}
|
||||
|
||||
ConfigurationKPI::updateValue('MAIN_COUNTRY', array($this->context->language->id => $value));
|
||||
ConfigurationKPI::updateValue('MAIN_COUNTRY_EXPIRE', array($this->context->language->id => strtotime('+1 day')));
|
||||
break;
|
||||
|
||||
case 'orders_per_customer':
|
||||
$value = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
|
||||
SELECT COUNT(*)
|
||||
|
||||
@@ -207,7 +207,11 @@ class AdminTranslationsControllerCore extends AdminController
|
||||
|
||||
$this->toolbar_scroll = false;
|
||||
$this->base_tpl_view = 'main.tpl';
|
||||
return parent::renderView();
|
||||
|
||||
$this->content .= $this->renderKpis();
|
||||
$this->content .= parent::renderView();
|
||||
|
||||
return $this->content;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -280,6 +284,7 @@ class AdminTranslationsControllerCore extends AdminController
|
||||
elseif (!touch($file_path))
|
||||
throw new PrestaShopException(sprintf(Tools::displayError('File "%s" cannot be created'), $file_path));
|
||||
}
|
||||
$kpi_key = substr(strtoupper(Tools::getValue('theme').'_'.Tools::getValue('lang')), 0, 16);
|
||||
|
||||
if ($fd = fopen($file_path, 'w'))
|
||||
{
|
||||
@@ -305,6 +310,9 @@ class AdminTranslationsControllerCore extends AdminController
|
||||
if (!empty($value))
|
||||
$to_insert[$key] = $value;
|
||||
|
||||
ConfigurationKPI::updateValue('TRANSLATE_TOTAL_'.$kpi_key, count($_POST));
|
||||
ConfigurationKPI::updateValue('TRANSLATE_DONE_'.$kpi_key, count($to_insert));
|
||||
|
||||
// translations array is ordered by key (easy merge)
|
||||
ksort($to_insert);
|
||||
$tab = $translation_informations['var'];
|
||||
@@ -1227,6 +1235,51 @@ class AdminTranslationsControllerCore extends AdminController
|
||||
$this->getTranslationsInformations();
|
||||
}
|
||||
|
||||
public function renderKpis()
|
||||
{
|
||||
$time = time();
|
||||
$kpis = array();
|
||||
|
||||
/* The data generation is located in AdminStatsControllerCore */
|
||||
|
||||
$helper = new HelperKpi();
|
||||
$helper->id = 'box-languages';
|
||||
$helper->icon = 'icon-microphone';
|
||||
$helper->color = 'color1';
|
||||
$helper->title = $this->l('Enabled Languages');
|
||||
if (ConfigurationKPI::get('ENABLED_LANGUAGES') !== false)
|
||||
$helper->value = ConfigurationKPI::get('ENABLED_LANGUAGES');
|
||||
if (ConfigurationKPI::get('ENABLED_LANGUAGES_EXPIRE') < $time)
|
||||
$helper->source = $this->context->link->getAdminLink('AdminStats').'&ajax=1&action=getKpi&kpi=enabled_languages';
|
||||
$kpis[] = $helper->generate();
|
||||
|
||||
$helper = new HelperKpi();
|
||||
$helper->id = 'box-country';
|
||||
$helper->icon = 'icon-home';
|
||||
$helper->color = 'color2';
|
||||
$helper->title = $this->l('Main Country');
|
||||
$helper->subtitle = $this->l('30 Days');
|
||||
if (ConfigurationKPI::get('MAIN_COUNTRY', $this->context->language->id) !== false)
|
||||
$helper->value = ConfigurationKPI::get('MAIN_COUNTRY', $this->context->language->id);
|
||||
if (ConfigurationKPI::get('MAIN_COUNTRY_EXPIRE', $this->context->language->id) < $time)
|
||||
$helper->source = $this->context->link->getAdminLink('AdminStats').'&ajax=1&action=getKpi&kpi=main_country';
|
||||
$kpis[] = $helper->generate();
|
||||
|
||||
$helper = new HelperKpi();
|
||||
$helper->id = 'box-country';
|
||||
$helper->icon = 'icon-list';
|
||||
$helper->color = 'color3';
|
||||
$helper->title = $this->l('Front Office Translations');
|
||||
if (ConfigurationKPI::get('FRONTOFFICE_TRANSLATIONS') !== false)
|
||||
$helper->value = ConfigurationKPI::get('FRONTOFFICE_TRANSLATIONS');
|
||||
if (ConfigurationKPI::get('FRONTOFFICE_TRANSLATIONS_EXPIRE') < $time)
|
||||
$helper->source = $this->context->link->getAdminLink('AdminStats').'&ajax=1&action=getKpi&kpi=frontoffice_translations';
|
||||
$kpis[] = $helper->generate();
|
||||
|
||||
$helper = new HelperKpiRow();
|
||||
$helper->kpis = $kpis;
|
||||
return $helper->generate();
|
||||
}
|
||||
|
||||
/**
|
||||
* AdminController::postProcess() override
|
||||
@@ -1253,35 +1306,28 @@ class AdminTranslationsControllerCore extends AdminController
|
||||
else
|
||||
$this->errors[] = Tools::displayError('You do not have permission to add this.');
|
||||
}
|
||||
else if (Tools::isSubmit('submitExport'))
|
||||
elseif (Tools::isSubmit('submitExport'))
|
||||
{
|
||||
if ($this->tabAccess['add'] === '1')
|
||||
$this->submitExportLang();
|
||||
else
|
||||
$this->errors[] = Tools::displayError('You do not have permission to add this.');
|
||||
}
|
||||
else if (Tools::isSubmit('submitImport'))
|
||||
elseif (Tools::isSubmit('submitImport'))
|
||||
{
|
||||
if ($this->tabAccess['add'] === '1')
|
||||
$this->submitImportLang();
|
||||
else
|
||||
$this->errors[] = Tools::displayError('You do not have permission to add this.');
|
||||
}
|
||||
else if (Tools::isSubmit('submitAddLanguage'))
|
||||
elseif (Tools::isSubmit('submitAddLanguage'))
|
||||
{
|
||||
if ($this->tabAccess['add'] === '1')
|
||||
$this->submitAddLang();
|
||||
else
|
||||
$this->errors[] = Tools::displayError('You do not have permission to add this.');
|
||||
}
|
||||
else if (Tools::isSubmit('submitTranslationsFront'))
|
||||
{
|
||||
if ($this->tabAccess['edit'] === '1')
|
||||
$this->writeTranslationFile();
|
||||
else
|
||||
$this->errors[] = Tools::displayError('You do not have permission to edit this.');
|
||||
}
|
||||
else if (Tools::isSubmit('submitTranslationsPdf'))
|
||||
elseif (Tools::isSubmit('submitTranslationsPdf'))
|
||||
{
|
||||
if ($this->tabAccess['edit'] === '1')
|
||||
// Only the PrestaShop team should write the translations into the _PS_TRANSLATIONS_DIR_
|
||||
@@ -1292,36 +1338,21 @@ class AdminTranslationsControllerCore extends AdminController
|
||||
else
|
||||
$this->errors[] = Tools::displayError('You do not have permission to edit this.');
|
||||
}
|
||||
else if (Tools::isSubmit('submitTranslationsBack'))
|
||||
elseif (Tools::isSubmit('submitTranslationsBack') || Tools::isSubmit('submitTranslationsErrors') || Tools::isSubmit('submitTranslationsFields') || Tools::isSubmit('submitTranslationsFront'))
|
||||
{
|
||||
if ($this->tabAccess['edit'] === '1')
|
||||
$this->writeTranslationFile();
|
||||
else
|
||||
$this->errors[] = Tools::displayError('You do not have permission to edit this.');
|
||||
}
|
||||
else if (Tools::isSubmit('submitTranslationsErrors'))
|
||||
{
|
||||
if ($this->tabAccess['edit'] === '1')
|
||||
$this->writeTranslationFile();
|
||||
else
|
||||
$this->errors[] = Tools::displayError('You do not have permission to edit this.');
|
||||
}
|
||||
else if (Tools::isSubmit('submitTranslationsFields'))
|
||||
{
|
||||
if ($this->tabAccess['edit'] === '1')
|
||||
$this->writeTranslationFile();
|
||||
else
|
||||
$this->errors[] = Tools::displayError('You do not have permission to edit this.');
|
||||
|
||||
}
|
||||
else if (Tools::isSubmit('submitTranslationsMails') || Tools::isSubmit('submitTranslationsMailsAndStay'))
|
||||
elseif (Tools::isSubmit('submitTranslationsMails') || Tools::isSubmit('submitTranslationsMailsAndStay'))
|
||||
{
|
||||
if ($this->tabAccess['edit'] === '1')
|
||||
$this->submitTranslationsMails();
|
||||
else
|
||||
$this->errors[] = Tools::displayError('You do not have permission to edit this.');
|
||||
}
|
||||
else if (Tools::isSubmit('submitTranslationsModules'))
|
||||
elseif (Tools::isSubmit('submitTranslationsModules'))
|
||||
{
|
||||
if ($this->tabAccess['edit'] === '1')
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user