mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-20 00:58:48 +02:00
N°1588 - Count on Managed Brick sometimes wrong
This commit is contained in:
@@ -1068,7 +1068,6 @@ class DBObjectSearch extends DBSearch
|
||||
{
|
||||
if (($oSearch->GetFirstJoinedClassAlias() == $sClassAlias))
|
||||
{
|
||||
$oSearch->ResetCondition();
|
||||
$oSearch = $oSearch->IntersectSubClass($oFilter, $aRootClasses);
|
||||
return $oSearch->GetCriteria();
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ use Combodo\iTop\Portal\Helper\ApplicationHelper;
|
||||
use DBObject;
|
||||
use DBObjectSet;
|
||||
use DBSearch;
|
||||
use DBUnionSearch;
|
||||
use Dict;
|
||||
use Exception;
|
||||
use FieldExpression;
|
||||
@@ -343,11 +344,13 @@ class ManageBrickController extends BrickController
|
||||
// Otherwise we create the tabs from the SQL expressions
|
||||
else
|
||||
{
|
||||
$aConditionQueryGrouping = array();
|
||||
foreach ($aGroupingTabs['groups'] as $aGroup)
|
||||
{
|
||||
$oConditionQuery = $oQuery->Intersect(DBSearch::FromOQL($aGroup['condition']));
|
||||
$oDBSearch = DBSearch::FromOQL($aGroup['condition']);
|
||||
$oConditionQuery = $oQuery->Intersect($oDBSearch);
|
||||
// - Restricting query to scope
|
||||
|
||||
array_push($aConditionQueryGrouping,$oDBSearch);
|
||||
$bHasScope = $oScopeValidator->AddScopeToQuery($oConditionQuery, $oConditionQuery->GetClass());
|
||||
if ($bHasScope)
|
||||
{
|
||||
@@ -368,7 +371,26 @@ class ManageBrickController extends BrickController
|
||||
'condition' => $oConditionQuery,
|
||||
'count' => $iGroupCount,
|
||||
);
|
||||
$iCount += $iGroupCount;
|
||||
}
|
||||
try
|
||||
{
|
||||
$oConditionQuery = $oQuery->Intersect(new DBUnionSearch($aConditionQueryGrouping));
|
||||
$bHasScope = $oScopeValidator->AddScopeToQuery($oConditionQuery, $oConditionQuery->GetClass());
|
||||
if ($bHasScope)
|
||||
{
|
||||
// - Building ObjectSet
|
||||
$oConditionSet = new DBObjectSet($oConditionQuery);
|
||||
$iCount = $oConditionSet->Count();
|
||||
}
|
||||
else
|
||||
{
|
||||
$oConditionSet = null;
|
||||
$iCount = 0;
|
||||
}
|
||||
}
|
||||
catch (Exception $e){
|
||||
$oConditionSet = null;
|
||||
$iCount = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{# itop-portal-base/portal/templates/bricks/manage/layout.html.twig #}
|
||||
{% extends 'itop-portal-base/portal/templates/bricks/layout.html.twig' %}
|
||||
|
||||
{% block pMainHeaderTitle %}{{ oBrick.GetTitle()|dict_s }} ({{ iCount }}) {% endblock %}
|
||||
{% block pMainHeaderTitle %}{{ oBrick.GetTitle()|dict_s }} {% if iCount >= 0 %} ({{ iCount }}){% endif %} {% endblock %}
|
||||
|
||||
{% block pMainHeaderActions %}
|
||||
{% if oBrick.GetAvailablesDisplayModes|length > 1 %}
|
||||
|
||||
@@ -112,6 +112,26 @@ class DBSearchIntersectTest extends ItopDataTestCase
|
||||
'alias' => "P",
|
||||
'result' => "SELECT `L` FROM Location AS `L` JOIN Person AS `P` ON `P`.location_id = `L`.id JOIN Location AS `L1` ON `P`.location_id = `L1`.id WHERE (`L1`.`org_id` = 3)");
|
||||
|
||||
$aTests['Test Subclass1'] = array(
|
||||
'left' => "SELECT `U` FROM UserRequest AS `U` WHERE `U`.agent_id = 3",
|
||||
'right' => "SELECT `Ticket` WHERE org_id = 3",
|
||||
'alias' => "U",
|
||||
'result' => "SELECT `U` FROM UserRequest AS `U` WHERE (((`U`.`agent_id` = 3) AND (`U`.`org_id` = 3)) AND ((`U`.`agent_id` = 3) AND (`U`.`org_id` = 3)))");
|
||||
|
||||
$aTests['Test Subclass and join'] = array(
|
||||
'left' => "SELECT `UserRequest` FROM UserRequest AS `UserRequest` JOIN Person AS `P` ON `UserRequest`.agent_id = `P`.id WHERE `UserRequest`.agent_id = 3",
|
||||
'right' => "SELECT `Ticket` WHERE org_id = 3",
|
||||
'alias' => "UserRequest",
|
||||
'result' => "SELECT `UserRequest` FROM UserRequest AS `UserRequest` JOIN Person AS `P` ON `UserRequest`.agent_id = `P`.id WHERE (((`UserRequest`.`agent_id` = 3) AND (`UserRequest`.`org_id` = 3)) AND ((`UserRequest`.`agent_id` = 3) AND (`UserRequest`.`org_id` = 3)))");
|
||||
|
||||
$aTests['Test Subclass and union'] = array(
|
||||
'left' => "SELECT `U` FROM UserRequest AS `U` WHERE `U`.agent_id = 3 UNION SELECT `T` FROM Ticket AS `T` WHERE `T`.agent_id = 3 ",
|
||||
'right' => "SELECT `Ticket` WHERE org_id = 3",
|
||||
'alias' => "U",
|
||||
'result' => "SELECT `U` FROM UserRequest AS `U` WHERE (((`U`.`agent_id` = 3) AND (`U`.`org_id` = 3)) AND ((`U`.`agent_id` = 3) AND (`U`.`org_id` = 3))) UNION SELECT `T` FROM Ticket AS `T` WHERE ((`T`.`agent_id` = 3) AND (`T`.`org_id` = 3))");
|
||||
|
||||
|
||||
|
||||
return $aTests;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user