diff --git a/public/main/forum/forumfunction.inc.php b/public/main/forum/forumfunction.inc.php
index b014481ae8..e088f6497f 100644
--- a/public/main/forum/forumfunction.inc.php
+++ b/public/main/forum/forumfunction.inc.php
@@ -807,6 +807,7 @@ function store_forum($values, $courseInfo = [], $returnId = false)
->setForumOrder(isset($new_max) ? $new_max : null)
;
} else {
+ /** @var CForumForum $forum */
$forum = $repo->find($values['forum_id']);
}
@@ -4603,7 +4604,7 @@ function forum_search()
$form->setDefaults($values);
$form->display();
// Display the search results.
- display_forum_search_results(stripslashes($values['search_term']));
+ display_forum_search_results($values['search_term']);
} else {
$form->display();
}
@@ -4933,13 +4934,13 @@ function edit_forum_attachment_file($file_comment, $post_id, $id_attach)
size ='".$attachment['size']."'
WHERE c_id = $course_id AND id = '$safe_id_attach'";
Database::query($sql);
- api_item_property_update(
+ /*api_item_property_update(
$_course,
TOOL_FORUM_ATTACH,
$safe_id_attach,
'ForumAttachmentUpdated',
api_get_user_id()
- );
+ );*/
}
}
}
diff --git a/public/main/work/upload_from_template.php b/public/main/work/upload_from_template.php
index 7654b69aa5..7b0d329c6e 100644
--- a/public/main/work/upload_from_template.php
+++ b/public/main/work/upload_from_template.php
@@ -2,6 +2,8 @@
/* For licensing terms, see /license.txt */
+use Chamilo\CoreBundle\Framework\Container;
+
require_once __DIR__.'/../inc/global.inc.php';
$current_course_tool = TOOL_STUDENTPUBLICATION;
@@ -75,11 +77,16 @@ $form->addElement('hidden', 'id', $work_id);
$form->addElement('hidden', 'sec_token', $token);
$documentTemplateData = getDocumentTemplateFromWork($work_id, $course_info, $documentId);
-
$defaults = [];
if (!empty($documentTemplateData)) {
- $defaults['title'] = $userInfo['complete_name'].'_'.$documentTemplateData['title'].'_'.substr(api_get_utc_datetime(), 0, 10);
- $defaults['description'] = $documentTemplateData['file_content'];
+ $defaults['title'] = $userInfo['complete_name'].'_'.
+ $documentTemplateData->getTitle().'_'.substr(
+ api_get_utc_datetime(),
+ 0,
+ 10
+ );
+ $docRepo = Container::getDocumentRepository();
+ $defaults['description'] = $docRepo->getResourceFileContent($documentTemplateData);
}
$form->setDefaults($defaults);
diff --git a/public/main/work/work.lib.php b/public/main/work/work.lib.php
index d5774763fd..1edfabd959 100644
--- a/public/main/work/work.lib.php
+++ b/public/main/work/work.lib.php
@@ -2299,12 +2299,12 @@ function get_work_user_list(
// If URL is present then there's a file to download keep BC.
if ($work['contains_file']) {
$downloadUrl = $router->generate('chamilo_core_resource_download',
- [
- 'id' => $studentPublication->getResourceNode()->getId(),
- 'tool' => 'student_publication',
- 'type' => 'student_publications',
- ]
- ).'?'.api_get_cidreq();
+ [
+ 'id' => $studentPublication->getResourceNode()->getId(),
+ 'tool' => 'student_publication',
+ 'type' => 'student_publications',
+ ]
+ ).'?'.api_get_cidreq();
$linkToDownload = ''.$saveIcon.' ';
}
@@ -3219,32 +3219,35 @@ function allowOnlySubscribedUser($userId, $workId, $courseId, $forceAccessForCou
* @param array $courseInfo
* @param int $documentId
*
- * @return array
+ * @return CDocument
*/
function getDocumentTemplateFromWork($workId, $courseInfo, $documentId)
{
$documents = getAllDocumentToWork($workId, $courseInfo['real_id']);
-
$docRepo = Container::getDocumentRepository();
if (!empty($documents)) {
foreach ($documents as $doc) {
- if ($documentId != $doc['document_id']) {
+ if ($documentId !== $doc['document_id']) {
continue;
}
+
/** @var CDocument $docData */
$docData = $docRepo->find($doc['document_id']);
- $fileInfo = pathinfo($docData['path']);
+
+ return $docData;
+
+ /*$fileInfo = pathinfo($docData['path']);
if ('html' == $fileInfo['extension']) {
if (file_exists($docData['absolute_path']) && is_file($docData['absolute_path'])) {
$docData['file_content'] = file_get_contents($docData['absolute_path']);
return $docData;
}
- }
+ }*/
}
}
- return [];
+ return null;
}
/**
@@ -3256,14 +3259,21 @@ function getDocumentTemplateFromWork($workId, $courseInfo, $documentId)
function getAllDocumentsFromWorkToString($workId, $courseInfo)
{
$documents = getAllDocumentToWork($workId, $courseInfo['real_id']);
+ $docRepo = Container::getDocumentRepository();
$content = null;
if (!empty($documents)) {
$content .= '
';
$content .= '';
foreach ($documents as $doc) {
- $docData = DocumentManager::get_document_data_by_id($doc['document_id'], $courseInfo['code']);
+ /** @var CDocument $docData */
+ $docData = $docRepo->find($doc['document_id']);
+ $url = $docRepo->getResourceFileUrl($docData);
if ($docData) {
- $content .= '- '.$docData['title'].'
';
+ $content .= '-
+ '.
+ $docData->getTitle().'
+
+
';
}
}
$content .= '
';
@@ -3294,14 +3304,6 @@ function getWorkComments(CStudentPublication $work)
{
$commentTable = Database::get_course_table(TABLE_STUDENT_PUBLICATION_ASSIGNMENT_COMMENT);
$userTable = Database::get_main_table(TABLE_MAIN_USER);
-
- /*$courseId = (int) $work['c_id'];
- $workId = (int) $work['iid'];
-
- if (empty($courseId) || empty($workId)) {
- return [];
- }*/
-
$workId = $work->getIid();
$sql = "SELECT
@@ -5671,12 +5673,9 @@ function exportAllStudentWorkFromPublication(
}
$assignment = get_work_assignment_by_id($workId);
-
$courseCode = $courseInfo['code'];
$header = get_lang('Course').': '.$courseInfo['title'];
- $teachers = CourseManager::getTeacherListFromCourseCodeToString(
- $courseCode
- );
+ $teachers = CourseManager::getTeacherListFromCourseCodeToString($courseCode);
if (!empty($sessionId)) {
$sessionInfo = api_get_session_info($sessionId);
@@ -5696,9 +5695,10 @@ function exportAllStudentWorkFromPublication(
$content = null;
$expiresOn = null;
-
if (!empty($assignment) && isset($assignment['expires_on'])) {
- $content .= '
'.get_lang('Posted deadline for sending the work (Visible to the learner)').': '.api_get_local_time($assignment['expires_on']);
+ $content .= '
'.
+ get_lang('Posted deadline for sending the work (Visible to the learner)').': '.
+ api_get_local_time($assignment['expires_on']);
$expiresOn = api_get_local_time($assignment['expires_on']);
}
@@ -5729,13 +5729,12 @@ function exportAllStudentWorkFromPublication(
}
$row = 1;
-
//$pdf->set_custom_header($header);
+ /** @var array $work */
foreach ($workList as $work) {
$content .= '
';
// getWorkComments need c_id
$work['c_id'] = $courseInfo['real_id'];
-
//$content .= get_lang('Date').': '.api_get_local_time($work['sent_date_from_db']).'
';
$score = null;
if (!empty($work['qualification_only'])) {
@@ -5743,13 +5742,11 @@ function exportAllStudentWorkFromPublication(
}
$comments = getWorkComments($work);
-
$feedback = null;
if (!empty($comments)) {
$content .= ''.get_lang('Feedback').':
';
foreach ($comments as $comment) {
- $feedback .= get_lang('User').': '.$comment['complete_name'].
- '
';
+ $feedback .= get_lang('User').': '.$comment['complete_name'].'
';
$feedback .= $comment['comment'].'
';
}
}
@@ -5760,12 +5757,10 @@ function exportAllStudentWorkFromPublication(
$table->setCellContents($row, 4, strip_tags($work['title']));
$table->setCellContents($row, 5, $score);
$table->setCellContents($row, 6, $feedback);
-
$row++;
}
$content = $table->toHtml();
-
if (!empty($content)) {
$params = [
'filename' => $workData['title'].'_'.api_get_local_time(),
diff --git a/src/CoreBundle/Traits/ControllerTrait.php b/src/CoreBundle/Traits/ControllerTrait.php
index a89e4b4d81..b8d861561f 100644
--- a/src/CoreBundle/Traits/ControllerTrait.php
+++ b/src/CoreBundle/Traits/ControllerTrait.php
@@ -26,15 +26,18 @@ use Chamilo\CourseBundle\Repository\CStudentPublicationCorrectionRepository;
use Chamilo\CourseBundle\Repository\CStudentPublicationRepository;
use Knp\Menu\FactoryInterface as MenuFactoryInterface;
use Sylius\Bundle\SettingsBundle\Form\Factory\SettingsFormFactory;
+use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Contracts\Translation\TranslatorInterface;
trait ControllerTrait
{
+ protected $container;
+
public static function getSubscribedServices(): array
{
- $services = parent::getSubscribedServices();
+ $services = AbstractController::getSubscribedServices();
$services['translator'] = TranslatorInterface::class;
$services['glide'] = Glide::class;
$services['chamilo.settings.manager'] = SettingsManager::class;
@@ -132,11 +135,11 @@ trait ControllerTrait
*/
protected function getSettingsManager()
{
- return $this->get('chamilo.settings.manager');
+ return $this->container->get('chamilo.settings.manager');
}
protected function getSettingsFormFactory()
{
- return $this->get('chamilo_settings.form_factory.settings');
+ return $this->container->get('chamilo_settings.form_factory.settings');
}
}
diff --git a/src/CoreBundle/Traits/CourseControllerTrait.php b/src/CoreBundle/Traits/CourseControllerTrait.php
index f2abde969d..f7a2fc9d7c 100644
--- a/src/CoreBundle/Traits/CourseControllerTrait.php
+++ b/src/CoreBundle/Traits/CourseControllerTrait.php
@@ -16,6 +16,7 @@ trait CourseControllerTrait
{
protected $course;
protected $session;
+ protected $container;
/**
* Gets the current Chamilo course based in the "_real_cid" session variable.
@@ -67,7 +68,7 @@ trait CourseControllerTrait
return null;
}
- return $this->getDoctrine()->getManager()->find(Session::class, $sessionId);
+ return $this->container->get('doctrine')->getManager()->find(Session::class, $sessionId);
}
public function getGroup()
@@ -82,7 +83,7 @@ trait CourseControllerTrait
return null;
}
- return $this->getDoctrine()->getManager()->find(CGroup::class, $groupId);
+ return $this->container->get('doctrine')->getManager()->find(CGroup::class, $groupId);
}
public function getCourseUrlQuery(): string
diff --git a/src/CoreBundle/Traits/ResourceControllerTrait.php b/src/CoreBundle/Traits/ResourceControllerTrait.php
index 1d4ee7db5c..5a8a431c1a 100644
--- a/src/CoreBundle/Traits/ResourceControllerTrait.php
+++ b/src/CoreBundle/Traits/ResourceControllerTrait.php
@@ -12,11 +12,15 @@ use Chamilo\CoreBundle\Repository\ResourceFactory;
use Chamilo\CoreBundle\Repository\ResourceNodeRepository;
use Chamilo\CoreBundle\Repository\ResourceRepository;
use Doctrine\ORM\EntityNotFoundException;
+use Psr\Container\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
trait ResourceControllerTrait
{
+ /** @var ContainerInterface */
+ protected $container;
+
public function getRepositoryFromRequest(Request $request): ResourceRepository
{
$tool = $request->get('tool');
@@ -94,7 +98,7 @@ trait ResourceControllerTrait
}
}
} else {
- $repo = $this->getDoctrine()->getRepository(ResourceNode::class);
+ $repo = $this->container->get('doctrine')->getRepository(ResourceNode::class);
$parentResourceNode = $repo->find($parentNodeId);
}