Skip to content

Commit

Permalink
UNZER-241 PHPMD fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Bartosz Sosnowski committed Nov 22, 2023
1 parent 9528e1b commit 9661e3e
Showing 1 changed file with 48 additions and 25 deletions.
73 changes: 48 additions & 25 deletions src/Controller/Admin/OrderList.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace OxidSolutionCatalysts\Unzer\Controller\Admin;

use OxidEsales\Eshop\Core\Exception\DatabaseConnectionException;
use OxidEsales\Eshop\Core\Exception\StandardException;
use OxidEsales\Eshop\Core\Registry;
use OxidSolutionCatalysts\Unzer\Model\Payment;
Expand All @@ -12,6 +13,15 @@

class OrderList extends OrderList_parent
{
/**
* @param $queries
* @param $queryForAppending
*
* @SuppressWarnings(PHPMD.StaticAccess)
*
* @return string
* @throws DatabaseConnectionException
*/
protected function prepareWhereQuery($queries, $queryForAppending)
{
$database = \OxidEsales\Eshop\Core\DatabaseProvider::getDb();
Expand All @@ -31,6 +41,16 @@ protected function prepareWhereQuery($queries, $queryForAppending)

return $query;
}

/**
* @param array $whereQuery
* @param string $filterQuery
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*
* @return string
* @throws DatabaseConnectionException
*/
protected function prepareOrderListQuery(array $whereQuery, string $filterQuery): string
{
if (is_array($whereQuery) && count($whereQuery)) {
Expand All @@ -46,43 +66,46 @@ protected function prepareOrderListQuery(array $whereQuery, string $filterQuery)
//removing % symbols
$fieldValue = $this->processFilter($fieldValue);
if (strlen($fieldValue)) {
$database = \OxidEsales\Eshop\Core\DatabaseProvider::getDb();
$values = explode(' ', $fieldValue);
//for each search field using AND action
$queryBoolAction = ' and (';

$db = \OxidEsales\Eshop\Core\DatabaseProvider::getDb();
//oxordernr is combined with oxunzerordernr
if ("oxorder.oxordernr" === $identifierName) {
$quotedOxOrderNrIdentifierName = $db->quoteIdentifier("oxorder.oxordernr");
$quotedOxUnzerOrderNrIdentifierName = $db->quoteIdentifier("oxorder.oxunzerordernr");
$oxOrderNr = $database->quoteIdentifier("oxorder.oxordernr");
$oxUnzerOrderNr = $database->quoteIdentifier("oxorder.oxunzerordernr");
$orderNrQuery = [];
foreach ($values as $value) {
$orderNrQuery[] = "({$quotedOxOrderNrIdentifierName} like '{$value}'"
. " or {$quotedOxUnzerOrderNrIdentifierName} like '{$value}')";
$orderNrQuery[] = "({$oxOrderNr} like '{$value}'"
. " or {$oxUnzerOrderNr} like '{$value}')";
}
$filterQuery .= "and (" . implode(" or ", $orderNrQuery) . ")";
} else {
foreach ($values as $value) {
// trying to search spec chars in search value
// if found, add cleaned search value to search sql
$uml = $myUtilsString->prepareStrForSearch($value);
if ($uml) {
$queryBoolAction .= '(';
}
$quotedIdentifierName = $db->quoteIdentifier($identifierName);
$filterQuery .= " {$queryBoolAction} {$quotedIdentifierName} ";
//for search in same field for different values using AND
$queryBoolAction = ' and ';
$filterQuery .= $this->buildFilter($value, $isSearchValue);
if ($uml) {
$filterQuery .= " or {$quotedIdentifierName} ";

$filterQuery .= $this->buildFilter($uml, $isSearchValue);
$filterQuery .= ')'; // end of OR section
}

continue;
}

foreach ($values as $value) {
// trying to search spec chars in search value
// if found, add cleaned search value to search sql
$uml = $myUtilsString->prepareStrForSearch($value);
if ($uml) {
$queryBoolAction .= '(';
}
$quotedIdentifierName = $database->quoteIdentifier($identifierName);
$filterQuery .= " {$queryBoolAction} {$quotedIdentifierName} ";
//for search in same field for different values using AND
$queryBoolAction = ' and ';
$filterQuery .= $this->buildFilter($value, $isSearchValue);
if ($uml) {
$filterQuery .= " or {$quotedIdentifierName} ";

$filterQuery .= $this->buildFilter($uml, $isSearchValue);
$filterQuery .= ')'; // end of OR section
}
}
// end for AND action
$filterQuery .= ' ) ';
}
}
}
}
Expand Down

0 comments on commit 9661e3e

Please sign in to comment.