Skip to content

Commit

Permalink
1.26.0
Browse files Browse the repository at this point in the history
[-] Удаляем модуль SBStatistic. Он подключается теперь как `karelwintersky/arris.drcalculus`.
[*] Фикс в MySQLWrapper, поддерживающий offset в запросах page+limit+offset
  • Loading branch information
KarelWintersky committed Jun 10, 2020
1 parent 73f07bd commit aa00762
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 327 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"ext-mysqli": "*",
"ext-pdo": "*",
"ext-simplexml": "*",
"karelwintersky/arris": "^1.52"
"karelwintersky/arris": "^1.52",
"cmfcmf/openweathermap-php-api": "^3.2"
},
"require-dev": {
"monolog/monolog": "^1.23",
Expand Down
41 changes: 0 additions & 41 deletions interfaces/SBStatisticInterface.php

This file was deleted.

30 changes: 20 additions & 10 deletions sources/MySQLWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
namespace SteamBoat;

use Arris\DB;
use Exception;
use Monolog\Logger;
use mysqli_result;
use Arris\AppLogger;

/**
* Class MySQLWrapper
Expand Down Expand Up @@ -69,11 +67,9 @@ class MySQLWrapper implements MySQLWrapperInterface

public function __construct($config, $logger = null)
{
if ($logger instanceof Logger) {
$this->_logger = $logger;
} else {
$this->_logger = AppLogger::addNullLogger();
}
$this->_logger = $logger instanceof Logger
? $logger
: (new Logger('null'))->pushHandler(new \Monolog\Handler\NullHandler());

$this->options['DB_SLOW_QUERY_THRESHOLD'] = getenv('DB.SLOW_QUERY_THRESHOLD') ?: 1;

Expand Down Expand Up @@ -225,20 +221,34 @@ public function create($fields, $table, $hash = null, $joins = null, $needpages
}
unset($hash['perpage']);

// page, limit, offset
if (isset($hash['page']) and is_numeric($hash['page']) and isset($hash['limit'])) {
$from = (ceil($hash['page']) - 1) * $hash['limit'];
$limit = "LIMIT " . $from . ", " . $hash['limit'];
if (isset($hash['offset'])) {
$limit = "LIMIT {$hash['limit']} OFFSET {$hash['offset']}";
} else {
$from = (ceil($hash['page']) - 1) * $hash['limit'];
$limit = "LIMIT " . $from . ", " . $hash['limit'];
}
}

if (isset($hash['limit']) and is_numeric($hash['limit']) and !isset($hash['page'])) {
$limit = "LIMIT " . ceil($hash['limit']);
$_lim = ceil($hash['limit']);
if (isset($hash['offset'])) {
$limit = "LIMIT {$_lim} OFFSET {$hash['offset']}";
} else {
$limit = "LIMIT {$_lim}";
}
}

// все записи
if (isset($hash['limit']) and $hash['limit'] == "all" and !isset($hash['page'])) {
$limit = "";
}

if (isset($hash['offset'])) {
unset($hash['offset']);
}

$order = "";
if (isset($hash['order'])) {
$order = "ORDER BY " . $hash['order'];
Expand Down
275 changes: 0 additions & 275 deletions sources/SBStatistic.php

This file was deleted.

0 comments on commit aa00762

Please sign in to comment.