From 4085839d35a9d92df801247ab605aa7b7bb533b2 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Tue, 29 Dec 2020 13:51:48 +0100 Subject: [PATCH] Student publication: Fix downdload all, fix delete correction. --- public/main/work/upload_corrections.php | 4 +- public/main/work/work_list_all.php | 50 ++++++++++++++----- .../Controller/ResourceController.php | 11 ++-- .../Entity/CStudentPublicationComment.php | 10 ++-- 4 files changed, 51 insertions(+), 24 deletions(-) diff --git a/public/main/work/upload_corrections.php b/public/main/work/upload_corrections.php index a60e0ad7df..9e3250c3eb 100644 --- a/public/main/work/upload_corrections.php +++ b/public/main/work/upload_corrections.php @@ -2,8 +2,6 @@ /* For licensing terms, see /license.txt */ -use Symfony\Component\Finder\Finder; - require_once __DIR__.'/../inc/global.inc.php'; $current_course_tool = TOOL_STUDENTPUBLICATION; @@ -38,7 +36,7 @@ if (empty($workInfo)) { $student_can_edit_in_session = api_is_allowed_to_session_edit(false, true); -$homework = get_work_assignment_by_id($workInfo['id']); +$homework = get_work_assignment_by_id($workInfo['iid']); $validationStatus = getWorkDateValidationStatus($homework); $interbreadcrumb[] = [ diff --git a/public/main/work/work_list_all.php b/public/main/work/work_list_all.php index d66b54f127..d7014849d1 100644 --- a/public/main/work/work_list_all.php +++ b/public/main/work/work_list_all.php @@ -2,6 +2,9 @@ /* For licensing terms, see /license.txt */ +use Chamilo\CoreBundle\Framework\Container; +use Chamilo\CourseBundle\Entity\CStudentPublication; + require_once __DIR__.'/../inc/global.inc.php'; $current_course_tool = TOOL_STUDENTPUBLICATION; @@ -25,6 +28,7 @@ if (empty($my_folder_data)) { $work_data = get_work_assignment_by_id($workId); +$studentPublicationRepo = Container::getStudentPublicationRepository(); $isDrhOfCourse = CourseManager::isUserSubscribedInCourseAsDrh( api_get_user_id(), api_get_course_info() @@ -113,8 +117,11 @@ switch ($action) { $result = get_work_user_list(null, null, null, null, $workId); if ($result) { foreach ($result as $item) { - $workToDelete = get_work_data_by_id($item['id']); - deleteCorrection($courseInfo, $workToDelete); + /** @var CStudentPublication $work */ + $work = $studentPublicationRepo->find($item['id']); + if ($work) { + deleteCorrection( $work); + } } Display::addFlash( Display::return_message(get_lang('Deleted'), 'confirmation') @@ -172,19 +179,22 @@ $actionsLeft = ''; + $actionsLeft .= ''; $actionsLeft .= Display::return_icon('new_document.png', get_lang('Add document'), '', ICON_SIZE_MEDIUM).''; } - $actionsLeft .= ''; + $actionsLeft .= ''; $actionsLeft .= Display::return_icon('addworkuser.png', get_lang('Add a user'), '', ICON_SIZE_MEDIUM).''; - $actionsLeft .= ''; + $actionsLeft .= ''; $actionsLeft .= Display::return_icon('pdf.png', get_lang('Export'), '', ICON_SIZE_MEDIUM).''; - $display_output = ''. + $displayOutput = ''. Display::return_icon('exercice_uncheck.png', get_lang('View missing assignments'), '', ICON_SIZE_MEDIUM).''; $editLink = ''; @@ -198,7 +208,19 @@ if (api_is_allowed_to_session_edit(false, true) && !empty($workId) && !$isDrhOfC $count = get_count_work($workId); if ($count > 0) { - $display_output .= ''. + $router = Container::getRouter(); + /** @var CStudentPublication $studentPublication */ + $studentPublication = $studentPublicationRepo->find($workId); + $downloadUrl = $router->generate( + 'chamilo_core_resource_download', + [ + 'id' => $studentPublication->getResourceNode()->getId(), + 'tool' => 'student_publication', + 'type' => 'student_publications', + ] + ); + + $displayOutput .= ''. Display::return_icon( 'save_pack.png', get_lang('Download assignments package'), @@ -206,8 +228,10 @@ if (api_is_allowed_to_session_edit(false, true) && !empty($workId) && !$isDrhOfC ICON_SIZE_MEDIUM ).' '.get_lang('Download assignments package').''; } - $actionsLeft .= $display_output; - $url = api_get_path(WEB_CODE_PATH).'work/upload_corrections.php?'.api_get_cidreq().'&id='.$workId; + $actionsLeft .= $displayOutput; + + // @todo fix upload corrections. + /*$url = api_get_path(WEB_CODE_PATH).'work/upload_corrections.php?'.api_get_cidreq().'&id='.$workId; $actionsLeft .= ''. Display::return_icon( 'upload_package.png', @@ -215,9 +239,9 @@ if (api_is_allowed_to_session_edit(false, true) && !empty($workId) && !$isDrhOfC '', ICON_SIZE_MEDIUM ).' '.get_lang('Upload corrections package').''; - - $url = api_get_path(WEB_CODE_PATH).'work/work_list_all.php?'.api_get_cidreq( - ).'&id='.$workId.'&action=delete_correction'; + */ + $url = api_get_path(WEB_CODE_PATH). + 'work/work_list_all.php?'.api_get_cidreq().'&id='.$workId.'&action=delete_correction'; $actionsLeft .= Display::toolbarButton(get_lang('Delete all corrections'), $url, 'trash', 'danger'); } diff --git a/src/CoreBundle/Controller/ResourceController.php b/src/CoreBundle/Controller/ResourceController.php index 3470775db8..014f28c003 100644 --- a/src/CoreBundle/Controller/ResourceController.php +++ b/src/CoreBundle/Controller/ResourceController.php @@ -589,7 +589,6 @@ class ResourceController extends AbstractResourceController implements CourseCon { $id = (int) $request->get('id'); - $em = $this->getDoctrine(); /** @var ResourceNode $resourceNode */ $resourceNode = $this->getResourceNodeRepository()->find($id); @@ -614,10 +613,11 @@ class ResourceController extends AbstractResourceController implements CourseCon $zipName = $resourceNode->getSlug().'.zip'; $rootNodePath = $resourceNode->getPathForDisplay(); $resourceNodeRepo = $repo->getResourceNodeRepository(); + $type = $repo->getResourceType(); $criteria = Criteria::create() ->where(Criteria::expr()->neq('resourceFile', null)) // must have a file - // ->andWhere(Criteria::expr()->eq('resourceType', $type)) + ->andWhere(Criteria::expr()->eq('resourceType', $type)) // only download same type ; /** @var ArrayCollection|ResourceNode[] $children */ @@ -646,8 +646,11 @@ class ResourceController extends AbstractResourceController implements CourseCon /** @var ResourceNode $node */ foreach ($children as $node) { $stream = $repo->getResourceNodeFileStream($node); - $fileToDisplay = str_replace($rootNodePath, '', $node->getPathForDisplay()); - $zip->addFileFromStream($fileToDisplay, $stream); + $fileName = $node->getResourceFile()->getOriginalName(); + //$fileToDisplay = basename($node->getPathForDisplay()); + //$fileToDisplay = str_replace($rootNodePath, '', $node->getPathForDisplay()); + //error_log($fileToDisplay); + $zip->addFileFromStream($fileName, $stream); } $zip->finish(); } diff --git a/src/CourseBundle/Entity/CStudentPublicationComment.php b/src/CourseBundle/Entity/CStudentPublicationComment.php index ddb6e3b43e..c3c8e97d6c 100644 --- a/src/CourseBundle/Entity/CStudentPublicationComment.php +++ b/src/CourseBundle/Entity/CStudentPublicationComment.php @@ -7,6 +7,7 @@ namespace Chamilo\CourseBundle\Entity; use Chamilo\CoreBundle\Entity\AbstractResource; use Chamilo\CoreBundle\Entity\ResourceInterface; use Doctrine\ORM\Mapping as ORM; +use Cocur\Slugify\Slugify; /** * CStudentPublicationComment. @@ -233,9 +234,6 @@ class CStudentPublicationComment extends AbstractResource implements ResourceInt return $this->sentAt; } - /** - * Resource identifier. - */ public function getResourceIdentifier(): int { return $this->getIid(); @@ -243,7 +241,11 @@ class CStudentPublicationComment extends AbstractResource implements ResourceInt public function getResourceName(): string { - return (string) substr(str_replace('/', '-', strip_tags($this->getComment())), 0, 40); + $text = strip_tags($this->getComment()); + $slugify = new Slugify(); + $text = $slugify->slugify($text); + + return (string) substr($text, 0, 40); } public function setResourceName(string $name): self