Skip to content

Commit

Permalink
Merge pull request #66 from PrestaShop/dev
Browse files Browse the repository at this point in the history
Release 2.3.0
  • Loading branch information
PierreRambaud authored Jun 26, 2019
2 parents d00ffa8 + a9d649f commit 6f4c8fa
Show file tree
Hide file tree
Showing 487 changed files with 1,106 additions and 1,485 deletions.
9 changes: 9 additions & 0 deletions .github/release-drafter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
change-template: '- $TITLE (#$NUMBER)'
template: |
## Changelog
$CHANGES
### Contributors
$CONTRIBUTORS
50 changes: 13 additions & 37 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
language: php

addons:
apt:
packages:
- apache2
- postfix
- libapache2-mod-fastcgi
- libappindicator1
- fonts-liberation

cache:
directories:
- $HOME/.composer/cache
Expand All @@ -17,39 +8,24 @@ sudo: required
dist: trusty

php:
- "5.6"
- "7.1"
- "7.2"
- '5.6'
- '7.1'
- '7.2'

env:
global:
- SYMFONY_DEPRECATIONS_HELPER=disabled
- SYMFONY_PHPUNIT_VERSION=5.7
- MODULE_DIR=/tmp/gamification
- MODULE_SCRIPTS_DIR=/tmp/gamification/tools
global:
- SYMFONY_DEPRECATIONS_HELPER=disabled
- SYMFONY_PHPUNIT_VERSION=5.7.27

matrix:
- PS_VERSION=1.7.4.x
- PS_VERSION=1.7.5.x

allow_failures:
- php: 7.2
allow_failures:
- php: 7.2

fast_finish: true
script:
- composer install
- composer cs-fix-test
- composer test

before_script:
- ./tools/move_module.sh
- $MODULE_SCRIPTS_DIR/get_prestashop.sh
- $MODULE_SCRIPTS_DIR/install_webserver.sh
- $MODULE_SCRIPTS_DIR/start_prestashop.sh
- $MODULE_SCRIPTS_DIR/install_module.sh gamification

script:
- cd $TRAVIS_BUILD_DIR/modules/gamification
- composer cs-fix-test
- composer test

notifications:
email:
email:
on_success: never
on_failure: always
112 changes: 65 additions & 47 deletions classes/Advice.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,27 @@
class Advice extends ObjectModel
{
public $id;

public $id_ps_advice;

public $id_tab;

public $validated;

public $hide;

public $selector;

public $location;

public $html;

public $start_day;

public $stop_day;

public $weight;

/**
* @see ObjectModel::$definition
*/
Expand All @@ -69,33 +69,63 @@ class Advice extends ObjectModel
'html' => array('type' => self::TYPE_HTML, 'lang' => true, 'required' => true, 'validate' => 'isString'),
),
);

public static function getIdByIdPs($id_ps_advice)
{
$query = new DbQuery();
$query->select('id_advice');
$query->from('advice', 'b');
$query->where('`id_ps_advice` = '.(int)$id_ps_advice);

return (int)Db::getInstance()->getValue($query);
}

public static function getValidatedByIdTab($id_tab, $premium = false, $addons = false)
/**
* @param int $idTab
* @param bool $includePremium [default=false] True to include Premium as well
* @param bool $includeAddons [default=false] True to include Addons as well
*
* @return array[]
* @throws PrestaShopDatabaseException
*/
public static function getValidatedByIdTab($idTab, $includePremium = false, $includeAddons = false)
{
$query = new DbQuery();
$query->select('a.`id_ps_advice`, a.`selector`, a.`location`, al.`html`, a.`weight`');
$query->from('advice', 'a');
$query->join('
LEFT JOIN `'._DB_PREFIX_.'advice_lang` al ON al.`id_advice` = a.`id_advice`
LEFT JOIN `'._DB_PREFIX_.'tab_advice` at ON at.`id_advice` = a.`id_advice` ');

$query->where('
a.`validated` = 1 AND
a.`hide` = 0 AND
al.`id_lang` = '.(int)Context::getContext()->language->id.' AND
at.`id_tab` = '.(int)$id_tab.' AND
((a.`start_day` = 0 AND a.`stop_day` = 0) OR ('.date('d').' >= a.`start_day` AND '.date('d').' <= a.`stop_day`))');

LEFT JOIN `'._DB_PREFIX_.'tab_advice` at ON at.`id_advice` = a.`id_advice`
');

$selectorsToExclude = array();
if (!$includePremium) {
$selectorsToExclude[] = '#dashtrends';
}
if (!$includeAddons) {
$selectorsToExclude[] = 'addons';
}

$selectorsToExcludeSql = '';
if (!empty($selectorsToExclude)) {
$selectorsToExcludeSql = 'AND a.selector NOT IN("' . implode('","', $selectorsToExclude) . '")';
}

$query->where(sprintf(
"a.validated = 1
AND a.hide = 0
AND al.id_lang = %d
AND at.id_tab = %d
$selectorsToExcludeSql
AND (
(a.start_day = 0 AND a.stop_day = 0)
OR (%s BETWEEN a.start_day AND a.stop_day)
)",
(int) Context::getContext()->language->id,
$idTab,
date('d')
));

$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query);
$advices = array();
if (is_array($result)) {
Expand All @@ -106,28 +136,14 @@ public static function getValidatedByIdTab($id_tab, $premium = false, $addons =
'html' => $res['html'],
'id_ps_advice' => $res['id_ps_advice'],
'weight' => $res['weight']
);
);
}
}
if (!$premium) {
foreach ($advices as $k => $a) {
if ($a['selector'] == '#dashtrends') {
unset($advices[$k]);
}
}
}
if (!$addons) {
foreach ($advices as $k => $a) {
if ($a['selector'] == 'addons') {
unset($advices[$k]);
}
}
}


