forked from chamilo/chamilo-lms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCLinkDetailsController.php
57 lines (47 loc) · 2.01 KB
/
CLinkDetailsController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
declare(strict_types=1);
/* For licensing terms, see /license.txt */
namespace Chamilo\CoreBundle\Controller\Api;
use Chamilo\CoreBundle\Repository\AssetRepository;
use Chamilo\CourseBundle\Entity\CLink;
use Chamilo\CourseBundle\Repository\CShortcutRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
class CLinkDetailsController extends AbstractController
{
public function __invoke(CLink $link, CShortcutRepository $shortcutRepository, AssetRepository $assetRepository): Response
{
$shortcut = $shortcutRepository->getShortcutFromResource($link);
$isOnHomepage = null !== $shortcut;
$parentResourceNodeId = null;
if ($link->getResourceNode() && $link->getResourceNode()->getParent()) {
$parentResourceNodeId = $link->getResourceNode()->getParent()->getId();
}
$resourceLinkList = [];
if ($link->getResourceLinkEntityList()) {
foreach ($link->getResourceLinkEntityList() as $resourceLink) {
$resourceLinkList[] = [
'visibility' => $resourceLink->getVisibility(),
'cid' => $resourceLink->getCourse()->getId(),
'sid' => $resourceLink->getSession()->getId(),
];
}
}
$details = [
'url' => $link->getUrl(),
'title' => $link->getTitle(),
'description' => $link->getDescription(),
'onHomepage' => $isOnHomepage,
'target' => $link->getTarget(),
'parentResourceNodeId' => $parentResourceNodeId,
'resourceLinkList' => $resourceLinkList,
'category' => $link->getCategory()?->getIid(),
];
if (null !== $link->getCustomImage()) {
$details['customImageUrl'] = $assetRepository->getAssetUrl($link->getCustomImage());
} else {
$details['customImageUrl'] = null;
}
return $this->json($details, Response::HTTP_OK);
}
}