Skip to content
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

[MBO-94] Remove badges and Merchant expertise page #105

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## About

Check your completion rate and unblock all badges to become an e-commerce expert within the blink of an eye!
Pushes advices about your shop and modules

### Execute the test suite

Expand Down
131 changes: 0 additions & 131 deletions classes/Badge.php

This file was deleted.

154 changes: 2 additions & 152 deletions classes/Condition.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,36 +86,6 @@ public static function getIdByIdPs($id_ps_condition)
public static function getIdsByHookCalculation($hook_name)
{
$ids = [];
$in = [];

$sub_query = new DbQuery();
$sub_query->select('id_badge');
$sub_query->from('badge', 'b');
$sub_query->where('b.`validated` = 0');

$sub_results = Db::getInstance()->executeS($sub_query);

foreach ($sub_results as $sub_result) {
$in[] = $sub_result['id_badge'];
}

$query = new DbQuery();
$query->select('c.`id_condition`');
$query->from('condition', 'c');
$query->join('LEFT JOIN `' . _DB_PREFIX_ . 'condition_badge` cb ON cb.`id_condition` = c.`id_condition`');
$query->where('c.`calculation_type` = \'hook\'');
$query->where('c.`calculation_detail` = \'' . pSQL($hook_name) . '\'');
$query->where('c.`validated` = 0');
if (count($in)) {
$query->where('cb.`id_badge` IN (' . implode(',', $in) . ')');
}
$query->groupBy('c.`id_condition`');

$result = Db::getInstance()->executeS($query);

foreach ($result as $r) {
$ids[] = $r['id_condition'];
}

$sub_query = new DbQuery();
$sub_query->select('id_advice');
Expand Down Expand Up @@ -149,127 +119,6 @@ public static function getIdsByHookCalculation($hook_name)
return array_unique($ids);
}

public static function getIdsDailyCalculation()
{
$ids = [];
$in = [];

//badges conditions validation
$sub_query = new DbQuery();
$sub_query->select('id_badge');
$sub_query->from('badge', 'b');

$sub_results = Db::getInstance()->executeS($sub_query);

foreach ($sub_results as $sub_result) {
$in[] = $sub_result['id_badge'];
}

$query = new DbQuery();
$query->select('c.`id_condition`');
$query->from('condition', 'c');
$query->join('LEFT JOIN `' . _DB_PREFIX_ . 'condition_badge` cb ON cb.`id_condition` = c.`id_condition`');
$query->where('c.`calculation_type` = \'time\'');
$query->where('DATEDIFF(NOW(), `date_upd`) >= `calculation_detail`');
$query->where('c.`validated` = 0');
if (count($in)) {
$query->where('cb.`id_badge` IN (' . implode(',', $in) . ')');
}
$query->groupBy('c.`id_condition`');

$result = Db::getInstance()->executeS($query);

foreach ($result as $r) {
$ids[] = $r['id_condition'];
}

//advice conditions validation
$sub_query = new DbQuery();
$sub_query->select('id_advice');
$sub_query->from('advice', 'a');

$sub_results = Db::getInstance()->executeS($sub_query);

$in = [];

foreach ($sub_results as $sub_result) {
$in[] = $sub_result['id_advice'];
}

$query = new DbQuery();
$query->select('c.`id_condition`');
$query->from('condition', 'c');
$query->join('LEFT JOIN `' . _DB_PREFIX_ . 'condition_advice` ca ON ca.`id_condition` = c.`id_condition`');
$query->where('c.`calculation_type` = \'time\'');
$query->where('DATEDIFF(NOW(), `date_upd`) >= `calculation_detail`');
$query->where('c.`validated` = 0');
if (count($in)) {
$query->where('ca.`id_advice` IN (' . implode(',', $in) . ')');
}
$query->groupBy('c.`id_condition`');

$result = Db::getInstance()->executeS($query);
foreach ($result as $r) {
$ids[] = $r['id_condition'];
}

return array_unique($ids);
}

