Skip to content

Commit 082e61f

Browse files
committed
Replacing usage of UrlManager::get_url_data with EntityRepository::findAll - refs BT#22639
1 parent 8d8ac6b commit 082e61f

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

public/main/admin/access_urls.php

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99
* @author Yannick Warnier <[email protected]>
1010
*/
1111

12+
use Chamilo\CoreBundle\Entity\AccessUrl;
1213
use Chamilo\CoreBundle\Enums\ActionIcon;
1314
use Chamilo\CoreBundle\Enums\StateIcon;
15+
use Chamilo\CoreBundle\Framework\Container;
1416
use Symfony\Component\HttpFoundation\Request as HttpRequest;
1517

1618
$cidReset = true;
@@ -26,7 +28,8 @@
2628

2729
$my_user_url_list = api_get_access_url_from_user(api_get_user_id());
2830
$current_access_url_id = api_get_current_access_url_id();
29-
$url_list = UrlManager::get_url_data();
31+
/** @var array<int, AccessUrl> $url_list */
32+
$url_list = Container::getAccessUrlRepository()->findAll();
3033

3134
// Actions
3235
if ($httpRequest->query->has('action')) {
@@ -55,9 +58,9 @@
5558
if (api_is_platform_admin() && -1 != $current_access_url_id) {
5659
$url_str = '';
5760
foreach ($url_list as $u) {
58-
if (!in_array($u['id'], $my_user_url_list)) {
59-
UrlManager::add_user_to_url(api_get_user_id(), $u['id']);
60-
$url_str .= $u['url'] . '<br />';
61+
if (!in_array($u->getId(), $my_user_url_list)) {
62+
UrlManager::add_user_to_url(api_get_user_id(), $u->getId());
63+
$url_str .= $u->getUrl() . '<br />';
6164
}
6265
}
6366
echo Display::return_message(
@@ -76,8 +79,8 @@
7679
// Checking if the admin is registered in all sites
7780
$url_string = '';
7881
foreach ($url_list as $u) {
79-
if (!in_array($u['id'], $my_user_url_list)) {
80-
$url_string .= $u['url'] . '<br />';
82+
if (!in_array($u->getId(), $my_user_url_list)) {
83+
$url_string .= $u->getUrl() . '<br />';
8184
}
8285
}
8386
if (!empty($url_string)) {
@@ -110,8 +113,8 @@
110113
// 1) Find the default URL (ID = 1)
111114
$defaultUrl = 'http://localhost/';
112115
foreach ($url_list as $u) {
113-
if ((string)$u['id'] === '1') {
114-
$defaultUrl = trim($u['url']);
116+
if ($u->getId() === 1) {
117+
$defaultUrl = trim($u->getUrl());
115118
break;
116119
}
117120
}
@@ -182,29 +185,29 @@
182185

183186
$rows = [];
184187
foreach ($url_list as $u) {
185-
$link = Display::url($u['url'], $u['url'], ['target' => '_blank']);
186-
$desc = $u['description'];
187-
$ts = api_get_local_time($u['tms']);
188-
$active = ($u['active'] === '1');
188+
$link = Display::url($u->getUrl(), $u->getUrl(), ['target' => '_blank']);
189+
$desc = $u->getDescription();
190+
$ts = api_get_local_time($u->getTms());
191+
$active = ($u->getActive() === 1);
189192

190193
$iconAction = $active ? 'lock' : 'unlock';
191194
$stateIcon = $active ? StateIcon::ACTIVE : StateIcon::INACTIVE;
192195

193-
if ((string)$u['id'] === '1') {
196+
if ($u->getId() === 1) {
194197
$status = Display::getMdiIcon($stateIcon, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang(ucfirst($iconAction)));
195198
} else {
196-
$status = '<a href="access_urls.php?action=' . $iconAction . '&url_id=' . $u['id'] . '">' .
199+
$status = '<a href="access_urls.php?action=' . $iconAction . '&url_id=' . $u->getId() . '">' .
197200
Display::getMdiIcon($stateIcon, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang(ucfirst($iconAction))) .
198201
'</a>';
199202
}
200203

201204
$rowActions = Display::url(
202205
Display::getMdiIcon(ActionIcon::EDIT, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Edit')),
203-
"access_url_edit.php?url_id={$u['id']}"
206+
"access_url_edit.php?url_id={$u->getId()}"
204207
);
205208

206-
if ((string)$u['id'] !== '1') {
207-
$rowActions .= '<a href="access_urls.php?action=delete_url&url_id=' . $u['id'] . '" ' .
209+
if ($u->getId() !== 1) {
210+
$rowActions .= '<a href="access_urls.php?action=delete_url&url_id=' . $u->getId() . '" ' .
208211
'onclick="return confirm(\'' . addslashes(get_lang('Please confirm your choice')) . '\');">' .
209212
Display::getMdiIcon('delete', 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Delete')) .
210213
'</a>';

0 commit comments

Comments
 (0)