From 0450fa6ab3b5b291d4dcf7dc69712ec911f0dab5 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Sat, 23 Nov 2019 21:53:52 +0100 Subject: [PATCH] Minor - update document grid --- .../Controller/ResourceController.php | 31 ++++++++++++------- .../Entity/Resource/AbstractResource.php | 3 ++ src/CourseBundle/Entity/CDocument.php | 2 +- .../Resources/views/Resource/index.html.twig | 4 +-- 4 files changed, 26 insertions(+), 14 deletions(-) diff --git a/src/CoreBundle/Controller/ResourceController.php b/src/CoreBundle/Controller/ResourceController.php index 56335a265b..376181d75a 100644 --- a/src/CoreBundle/Controller/ResourceController.php +++ b/src/CoreBundle/Controller/ResourceController.php @@ -10,10 +10,8 @@ use APY\DataGridBundle\Grid\Export\ExcelExport; use APY\DataGridBundle\Grid\Grid; use APY\DataGridBundle\Grid\Row; use APY\DataGridBundle\Grid\Source\Entity; -use Chamilo\CoreBundle\Block\BreadcrumbBlockService; use Chamilo\CoreBundle\Component\Utils\Glide; use Chamilo\CoreBundle\Entity\Resource\AbstractResource; -use Chamilo\CoreBundle\Entity\Resource\ResourceFile; use Chamilo\CoreBundle\Entity\Resource\ResourceLink; use Chamilo\CoreBundle\Entity\Resource\ResourceNode; use Chamilo\CoreBundle\Security\Authorization\Voter\ResourceNodeVoter; @@ -26,24 +24,15 @@ use Doctrine\Common\Collections\Criteria; use Doctrine\ORM\QueryBuilder; use FOS\CKEditorBundle\Form\Type\CKEditorType; use League\Flysystem\Filesystem; -use Oneup\UploaderBundle\Uploader\Response\EmptyResponse; -use Sylius\Bundle\ResourceBundle\Event\ResourceControllerEvent; -use Sylius\Component\Resource\Exception\UpdateHandlingException; -use Sylius\Component\Resource\ResourceActions; use Symfony\Component\Filesystem\Exception\FileNotFoundException; -use Symfony\Component\HttpFoundation\File\Exception\UploadException; use Symfony\Component\HttpFoundation\File\UploadedFile; -use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\ResponseHeaderBag; use Symfony\Component\HttpFoundation\StreamedResponse; -use Symfony\Component\HttpKernel\Exception\HttpException; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\Routing\Annotation\Route; -use Symfony\Component\Routing\Generator\UrlGeneratorInterface; -use Symfony\Component\Routing\RouterInterface; use Vich\UploaderBundle\Util\Transliterator; use ZipStream\Option\Archive; use ZipStream\ZipStream; @@ -146,6 +135,9 @@ class ResourceController extends AbstractResourceController implements CourseCon $routeParams = ['tool' => $tool, 'type' => $type, 'cidReq' => $courseIdentifier, 'id']; // Title link. + $grid->getColumn('title')->setTitle($this->trans('Name')); + $grid->getColumn('filetype')->setTitle($this->trans('Type')); + $grid->getColumn('title')->manipulateRenderCell( function ($value, Row $row, $router) use ($routeParams) { /** @var CDocument $entity */ @@ -173,6 +165,23 @@ class ResourceController extends AbstractResourceController implements CourseCon } ); + $grid->getColumn('filetype')->manipulateRenderCell( + function ($value, Row $row, $router) use ($routeParams) { + /** @var CDocument $entity */ + $entity = $row->getEntity(); + $resourceNode = $entity->getResourceNode(); + + if ($resourceNode->hasResourceFile()) { + $file = $resourceNode->getResourceFile(); + return $file->getMimeType(); + } + + return $this->trans('Folder'); + } + ); + + $grid->setHiddenColumns(['iid']); + // Delete mass action. if ($this->isGranted(ResourceNodeVoter::ROLE_CURRENT_COURSE_TEACHER)) { $deleteMassAction = new MassAction( diff --git a/src/CoreBundle/Entity/Resource/AbstractResource.php b/src/CoreBundle/Entity/Resource/AbstractResource.php index c3b94ce3bd..f1852656e3 100644 --- a/src/CoreBundle/Entity/Resource/AbstractResource.php +++ b/src/CoreBundle/Entity/Resource/AbstractResource.php @@ -3,6 +3,7 @@ namespace Chamilo\CoreBundle\Entity\Resource; +use APY\DataGridBundle\Grid\Mapping as GRID; use Chamilo\CoreBundle\Entity\Course; use Chamilo\CoreBundle\Entity\Session; use Doctrine\Common\Collections\Criteria; @@ -17,6 +18,8 @@ use Sylius\Component\Resource\Model\ResourceInterface; abstract class AbstractResource implements ResourceInterface { /** + * @GRID\Column(field="resourceNode.createdAt", title="Date added", type="datetime") + * * @ORM\OneToOne(targetEntity="Chamilo\CoreBundle\Entity\Resource\ResourceNode", cascade={"remove"}, orphanRemoval=true) * @ORM\JoinColumn(name="resource_node_id", referencedColumnName="id", onDelete="CASCADE") */ diff --git a/src/CourseBundle/Entity/CDocument.php b/src/CourseBundle/Entity/CDocument.php index ad964faa93..94da5e077d 100644 --- a/src/CourseBundle/Entity/CDocument.php +++ b/src/CourseBundle/Entity/CDocument.php @@ -26,7 +26,7 @@ use Doctrine\ORM\Mapping as ORM; * @ORM\Index(name="idx_cdoc_sid", columns={"session_id"}), * } * ) - * @GRID\Source(columns="iid, title, filetype", filterable=false) + * @GRID\Source(columns="iid, title, filetype, resourceNode.createdAt", filterable=false) * @ORM\Entity */ class CDocument extends AbstractResource implements ResourceInterface diff --git a/src/ThemeBundle/Resources/views/Resource/index.html.twig b/src/ThemeBundle/Resources/views/Resource/index.html.twig index 73094c785f..47bef94dc0 100644 --- a/src/ThemeBundle/Resources/views/Resource/index.html.twig +++ b/src/ThemeBundle/Resources/views/Resource/index.html.twig @@ -5,11 +5,11 @@
- {{ 'Create folder' | trans }} + {{ 'New folder' | trans }} - {{ 'Create document' | trans }} + {{ 'Create new document' | trans }}