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