return $advices;
}
public static function getValidatedPremiumByIdTab($id_tab)

public static function getValidatedPremiumOnlyByIdTab($id_tab)
{
$advices = self::getValidatedByIdTab($id_tab, true);

Expand All @@ -136,22 +152,22 @@ public static function getValidatedPremiumByIdTab($id_tab)
unset($advices[$k]);
}
}

return $advices;
}
public static function getAddonsAdviceByIdTab($id_tab)

public static function getValidatedAddonsOnlyByIdTab($id_tab)
{
$advices = self::getValidatedByIdTab($id_tab, false, true);
foreach ($advices as $k => $a) {
if ($a['selector'] != 'addons') {
unset($advices[$k]);
}
}

return $advices;
}

public static function getIdsAdviceToValidate()
{
$ids = array();
Expand All @@ -166,15 +182,16 @@ public static function getIdsAdviceToValidate()
$query->having('count(*) = SUM(c.`validated`)');

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

if (is_array($result)) {
foreach ($result as $advice) {
$ids[] = $advice['id_advice'];
}
}

return $ids;
}

public static function getIdsAdviceToUnvalidate()
{
$ids = array();
Expand All @@ -189,12 +206,13 @@ public static function getIdsAdviceToUnvalidate()
$query->having('count(*) = SUM(c.`validated`)');

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

if (is_array($result)) {
foreach ($result as $advice) {
$ids[] = $advice['id_advice'];
}
}

return $ids;
}
}
3 changes: 3 additions & 0 deletions classes/Badge.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public function validate()
{
$this->validated = 1;
$this->save();

return true;
}

Expand Down Expand Up @@ -113,6 +114,7 @@ public static function getIdsBadgesToValidate()
foreach ($result as $badge) {
$ids[] = $badge['id_badge'];
}

return $ids;
}

Expand All @@ -123,6 +125,7 @@ public function getNextBadgeId()
$query->from('badge', 'b');
$query->where('b.id_group = \''.pSQL($this->id_group).'\' AND b.validated = 0');
$query->orderBy('b.group_position');

return Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($query);
}
}
2 changes: 1 addition & 1 deletion classes/Condition.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,6 @@ public static function getIdsDailyCalculation()
$ids[] = $r['id_condition'];
}


return array_unique($ids);
}

Expand Down Expand Up @@ -349,6 +348,7 @@ protected function makeCalculation($operator, $arg1, $arg2)
break;
break;
}

return (bool)$result;
}
}
3 changes: 2 additions & 1 deletion classes/GamificationTools.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@ public static function parseMetaData($content)

/**
* Retrieve Json api file, forcing gzip compression to save bandwith.
*
* @param string $url
* @param bool $withResponseHeaders
*
* @return string|bool
*/
public static function retrieveJsonApiFile($url, $withResponseHeaders = false)
Expand All @@ -70,7 +72,6 @@ public static function retrieveJsonApiFile($url, $withResponseHeaders = false)

curl_close($curl);


return $content;
}
}
6 changes: 5 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
}
],
"require": {
"php": ">=5.6"
"php": ">=5.6",
"ext-json": "*"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.12",
Expand All @@ -20,6 +21,9 @@
"symfony/debug": "^3.4"
},
"config": {
"platform": {
"php": "5.6.0"
},
"preferred-install": "dist"
},
"scripts": {
Expand Down
Loading

0 comments on commit 6f4c8fa

Please sign in to comment.