Student publication: Use CStudentPublicationCorrection to save content.

pull/3741/head
Julio Montoya 4 years ago
parent 5d573f6289
commit 848f15b3cf
  1. 30
      public/main/template/default/work/view.html.twig
  2. 107
      public/main/work/view.php
  3. 59
      public/main/work/work.lib.php
  4. 20
      public/main/work/work_list_all.php
  5. 16
      src/CoreBundle/EventListener/AssetListener.php
  6. 10
      src/CoreBundle/EventListener/CourseListener.php
  7. 6
      src/CoreBundle/Resources/views/Work/comments.html.twig
  8. 41
      src/CoreBundle/Resources/views/Work/view.html.twig
  9. 25
      src/CoreBundle/Traits/ControllerTrait.php
  10. 53
      src/CourseBundle/Entity/CStudentPublication.php
  11. 2
      src/CourseBundle/Entity/CStudentPublicationComment.php

@ -1,30 +0,0 @@
{% autoescape false %}
<div class="page-header">
<h2>
{{ work.title }}
</h2>
</div>
{% if work.description %}
<h3>
{{ 'Description' | get_lang }}
</h3>
<p>
{{ work.description }}
</p>
{% endif %}
{{ form }}
{% if work.contains_file and work.show_content %}
<h3>
{{ 'Content' | get_lang }}
</h3>
<p>
{{ work.show_content }}
</p>
{% endif %}
{% include template ~ '/work/comments.html.twig' %}
{% endautoescape %}

