Minor - get icon from resource

pull/3064/head
Julio Montoya 5 years ago
parent 302899470c
commit 9e016f3c93
  1. 11
      src/CoreBundle/Controller/ResourceController.php
  2. 20
      src/CoreBundle/Entity/Resource/ResourceNode.php

@ -174,6 +174,7 @@ class ResourceController extends AbstractResourceController implements CourseCon
$myParams['id'] = $id; $myParams['id'] = $id;
unset($myParams[0]); unset($myParams[0]);
$icon = $resourceNode->getIcon().'  ';
if ($resourceNode->hasResourceFile()) { if ($resourceNode->hasResourceFile()) {
$url = $router->generate( $url = $router->generate(
'chamilo_core_resource_show', 'chamilo_core_resource_show',
@ -186,7 +187,7 @@ class ResourceController extends AbstractResourceController implements CourseCon
$myParams $myParams
); );
return '<a data-fancybox="gallery" href="'.$url.'">'.$value.'</a>'; return $icon.'<a data-fancybox="gallery" href="'.$url.'">'.$value.'</a>';
} }
if ($resourceNode->isResourceFileAVideo()) { if ($resourceNode->isResourceFileAVideo()) {
@ -200,7 +201,7 @@ class ResourceController extends AbstractResourceController implements CourseCon
<source src="'.$url.'" type="video/mp4"> <source src="'.$url.'" type="video/mp4">
Your browser doesn\'t support HTML5 video tag. Your browser doesn\'t support HTML5 video tag.
</video> </video>
<a data-fancybox="gallery" data-width="640" data-height="360" href="#video'.$id.'">'.$value.'</a>'; '.$icon.' <a data-fancybox="gallery" data-width="640" data-height="360" href="#video'.$id.'">'.$value.'</a>';
} }
$url = $router->generate( $url = $router->generate(
@ -208,14 +209,14 @@ class ResourceController extends AbstractResourceController implements CourseCon
$myParams $myParams
); );
return '<a data-fancybox="gallery" data-type="iframe" data-src="'.$url.'" href="javascript:;" >'.$value.'</a>'; return $icon.'<a data-fancybox="gallery" data-type="iframe" data-src="'.$url.'" href="javascript:;" >'.$value.'</a>';
} else { } else {
$url = $router->generate( $url = $router->generate(
'chamilo_core_resource_list', 'chamilo_core_resource_list',
$myParams $myParams
); );
return '<a href="'.$url.'">'.$value.'</a>'; return $icon.'<a href="'.$url.'">'.$value.'</a>';
} }
} }
); );
@ -413,8 +414,6 @@ class ResourceController extends AbstractResourceController implements CourseCon
$resource = $repository->getRepository()->findOneBy(['resourceNode' => $resourceNodeId]); $resource = $repository->getRepository()->findOneBy(['resourceNode' => $resourceNodeId]);
$resourceNode = $resource->getResourceNode(); $resourceNode = $resource->getResourceNode();
$this->denyAccessUnlessGranted( $this->denyAccessUnlessGranted(
ResourceNodeVoter::VIEW, ResourceNodeVoter::VIEW,
$resourceNode, $resourceNode,

@ -457,4 +457,24 @@ class ResourceNode
return $this; return $this;
} }
/**
* @return string
*/
public function getIcon()
{
$class = 'fa fa-folder';
if ($this->hasResourceFile()) {
$class = 'far fa-file';
if ($this->isResourceFileAnImage()) {
$class = 'far fa-file-image';
}
if ($this->isResourceFileAVideo()) {
$class = 'far fa-file-video';
}
}
return '<i class="'.$class.'"></i>';
}
} }

Loading…
Cancel
Save