-
Notifications
You must be signed in to change notification settings - Fork 494
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Documents: Add support for URL-specific document variations - refs #5956 #5976
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,223 @@ | ||
<template> | ||
<div class="p-4 space-y-8"> | ||
<SectionHeader :title="t('Add File Variation')"> | ||
<BaseButton | ||
:label="t('Back to Documents')" | ||
icon="back" | ||
type="gray" | ||
@click="goBack" | ||
/> | ||
</SectionHeader> | ||
|
||
<div v-if="originalFile" class="bg-gray-100 p-4 rounded-md shadow-md"> | ||
<h3 class="text-lg font-semibold">{{ t('Original File') }}</h3> | ||
<p><strong>{{ t('Title:') }}</strong> {{ originalFile.originalName }}</p> | ||
<p><strong>{{ t('Format:') }}</strong> {{ originalFile.mimeType }}</p> | ||
<p><strong>{{ t('Size:') }}</strong> {{ prettyBytes(originalFile.size) }}</p> | ||
</div> | ||
|
||
<div class="space-y-6"> | ||
<h3 class="text-xl font-bold">{{ t('Upload New Variation') }}</h3> | ||
|
||
<form @submit.prevent="uploadVariation" class="flex flex-col space-y-4"> | ||
<div class="grid grid-cols-1 md:grid-cols-2 gap-4"> | ||
<BaseFileUpload | ||
@file-selected="onFileSelected" | ||
:label="t('Choose file')" | ||
accept=".pdf,.html,.docx,.mp4" | ||
required | ||
class="w-full" | ||
/> | ||
|
||
<Dropdown | ||
v-model="selectedAccessUrl" | ||
:options="accessUrls" | ||
optionLabel="url" | ||
optionValue="id" | ||
placeholder="Select a URL" | ||
class="w-full" | ||
/> | ||
</div> | ||
|
||
<div class="flex justify-end"> | ||
<BaseButton | ||
:label="t('Upload')" | ||
icon="file-upload" | ||
type="success" | ||
:disabled="!file" | ||
@click="uploadVariant(file, originalFile?.resourceNode?.id, selectedAccessUrl)" | ||
/> | ||
</div> | ||
</form> | ||
</div> | ||
|
||
<div> | ||
<h3 class="text-xl font-bold mb-4">{{ t('Current Variations') }}</h3> | ||
<DataTable :value="variations" class="w-full"> | ||
<Column field="title" :header="t('Title')" /> | ||
<Column field="mimeType" :header="t('Format')" /> | ||
<Column field="size" :header="t('Size')"> | ||
<template #body="slotProps"> | ||
{{ prettyBytes(slotProps.data.size) }} | ||
</template> | ||
</Column> | ||
<Column field="updatedAt" :header="t('Updated At')" /> | ||
<Column field="url" :header="t('URL')"> | ||
<template #body="slotProps"> | ||
<a | ||
:href="slotProps.data.path" | ||
target="_blank" | ||
class="text-blue-500 hover:underline" | ||
> | ||
{{ t('View') }} | ||
</a> | ||
</template> | ||
</Column> | ||
<Column field="creator" :header="t('Creator')" /> | ||
<Column field="accessUrl" :header="t('Associated URL')"> | ||
<template #body="slotProps"> | ||
<span> | ||
{{ slotProps.data.url ? slotProps.data.url : t('Default (No URL)') }} | ||
</span> | ||
</template> | ||
</Column> | ||
<Column> | ||
<template #header>{{ t('Actions') }}</template> | ||
<template #body="slotProps"> | ||
<BaseButton | ||
:label="t('Delete')" | ||
icon="delete" | ||
type="danger" | ||
@click="deleteVariant(slotProps.data.id)" | ||
/> | ||
</template> | ||
</Column> | ||
</DataTable> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script setup> | ||
import { ref, onMounted, computed } from "vue" | ||
import { useRoute, useRouter } from 'vue-router' | ||
import { useI18n } from 'vue-i18n' | ||
import axios from 'axios' | ||
import DataTable from 'primevue/datatable' | ||
import Column from 'primevue/column' | ||
import SectionHeader from "../../components/layout/SectionHeader.vue" | ||
import BaseButton from "../../components/basecomponents/BaseButton.vue" | ||
import BaseFileUpload from "../../components/basecomponents/BaseFileUpload.vue" | ||
import prettyBytes from 'pretty-bytes' | ||
import { useCidReq } from "../../composables/cidReq" | ||
import { useSecurityStore } from "../../store/securityStore" | ||
const securityStore = useSecurityStore() | ||
const route = useRoute() | ||
const router = useRouter() | ||
const { t } = useI18n() | ||
const { cid, sid, gid } = useCidReq() | ||
const file = ref(null) | ||
const variations = ref([]) | ||
const originalFile = ref(null) | ||
const resourceFileId = route.params.resourceFileId | ||
const selectedAccessUrl = ref(null) | ||
const accessUrls = ref([]) | ||
const isAdmin = computed(() => securityStore.isAdmin) | ||
onMounted(async () => { | ||
if (!isAdmin.value) { | ||
await router.push({ name: 'DocumentsList' }) | ||
return | ||
} | ||
await fetchOriginalFile() | ||
await fetchVariations() | ||
await fetchAccessUrls() | ||
}) | ||
async function fetchVariations() { | ||
if (!originalFile.value?.resourceNode?.id) { | ||
console.error('ResourceNodeId is undefined. Cannot fetch variations.') | ||
return | ||
} | ||
try { | ||
const resourceNodeId = originalFile.value.resourceNode.id | ||
const response = await axios.get(`/r/resource_files/${resourceNodeId}/variants`) | ||
variations.value = response.data | ||
} catch (error) { | ||
console.error('Error fetching variations:', error) | ||
} | ||
} | ||
async function fetchAccessUrls() { | ||
try { | ||
const response = await axios.get('/api/access_urls') | ||
if (Array.isArray(response.data['hydra:member'])) { | ||
const currentAccessUrlId = window.access_url_id | ||
accessUrls.value = response.data['hydra:member'].filter( | ||
(url) => url.id !== currentAccessUrlId | ||
) | ||
} else { | ||
accessUrls.value = [] | ||
} | ||
} catch (error) { | ||
console.error('Error fetching access URLs:', error) | ||
accessUrls.value = [] | ||
} | ||
} | ||
async function fetchOriginalFile() { | ||
try { | ||
const response = await axios.get(`/api/resource_files/${resourceFileId}`) | ||
originalFile.value = response.data | ||
} catch (error) { | ||
console.error('Error fetching original file:', error) | ||
} | ||
} | ||
async function uploadVariant(file, resourceNodeId, accessUrlId) { | ||
if (!resourceNodeId) { | ||
console.error('ResourceNodeId is undefined. Check originalFile:', originalFile.value) | ||
return | ||
} | ||
const formData = new FormData() | ||
formData.append('file', file) | ||
formData.append('resourceNodeId', resourceNodeId) | ||
if (accessUrlId) { | ||
formData.append('accessUrlId', accessUrlId) | ||
} | ||
try { | ||
const response = await axios.post('/api/resource_files/add_variant', formData) | ||
console.log('Variant uploaded or updated successfully:', response.data) | ||
await fetchVariations() | ||
file.value = null | ||
selectedAccessUrl.value = null | ||
} catch (error) { | ||
console.error('Error uploading variant:', error) | ||
} | ||
} | ||
async function deleteVariant(variantId) { | ||
try { | ||
await axios.delete(`/r/resource_files/${variantId}/delete_variant`) | ||
console.log('Variant deleted successfully.') | ||
await fetchVariations() | ||
} catch (error) { | ||
console.error('Error deleting variant:', error) | ||
} | ||
} | ||
function onFileSelected(selectedFile) { | ||
file.value = selectedFile | ||
} | ||
function goBack() { | ||
let queryParams = { cid, sid, gid } | ||
router.push({ name: "DocumentsList", params: { node: parent.id }, query: queryParams }) | ||
} | ||
</script> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* For licensing terms, see /license.txt */ | ||
|
||
namespace Chamilo\CoreBundle\Controller; | ||
|
||
use Chamilo\CoreBundle\Entity\ResourceFile; | ||
use Chamilo\CoreBundle\Entity\ResourceNode; | ||
use Chamilo\CoreBundle\Entity\AccessUrl; | ||
use Doctrine\ORM\EntityManagerInterface; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; | ||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; | ||
|
||
class AddVariantResourceFileAction | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing class doc comment |
||
{ | ||
public function __invoke(Request $request, EntityManagerInterface $em): ResourceFile | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing function doc comment |
||
{ | ||
$uploadedFile = $request->files->get('file'); | ||
if (!$uploadedFile) { | ||
throw new BadRequestHttpException('"file" is required'); | ||
} | ||
|
||
$resourceNodeId = $request->get('resourceNodeId'); | ||
if (!$resourceNodeId) { | ||
throw new BadRequestHttpException('"resourceNodeId" is required'); | ||
} | ||
|
||
$resourceNode = $em->getRepository(ResourceNode::class)->find($resourceNodeId); | ||
if (!$resourceNode) { | ||
throw new NotFoundHttpException('ResourceNode not found'); | ||
} | ||
|
||
$accessUrlId = $request->get('accessUrlId'); | ||
$accessUrl = null; | ||
if ($accessUrlId) { | ||
$accessUrl = $em->getRepository(AccessUrl::class)->find($accessUrlId); | ||
if (!$accessUrl) { | ||
throw new NotFoundHttpException('AccessUrl not found'); | ||
} | ||
} | ||
|
||
$existingResourceFile = $em->getRepository(ResourceFile::class)->findOneBy([ | ||
'resourceNode' => $resourceNode, | ||
'accessUrl' => $accessUrl, | ||
]); | ||
|
||
if ($existingResourceFile) { | ||
$existingResourceFile->setTitle($uploadedFile->getClientOriginalName()); | ||
$existingResourceFile->setFile($uploadedFile); | ||
$existingResourceFile->setUpdatedAt(\DateTime::createFromImmutable(new \DateTimeImmutable())); | ||
$resourceFile = $existingResourceFile; | ||
} else { | ||
$resourceFile = new ResourceFile(); | ||
$resourceFile->setTitle($uploadedFile->getClientOriginalName()); | ||
$resourceFile->setFile($uploadedFile); | ||
$resourceFile->setResourceNode($resourceNode); | ||
|
||
if ($accessUrl) { | ||
$resourceFile->setAccessUrl($accessUrl); | ||
} | ||
} | ||
|
||
$em->persist($resourceFile); | ||
$em->flush(); | ||
|
||
return $resourceFile; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,15 +7,19 @@ | |
namespace Chamilo\CoreBundle\Controller; | ||
|
||
use Chamilo\CoreBundle\Entity\Course; | ||
use Chamilo\CoreBundle\Entity\ResourceFile; | ||
use Chamilo\CoreBundle\Entity\ResourceLink; | ||
use Chamilo\CoreBundle\Entity\ResourceNode; | ||
use Chamilo\CoreBundle\Entity\Session; | ||
use Chamilo\CoreBundle\Entity\User; | ||
use Chamilo\CoreBundle\Repository\ResourceFileRepository; | ||
use Chamilo\CoreBundle\Repository\ResourceNodeRepository; | ||
use Chamilo\CoreBundle\Repository\ResourceWithLinkInterface; | ||
use Chamilo\CoreBundle\Repository\TrackEDownloadsRepository; | ||
use Chamilo\CoreBundle\Security\Authorization\Voter\ResourceNodeVoter; | ||
use Chamilo\CoreBundle\ServiceHelper\AccessUrlHelper; | ||
use Chamilo\CoreBundle\ServiceHelper\UserHelper; | ||
use Chamilo\CoreBundle\Settings\SettingsManager; | ||
use Chamilo\CoreBundle\Tool\ToolChain; | ||
use Chamilo\CoreBundle\Traits\ControllerTrait; | ||
use Chamilo\CoreBundle\Traits\CourseControllerTrait; | ||
|
@@ -59,6 +63,7 @@ class ResourceController extends AbstractResourceController implements CourseCon | |
public function __construct( | ||
private readonly UserHelper $userHelper, | ||
private readonly ResourceNodeRepository $resourceNodeRepository, | ||
private readonly ResourceFileRepository $resourceFileRepository | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line indented incorrectly; expected 4 spaces, found 8 |
||
) {} | ||
|
||
#[Route(path: '/{tool}/{type}/{id}/disk_space', methods: ['GET', 'POST'], name: 'chamilo_core_resource_disk_space')] | ||
|
@@ -136,21 +141,55 @@ public function diskSpace(Request $request): Response | |
* View file of a resource node. | ||
*/ | ||
#[Route('/{tool}/{type}/{id}/view', name: 'chamilo_core_resource_view', methods: ['GET'])] | ||
public function view(Request $request, TrackEDownloadsRepository $trackEDownloadsRepository): Response | ||
{ | ||
public function view( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You must use "/**" style comments for a function comment |
||
Request $request, | ||
TrackEDownloadsRepository $trackEDownloadsRepository, | ||
SettingsManager $settingsManager, | ||
AccessUrlHelper $accessUrlHelper | ||
): Response { | ||
|
||
$id = $request->get('id'); | ||
$filter = (string) $request->get('filter'); // See filters definitions in /config/services.yml. | ||
$resourceFileId = $request->get('resourceFileId'); | ||
$filter = (string) $request->get('filter'); | ||
$resourceNode = $this->getResourceNodeRepository()->findOneBy(['uuid' => $id]); | ||
|
||
if (null === $resourceNode) { | ||
throw new FileNotFoundException($this->trans('Resource not found')); | ||
} | ||
|
||
$resourceFile = null; | ||
if ($resourceFileId) { | ||
$resourceFile = $this->resourceFileRepository->find($resourceFileId); | ||
} | ||
|
||
if (!$resourceFile) { | ||
$accessUrlSpecificFiles = $settingsManager->getSetting('course.access_url_specific_files') && $accessUrlHelper->isMultiple(); | ||
$currentUrl = $accessUrlHelper->getCurrent()?->getUrl(); | ||
|
||
$resourceFiles = $resourceNode->getResourceFiles(); | ||
|
||
if ($accessUrlSpecificFiles) { | ||
foreach ($resourceFiles as $file) { | ||
if ($file->getAccessUrl() && $file->getAccessUrl()->getUrl() === $currentUrl) { | ||
$resourceFile = $file; | ||
break; | ||
} | ||
} | ||
} | ||
|
||
if (!$resourceFile) { | ||
$resourceFile = $resourceFiles->filter(fn($file) => $file->getAccessUrl() === null)->first(); | ||
} | ||
} | ||
|
||
if (!$resourceFile) { | ||
throw new FileNotFoundException($this->trans('Resource file not found for the given resource node')); | ||
} | ||
|
||
$user = $this->userHelper->getCurrent(); | ||
$firstResourceLink = $resourceNode->getResourceLinks()->first(); | ||
$firstResourceFile = $resourceNode->getResourceFiles()->first(); | ||
if ($firstResourceLink && $user && $firstResourceFile) { | ||
$url = $firstResourceFile->getOriginalName(); | ||
if ($firstResourceLink && $user) { | ||
$url = $resourceFile->getOriginalName(); | ||
$trackEDownloadsRepository->saveDownload($user, $firstResourceLink, $url); | ||
} | ||
|
||
|
@@ -166,7 +205,7 @@ public function view(Request $request, TrackEDownloadsRepository $trackEDownload | |
); | ||
} | ||
|
||
return $this->processFile($request, $resourceNode, 'show', $filter, $allUserInfo); | ||
return $this->processFile($request, $resourceNode, 'show', $filter, $allUserInfo, $resourceFile); | ||
} | ||
|
||
/** | ||
|
@@ -212,8 +251,12 @@ public function link(Request $request, RouterInterface $router, CLinkRepository | |
* Download file of a resource node. | ||
*/ | ||
#[Route('/{tool}/{type}/{id}/download', name: 'chamilo_core_resource_download', methods: ['GET'])] | ||
public function download(Request $request, TrackEDownloadsRepository $trackEDownloadsRepository): Response | ||
{ | ||
public function download( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You must use "/**" style comments for a function comment |
||
Request $request, | ||
TrackEDownloadsRepository $trackEDownloadsRepository, | ||
SettingsManager $settingsManager, | ||
AccessUrlHelper $accessUrlHelper | ||
): Response { | ||
$id = $request->get('id'); | ||
$resourceNode = $this->getResourceNodeRepository()->findOneBy(['uuid' => $id]); | ||
|
||
|
@@ -229,21 +272,38 @@ public function download(Request $request, TrackEDownloadsRepository $trackEDown | |
$this->trans('Unauthorised access to resource') | ||
); | ||
|
||
$accessUrlSpecificFiles = $settingsManager->getSetting('course.access_url_specific_files') && $accessUrlHelper->isMultiple(); | ||
$currentUrl = $accessUrlHelper->getCurrent()?->getUrl(); | ||
|
||
$resourceFiles = $resourceNode->getResourceFiles(); | ||
$resourceFile = null; | ||
|
||
if ($accessUrlSpecificFiles) { | ||
foreach ($resourceFiles as $file) { | ||
if ($file->getAccessUrl() && $file->getAccessUrl()->getUrl() === $currentUrl) { | ||
$resourceFile = $file; | ||
break; | ||
} | ||
} | ||
} | ||
|
||
$resourceFile ??= $resourceFiles->filter(fn($file) => $file->getAccessUrl() === null)->first(); | ||
|
||
// If resource node has a file just download it. Don't download the children. | ||
if ($resourceNode->hasResourceFile()) { | ||
if ($resourceFile) { | ||
$user = $this->userHelper->getCurrent(); | ||
$firstResourceLink = $resourceNode->getResourceLinks()->first(); | ||
if ($firstResourceLink) { | ||
$url = $resourceNode->getResourceFiles()->first()->getOriginalName(); | ||
|
||
if ($firstResourceLink && $user) { | ||
$url = $resourceFile->getOriginalName(); | ||
$trackEDownloadsRepository->saveDownload($user, $firstResourceLink, $url); | ||
} | ||
|
||
// Redirect to download single file. | ||
return $this->processFile($request, $resourceNode, 'download'); | ||
return $this->processFile($request, $resourceNode, 'download', '', null, $resourceFile); | ||
} | ||
|
||
$zipName = $resourceNode->getSlug().'.zip'; | ||
// $rootNodePath = $resourceNode->getPathForDisplay(); | ||
$resourceNodeRepo = $repo->getResourceNodeRepository(); | ||
$type = $repo->getResourceType(); | ||
|
||
|
@@ -282,12 +342,14 @@ function () use ($zipName, $children, $repo): void { | |
|
||
/** @var ResourceNode $node */ | ||
foreach ($children as $node) { | ||
$stream = $repo->getResourceNodeFileStream($node); | ||
$fileName = $node->getResourceFiles()->first()->getOriginalName(); | ||
// $fileToDisplay = basename($node->getPathForDisplay()); | ||
// $fileToDisplay = str_replace($rootNodePath, '', $node->getPathForDisplay()); | ||
// error_log($fileToDisplay); | ||
$zip->addFileFromStream($fileName, $stream); | ||
$resourceFiles = $node->getResourceFiles(); | ||
$resourceFile = $resourceFiles->filter(fn($file) => $file->getAccessUrl() === null)->first(); | ||
|
||
if ($resourceFile) { | ||
$stream = $repo->getResourceNodeFileStream($resourceFile); | ||
$fileName = $resourceFile->getOriginalName(); | ||
$zip->addFileFromStream($fileName, $stream); | ||
} | ||
} | ||
$zip->finish(); | ||
} | ||
|
@@ -458,15 +520,60 @@ public function changeVisibilityAll( | |
return new Response(null, Response::HTTP_NO_CONTENT); | ||
} | ||
|
||
private function processFile(Request $request, ResourceNode $resourceNode, string $mode = 'show', string $filter = '', ?array $allUserInfo = null): mixed | ||
#[Route('/resource_files/{resourceNodeId}/variants', name: 'chamilo_core_resource_files_variants', methods: ['GET'])] | ||
ywarnier marked this conversation as resolved.
Show resolved
Hide resolved
|
||
public function getVariants(string $resourceNodeId, EntityManagerInterface $em): JsonResponse | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You must use "/**" style comments for a function comment |
||
{ | ||
$variants = $em->getRepository(ResourceFile::class)->createQueryBuilder('rf') | ||
->join('rf.resourceNode', 'rn') | ||
->leftJoin('rn.creator', 'creator') | ||
->where('rf.resourceNode = :resourceNodeId') | ||
->andWhere('rf.accessUrl IS NOT NULL') | ||
->setParameter('resourceNodeId', $resourceNodeId) | ||
->getQuery() | ||
->getResult(); | ||
|
||
$data = []; | ||
|
||
/* @var ResourceFile $variant */ | ||
foreach ($variants as $variant) { | ||
$data[] = [ | ||
'id' => $variant->getId(), | ||
'title' => $variant->getOriginalName(), | ||
'mimeType' => $variant->getMimeType(), | ||
'size' => $variant->getSize(), | ||
'updatedAt' => $variant->getUpdatedAt()->format('Y-m-d H:i:s'), | ||
'url' => $variant->getAccessUrl() ? $variant->getAccessUrl()->getUrl() : null, | ||
'path' => $this->resourceNodeRepository->getResourceFileUrl($variant->getResourceNode(), [], null, $variant), | ||
'creator' => $variant->getResourceNode()->getCreator() ? $variant->getResourceNode()->getCreator()->getFullName() : 'Unknown', | ||
]; | ||
} | ||
|
||
return $this->json($data); | ||
} | ||
|
||
#[Route('/resource_files/{id}/delete_variant', methods: ['DELETE'], name: 'chamilo_core_resource_files_delete_variant')] | ||
ywarnier marked this conversation as resolved.
Show resolved
Hide resolved
|
||
public function deleteVariant(int $id, EntityManagerInterface $em): JsonResponse | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You must use "/**" style comments for a function comment |
||
{ | ||
$variant = $em->getRepository(ResourceFile::class)->find($id); | ||
if (!$variant) { | ||
return $this->json(['error' => 'Variant not found'], Response::HTTP_NOT_FOUND); | ||
} | ||
|
||
$em->remove($variant); | ||
$em->flush(); | ||
|
||
return $this->json(['success' => true]); | ||
} | ||
|
||
private function processFile(Request $request, ResourceNode $resourceNode, string $mode = 'show', string $filter = '', ?array $allUserInfo = null, ?ResourceFile $resourceFile = null): mixed | ||
{ | ||
$this->denyAccessUnlessGranted( | ||
ResourceNodeVoter::VIEW, | ||
$resourceNode, | ||
$this->trans('Unauthorised view access to resource') | ||
); | ||
|
||
$resourceFile = $resourceNode->getResourceFiles()->first(); | ||
$resourceFile ??= $resourceNode->getResourceFiles()->first(); | ||
|
||
if (!$resourceFile) { | ||
throw $this->createNotFoundException($this->trans('File not found for resource')); | ||
|
@@ -523,7 +630,7 @@ private function processFile(Request $request, ResourceNode $resourceNode, strin | |
|
||
// Modify the HTML content before displaying it. | ||
if (str_contains($mimeType, 'html')) { | ||
$content = $resourceNodeRepo->getResourceNodeFileContent($resourceNode); | ||
$content = $resourceNodeRepo->getResourceNodeFileContent($resourceNode, $resourceFile); | ||
|
||
if (null !== $allUserInfo) { | ||
$tagsToReplace = $allUserInfo[0]; | ||
|
@@ -569,8 +676,8 @@ private function processFile(Request $request, ResourceNode $resourceNode, strin | |
} | ||
|
||
$response = new StreamedResponse( | ||
function () use ($resourceNode, $start, $length): void { | ||
$this->streamFileContent($resourceNode, $start, $length); | ||
function () use ($resourceNodeRepo, $resourceFile, $start, $length): void { | ||
$this->streamFileContent($resourceNodeRepo, $resourceFile, $start, $length); | ||
} | ||
); | ||
|
||
|
@@ -611,9 +718,9 @@ private function getRange(Request $request, int $fileSize): array | |
return [$start, $end, $length]; | ||
} | ||
|
||
private function streamFileContent(ResourceNode $resourceNode, int $start, int $length): void | ||
private function streamFileContent(ResourceNodeRepository $resourceNodeRepo, ResourceFile $resourceFile, int $start, int $length): void | ||
{ | ||
$stream = $this->resourceNodeRepository->getResourceNodeFileStream($resourceNode); | ||
$stream = $resourceNodeRepo->getResourceNodeFileStream($resourceFile->getResourceNode(), $resourceFile); | ||
|
||
fseek($stream, $start); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ | |
use ApiPlatform\Metadata\GetCollection; | ||
use ApiPlatform\Metadata\Post; | ||
use ApiPlatform\Serializer\Filter\PropertyFilter; | ||
use Chamilo\CoreBundle\Controller\AddVariantResourceFileAction; | ||
use Chamilo\CoreBundle\Controller\CreateResourceFileAction; | ||
use Chamilo\CoreBundle\Repository\ResourceFileRepository; | ||
use DateTime; | ||
|
@@ -40,6 +41,7 @@ | |
new Post( | ||
controller: CreateResourceFileAction::class, | ||
openapiContext: [ | ||
'summary' => 'Create a new resource file', | ||
'requestBody' => [ | ||
'content' => [ | ||
'multipart/form-data' => [ | ||
|
@@ -62,6 +64,37 @@ | |
], | ||
deserialize: false | ||
), | ||
new Post( | ||
uriTemplate: '/resource_files/add_variant', | ||
controller: AddVariantResourceFileAction::class, | ||
openapiContext: [ | ||
'summary' => 'Add a variant to an existing resource file', | ||
'requestBody' => [ | ||
'content' => [ | ||
'multipart/form-data' => [ | ||
'schema' => [ | ||
'type' => 'object', | ||
'properties' => [ | ||
'file' => [ | ||
'type' => 'string', | ||
'format' => 'binary', | ||
], | ||
'resourceNodeId' => [ | ||
'type' => 'integer', | ||
], | ||
'accessUrlId' => [ | ||
'type' => 'integer', | ||
], | ||
], | ||
], | ||
], | ||
], | ||
], | ||
], | ||
security: 'is_granted(\'ROLE_USER\')', | ||
deserialize: false, | ||
name: 'add_variant' | ||
), | ||
new GetCollection(), | ||
], | ||
normalizationContext: [ | ||
|
@@ -150,6 +183,11 @@ class ResourceFile implements Stringable | |
#[ORM\Column(type: 'datetime')] | ||
protected $updatedAt; | ||
|
||
#[ORM\ManyToOne(targetEntity: AccessUrl::class)] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perl-style comments are not allowed. Use "// Comment." or "/* comment */" instead. |
||
#[ORM\JoinColumn(name: 'access_url_id', referencedColumnName: 'id', nullable: true, onDelete: 'SET NULL')] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perl-style comments are not allowed. Use "// Comment." or "/* comment */" instead. |
||
protected ?AccessUrl $accessUrl = null; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line indented incorrectly; expected 8 spaces, found 4 |
||
|
||
#[Groups(['resource_file:read', 'resource_node:read', 'document:read'])] | ||
#[ORM\ManyToOne(inversedBy: 'resourceFiles')] | ||
private ?ResourceNode $resourceNode = null; | ||
|
||
|
@@ -332,6 +370,17 @@ public function setFile(File|UploadedFile|null $file = null): self | |
return $this; | ||
} | ||
|
||
public function getAccessUrl(): ?AccessUrl | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line indented incorrectly; expected 8 spaces, found 4 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing function doc comment |
||
{ | ||
return $this->accessUrl; | ||
} | ||
|
||
public function setAccessUrl(?AccessUrl $accessUrl): self | ||
{ | ||
$this->accessUrl = $accessUrl; | ||
return $this; | ||
} | ||
|
||
public function getResourceNode(): ?ResourceNode | ||
{ | ||
return $this->resourceNode; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* For licensing terms, see /license.txt */ | ||
|
||
namespace Chamilo\CoreBundle\Migrations\Schema\V200; | ||
|
||
use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo; | ||
use Doctrine\DBAL\Schema\Schema; | ||
|
||
final class Version20241214083500 extends AbstractMigrationChamilo | ||
{ | ||
public function getDescription(): string | ||
{ | ||
return 'Add access_url_id field to resource_file table'; | ||
} | ||
|
||
public function up(Schema $schema): void | ||
{ | ||
if ($schema->hasTable('resource_file')) { | ||
$this->addSql( | ||
'ALTER TABLE resource_file ADD access_url_id INT DEFAULT NULL' | ||
); | ||
$this->addSql( | ||
'ALTER TABLE resource_file ADD CONSTRAINT FK_RESOURCE_FILE_ACCESS_URL FOREIGN KEY (access_url_id) REFERENCES access_url (id) ON DELETE SET NULL' | ||
); | ||
$this->addSql( | ||
'CREATE INDEX IDX_RESOURCE_FILE_ACCESS_URL ON resource_file (access_url_id)' | ||
); | ||
} | ||
|
||
$result = $this->connection | ||
->executeQuery( | ||
"SELECT COUNT(1) FROM settings WHERE variable = 'access_url_specific_files' AND category = 'course'" | ||
) | ||
; | ||
$count = $result->fetchNumeric()[0]; | ||
if (empty($count)) { | ||
$this->addSql( | ||
"INSERT INTO settings (variable, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('access_url_specific_files','course','false','Access Url Specific Files','','',NULL, 1)" | ||
); | ||
} | ||
} | ||
|
||
public function down(Schema $schema): void | ||
{ | ||
if ($schema->hasTable('resource_file')) { | ||
$this->addSql( | ||
'ALTER TABLE resource_file DROP FOREIGN KEY FK_RESOURCE_FILE_ACCESS_URL' | ||
); | ||
$this->addSql( | ||
'DROP INDEX IDX_RESOURCE_FILE_ACCESS_URL ON resource_file' | ||
); | ||
$this->addSql( | ||
'ALTER TABLE resource_file DROP COLUMN access_url_id' | ||
); | ||
} | ||
} | ||
} |
Unchanged files with check annotations Beta
{ | ||
$this | ||
->setDescription('Send scheduled announcements to all users.') | ||
->addOption('debug', null, null, 'If set, debug messages will be shown.') | ||
Check failure on line 39 in src/CoreBundle/Command/SendScheduledAnnouncementsCommand.php
|
||
; | ||
} | ||
throw $this->createAccessDeniedException(); | ||
} | ||
return $clientRegistry->getClient($providerName)->redirect(); | ||
Check failure on line 25 in src/CoreBundle/Controller/OAuth2/AbstractProviderController.php
|
||
} | ||
} |
array $redirectParams = [], | ||
array $collaborators = [] | ||
): AbstractProvider { | ||
$customConfig = match ($class) { | ||
Check failure on line 35 in src/CoreBundle/Decorator/OAuth2ProviderFactoryDecorator.php
|
||
GenericProvider::class => $this->authenticationConfigHelper->getProviderConfig('generic'), | ||
Facebook::class => $this->authenticationConfigHelper->getProviderConfig('facebook'), | ||
Keycloak::class => $this->authenticationConfigHelper->getProviderConfig('keycloak'), | ||
$redirectParams = $customConfig['redirect_params'] ?? []; | ||
$customOptions = match ($class) { | ||
Check failure on line 44 in src/CoreBundle/Decorator/OAuth2ProviderFactoryDecorator.php
|
||
GenericProvider::class => $this->authenticationConfigHelper->getProviderOptions( | ||
'generic', | ||
[ |
public function isCourseTutor(?Course $course = null, ?Session $session = null): bool | ||
{ | ||
return $session?->hasCoachInCourseList($user) || $course?->getSubscriptionByUser($user)?->isTutor(); | ||
Check failure on line 2415 in src/CoreBundle/Entity/User.php
|
||
} | ||
} |
return null; | ||
} | ||
if (\is_object($value) && method_exists($value, 'getId')) { | ||
Check failure on line 49 in src/CoreBundle/Form/DataTransformer/ResourceToIdentifierTransformer.php
|
||
return $value; | ||
Check failure on line 50 in src/CoreBundle/Form/DataTransformer/ResourceToIdentifierTransformer.php
|
||
} | ||
$resource = $this->repository->find($value); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a single space around assignment operators