@ -4,6 +4,8 @@
use Chamilo\CoreBundle\Framework\Container;
use Chamilo\CourseBundle\Entity\CStudentPublication;
use Chamilo\CourseBundle\Entity\CStudentPublicationCorrection;
use Symfony\Component\HttpFoundation\File\UploadedFile;
require_once __DIR__.'/../inc/global.inc.php';
$current_course_tool = TOOL_STUDENTPUBLICATION;
@ -83,10 +85,10 @@ if (($isDrhOfCourse || $allowEdition || $isDrhOfSession || user_is_author($id))
$workId = $work->getIid();
if ((
0 == $courseInfo['show_score'] &&
1 == $work['active'] &&
1 == $work['accepted']
1 == $work->getActive() &&
1 == $work->getAccepted()
) ||
$isCourseManager || user_is_author($id) || $isDrhOfCourse || $isDrhOfSession
$isCourseManager || $isDrhOfCourse || $isDrhOfSession || user_is_author($id)
) {
if ('edit' === $page) {
$url = api_get_path(WEB_CODE_PATH).
@ -117,22 +119,24 @@ if (($isDrhOfCourse || $allowEdition || $isDrhOfSession || user_is_author($id))
if ($allowEdition) {
$work_table = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
$sql = "UPDATE $work_table
SET
qualificator_id = '".api_get_user_id()."',
qualification = '".api_float_val($_POST['qualification'])."',
date_of_qualification = '".api_get_utc_datetime()."'
WHERE c_id = ".$courseInfo['real_id']." AND id = $id";
Database::query($sql);
if (isset($_POST['qualification'])) {
$work->setQualificatorId(api_get_user_id());
$work->setQualification(api_float_val($_POST['qualification']));
$work->setDateOfQualification(api_get_utc_datetime(null, true, true));
$repo->update($work);
}
Display::addFlash(Display::return_message(get_lang('Updated')));
$resultUpload = uploadWork(
/*$resultUpload = uploadWork(
$folderData,
$courseEntity,
true,
$work
);
if ($resultUpload) {
);*/
/*if ($resultUpload) {
$work_table = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
if (isset($resultUpload['url']) && !empty($resultUpload['url'])) {
$title = isset($resultUpload['filename']) && !empty($resultUpload['filename']) ? $resultUpload['filename'] : get_lang('Untitled');
@ -147,6 +151,26 @@ if (($isDrhOfCourse || $allowEdition || $isDrhOfSession || user_is_author($id))
Display::return_message(get_lang('The file has successfully been uploaded.'))
);
}
}*/
$request = Container::getRequest();
$file = $request->files->get('file');
if (is_array($file)) {
/** @var UploadedFile $file */
$file = $file[0];
}
if (null !== $file) {
$em = Database::getManager();
$correction = new CStudentPublicationCorrection();
$correction
->setParent($work)
->setTitle($file->getClientOriginalName());
// @todo improve file upload.
$correctionRepo = Container::getStudentPublicationCorrectionRepository();
$correctionRepo->create($correction);
$correctionRepo->addFile($correction, $file);
$correctionRepo->update($correction);
}
}
@ -166,8 +190,8 @@ if (($isDrhOfCourse || $allowEdition || $isDrhOfSession || user_is_author($id))
break;
case 'delete_correction':
if ($allowEdition && isset($work['url_correction']) && !empty($work['url_correction'])) {
deleteCorrection($courseInfo, $work);
if ($allowEdition) {
deleteCorrection($work);
Display::addFlash(Display::return_message(get_lang('Deleted')));
}
@ -185,7 +209,7 @@ if (($isDrhOfCourse || $allowEdition || $isDrhOfSession || user_is_author($id))
$actions = '';
if ($work->getContainsFile()) {
if (isset($work['download_url']) && !empty($work['download_url'])) {
if ($work->getResourceNode()->hasResourceFile()) {
$actions = Display::url(
Display::return_icon(
'back.png',
@ -196,23 +220,41 @@ if (($isDrhOfCourse || $allowEdition || $isDrhOfSession || user_is_author($id))
api_get_path(WEB_CODE_PATH).'work/work.php?'.api_get_cidreq()
);
// Check if file can be downloaded
$file = getFileContents($work['id'], $courseInfo, api_get_session_id(), false);
if (!empty($file)) {
$actions .= Display::url(
Display::return_icon(
'save.png',
get_lang('Download'),
null,
ICON_SIZE_MEDIUM
),
$work['download_url']
);
}
$router = Container::getRouter();
$url = $router->generate(
'chamilo_core_resource_download',
[
'id' => $work->getResourceNode()->getId(),
'tool' => 'student_publication',
'type' => 'student_publications',
]
);
$actions .= Display::url(
Display::return_icon(
'save.png',
get_lang('Download'),
null,
ICON_SIZE_MEDIUM
),
$url
);
}
}
if (isset($work['url_correction']) && !empty($work['url_correction']) && !empty($work['download_url'])) {
$correctionNode = $work->getCorrection();
if (null !== $correctionNode) {
$router = Container::getRouter();
$url = $router->generate(
'chamilo_core_resource_download',
[
'id' => $correctionNode->getId(),
'tool' => 'student_publication',
'type' => 'student_publications_corrections',
]
).api_get_cidreq();
$actions .= Display::url(
Display::return_icon(
'check-circle.png',
@ -220,7 +262,7 @@ if (($isDrhOfCourse || $allowEdition || $isDrhOfSession || user_is_author($id))
null,
ICON_SIZE_MEDIUM
),
$work['download_url'].'&correction=1'
$url
);
if ($allowEdition) {
@ -247,8 +289,7 @@ if (($isDrhOfCourse || $allowEdition || $isDrhOfSession || user_is_author($id))
$tpl->assign('form', $commentForm);
}
$tpl->assign('is_allowed_to_edit', api_is_allowed_to_edit());
$template = $tpl->get_template('work/view.tpl');
$content = $tpl->fetch($template);
$content = $tpl->fetch('@ChamiloCore/Work/view.html.twig');
$tpl->assign('content', $content);
$tpl->display_one_col_template();
} else {

@ -3678,12 +3678,12 @@ function deleteCommentFile($id, $courseInfo = [])
* @param array $courseInfo
* @param int $userId
* @param array $parentWork
* @param array $work
* @param CStudentPublication $work
* @param array $data
*
* @return int
*/
function addWorkComment($courseInfo, $userId, $parentWork, $work, $data)
function addWorkComment($courseInfo, $userId, $parentWork, CStudentPublication $studentPublication, $data)
{
$fileData = isset($data['attachment']) ? $data['attachment'] : null;
// If no attachment and no comment then don't save comment
@ -3693,13 +3693,10 @@ function addWorkComment($courseInfo, $userId, $parentWork, $work, $data)
$courseId = $courseInfo['real_id'];
$courseEntity = api_get_course_entity($courseId);
/** @var CStudentPublication $studentPublication */
$studentPublication = Container::getStudentPublicationRepository()->find($work['iid']);
$request = Container::getRequest();
$fileObject = $request->files->get('attachment');
if (is_array($fileObject)) {
$fileObject = $fileObject[0];
$file = $request->files->get('attachment');
if (is_array($file)) {
$file = $file[0];
}
$em = Database::getManager();
@ -3708,7 +3705,7 @@ function addWorkComment($courseInfo, $userId, $parentWork, $work, $data)
->setCId($courseId)
->setComment($data['comment'])
->setUserId($userId)
->setWorkId($work['iid'])
->setWorkId($studentPublication->getIid())
->setParent($studentPublication)
->addCourseLink(
$courseEntity,
@ -3719,8 +3716,8 @@ function addWorkComment($courseInfo, $userId, $parentWork, $work, $data)
$repo = Container::getStudentPublicationCommentRepository();
$repo->create($comment);
if ($fileObject) {
$repo->addFile($comment, $fileObject);
if ($file) {
$repo->addFile($comment, $file);
$em->flush();
}
@ -3728,7 +3725,7 @@ function addWorkComment($courseInfo, $userId, $parentWork, $work, $data)
if (api_is_allowed_to_edit()) {
if (isset($data['send_email']) && $data['send_email']) {
// Teacher sends a feedback
$userIdListToSend = [$work['user_id']];
$userIdListToSend = [$studentPublication->getUserId()];
}
} else {
$sessionId = api_get_session_id();
@ -3755,10 +3752,11 @@ function addWorkComment($courseInfo, $userId, $parentWork, $work, $data)
$userIdListToSend = [];
}
}
$url = api_get_path(WEB_CODE_PATH).'work/view.php?'.api_get_cidreq().'&id='.$work['iid'];
$id = $studentPublication->getIid();
$title = $studentPublication->getTitle();
$url = api_get_path(WEB_CODE_PATH).'work/view.php?'.api_get_cidreq().'&id='.$id;
$subject = sprintf(get_lang('There\'s a new feedback in work: %s'), $parentWork['title']);
$content = sprintf(get_lang('There\'s a new feedback in work: %sInWorkXHere'), $work['title'], $url);
$content = sprintf(get_lang('There\'s a new feedback in work: %sInWorkXHere'), $title, $url);
if (!empty($data['comment'])) {
$content .= '<br /><b>'.get_lang('Comment').':</b><br />'.$data['comment'];
@ -4858,7 +4856,7 @@ function deleteWorkItem($item_id, $courseInfo)
// We found the current user is the author
$sql = "SELECT url, contains_file, user_id, session_id, parent_id
FROM $work_table
WHERE c_id = $course_id AND id = $item_id";
WHERE iid = $item_id";
$result = Database::query($sql);
$row = Database::fetch_array($result);
$count = Database::num_rows($result);
@ -5949,29 +5947,14 @@ function protectWork($courseInfo, $workId)
}
}
/**
* @param array $courseInfo
* @param array $work
*/
function deleteCorrection($courseInfo, $work)
function deleteCorrection(CStudentPublication $work)
{
throw new Exception('deleteCorrection');
/*
if (isset($work['url_correction']) && !empty($work['url_correction']) && isset($work['iid'])) {
$id = $work['iid'];
$table = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
$sql = "UPDATE $table SET
url_correction = '',
title_correction = ''
WHERE iid = $id";
Database::query($sql);
$coursePath = api_get_path(SYS_COURSE_PATH).$courseInfo['path'].'/';
if (file_exists($coursePath.$work['url_correction'])) {
if (Security::check_abs_path($coursePath.$work['url_correction'], $coursePath)) {
unlink($coursePath.$work['url_correction']);
}
}
}*/
$correctionNode = $work->getCorrection();
if (null !== $correctionNode) {
$em = Database::getManager();
$em->remove($correctionNode);
$em->flush();
}
}
/**

@ -199,14 +199,26 @@ if (api_is_allowed_to_session_edit(false, true) && !empty($workId) && !$isDrhOfC
$count = get_count_work($workId);
if ($count > 0) {
$display_output .= '<a class="btn-toolbar" href="downloadfolder.inc.php?id='.$workId.'&'.api_get_cidreq().'">'.
Display::return_icon('save_pack.png', get_lang('Download assignments package'), null, ICON_SIZE_MEDIUM).' '.get_lang('Download assignments package').'</a>';
Display::return_icon(
'save_pack.png',
get_lang('Download assignments package'),
null,
ICON_SIZE_MEDIUM
).' '.get_lang('Download assignments package').'</a>';
}
$actionsLeft .= $display_output;
$url = api_get_path(WEB_CODE_PATH).'work/upload_corrections.php?'.api_get_cidreq().'&id='.$workId;
$actionsLeft .= '<a class="btn-toolbar" href="'.$url.'">'.
Display::return_icon('upload_package.png', get_lang('Upload corrections package'), '', ICON_SIZE_MEDIUM).' '.get_lang('Upload corrections package').'</a>';
$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, 'remove', 'danger');
Display::return_icon(
'upload_package.png',
get_lang('Upload corrections package'),
'',
ICON_SIZE_MEDIUM
).' '.get_lang('Upload corrections package').'</a>';
$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');
}
echo Display::toolbarAction('toolbar-worklist', [$actionsLeft]);

@ -27,13 +27,15 @@ class AssetListener
{
/** @var Asset $asset */
$asset = $event->getObject();
$mapping = $event->getMapping();
$folder = $mapping->getFile($asset)->getFilename();
// Deletes scorm folder: example: assets/scorm/myABC .
if (Asset::SCORM === $asset->getCategory() && !empty($folder)) {
$folder = Asset::SCORM.'/'.$folder;
$this->assetRepository->getFileSystem()->deleteDir($folder);
if ($asset instanceof Asset) {
$mapping = $event->getMapping();
$folder = $mapping->getFile($asset)->getFilename();
// Deletes scorm folder: example: assets/scorm/myABC .
if (Asset::SCORM === $asset->getCategory() && !empty($folder)) {
$folder = Asset::SCORM.'/'.$folder;
$this->assetRepository->getFileSystem()->deleteDir($folder);
}
}
}
}

@ -4,6 +4,7 @@
namespace Chamilo\CoreBundle\EventListener;
use Chamilo\CoreBundle\Controller\EditorController;
use Chamilo\CoreBundle\Entity\Course;
use Chamilo\CoreBundle\Entity\Session;
use Chamilo\CoreBundle\Entity\User;
@ -77,6 +78,7 @@ class CourseListener
$courseId = (int) $request->get('cid');
$checker = $container->get('security.authorization_checker');
//dump("cid value in request: $courseId");
if (!empty($courseId)) {
if ($sessionHandler->has('course')) {
/** @var Course $courseFromSession */
@ -84,7 +86,7 @@ class CourseListener
if ($courseId === $courseFromSession->getId()) {
$course = $courseFromSession;
$courseInfo = $sessionHandler->get('_course');
//dump("Course loaded from Session $courseId");
//dump("Course #$courseId loaded from Session ");
}
}
$course = null;
@ -97,7 +99,7 @@ class CourseListener
throw new NotFoundHttpException($translator->trans('Course does not exist'));
}
//dump("Course loaded from DB $courseId");
//dump("Course loaded from DB #$courseId");
$courseInfo = api_get_course_info($course->getCode());
}
@ -247,9 +249,9 @@ class CourseListener
// This controller implements ToolInterface? Then set the course/session
if (is_array($controllerList) &&
(
$controllerList[0] instanceof CourseControllerInterface
$controllerList[0] instanceof CourseControllerInterface ||
$controllerList[0] instanceof EditorController
//$controllerList[0] instanceof ResourceController
//|| $controllerList[0] instanceof LegacyController
)
) {

@ -8,9 +8,9 @@
{% for comment in comments %}
<li>
<div class="page-header">
<a href="{{ _p.web_code }}">
<img height="24" src="{{ comment.picture }}"/> {{ comment.complete_name }}
</a>- {{ comment.sent_at_with_label }}
<img height="24" src="{{ comment.picture }}"/> {{ comment.complete_name }}
- {{ comment.sent_at_with_label }}
</div>
<p>
{% if comment.comment is not empty %}

@ -0,0 +1,41 @@
{% autoescape false %}
<div class="page-header">
<h2>
{{ work.title }}
</h2>
</div>
{% if work.description %}
<h3>
{{ 'Description' | get_lang }}
</h3>
<p>
{{ work.description }}
</p>
{% endif %}
{{ form }}
{% if work.getResourceNode and work.getResourceNode.hasResourceFile %}
<h3>
{{ 'Content' | get_lang }}
</h3>
<p>
<a class="btn btn-success"
href="{{ url('chamilo_core_resource_view', {
'id': work.resourceNode.id,
'cid': course ? course.id : 0,
'sid': session ? session.id : 0,
'tool' : 'student_publication',
'type' : 'student_publications',
'mode' : 'download'
})
}}">
{{ 'Download' | trans}}
</a>
</p>
{% endif %}
{% include '@ChamiloCore/Work/comments.html.twig' %}
{% endautoescape %}

@ -21,6 +21,8 @@ use Chamilo\CourseBundle\Repository\CLpCategoryRepository;
use Chamilo\CourseBundle\Repository\CLpRepository;
use Chamilo\CourseBundle\Repository\CQuizQuestionCategoryRepository;
use Chamilo\CourseBundle\Repository\CQuizQuestionRepository;
use Chamilo\CourseBundle\Repository\CStudentPublicationCommentRepository;
use Chamilo\CourseBundle\Repository\CStudentPublicationCorrectionRepository;
use Chamilo\CourseBundle\Repository\CStudentPublicationRepository;
use Knp\Menu\FactoryInterface as MenuFactoryInterface;
use Sylius\Bundle\SettingsBundle\Form\Factory\SettingsFormFactory;
@ -37,14 +39,19 @@ trait ControllerTrait
$services['glide'] = Glide::class;
$services['chamilo.settings.manager'] = SettingsManager::class;
$services['chamilo_settings.form_factory.settings'] = SettingsFormFactory::class;
$services[] = ResourceFactory::class;
$services[] = ResourceNodeRepository::class;
/*
The following classes are needed in order to load the resources files when using the /r/ path
For example: http://my.chamilomaster.net/r/agenda/event_attachments/96/download?cid=1&sid=0&gid=0
Then the repository CCalendarEventAttachmentRepository need to be added here,
because it was set in the tools.yml like this:
chamilo_core.tool.agenda:
(...)
event_attachments:
repository: Chamilo\CourseBundle\Repository\CCalendarEventAttachmentRepository
*/
$services[] = ResourceFactory::class;
$services[] = ResourceNodeRepository::class;
$services[] = CAnnouncementRepository::class;
$services[] = CAnnouncementAttachmentRepository::class;
$services[] = CAttendanceRepository::class;
@ -58,19 +65,11 @@ trait ControllerTrait
$services[] = CQuizQuestionRepository::class;
$services[] = CQuizQuestionCategoryRepository::class;
$services[] = CStudentPublicationRepository::class;
$services[] = CStudentPublicationCommentRepository::class;
$services[] = CStudentPublicationCorrectionRepository::class;
$services[] = IllustrationRepository::class;
/*$services[] = CAttendanceRepository::class;
$services[] = CDocumentRepository::class;
$services[] = CDocumentRepository::class;
$services[] = CDocumentRepository::class;
$services[] = CDocumentRepository::class;
$services[] = CDocumentRepository::class;
$services[] = CDocumentRepository::class;
$services[] = CDocumentRepository::class;*/
return $services;
}

@ -56,20 +56,6 @@ class CStudentPublication extends AbstractResource implements ResourceInterface
*/
protected $url;
/**
* @var string
*
* @ORM\Column(name="url_correction", type="string", length=500, nullable=true)
*/
protected $urlCorrection;
/**
* @var string
*
* @ORM\Column(name="title_correction", type="string", length=255, nullable=true)
*/
protected $titleCorrection;
/**
* @var string
*
@ -721,42 +707,6 @@ class CStudentPublication extends AbstractResource implements ResourceInterface
return $this->cId;
}
/**
* @return string
*/
public function getUrlCorrection()
{
return $this->urlCorrection;
}
/**
* @param string $urlCorrection
*/
public function setUrlCorrection($urlCorrection)
{
$this->urlCorrection = $urlCorrection;
return $this;
}
/**
* @return string
*/
public function getTitleCorrection()
{
return $this->titleCorrection;
}
/**
* @param string $titleCorrection
*/
public function setTitleCorrection($titleCorrection)
{
$this->titleCorrection = $titleCorrection;
return $this;
}
/**
* @return int
*/
@ -802,7 +752,8 @@ class CStudentPublication extends AbstractResource implements ResourceInterface
if ($this->hasResourceNode()) {
$children = $this->getResourceNode()->getChildren();
foreach ($children as $child) {
if ($child instanceof CStudentPublicationCorrection) {
$name = $child->getResourceType()->getName();
if ('student_publications_corrections' === $name) {
return $child;
}
}

@ -243,7 +243,7 @@ class CStudentPublicationComment extends AbstractResource implements ResourceInt
public function getResourceName(): string
{
return (string) substr($this->getComment(), 0, 80);
return (string) substr(str_replace('/', '-', strip_tags($this->getComment())), 0, 40);
}
public function setResourceName(string $name): self

Loading…
Cancel
Save