mirror of
https://github.com/Combodo/iTop.git
synced 2026-02-13 07:24:13 +01:00
N°3294 - Introduce counters in OQL menu entries (fix when silo changes)
This commit is contained in:
@@ -181,6 +181,7 @@ class DisplayBlock
|
|||||||
/** bool open by default the search */
|
/** bool open by default the search */
|
||||||
'class', /** class name */
|
'class', /** class name */
|
||||||
'search_header_force_dropdown', /** Html for <select> to choose the class to search */
|
'search_header_force_dropdown', /** Html for <select> to choose the class to search */
|
||||||
|
'this',
|
||||||
], DataTableUIBlockFactory::GetAllowedParams()),
|
], DataTableUIBlockFactory::GetAllowedParams()),
|
||||||
'search' => array_merge([
|
'search' => array_merge([
|
||||||
'baseClass',
|
'baseClass',
|
||||||
|
|||||||
@@ -1157,33 +1157,41 @@ class OQLMenuNode extends MenuNode
|
|||||||
public function GetEntriesCount()
|
public function GetEntriesCount()
|
||||||
{
|
{
|
||||||
// Count the entries up to 99
|
// Count the entries up to 99
|
||||||
$oFilter = DBSearch::FromOQL($this->sOQL);
|
$oSearch = DBSearch::FromOQL($this->sOQL);
|
||||||
$oAppContext = new ApplicationContext();
|
|
||||||
$iCurrentOrganization = $oAppContext->GetCurrentValue('org_id');
|
|
||||||
|
|
||||||
if( isset($iCurrentOrganization) && $iCurrentOrganization!="" ) {
|
$oAppContext = new ApplicationContext();
|
||||||
$aAllowedOrgs[] = intval( $iCurrentOrganization);
|
$sClass = $oSearch->GetClass();
|
||||||
$aSettings['bSearchMode'] = true;
|
foreach ($oAppContext->GetNames() as $key) {
|
||||||
$aSelectedClasses = $oFilter->GetSelectedClasses();
|
// Find the value of the object corresponding to each 'context' parameter
|
||||||
foreach ($aSelectedClasses as $sClassAlias => $sClass) {
|
$aCallSpec = [$sClass, 'MapContextParam'];
|
||||||
//MakeSelectFilter($sClass, $aAllowedOrgs, $aSettings = array(), $sAttCode = null)
|
$sAttCode = '';
|
||||||
$sAttCode = $sClass::MapContextParam('org_id');
|
if (is_callable($aCallSpec)) {
|
||||||
if(!is_null($sAttCode) && MetaModel::IsValidAttCode($sClass,$sAttCode)) {
|
$sAttCode = call_user_func($aCallSpec, $key); // Returns null when there is no mapping for this parameter
|
||||||
$oVisibleObjects = UserRights::MakeSelectFilter($sClass, $aAllowedOrgs, $aSettings, $sAttCode);
|
}
|
||||||
if ($oVisibleObjects === false) {
|
|
||||||
// Make sure this is a valid search object, saying NO for all
|
if (MetaModel::IsValidAttCode($sClass, $sAttCode)) {
|
||||||
$oVisibleObjects = DBObjectSearch::FromEmptySet($sClass);
|
// Add Hierarchical condition if hierarchical key
|
||||||
}
|
$oAttDef = MetaModel::GetAttributeDef($sClass, $sAttCode);
|
||||||
if (is_object($oVisibleObjects)) {
|
if (isset($oAttDef) && ($oAttDef->IsExternalKey())) {
|
||||||
$oVisibleObjects->AllowAllData();
|
$defaultValue = intval($oAppContext->GetCurrentValue($key));
|
||||||
$oFilter = $oFilter->Filter($sClassAlias, $oVisibleObjects);
|
try {
|
||||||
|
/** @var AttributeExternalKey $oAttDef */
|
||||||
|
$sTargetClass = $oAttDef->GetTargetClass();
|
||||||
|
$sHierarchicalKeyCode = MetaModel::IsHierarchicalClass($sTargetClass);
|
||||||
|
if ($sHierarchicalKeyCode !== false) {
|
||||||
|
$oFilter = new DBObjectSearch($sTargetClass);
|
||||||
|
$oFilter->AddCondition('id', $defaultValue);
|
||||||
|
$oHKFilter = new DBObjectSearch($sTargetClass);
|
||||||
|
$oHKFilter->AddCondition_PointingTo($oFilter, $sHierarchicalKeyCode, TREE_OPERATOR_BELOW);
|
||||||
|
$oSearch->AddCondition_PointingTo($oHKFilter, $sAttCode);
|
||||||
|
}
|
||||||
|
} catch (Exception $e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
$oSet = new DBObjectSet($oFilter);
|
|
||||||
|
$oSet = new DBObjectSet($oSearch);
|
||||||
$iCount = $oSet->CountWithLimit(99);
|
$iCount = $oSet->CountWithLimit(99);
|
||||||
if ($iCount > 99) {
|
if ($iCount > 99) {
|
||||||
$iCount = "99+";
|
$iCount = "99+";
|
||||||
|
|||||||
Reference in New Issue
Block a user