Skip to content
This repository has been archived by the owner on Jan 10, 2023. It is now read-only.

Commit

Permalink
Фикс релейшена к пользователю (#20)
Browse files Browse the repository at this point in the history
* Update BaseQuery.php

* Update BaseRelationQuery.php

* Update UserQuery.php

* Update RelationTest.php
  • Loading branch information
MsNatali authored and arrilot committed Jun 7, 2018
1 parent ff59a6a commit d315c2d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/Queries/BaseQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -565,4 +565,9 @@ public function __call($method, $parameters)

throw new BadMethodCallException("Call to undefined method {$className}::{$method}()");
}

protected function prepareMultiFilter(&$key, &$value)
{

}
}
8 changes: 7 additions & 1 deletion src/Queries/BaseRelationQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,14 @@ protected function filterByModels($models)
if (preg_match('/^PROPERTY_(.*)_VALUE$/', $primary, $matches) && !empty($matches[1])) {
$primary = 'PROPERTY_' . $matches[1];
}
$values = array_unique($values, SORT_REGULAR);
if (count($values) == 1) {
$values = current($values);
} else {
$this->prepareMultiFilter($primary, $values);
}

$this->filter([$primary => array_unique($values, SORT_REGULAR)]);
$this->filter([$primary => $values]);
$this->select[] = $primary;
}

Expand Down
5 changes: 5 additions & 0 deletions src/Queries/UserQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,4 +222,9 @@ protected function normalizeUfSelect()
{
return preg_grep('/^(UF_+)/', $this->select);
}

protected function prepareMultiFilter(&$key, &$value)
{
$value = join(' | ', $value);
}
}
4 changes: 2 additions & 2 deletions tests/RelationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public function testOne()


$bxObject = m::mock('obj');
$bxObject->shouldReceive('GetList')->with(m::any(), ['IBLOCK_ID' => TestElement2::IBLOCK_ID, 'PROPERTY_ELEMENT' => [1]], m::any(), ['nPageSize' => 1], m::any())->once()->andReturn(m::self());
$bxObject->shouldReceive('GetList')->with(m::any(), ['IBLOCK_ID' => TestElement2::IBLOCK_ID, 'PROPERTY_ELEMENT' => 1], m::any(), ['nPageSize' => 1], m::any())->once()->andReturn(m::self());
$brandField = [
'ID' => 1,
'NAME' => 'Название',
Expand All @@ -155,4 +155,4 @@ public function testOne()
// Проверка, что не выполняются дополнительные запросы
$product->element;
}
}
}

0 comments on commit d315c2d

Please sign in to comment.