public static function getIdsByBadgeGroupPosition($badge_group_position)
{
$ids = [];

$sub_query = new DbQuery();
$sub_query->select('id_badge');
$sub_query->from('badge', 'b');
$sub_query->where('b.`group_position` = ' . (int) $badge_group_position);
$sub_query->where('b.`validated` = 0');
$sub_query->groupBy('b.`id_group`');

$query = new DbQuery();
$query->select('c.`id_condition`');
$query->from('condition', 'c');
$query->join('LEFT JOIN `' . _DB_PREFIX_ . 'condition_badge` cb ON cb.`id_condition` = c.`id_condition`');
$query->where('c.`validated` = 0');
$query->where('cb.`id_badge` IN (' . $sub_query . ')');
$query->groupBy('c.`id_condition`');

$result = Db::getInstance()->executeS($query);
foreach ($result as $r) {
$ids[] = $r['id_condition'];
}

return $ids;
}

public static function getIdsByBadgeGroup($badge_group)
{
$ids = [];

$sub_query = new DbQuery();
$sub_query->select('id_badge');
$sub_query->from('badge', 'b');
$sub_query->where('b.`id_group` = ' . (int) $badge_group);
$sub_query->where('b.`validated` = 0');
$sub_query->groupBy('b.`id_group`');

$query = new DbQuery();
$query->select('c.`id_condition`');
$query->from('condition', 'c');
$query->join('LEFT JOIN `' . _DB_PREFIX_ . 'condition_badge` cb ON cb.`id_condition` = c.`id_condition`');
$query->where('c.`validated` = 0');
$query->where('cb.`id_badge` IN (' . $sub_query . ')');
$query->groupBy('c.`id_condition`');

$result = Db::getInstance()->executeS($query);
foreach ($result as $r) {
$ids[] = $r['id_condition'];
}

return $ids;
}

public function processCalculation()
{
switch ($this->type) {
Expand Down Expand Up @@ -300,7 +149,8 @@ protected function processSql()
if ($this->makeCalculation($this->operator, $this->result, $this->value)) {
$this->validated = 1;
}
$this->save();

return $this->save();
}

protected function processConfiguration()
Expand Down
28 changes: 25 additions & 3 deletions classes/GamificationTools.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,38 @@ public static function parseMetaData($content)
{
$meta_data = [
'PREFIX_' => _DB_PREFIX_,
];
];
//replace define
$content = str_replace(array_keys($meta_data), array_values($meta_data), $content);

$moduleName = null;
preg_match('#&module_name=(.*)&#', $content, $moduleNameMatches);
if (isset($moduleNameMatches[1])) {
$moduleName = $moduleNameMatches[1];
}

//replace meta data
$content = preg_replace_callback('#\{config\}([a-zA-Z0-9_-]*)\{/config\}#', function ($matches) {
return Configuration::get($matches[1]);
}, $content);
$content = preg_replace_callback('#\{link\}(.*)\{/link\}#', function ($matches) {
return Context::getContext()->link->getAdminLink($matches[1]);
$content = preg_replace_callback('#\{link\}(.*)\{/link\}#', function ($matches) use ($moduleName) {
$adminController = $matches[1];
if ('AdminModules' === $adminController) {
$mboIsActive = Module::isInstalled('ps_mbo') && Module::isEnabled('ps_mbo');
if (!$mboIsActive && !empty($moduleName)) {
return sprintf('https://addons.prestashop.com/search.php?%s', http_build_query([
'search_query' => $moduleName,
'utm_source' => 'back-office',
'utm_medium' => 'search',
'utm_campaign' => 'back-office-' . Context::getContext()->language->iso_code,
'utm_content' => 'download',
]));
}

$adminController = 'AdminPsMboModule';
}

return Context::getContext()->link->getAdminLink($adminController);
}, $content);
$content = preg_replace_callback('#\{employee\}(.*)\{/employee\}#', function ($matches) {
return Context::getContext()->employee->$matches[1];
Expand Down
4 changes: 2 additions & 2 deletions config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
<module>
<name>gamification</name>
<displayName><![CDATA[Merchant Expertise]]></displayName>
<version><![CDATA[2.5.0]]></version>
<version><![CDATA[3.0.0]]></version>
<description><![CDATA[Become an e-commerce expert within the blink of an eye!]]></description>
<author><![CDATA[PrestaShop]]></author>
<tab><![CDATA[administration]]></tab>
<is_configurable>1</is_configurable>
<is_configurable>0</is_configurable>
<need_instance>1</need_instance>
<limited_countries></limited_countries>
</module>
Loading