Fix PHP warnings

pull/3768/head
Julio Montoya 5 years ago
parent 2376362857
commit 7cc603c06a
  1. 7
      public/main/forum/forumfunction.inc.php
  2. 13
      public/main/work/upload_from_template.php
  3. 65
      public/main/work/work.lib.php
  4. 9
      src/CoreBundle/Traits/ControllerTrait.php
  5. 5
      src/CoreBundle/Traits/CourseControllerTrait.php
  6. 6
      src/CoreBundle/Traits/ResourceControllerTrait.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()
);
);*/
}
}
}

@ -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);

@ -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 = '<a href="'.$downloadUrl.'">'.$saveIcon.'</a> ';
}
@ -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 .= '<ul class="nav nav-list well">';
$content .= '<li class="nav-header">'.get_lang('Documents').'</li>';
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 .= '<li><a class="link_to_download" target="_blank" href="'.$docData['url'].'">'.$docData['title'].'</a></li>';
$content .= '<li>
<a class="link_to_download" target="_blank" href="'.$url.'">'.
$docData->getTitle().'
</a>
</li>';
}
}
$content .= '</ul><br />';
@ -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 .= '<br /><strong>'.get_lang('Posted deadline for sending the work (Visible to the learner)').'</strong>: '.api_get_local_time($assignment['expires_on']);
$content .= '<br /><strong>'.
get_lang('Posted deadline for sending the work (Visible to the learner)').'</strong>: '.
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 .= '<hr />';
// getWorkComments need c_id
$work['c_id'] = $courseInfo['real_id'];
//$content .= get_lang('Date').': '.api_get_local_time($work['sent_date_from_db']).'<br />';
$score = null;
if (!empty($work['qualification_only'])) {
@ -5743,13 +5742,11 @@ function exportAllStudentWorkFromPublication(
}
$comments = getWorkComments($work);
$feedback = null;
if (!empty($comments)) {
$content .= '<h4>'.get_lang('Feedback').': </h4>';
foreach ($comments as $comment) {
$feedback .= get_lang('User').': '.$comment['complete_name'].
'<br />';
$feedback .= get_lang('User').': '.$comment['complete_name'].'<br />';
$feedback .= $comment['comment'].'<br />';
}
}
@ -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(),

@ -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');
}
}

@ -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

@ -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);
}

Loading…
Cancel
Save