Skip to content

Commit

Permalink
[GT-183] Update code to line limit
Browse files Browse the repository at this point in the history
  • Loading branch information
Sae126V committed Aug 24, 2023
1 parent bf4b0a1 commit fb9a3ce
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 18 deletions.
47 changes: 37 additions & 10 deletions htdocs/web_portal/components/Draw_Components/menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ function draw_menu($mainMenuNameFromXML)
$user = $userService->getUserByPrinciple($identifier);

// Open the XML file of possible menus as a SimpleXML object
$menusInXML = simplexml_load_file(__DIR__ . '/../../../../config/web_portal/menu.xml');
$menusInXML = simplexml_load_file(
__DIR__ . '/../../../../config/web_portal/menu.xml'
);
$menusInHTML = xml_to_html($mainMenuNameFromXML, $menusInXML, $user);

return $menusInHTML;
Expand All @@ -54,8 +56,13 @@ function xml_to_html($mainMenuNameFromXML, $menusInXML, $user)
$html .= "<ul class=\"Smaller_Left_Padding Smaller_Top_Margin\">";
$isUserAdmin = isset($user) ? $user->isAdmin() : false;

foreach ($menusInXML->$mainMenuNameFromXML->children() as $key => $value) {
// Check if the display of menu is overridden in the local configuration
foreach (
$menusInXML->$mainMenuNameFromXML->children() as $key => $value
) {
/**
* Check if the display of menu is overridden
* in the local configuration
*/
if (\Factory::getConfigService()->showMenu($key)) {
if ($key == "ViewServiceTypes") {
if ($isUserAdmin) {
Expand All @@ -80,14 +87,22 @@ function add_menu_item($menuItem, $isUserAdmin)
if ($key == "spacer") {
$showOnInstanceValue = $menuItem->show_on_instance;

// If the spacer has a show_on_instance type that we want to show, then show it
/**
* If the spacer has a show_on_instance type that we want to show,
* then show it.
*/
if (
!empty($showOnInstanceValue) &&
canMenuItemBeDisplayed($showOnInstanceValue, $portalIsReadOnly, $isUserAdmin)
canMenuItemBeDisplayed(
$showOnInstanceValue,
$portalIsReadOnly,
$isUserAdmin
)
) {
return "</ul>
<h4 class='menu_title'>$value</h4>
<ul class=\"Smaller_Left_Padding Smaller_Top_Margin\">";
<ul class=\"Smaller_Left_Padding Smaller_Top_Margin\">
";
}

return;
Expand All @@ -98,7 +113,13 @@ function add_menu_item($menuItem, $isUserAdmin)
$name = $menuItem->name;
$link = $menuItem->link;

if (canMenuItemBeDisplayed($showOnInstanceValue, $portalIsReadOnly, $isUserAdmin)) {
if (
canMenuItemBeDisplayed(
$showOnInstanceValue,
$portalIsReadOnly,
$isUserAdmin
)
) {
$html .= "<li class=\"Menu_Item\">" .
"<a href=\"" . htmlspecialchars($link) . "\">
<span class=\"menu_link\">" .
Expand All @@ -111,11 +132,17 @@ function add_menu_item($menuItem, $isUserAdmin)
return $html;
}

function canMenuItemBeDisplayed($showOnInstanceValue, $portalIsReadOnly, $isUserAdmin)
{
function canMenuItemBeDisplayed(
$showOnInstanceValue,
$portalIsReadOnly,
$isUserAdmin
) {
return (
($showOnInstanceValue == "all") or
($showOnInstanceValue == "write_enabled" and (!$portalIsReadOnly or $isUserAdmin)) or
(
$showOnInstanceValue == "write_enabled" and
(!$portalIsReadOnly or $isUserAdmin)
) or
(($showOnInstanceValue == "admin") and ($isUserAdmin))
);
}
3 changes: 2 additions & 1 deletion htdocs/web_portal/controllers/admin/view_service_type.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ function view_service_type($slicedURLSearchName)
$params['isUserAdmin'] = checkUserForAdminCredentials($user);

if (!$params['isUserAdmin'] && $slicedURLSearchName == "Admin") {
checkUserIsAdmin(); // Since the user is NOT an Admin, it will throw an ERROR.
// Since the user is NOT an Admin, it will throw an ERROR.
checkUserIsAdmin();
}

if (!isset($_REQUEST['id']) || !is_numeric($_REQUEST['id'])) {
Expand Down
3 changes: 2 additions & 1 deletion htdocs/web_portal/controllers/admin/view_service_types.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ function show_all($slicedURLSearchName)
$params['isUserAdmin'] = checkUserForAdminCredentials($user);

if (!$params['isUserAdmin'] && $slicedURLSearchName == 'Admin') {
checkUserIsAdmin(); // Since the user is NOT an Admin, it will throw an ERROR.
// Since the user is NOT an Admin, it will throw an ERROR.
checkUserIsAdmin();
}

$serviceTypes = \Factory::getServiceTypeService()->getServiceTypes();
Expand Down
3 changes: 2 additions & 1 deletion htdocs/web_portal/controllers/utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,8 @@ function portalIsReadOnlyAndUserIsNotAdmin(\user $user = null)
// this block is required to deal with unregistered users (where $user is null)
$userIsAdmin = false;
if (! is_null($user)) {
if (checkUserForAdminCredentials($user)) { // sub query required becauser ->isAdmin can't be called on null
// Sub query required becauser ->isAdmin can't be called on null
if (checkUserForAdminCredentials($user)) {
$userIsAdmin = true;
}
}
Expand Down
4 changes: 2 additions & 2 deletions htdocs/web_portal/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ function testForHtmlSpecialChars($value, $key){

/**
* Helper method to get a relative PATH for the required file when `Page_type`
* is equals to either `Service_Types`, `Service_Type`, `Admin_Service_Types` or
* `Admin_Service_Type`.
* is equals to either `Service_Types`, `Service_Type`, `Admin_Service_Types`
* or `Admin_Service_Type`.
*/
function helperForServiceTypes($iServiceType)
{
Expand Down
10 changes: 7 additions & 3 deletions htdocs/web_portal/views/admin/view_service_types.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@
</tr>
<?php
$num = 2;
$searchName = $params['isUserAdmin'] ? 'Admin_Service_Type' : 'Service_Type';
$searchName = $params['isUserAdmin']
? 'Admin_Service_Type'
: 'Service_Type';

if ($numberOfServiceTypes > 0) {
foreach ($params['ServiceTypes'] as $serviceType) {
Expand All @@ -52,8 +54,10 @@
<div style="background-color: inherit;">
<span style="vertical-align: middle;">
<?php
echo "<a href=\"index.php?Page_Type=" . $searchName
. "&amp;id=" . $serviceType->getId() . "\">"
echo "<a href=\"index.php?Page_Type="
. $searchName
. "&amp;id=" . $serviceType->getId()
. "\">"
. $serviceType->getName()
. "</a>";
?>
Expand Down

0 comments on commit fb9a3ce

Please sign in to comment.