N°3294 - Introduce counters in OQL menu entries

This commit is contained in:
acognet
2021-01-21 17:24:15 +01:00
parent b8aeef1d71
commit 5dcddf2317
4 changed files with 40 additions and 2 deletions

View File

@@ -1157,8 +1157,33 @@ class OQLMenuNode extends MenuNode
public function GetEntriesCount()
{
// Count the entries up to 99
$oFilter = DBSearch::FromOQL($this->sOQL);
$oAppContext = new ApplicationContext();
$iCurrentOrganization = $oAppContext->GetCurrentValue('org_id');
$oSet = new DBObjectSet(DBSearch::FromOQL($this->sOQL));
if( isset($iCurrentOrganization) && $iCurrentOrganization!="" ) {
$aAllowedOrgs[] = intval( $iCurrentOrganization);
$aSettings['bSearchMode'] = true;
$aSelectedClasses = $oFilter->GetSelectedClasses();
foreach ($aSelectedClasses as $sClassAlias => $sClass) {
//MakeSelectFilter($sClass, $aAllowedOrgs, $aSettings = array(), $sAttCode = null)
$sAttCode = $sClass::MapContextParam('org_id');
if(!is_null($sAttCode) && MetaModel::IsValidAttCode($sClass,$sAttCode)) {
$oVisibleObjects = UserRights::MakeSelectFilter($sClass, $aAllowedOrgs, $aSettings, $sAttCode);
if ($oVisibleObjects === false) {
// Make sure this is a valid search object, saying NO for all
$oVisibleObjects = DBObjectSearch::FromEmptySet($sClass);
}
if (is_object($oVisibleObjects)) {
$oVisibleObjects->AllowAllData();
$oFilter = $oFilter->Filter($sClassAlias, $oVisibleObjects);
}
}
}
}
$oSet = new DBObjectSet($oFilter);
$iCount = $oSet->CountWithLimit(99);
if ($iCount > 99) {
$iCount = "99+";

View File

@@ -27,6 +27,7 @@ $(function()
active_menu_group: null,
display_counts: false,
filter_keyup_throttle: 200, // In milliseconds
org_id:''
},
css_classes:
{
@@ -362,7 +363,8 @@ $(function()
method: "POST",
url: GetAbsoluteUrlAppRoot() + 'pages/ajax.render.php',
data: {
operation: "get_menus_count"
operation: "get_menus_count",
c: { org_id: me.options.org_id }
},
dataType: "json"
})

View File

@@ -423,5 +423,15 @@ JS;
return $this;
}
public function GetOrgId(){
$oAppContext = new ApplicationContext();
$iCurrentOrganization = $oAppContext->GetCurrentValue('org_id');
if(!empty($iCurrentOrganization)) {
return $iCurrentOrganization;
}
return '';
}
}

View File

@@ -1,5 +1,6 @@
$('#{{ oUIBlock.GetId() }}').navigation_menu({
display_counts: {% if get_config_parameter('display_menus_count') %} true {% else %} false {% endif %}
{%if oUIBlock.GetOrgId()%}, org_id: {{ oUIBlock.GetOrgId()}} {% endif %}
});
$('#{{ oUIBlock.GetId() }}').navigation_menu('refreshCounts', null);