N°8796 - Add PHP code style validation in iTop and extensions - format whole code base

This commit is contained in:
odain
2025-11-07 15:39:53 +01:00
parent 12f23113f5
commit 890a2568c8
2110 changed files with 53099 additions and 63885 deletions

View File

@@ -1,4 +1,5 @@
<?php
/*
* @copyright Copyright (C) 2010-2024 Combodo SAS
* @license http://opensource.org/licenses/AGPL-3.0
@@ -13,7 +14,6 @@ require_once(APPROOT.'/application/utils.inc.php');
require_once(APPROOT.'/application/template.class.inc.php');
require_once(APPROOT."/application/user.dashboard.class.inc.php");
/**
* This class manipulates, stores and displays the navigation menu used in the application
* In order to improve the modularity of the data model and to ease the update/migration
@@ -52,43 +52,40 @@ class ApplicationMenu
/**
* @var bool
*/
static $bAdditionalMenusLoaded = false;
public static $bAdditionalMenusLoaded = false;
/**
* @var array
*/
static $aRootMenus = array();
public static $aRootMenus = [];
/**
* @var array
*/
static $aMenusIndex = array();
public static $aMenusIndex = [];
/**
* @var array
*/
static $aMenusById = [];
public static $aMenusById = [];
/**
* @var string
*/
static $sFavoriteSiloQuery = 'SELECT Organization';
public static $sFavoriteSiloQuery = 'SELECT Organization';
/**
* @return void
*/
public static function LoadAdditionalMenus()
{
if (!self::$bAdditionalMenusLoaded)
{
if (!self::$bAdditionalMenusLoaded) {
// Build menus from module handlers
//
/** @var \ModuleHandlerApiInterface $oPHPClass */
foreach(MetaModel::EnumPlugins('ModuleHandlerApiInterface') as $oPHPClass)
{
$oPHPClass::OnMenuCreation();
}
foreach (MetaModel::EnumPlugins('ModuleHandlerApiInterface') as $oPHPClass) {
$oPHPClass::OnMenuCreation();
}
// Build menus from the menus themselves (e.g. the ShortcutContainerMenuNode will do that)
//
foreach(self::$aRootMenus as $aMenu)
{
foreach (self::$aRootMenus as $aMenu) {
$oMenuNode = self::GetMenuNode($aMenu['index']);
$oMenuNode->PopulateChildMenus();
}
@@ -125,8 +122,7 @@ class ApplicationMenu
*/
public static function CheckMenuIdEnabled($sMenuId)
{
if (self::IsMenuIdEnabled($sMenuId) === false)
{
if (self::IsMenuIdEnabled($sMenuId) === false) {
require_once(APPROOT.'/setup/setuppage.class.inc.php');
$oP = new ErrorPage(Dict::S('UI:PageTitle:FatalError'));
$oP->add("<h1>".Dict::S('UI:Login:Error:AccessRestricted')."</h1>\n");
@@ -142,7 +138,7 @@ class ApplicationMenu
* @return bool true if the menu exists and current user is allowed to see the menu
* @since 3.2.0
*/
public static function IsMenuIdEnabled($sMenuId):bool
public static function IsMenuIdEnabled($sMenuId): bool
{
self::LoadAdditionalMenus();
$oMenuNode = self::GetMenuNode(self::GetMenuIndexById($sMenuId));
@@ -160,22 +156,18 @@ class ApplicationMenu
public static function InsertMenu(MenuNode $oMenuNode, $iParentIndex, $fRank)
{
$index = self::GetMenuIndexById($oMenuNode->GetMenuId());
if ($index == -1)
{
if ($index == -1) {
// The menu does not already exist, insert it
$index = count(self::$aMenusIndex);
if ($iParentIndex == -1)
{
if ($iParentIndex == -1) {
$sParentId = '';
self::$aRootMenus[] = array ('rank' => $fRank, 'index' => $index);
}
else
{
self::$aRootMenus[] = ['rank' => $fRank, 'index' => $index];
} else {
/** @var \MenuNode $oNode */
$oNode = self::$aMenusIndex[$iParentIndex]['node'];
$sParentId = $oNode->GetMenuId();
self::$aMenusIndex[$iParentIndex]['children'][] = array ('rank' => $fRank, 'index' => $index);
self::$aMenusIndex[$iParentIndex]['children'][] = ['rank' => $fRank, 'index' => $index];
}
// Note: At the time when 'parent', 'rank' and 'source_file' have been added for the reflection API,
@@ -183,11 +175,9 @@ class ApplicationMenu
//
$aBacktrace = debug_backtrace();
$sFile = isset($aBacktrace[2]["file"]) ? $aBacktrace[2]["file"] : $aBacktrace[1]["file"];
self::$aMenusIndex[$index] = array('node' => $oMenuNode, 'children' => array(), 'parent' => $sParentId, 'rank' => $fRank, 'source_file' => $sFile);
self::$aMenusIndex[$index] = ['node' => $oMenuNode, 'children' => [], 'parent' => $sParentId, 'rank' => $fRank, 'source_file' => $sFile];
self::$aMenusById[$oMenuNode->GetMenuId()] = $index;
}
else
{
} else {
// the menu already exists, let's combine the conditions that make it visible
/** @var \MenuNode $oNode */
$oNode = self::$aMenusIndex[$index]['node'];
@@ -217,7 +207,7 @@ class ApplicationMenu
* @throws \DictExceptionMissingString
* @since 3.0.0
*/
public static function GetMenusCount($aExtraParams = array())
public static function GetMenusCount($aExtraParams = [])
{
$aMenuGroups = static::GetMenuGroups($aExtraParams);
@@ -260,18 +250,16 @@ class ApplicationMenu
* @throws \DictExceptionMissingString
* @since 3.0.0
*/
public static function GetMenuGroups($aExtraParams = array())
public static function GetMenuGroups($aExtraParams = [])
{
self::LoadAdditionalMenus();
// Sort the root menu based on the rank
usort(self::$aRootMenus, array('ApplicationMenu', 'CompareOnRank'));
usort(self::$aRootMenus, ['ApplicationMenu', 'CompareOnRank']);
$aMenuGroups = [];
foreach(static::$aRootMenus as $aMenuGroup)
{
if(!static::CanDisplayMenu($aMenuGroup))
{
foreach (static::$aRootMenus as $aMenuGroup) {
if (!static::CanDisplayMenu($aMenuGroup)) {
continue;
}
@@ -322,26 +310,23 @@ class ApplicationMenu
* @throws \Exception
* @since 3.0.0
*/
public static function GetSubMenuNodes($sMenuGroupIdx, $aExtraParams = array())
public static function GetSubMenuNodes($sMenuGroupIdx, $aExtraParams = [])
{
$aSubMenuItems = self::GetChildren($sMenuGroupIdx);
// Sort the children based on the rank
usort($aSubMenuItems, array('ApplicationMenu', 'CompareOnRank'));
usort($aSubMenuItems, ['ApplicationMenu', 'CompareOnRank']);
$aSubMenuNodes = [];
foreach($aSubMenuItems as $aSubMenuItem)
{
if(!static::CanDisplayMenu($aSubMenuItem))
{
foreach ($aSubMenuItems as $aSubMenuItem) {
if (!static::CanDisplayMenu($aSubMenuItem)) {
continue;
}
$sSubMenuItemIdx = $aSubMenuItem['index'];
$oSubMenuNode = static::GetMenuNode($sSubMenuItemIdx);
if(!$oSubMenuNode->IsEnabled())
{
if (!$oSubMenuNode->IsEnabled()) {
continue;
}
@@ -372,7 +357,7 @@ class ApplicationMenu
DeprecatedCallsLog::NotifyDeprecatedPhpMethod('use static::GetMenuGroups() instead');
self::LoadAdditionalMenus();
// Sort the root menu based on the rank
usort(self::$aRootMenus, array('ApplicationMenu', 'CompareOnRank'));
usort(self::$aRootMenus, ['ApplicationMenu', 'CompareOnRank']);
$iAccordion = 0;
$iActiveAccordion = $iAccordion;
$iActiveMenu = self::GetMenuIndexById(self::GetActiveNodeId());
@@ -387,8 +372,7 @@ class ApplicationMenu
$aChildren = self::GetChildren($aMenu['index']);
$bActive = self::DisplaySubMenu($oPage, $aChildren, $aExtraParams, $iActiveMenu);
$oPage->AddToMenu('</ul>');
if ($bActive)
{
if ($bActive) {
$iActiveAccordion = $iAccordion;
}
$oPage->AddToMenu('</div>');
@@ -396,7 +380,7 @@ class ApplicationMenu
}
$oPage->add_ready_script(
<<<EOF
<<<EOF
// Accordion Menu
$("#accordion").css({display:'block'}).accordion({ header: "h3", heightStyle: "content", collapsible: true, active: $iActiveAccordion, icons: false, animate: true }); // collapsible will be enabled once the item will be selected
EOF
@@ -411,21 +395,15 @@ EOF
private static function CanDisplayMenu($aMenu)
{
$oMenuNode = self::GetMenuNode($aMenu['index']);
if ($oMenuNode->IsEnabled())
{
if ($oMenuNode->IsEnabled()) {
$aChildren = self::GetChildren($aMenu['index']);
if (count($aChildren) > 0)
{
foreach($aChildren as $aSubMenu)
{
if (self::CanDisplayMenu($aSubMenu))
{
if (count($aChildren) > 0) {
foreach ($aChildren as $aSubMenu) {
if (self::CanDisplayMenu($aSubMenu)) {
return true;
}
}
}
else
{
} else {
return true;
}
}
@@ -450,46 +428,38 @@ EOF
DeprecatedCallsLog::NotifyDeprecatedPhpMethod('use static::GetSubMenuNodes() instead');
// Sort the menu based on the rank
$bActive = false;
usort($aMenus, array('ApplicationMenu', 'CompareOnRank'));
usort($aMenus, ['ApplicationMenu', 'CompareOnRank']);
foreach ($aMenus as $aMenu) {
if (!self::CanDisplayMenu($aMenu)) {
continue;
}
$index = $aMenu['index'];
$oMenu = self::GetMenuNode($index);
if ($oMenu->IsEnabled())
{
if ($oMenu->IsEnabled()) {
$aChildren = self::GetChildren($index);
$aCSSClasses = array('navigation-menu-item');
if (count($aChildren) > 0)
{
$aCSSClasses = ['navigation-menu-item'];
if (count($aChildren) > 0) {
$aCSSClasses[] = 'submenu';
}
$sHyperlink = $oMenu->GetHyperlink($aExtraParams);
$sItemHtml = '<li id="'.utils::GetSafeId('AccordionMenu_'.$oMenu->GetMenuID()).'" class="'.implode(' ', $aCSSClasses).'" data-menu-id="'.$oMenu->GetMenuID().'">';
if ($sHyperlink != '')
{
if ($sHyperlink != '') {
$sLinkTarget = '';
if ($oMenu->IsHyperLinkInNewWindow())
{
if ($oMenu->IsHyperLinkInNewWindow()) {
$sLinkTarget .= ' target="_blank"';
}
$sURL = '"'.$oMenu->GetHyperlink($aExtraParams).'"'.$sLinkTarget;
$sTitle = utils::HtmlEntities($oMenu->GetTitle());
$sItemHtml .= "<a href={$sURL}>{$sTitle}</a>";
}
else
{
} else {
$sItemHtml .= $oMenu->GetTitle();
}
$sItemHtml .= '</li>';
$oPage->AddToMenu($sItemHtml);
if ($iActiveMenu == $index)
{
if ($iActiveMenu == $index) {
$bActive = true;
}
if (count($aChildren) > 0)
{
if (count($aChildren) > 0) {
$oPage->AddToMenu('<ul>');
$bActive |= self::DisplaySubMenu($oPage, $aChildren, $aExtraParams, $iActiveMenu);
$oPage->AddToMenu('</ul>');
@@ -508,12 +478,10 @@ EOF
public static function CompareOnRank($a, $b)
{
$result = 1;
if ($a['rank'] == $b['rank'])
{
if ($a['rank'] == $b['rank']) {
$result = 0;
}
if ($a['rank'] < $b['rank'])
{
if ($a['rank'] < $b['rank']) {
$result = -1;
}
return $result;
@@ -561,8 +529,7 @@ EOF
{
$oAppContext = new ApplicationContext();
$sMenuId = $oAppContext->GetCurrentValue('menu', null);
if ($sMenuId === null)
{
if ($sMenuId === null) {
$sMenuId = self::GetDefaultMenuId();
}
return $sMenuId;
@@ -574,13 +541,12 @@ EOF
public static function GetDefaultMenuId()
{
static $sDefaultMenuId = null;
if (is_null($sDefaultMenuId))
{
if (is_null($sDefaultMenuId)) {
// Make sure the root menu is sorted on 'rank'
usort(self::$aRootMenus, array('ApplicationMenu', 'CompareOnRank'));
usort(self::$aRootMenus, ['ApplicationMenu', 'CompareOnRank']);
$oFirstGroup = self::GetMenuNode(self::$aRootMenus[0]['index']);
$aChildren = self::$aMenusIndex[$oFirstGroup->GetIndex()]['children'];
usort($aChildren, array('ApplicationMenu', 'CompareOnRank'));
usort($aChildren, ['ApplicationMenu', 'CompareOnRank']);
$oMenuNode = self::GetMenuNode($aChildren[0]['index']);
$sDefaultMenuId = $oMenuNode->GetMenuId();
}
@@ -594,13 +560,11 @@ EOF
public static function GetRootMenuId($sMenuId)
{
$iMenuIndex = self::GetMenuIndexById($sMenuId);
if ($iMenuIndex == -1)
{
if ($iMenuIndex == -1) {
return '';
}
$oMenu = ApplicationMenu::GetMenuNode($iMenuIndex);
while ($oMenu->GetParentIndex() != -1)
{
while ($oMenu->GetParentIndex() != -1) {
$oMenu = ApplicationMenu::GetMenuNode($oMenu->GetParentIndex());
}
return $oMenu->GetMenuId();
@@ -687,17 +651,17 @@ abstract class MenuNode
{
$this->sMenuId = $sMenuId;
$this->iParentIndex = $iParentIndex;
$this->aReflectionProperties = array();
$this->aReflectionProperties = [];
if (utils::IsNotNullOrEmptyString($sEnableClass)) {
$this->aReflectionProperties['enable_class'] = $sEnableClass;
$this->aReflectionProperties['enable_action'] = $iActionCode;
$this->aReflectionProperties['enable_permission'] = $iAllowedResults;
$this->aReflectionProperties['enable_stimulus'] = $sEnableStimulus;
}
$this->m_aEnableClasses = array($sEnableClass);
$this->m_aEnableActions = array($iActionCode);
$this->m_aEnableActionResults = array($iAllowedResults);
$this->m_aEnableStimuli = array($sEnableStimulus);
$this->m_aEnableClasses = [$sEnableClass];
$this->m_aEnableActions = [$iActionCode];
$this->m_aEnableActionResults = [$iAllowedResults];
$this->m_aEnableStimuli = [$sEnableStimulus];
$this->index = ApplicationMenu::InsertMenu($this, $iParentIndex, $fRank);
}
@@ -751,7 +715,6 @@ abstract class MenuNode
$oSearch->SetShowObsoleteData(utils::ShowObsoleteData());
DBSearchHelper::AddContextFilter($oSearch);
$oSet = new DBObjectSet($oSearch);
$iCount = $oSet->CountWithLimit(99);
if ($iCount > 99) {
@@ -802,8 +765,7 @@ abstract class MenuNode
*/
public function PopulateChildMenus()
{
foreach (ApplicationMenu::GetChildren($this->GetIndex()) as $aMenu)
{
foreach (ApplicationMenu::GetChildren($this->GetIndex()) as $aMenu) {
$index = $aMenu['index'];
$oMenu = ApplicationMenu::GetMenuNode($index);
$oMenu->PopulateChildMenus();
@@ -838,8 +800,7 @@ abstract class MenuNode
*/
public function AddCondition(MenuNode $oMenuNode)
{
foreach($oMenuNode->m_aEnableClasses as $index => $sClass )
{
foreach ($oMenuNode->m_aEnableClasses as $index => $sClass) {
$this->m_aEnableClasses[] = $sClass;
$this->m_aEnableActions[] = $oMenuNode->m_aEnableActions[$index];
$this->m_aEnableActionResults[] = $oMenuNode->m_aEnableActionResults[$index];
@@ -852,33 +813,24 @@ abstract class MenuNode
*/
public function IsEnabled()
{
foreach($this->m_aEnableClasses as $index => $sClass)
{
if ($sClass != null)
{
if (MetaModel::IsValidClass($sClass))
{
if ($this->m_aEnableStimuli[$index] != null)
{
if (!UserRights::IsStimulusAllowed($sClass, $this->m_aEnableStimuli[$index]))
{
foreach ($this->m_aEnableClasses as $index => $sClass) {
if ($sClass != null) {
if (MetaModel::IsValidClass($sClass)) {
if ($this->m_aEnableStimuli[$index] != null) {
if (!UserRights::IsStimulusAllowed($sClass, $this->m_aEnableStimuli[$index])) {
return false;
}
}
if ($this->m_aEnableActions[$index] != null)
{
if ($this->m_aEnableActions[$index] != null) {
// Menus access rights ignore the archive mode
utils::PushArchiveMode(false);
$iResult = UserRights::IsActionAllowed($sClass, $this->m_aEnableActions[$index]);
utils::PopArchiveMode();
if (!($iResult & $this->m_aEnableActionResults[$index]))
{
if (!($iResult & $this->m_aEnableActionResults[$index])) {
return false;
}
}
}
else
{
} else {
return false;
}
}
@@ -891,7 +843,7 @@ abstract class MenuNode
* @param array $aExtraParams
* @return mixed
*/
public abstract function RenderContent(WebPage $oPage, $aExtraParams = array());
abstract public function RenderContent(WebPage $oPage, $aExtraParams = []);
/**
* @param string $sHyperlink
@@ -900,16 +852,13 @@ abstract class MenuNode
*/
protected function AddParams($sHyperlink, $aExtraParams)
{
if (count($aExtraParams) > 0)
{
$aQuery = array();
if (count($aExtraParams) > 0) {
$aQuery = [];
$sSeparator = '?';
if (strpos($sHyperlink, '?') !== false)
{
if (strpos($sHyperlink, '?') !== false) {
$sSeparator = '&';
}
foreach($aExtraParams as $sName => $sValue)
{
foreach ($aExtraParams as $sName => $sValue) {
$aQuery[] = urlencode($sName).'='.urlencode($sValue);
}
$sHyperlink .= $sSeparator.implode('&', $aQuery);
@@ -925,7 +874,7 @@ abstract class MenuNode
class MenuGroup extends MenuNode
{
/** @var string DEFAULT_DECORATION_CLASSES Set to null by default so it is replaced by initials when none is specified */
const DEFAULT_DECORATION_CLASSES = null;
public const DEFAULT_DECORATION_CLASSES = null;
/** @var string The CSS classes used to display the menu group's icon */
protected $sDecorationClasses = self::DEFAULT_DECORATION_CLASSES;
@@ -945,8 +894,7 @@ class MenuGroup extends MenuNode
{
parent::__construct($sMenuId, -1 /* no parent, groups are at root level */, $fRank, $sEnableClass, $iActionCode, $iAllowedResults, $sEnableStimulus);
if(!empty($sDecorationClasses))
{
if (!empty($sDecorationClasses)) {
$this->sDecorationClasses = $sDecorationClasses;
}
}
@@ -987,7 +935,7 @@ class MenuGroup extends MenuNode
/**
* @inheritDoc
*/
public function RenderContent(WebPage $oPage, $aExtraParams = array())
public function RenderContent(WebPage $oPage, $aExtraParams = [])
{
assert(false); // Shall never be called, groups do not display any content
}
@@ -1027,7 +975,9 @@ class TemplateMenuNode extends MenuNode
*/
public function GetHyperlink($aExtraParams)
{
if ($this->sTemplateFile == '') return '';
if ($this->sTemplateFile == '') {
return '';
}
return parent::GetHyperlink($aExtraParams);
}
@@ -1035,18 +985,15 @@ class TemplateMenuNode extends MenuNode
* @inheritDoc
* @throws \Exception
*/
public function RenderContent(WebPage $oPage, $aExtraParams = array())
public function RenderContent(WebPage $oPage, $aExtraParams = [])
{
ApplicationMenu::CheckMenuIdEnabled($this->GetMenuId());
$sTemplate = @file_get_contents($this->sTemplateFile);
if ($sTemplate !== false)
{
if ($sTemplate !== false) {
$aExtraParams['table_id'] = 'Menu_'.$this->GetMenuId();
$oTemplate = new DisplayTemplate($sTemplate);
$oTemplate->Render($oPage, $aExtraParams);
}
else
{
} else {
$oPage->p("Error: failed to load template file: '{$this->sTemplateFile}'"); // No need to translate ?
}
}
@@ -1080,7 +1027,6 @@ class OQLMenuNode extends MenuNode
*/
protected $m_aParams;
/**
* Create a menu item based on an OQL query and inserts it into the application's main menu
* @param string $sMenuId Unique identifier of the menu (used to identify the menu for bookmarking, and for getting the labels from the dictionary)
@@ -1101,7 +1047,7 @@ class OQLMenuNode extends MenuNode
$this->sOQL = $sOQL;
$this->bSearch = $bSearch;
$this->bSearchFormOpen = $bSearchFormOpen;
$this->m_aParams = array();
$this->m_aParams = [];
$this->aReflectionProperties['oql'] = $sOQL;
$this->aReflectionProperties['do_search'] = $bSearch;
// Enhancement: we could set as the "enable" condition that the user has enough rights to "read" the objects
@@ -1115,8 +1061,7 @@ class OQLMenuNode extends MenuNode
public function SetParameters($aParams)
{
$this->m_aParams = $aParams;
foreach($aParams as $sKey => $value)
{
foreach ($aParams as $sKey => $value) {
$this->aReflectionProperties[$sKey] = $value;
}
}
@@ -1125,12 +1070,11 @@ class OQLMenuNode extends MenuNode
* @inheritDoc
* @throws \Exception
*/
public function RenderContent(WebPage $oPage, $aExtraParams = array())
public function RenderContent(WebPage $oPage, $aExtraParams = [])
{
$oTag = new ContextTag(ContextTag::TAG_OBJECT_SEARCH);
ApplicationMenu::CheckMenuIdEnabled($this->GetMenuId());
OQLMenuNode::RenderOQLSearch
(
OQLMenuNode::RenderOQLSearch(
$this->sOQL,
Dict::S($this->sPageTitle),
'Menu_'.$this->GetMenuId(),
@@ -1155,26 +1099,25 @@ class OQLMenuNode extends MenuNode
* @throws DictExceptionMissingString
* @throws OQLException
*/
public static function RenderOQLSearch($sOql, $sTitle, $sUsageId, $bSearchPane, $bSearchOpen, WebPage $oPage, $aExtraParams = array(), $bEnableBreadcrumb = false)
public static function RenderOQLSearch($sOql, $sTitle, $sUsageId, $bSearchPane, $bSearchOpen, WebPage $oPage, $aExtraParams = [], $bEnableBreadcrumb = false)
{
$sUsageId = utils::GetSafeId($sUsageId);
$oSearch = DBObjectSearch::FromOQL($sOql);
$sClass= $oSearch->GetClass();
$sClass = $oSearch->GetClass();
$sIcon = MetaModel::GetClassIcon($sClass, false);
if ($bSearchPane) {
$aParams = array_merge(['open' => $bSearchOpen, 'table_id' => $sUsageId, 'submit_on_load' => false], $aExtraParams);
$oBlock = new DisplayBlock($oSearch, DisplayBlock::ENUM_STYLE_SEARCH, false /* Asynchronous */, $aParams);
$oBlock->Display($oPage, 0);
$oPage->add("<div class='sf_results_area ibo-add-margin-top-250' data-target='search_results'>");
}
else {
} else {
$oPage->add("<div class='sf_results_area' data-target='search_results'>");
}
$aExtraParams['panel_class'] =$sClass;
$aExtraParams['panel_class'] = $sClass;
$aExtraParams['panel_title'] = $sTitle;
$aExtraParams['panel_icon'] = $sIcon;
$aParams = array_merge(array('table_id' => $sUsageId), $aExtraParams);
$aParams = array_merge(['table_id' => $sUsageId], $aExtraParams);
$oBlock = new DisplayBlock($oSearch, 'list', false /* Asynchronous */, $aParams);
$oBlock->Display($oPage, $sUsageId);
@@ -1239,14 +1182,14 @@ class SearchMenuNode extends MenuNode
* @throws \DictExceptionMissingString
* @throws \Exception
*/
public function RenderContent(WebPage $oPage, $aExtraParams = array())
public function RenderContent(WebPage $oPage, $aExtraParams = [])
{
ApplicationMenu::CheckMenuIdEnabled($this->GetMenuId());
$oPage->SetBreadCrumbEntry("menu-".$this->sMenuId, $this->GetTitle(), '', '', 'fas fa-search', iTopWebPage::ENUM_BREADCRUMB_ENTRY_ICON_TYPE_CSS_CLASSES);
$oSearch = new DBObjectSearch($this->sClass);
$sUsageId = 'Menu_'.utils::GetSafeId($this->GetMenuId());
$aParams = array_merge(array('table_id' =>$sUsageId), $aExtraParams);
$aParams = array_merge(['table_id' => $sUsageId], $aExtraParams);
$oBlock = new DisplayBlock($oSearch, 'search', false /* Asynchronous */, $aParams);
$oBlock->Display($oPage, 0);
}
@@ -1283,10 +1226,16 @@ class WebPageMenuNode extends MenuNode
* @param bool $bIsLinkInNewWindow for the {@link WebPageMenuNode::IsHyperLinkInNewWindow} method
*/
public function __construct(
$sMenuId, $sHyperlink, $iParentIndex, $fRank = 0.0, $sEnableClass = null, $iActionCode = null,
$iAllowedResults = UR_ALLOWED_YES, $sEnableStimulus = null, $bIsLinkInNewWindow = false
)
{
$sMenuId,
$sHyperlink,
$iParentIndex,
$fRank = 0.0,
$sEnableClass = null,
$iActionCode = null,
$iAllowedResults = UR_ALLOWED_YES,
$sEnableStimulus = null,
$bIsLinkInNewWindow = false
) {
parent::__construct($sMenuId, $iParentIndex, $fRank, $sEnableClass, $iActionCode, $iAllowedResults, $sEnableStimulus);
$this->sHyperlink = $sHyperlink;
$this->aReflectionProperties['url'] = $sHyperlink;
@@ -1299,7 +1248,7 @@ class WebPageMenuNode extends MenuNode
public function GetHyperlink($aExtraParams)
{
$aExtraParams['c[menu]'] = $this->GetMenuId();
return $this->AddParams( $this->sHyperlink, $aExtraParams);
return $this->AddParams($this->sHyperlink, $aExtraParams);
}
/**
@@ -1313,7 +1262,7 @@ class WebPageMenuNode extends MenuNode
/**
* @inheritDoc
*/
public function RenderContent(WebPage $oPage, $aExtraParams = array())
public function RenderContent(WebPage $oPage, $aExtraParams = [])
{
assert(false); // Shall never be called, the external web page will handle the display by itself
}
@@ -1374,10 +1323,8 @@ class NewObjectMenuNode extends MenuNode
$aSubClasses = MetaModel::EnumChildClasses($this->sClass, ENUM_CHILD_CLASSES_ALL); // Including the specified class itself
$bActionIsAllowed = false;
foreach($aSubClasses as $sCandidateClass)
{
if (!MetaModel::IsAbstract($sCandidateClass) && (UserRights::IsActionAllowed($sCandidateClass, UR_ACTION_MODIFY) == UR_ALLOWED_YES))
{
foreach ($aSubClasses as $sCandidateClass) {
if (!MetaModel::IsAbstract($sCandidateClass) && (UserRights::IsActionAllowed($sCandidateClass, UR_ACTION_MODIFY) == UR_ALLOWED_YES)) {
$bActionIsAllowed = true;
break; // Enough for now
}
@@ -1388,7 +1335,7 @@ class NewObjectMenuNode extends MenuNode
/**
* @inheritDoc
*/
public function RenderContent(WebPage $oPage, $aExtraParams = array())
public function RenderContent(WebPage $oPage, $aExtraParams = [])
{
assert(false); // Shall never be called, the external web page will handle the display by itself
}
@@ -1428,7 +1375,9 @@ class DashboardMenuNode extends MenuNode
*/
public function GetHyperlink($aExtraParams)
{
if ($this->sDashboardFile == '') return '';
if ($this->sDashboardFile == '') {
return '';
}
return parent::GetHyperlink($aExtraParams);
}
@@ -1446,12 +1395,11 @@ class DashboardMenuNode extends MenuNode
* @inheritDoc
* @throws \Exception
*/
public function RenderContent(WebPage $oPage, $aExtraParams = array())
public function RenderContent(WebPage $oPage, $aExtraParams = [])
{
ApplicationMenu::CheckMenuIdEnabled($this->GetMenuId());
$oDashboard = $this->GetDashboard();
if ($oDashboard != null)
{
if ($oDashboard != null) {
WebResourcesHelper::EnableC3JSToWebPage($oPage);
$sDivId = utils::Sanitize($this->sMenuId, '', 'element_identifier');
@@ -1482,9 +1430,7 @@ class DashboardMenuNode extends MenuNode
}
$oPage->SetBreadCrumbEntry("ui-dashboard-".$this->sMenuId, $this->GetTitle(), $sDescription, '', $sIcon, iTopWebPage::ENUM_BREADCRUMB_ENTRY_ICON_TYPE_CSS_CLASSES);
}
}
else
{
} else {
$oPage->p("Error: failed to load dashboard file: '{$this->sDashboardFile}'");
}
}
@@ -1497,12 +1443,9 @@ class DashboardMenuNode extends MenuNode
public function RenderEditor(WebPage $oPage)
{
$oDashboard = $this->GetDashboard();
if ($oDashboard != null)
{
if ($oDashboard != null) {
$oDashboard->RenderEditor($oPage);
}
else
{
} else {
$oPage->p("Error: failed to load dashboard file: '{$this->sDashboardFile}'");
}
}
@@ -1514,13 +1457,10 @@ class DashboardMenuNode extends MenuNode
public function AddDashlet($oDashlet)
{
$oDashboard = $this->GetDashboard();
if ($oDashboard != null)
{
if ($oDashboard != null) {
$oDashboard->AddDashlet($oDashlet);
$oDashboard->Save();
}
else
{
} else {
throw new Exception("Error: failed to load dashboard file: '{$this->sDashboardFile}'");
}
}
@@ -1543,7 +1483,7 @@ class ShortcutContainerMenuNode extends MenuNode
/**
* @inheritDoc
*/
public function RenderContent(WebPage $oPage, $aExtraParams = array())
public function RenderContent(WebPage $oPage, $aExtraParams = [])
{
}
@@ -1558,10 +1498,9 @@ class ShortcutContainerMenuNode extends MenuNode
//
$oBMSearch = new DBObjectSearch('Shortcut');
$oBMSearch->AddCondition('user_id', UserRights::GetUserId(), '=');
$oBMSet = new DBObjectSet($oBMSearch, array('friendlyname' => true)); // ascending on friendlyname
$oBMSet = new DBObjectSet($oBMSearch, ['friendlyname' => true]); // ascending on friendlyname
$fRank = 1;
while ($oShortcut = $oBMSet->Fetch())
{
while ($oShortcut = $oBMSet->Fetch()) {
$sName = $this->GetMenuId().'_'.$oShortcut->GetKey();
new ShortcutMenuNode($sName, $oShortcut, $this->GetIndex(), $fRank++);
}
@@ -1572,7 +1511,6 @@ class ShortcutContainerMenuNode extends MenuNode
}
}
require_once(APPROOT.'application/shortcut.class.inc.php');
/**
* This class defines a menu item which content is a shortcut.
@@ -1609,12 +1547,10 @@ class ShortcutMenuNode extends MenuNode
{
$sContext = $this->oShortcut->Get('context');
$aContext = unserialize($sContext);
if (isset($aContext['menu']))
{
if (isset($aContext['menu'])) {
unset($aContext['menu']);
}
foreach ($aContext as $sArgName => $sArgValue)
{
foreach ($aContext as $sArgName => $sArgValue) {
$aExtraParams[$sArgName] = $sArgValue;
}
return parent::GetHyperlink($aExtraParams);
@@ -1624,7 +1560,7 @@ class ShortcutMenuNode extends MenuNode
* @inheritDoc
* @throws \Exception
*/
public function RenderContent(WebPage $oPage, $aExtraParams = array())
public function RenderContent(WebPage $oPage, $aExtraParams = [])
{
ApplicationMenu::CheckMenuIdEnabled($this->GetMenuId());
$this->oShortcut->RenderContent($oPage, $aExtraParams);
@@ -1661,11 +1597,9 @@ class ShortcutMenuNode extends MenuNode
return true;
}
public function GetEntriesCount()
{
return $this->GetEntriesCountFromOQL($this->oShortcut->Get('oql'));
}
}