From c97b8dcdd1fecda5ce7406634f78fb8efe181d88 Mon Sep 17 00:00:00 2001 From: Yannick Warnier Date: Mon, 14 Sep 2020 11:57:07 +0200 Subject: [PATCH] Learnpath: Add sanity checks in the lp-specific user subscription configuration page to avoir null errors - refs BT#17726 --- main/lp/lp_subscribe_users.php | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/main/lp/lp_subscribe_users.php b/main/lp/lp_subscribe_users.php index ccd9a31b99..0c007c11fd 100644 --- a/main/lp/lp_subscribe_users.php +++ b/main/lp/lp_subscribe_users.php @@ -94,8 +94,15 @@ $subscribedUsersInLp = $itemRepo->getUsersSubscribedToItem( ); $selectedChoices = []; -foreach ($subscribedUsersInLp as $itemProperty) { - $selectedChoices[] = $itemProperty->getToUser()->getId(); +if (!empty($subscribedUsersInLp)) { + foreach ($subscribedUsersInLp as $itemProperty) { + if (!empty($itemProperty)) { + $getToUser = $itemProperty->getToUser(); + if (!empty($getToUser)) { + $selectedChoices[] = $getToUser->getId(); + } + } + } } //Building the form for Users @@ -140,8 +147,15 @@ $subscribedGroupsInLp = $itemRepo->getGroupsSubscribedToItem( $selectedGroupChoices = []; /** @var CItemProperty $itemProperty */ -foreach ($subscribedGroupsInLp as $itemProperty) { - $selectedGroupChoices[] = $itemProperty->getGroup()->getId(); +if (!empty($subscribedGroupsInLp)) { + foreach ($subscribedGroupsInLp as $itemProperty) { + if (!empty($itemProperty)) { + $getGroup = $itemProperty->getGroup(); + if (!empty($getGroup)) { + $selectedGroupChoices[] = $itemProperty->getGroup()->getId(); + } + } + } } $groupMultiSelect = $form->addElement(