Update from 1.11.x, fix queries, use iid, fix PHP warnings

pull/3741/head
Julio Montoya 4 years ago
parent 3ba91c46fc
commit 49b9ea1519
  1. 18
      public/main/course_info/infocours.php
  2. 12
      public/main/gradebook/gradebook_edit_all.php
  3. 14
      public/main/gradebook/lib/fe/catform.class.php
  4. 7
      public/main/gradebook/lib/fe/dataform.class.php
  5. 3
      public/main/inc/lib/document.lib.php
  6. 2
      public/main/lp/lp_add_category.php
  7. 2
      public/main/lp/lp_edit.php
  8. 2
      public/main/mySpace/myStudents.php
  9. 11
      public/main/survey/survey.lib.php
  10. 2
      public/main/work/edit.php
  11. 52
      public/main/work/view.php
  12. 47
      public/main/work/work.lib.php
  13. 3
      src/CoreBundle/Tool/Settings.php
  14. 9
      src/CoreBundle/Traits/ControllerTrait.php

@ -43,7 +43,7 @@ $router = Container::getRouter();
$translator = Container::getTranslator();
$show_delete_watermark_text_message = false;
if ('true' == api_get_setting('pdf_export_watermark_by_course')) {
if ('true' === api_get_setting('pdf_export_watermark_by_course')) {
if (isset($_GET['delete_watermark'])) {
PDF::delete_watermark($course_code);
$show_delete_watermark_text_message = true;
@ -67,13 +67,18 @@ function card_settings_open($id, $title, $open = false, $icon, $parent)
$html = '<div class="card">';
$html .= '<div class="card-header" id="card_'.$id.'">';
$html .= '<h5 class="card-title">';
$html .= '<a role="button" class="'.(($open) ? 'collapse' : ' ').'" data-toggle="collapse" data-target="#collapse_'.$id.'" aria-expanded="true" aria-controls="collapse_'.$id.'">';
$html .= '<a
role="button" class="'.(($open) ? 'collapse' : ' ').'"
data-toggle="collapse" data-target="#collapse_'.$id.'"
aria-expanded="true" aria-controls="collapse_'.$id.'">';
if ($icon) {
$html .= Display::return_icon($icon, null, null, ICON_SIZE_SMALL);
}
$html .= $title;
$html .= '</a></h5></div>';
$html .= '<div id="collapse_'.$id.'" class="collapse show" aria-labelledby="heading_'.$id.'" data-parent="#'.$parent.'">';
$html .= '<div
id="collapse_'.$id.'"
class="collapse show" aria-labelledby="heading_'.$id.'" data-parent="#'.$parent.'">';
$html .= '<div class="card-body">';
return $html;
@ -86,13 +91,16 @@ function card_settings_close()
return $html;
}
$form->addHtml(card_settings_open('course_settings', get_lang('Course settings'), true, 'settings.png', 'accordionSettings'));
$form->addHtml(
card_settings_open('course_settings', get_lang('Course settings'), true, 'settings.png', 'accordionSettings')
);
$image = '';
$illustrationUrl = $illustrationRepo->getIllustrationUrl($courseEntity, 'course_picture_medium');
if (!empty($illustrationUrl)) {
$image = '<div class="row"><label class="col-md-2 control-label">'.get_lang('Image').'</label>
$image = '<div class="row">
<label class="col-md-2 control-label">'.get_lang('Image').'</label>
<div class="col-md-8"><img class="img-thumbnail" src="'.$illustrationUrl.'" /></div></div>';
}

@ -39,7 +39,7 @@ $tbl_attendance = Database::get_course_table(TABLE_ATTENDANCE);
$table_evaluated[LINK_EXERCISE] = [
TABLE_QUIZ_TEST,
'title',
'id',
'iid',
get_lang('Test'),
];
$table_evaluated[LINK_DROPBOX] = [
@ -51,31 +51,31 @@ $table_evaluated[LINK_DROPBOX] = [
$table_evaluated[LINK_STUDENTPUBLICATION] = [
TABLE_STUDENT_PUBLICATION,
'url',
'id',
'iid',
get_lang('Assignments'),
];
$table_evaluated[LINK_LEARNPATH] = [
TABLE_LP_MAIN,
'name',
'id',
'iid',
get_lang('Courses'),
];
$table_evaluated[LINK_FORUM_THREAD] = [
TABLE_FORUM_THREAD,
'thread_title_qualify',
'thread_id',
'iid',
get_lang('Forum'),
];
$table_evaluated[LINK_ATTENDANCE] = [
TABLE_ATTENDANCE,
'attendance_title_qualify',
'id',
'iid',
get_lang('Attendance'),
];
$table_evaluated[LINK_SURVEY] = [
TABLE_SURVEY,
'code',
'survey_id',
'iid',
get_lang('Survey'),
];

@ -342,7 +342,7 @@ class CatForm extends FormValidator
if (isset($this->category_object) &&
0 == $this->category_object->get_parent_id() &&
(api_is_platform_admin() || 'true' == api_get_setting('teachers_can_change_grade_model_settings'))
(api_is_platform_admin() || 'true' === api_get_setting('teachers_can_change_grade_model_settings'))
) {
// Getting grade models
$obj = new GradeModel();
@ -370,7 +370,7 @@ class CatForm extends FormValidator
}
if (count($test_cats) > 1 || !empty($links)) {
if ('true' == api_get_setting('gradebook_enable_grade_model')) {
if ('true' === api_get_setting('gradebook_enable_grade_model')) {
$this->freeze('grade_model_id');
}
}
@ -404,23 +404,25 @@ class CatForm extends FormValidator
$documentId = $this->category_object->getDocumentId();
if (!empty($documentId)) {
$documentData = DocumentManager::get_document_data_by_id($documentId, api_get_course_id());
$repo = \Chamilo\CoreBundle\Framework\Container::getDocumentRepository();
/** @var \Chamilo\CourseBundle\Entity\CDocument $documentData */
$documentData = $repo->find($documentId);
if (!empty($documentData)) {
$this->addLabel(get_lang('Certificate'), $documentData['title']);
$this->addLabel(get_lang('Certificate'), $documentData->getTitle());
}
}
if (self::TYPE_ADD == $this->form_type) {
$this->addButtonCreate(get_lang('Add category'));
} else {
$this->addElement('hidden', 'editcat', intval($_GET['editcat']));
$this->addElement('hidden', 'editcat', (int) $_GET['editcat']);
$this->addButtonUpdate(get_lang('Edit this category'));
}
$setting = api_get_setting('tool_visible_by_default_at_creation');
$visibility_default = 1;
if (isset($setting['gradebook']) && 'false' == $setting['gradebook']) {
if (isset($setting['gradebook']) && 'false' === $setting['gradebook']) {
$visibility_default = 0;
}

@ -1,4 +1,5 @@
<?php
/* For licensing terms, see /license.txt */
/**
@ -8,9 +9,9 @@
*/
class DataForm extends FormValidator
{
const TYPE_IMPORT = 1;
const TYPE_EXPORT = 2;
const TYPE_EXPORT_PDF = 3;
public const TYPE_IMPORT = 1;
public const TYPE_EXPORT = 2;
public const TYPE_EXPORT_PDF = 3;
/**
* Builds a form containing form items based on a given parameter.

@ -1176,7 +1176,6 @@ class DocumentManager
$session_id = empty($session_id) ? api_get_session_id() : (int) $session_id;
$groupId = api_get_group_id();
//$www = api_get_path(WEB_COURSE_PATH).$course_info['path'].'/document';
$TABLE_DOCUMENT = Database::get_course_table(TABLE_DOCUMENT);
$id = (int) $id;
$sessionCondition = api_get_session_condition($session_id, true, true);
@ -1189,7 +1188,7 @@ class DocumentManager
}
$result = Database::query($sql);
$courseParam = '&cidReq='.$course_code.'&id='.$id.'&sid='.$session_id.'&gidReq='.$groupId;
$courseParam = '&cid='.$course_id.'&id='.$id.'&sid='.$session_id.'&gid='.$groupId;
if ($result && 1 == Database::num_rows($result)) {
$row = Database::fetch_array($result, 'ASSOC');
//@todo need to clarify the name of the URLs not nice right now

@ -69,7 +69,7 @@ if ($form->validate()) {
if ($id) {
$item = learnpath::getCategory($id);
$defaults = [
'id' => $item->getId(),
'id' => $item->getIid(),
'name' => $item->getName(),
];
$form->setDefaults($defaults);

@ -375,8 +375,10 @@ if ($form->validate()) {
$request = Container::getRequest();
if ($request->files->has('lp_preview_image')) {
$file = $request->files->get('lp_preview_image');
if (!empty($file)) {
$lpRepo->addFile($lp, $file);
}
}
$em->persist($lp);
$em->flush();

@ -2133,7 +2133,7 @@ if (empty($details)) {
echo '<td class="text-center">'.api_convert_and_format_date(
$results['sent_date_from_db']
).' '.$results['expiry_note'].'</td>';
$assignment = get_work_assignment_by_id($work->id, $courseInfo['real_id']);
$assignment = get_work_assignment_by_id($work->iid, $courseInfo['real_id']);
echo '<td class="text-center">';
if (!empty($assignment['expires_on'])) {

@ -311,7 +311,7 @@ class SurveyManager
$sql = 'SELECT survey_version FROM '.$table_survey.'
WHERE
c_id = '.$course_id.' AND
survey_id = '.intval($values['parent_id']);
iid = '.intval($values['parent_id']);
$rs = Database::query($sql);
$getversion = Database::fetch_array($rs, 'ASSOC');
if (empty($getversion['survey_version'])) {
@ -590,9 +590,6 @@ class SurveyManager
'".$_course['id']."')";
Database::query($sql);
$return = Database::insert_id();
$sql = "UPDATE $table_survey SET survey_id = $return WHERE iid = $return";
Database::query($sql);
} else {
$sql = "UPDATE $table_survey SET
code = '".Database::escape_string($values['survey_code'])."',
@ -2129,7 +2126,7 @@ class SurveyManager
$sql = "UPDATE $surveyTable
SET invited = 0, answered = 0
WHERE survey_id = $surveyId AND c_id = $courseId AND session_id = $sessionId ";
WHERE iid = $surveyId AND c_id = $courseId AND session_id = $sessionId ";
Database::query($sql);
return true;
@ -2176,10 +2173,6 @@ class SurveyManager
$newSurveyId = Database::insert($surveyTable, $surveyData);
if ($newSurveyId) {
$sql = "UPDATE $surveyTable SET survey_id = $newSurveyId
WHERE iid = $newSurveyId";
Database::query($sql);
$sql = "SELECT * FROM $surveyQuestionGroupTable
WHERE c_id = $originalCourseId AND survey_id = $surveyId";
$res = Database::query($sql);

@ -148,7 +148,7 @@ $form->addText('title', get_lang('Title'), true, ['id' => 'file_upload']);
if ($is_allowed_to_edit && !empty($item_id)) {
$sql = "SELECT contains_file, url
FROM $work_table
WHERE c_id = $course_id AND id ='$item_id' ";
WHERE c_id = $course_id AND iid ='$item_id' ";
$result = Database::query($sql);
if (false !== $result && Database::num_rows($result) > 0) {
$row = Database::fetch_array($result);

@ -2,25 +2,32 @@
/* 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;
require_once 'work.lib.php';
$id = isset($_GET['id']) ? (int) $_GET['id'] : null;
$work = get_work_data_by_id($id);
$repo = Container::getStudentPublicationRepository();
/** @var CStudentPublication $work */
$work = $repo->find($id);
if (empty($work)) {
api_not_allowed(true);
}
protectWork(api_get_course_info(), $work['parent_id']);
$parentId = $work->getParentId();
protectWork(api_get_course_info(), $parentId);
$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : null;
$page = isset($_REQUEST['page']) ? $_REQUEST['page'] : null;
$action = $_REQUEST['action'] ?? null;
$page = $_REQUEST['page'] ?? null;
$work['title'] = isset($work['title']) ? Security::remove_XSS($work['title']) : '';
$work['description'] = isset($work['description']) ? Security::remove_XSS($work['description']) : '';
/*$work['title'] = isset($work['title']) ? Security::remove_XSS($work['title']) : '';
$work['description'] = isset($work['description']) ? Security::remove_XSS($work['description']) : '';*/
$htmlHeadXtra[] = '<script>'.ExerciseLib::getJsCode().'</script>';
$interbreadcrumb[] = [
@ -28,7 +35,7 @@ $interbreadcrumb[] = [
'name' => get_lang('Assignments'),
];
$folderData = get_work_data_by_id($work['parent_id']);
$folderData = get_work_data_by_id($parentId);
$courseInfo = api_get_course_info();
$courseEntity = api_get_course_entity();
$isCourseManager = api_is_platform_admin() || api_is_coach() || api_is_allowed_to_edit(false, false, true);
@ -36,7 +43,9 @@ $isCourseManager = api_is_platform_admin() || api_is_coach() || api_is_allowed_t
$allowEdition = false;
if ($isCourseManager) {
$allowEdition = true;
if (!empty($work['qualification']) && api_get_configuration_value('block_student_publication_score_edition')) {
if (!empty($work->getQualification()) &&
api_get_configuration_value('block_student_publication_score_edition')
) {
$allowEdition = false;
}
}
@ -50,26 +59,28 @@ $isDrhOfCourse = CourseManager::isUserSubscribedInCourseAsDrh(
$courseInfo
);
$isDrhOfSession = !empty(SessionManager::getSessionFollowedByDrh(api_get_user_id(), $work['session_id']));
$isDrhOfSession = false;
// @todo fix $isDrhOfSession check
//$isDrhOfSession = !empty(SessionManager::getSessionFollowedByDrh(api_get_user_id(), $work['session_id']));
if ((user_is_author($id) || $isDrhOfCourse || $allowEdition || $isDrhOfSession) ||
if (($isDrhOfCourse || $allowEdition || $isDrhOfSession || user_is_author($id)) ||
(
0 == $courseInfo['show_score'] &&
1 == $work['active'] &&
1 == $work['accepted']
1 == $work->getActive() &&
1 == $work->getAccepted()
)
) {
if ((api_is_allowed_to_edit() || api_is_coach()) || api_is_drh()) {
$url_dir = api_get_path(WEB_CODE_PATH).'work/work_list_all.php?id='.$folderData['id'].'&'.api_get_cidreq();
$url_dir = api_get_path(WEB_CODE_PATH).'work/work_list_all.php?id='.$folderData['iid'].'&'.api_get_cidreq();
} else {
$url_dir = api_get_path(WEB_CODE_PATH).'work/work_list.php?id='.$folderData['id'].'&'.api_get_cidreq();
$url_dir = api_get_path(WEB_CODE_PATH).'work/work_list.php?id='.$folderData['iid'].'&'.api_get_cidreq();
}
$userInfo = api_get_user_info($work['user_id']);
$userInfo = api_get_user_info($work->getUserId());
$interbreadcrumb[] = ['url' => $url_dir, 'name' => $folderData['title']];
$interbreadcrumb[] = ['url' => '#', 'name' => $userInfo['complete_name']];
$interbreadcrumb[] = ['url' => '#', 'name' => $work['title']];
$interbreadcrumb[] = ['url' => '#', 'name' => $work->getTitle()];
$workId = $work->getIid();
if ((
0 == $courseInfo['show_score'] &&
1 == $work['active'] &&
@ -78,9 +89,10 @@ if ((user_is_author($id) || $isDrhOfCourse || $allowEdition || $isDrhOfSession)
$isCourseManager || user_is_author($id) || $isDrhOfCourse || $isDrhOfSession
) {
if ('edit' === $page) {
$url = api_get_path(WEB_CODE_PATH).'work/edit.php?id='.$folderData['id'].'&item_id='.$work['id'].'&'.api_get_cidreq();
$url = api_get_path(WEB_CODE_PATH).
'work/edit.php?id='.$folderData['iid'].'&item_id='.$workId.'&'.api_get_cidreq();
} else {
$url = api_get_path(WEB_CODE_PATH).'work/view.php?id='.$work['id'].'&'.api_get_cidreq();
$url = api_get_path(WEB_CODE_PATH).'work/view.php?id='.$workId.'&'.api_get_cidreq();
$allowRedirect = api_get_configuration_value('allow_redirect_to_main_page_after_work_upload');
$urlToRedirect = '';
@ -172,7 +184,7 @@ if ((user_is_author($id) || $isDrhOfCourse || $allowEdition || $isDrhOfSession)
$tpl->assign('comments', $comments);
$actions = '';
if (isset($work['contains_file']) && !empty($work['contains_file'])) {
if ($work->getContainsFile()) {
if (isset($work['download_url']) && !empty($work['download_url'])) {
$actions = Display::url(
Display::return_icon(

@ -142,15 +142,15 @@ function get_work_data_by_id($id, $courseId = 0, $sessionId = 0)
if (empty($studentPublication->getTitle())) {
$work['title'] = basename($studentPublication->getUrl());
}
$work['download_url'] = $router->generate(
$url = $router->generate(
'chamilo_core_resource_download',
[
'id' => $studentPublication->getResourceNode()->getId(),
'tool' => 'student_publication',
'type' => 'student_publications',
]
).'?'.api_get_cidreq();
);
$work['download_url'] = $url.'?'.api_get_cidreq();
$work['view_url'] = $webCodePath.'work/view.php?id='.$workId.'&'.api_get_cidreq();
$showUrl = $work['show_url'] = $webCodePath.'work/show_file.php?id='.$workId.'&'.api_get_cidreq();
$work['show_content'] = '';
@ -697,7 +697,7 @@ function build_work_move_to_selector($folders, $curdirpath, $move_file, $group_d
$move_file = (int) $move_file;
$tbl_work = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
$sql = "SELECT title, url FROM $tbl_work
WHERE c_id = $course_id AND id ='".$move_file."'";
WHERE c_id = $course_id AND iid ='".$move_file."'";
$result = Database::query($sql);
$row = Database::fetch_array($result, 'ASSOC');
$title = empty($row['title']) ? basename($row['url']) : $row['title'];
@ -3284,29 +3284,29 @@ function getWorkDescriptionToolbar()
}
/**
* @param array $work
*
* @return array
*/
function getWorkComments($work)
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'];
/*$courseId = (int) $work['c_id'];
$workId = (int) $work['iid'];
if (empty($courseId) || empty($workId)) {
return [];
}
}*/
$workId = $work->getIid();
$sql = "SELECT
c.id,
c.iid,
c.user_id
FROM $commentTable c
INNER JOIN $userTable u
ON (u.id = c.user_id)
WHERE c_id = $courseId AND work_id = $workId
WHERE work_id = $workId
ORDER BY sent_at
";
$result = Database::query($sql);
@ -3793,14 +3793,15 @@ function addWorkComment($courseInfo, $userId, $parentWork, $work, $data)
}
/**
* @param array $work
* @param array $workParent
*
* @return string
*/
function getWorkCommentForm($work, $workParent)
function getWorkCommentForm(CStudentPublication $work, $workParent)
{
$url = api_get_path(WEB_CODE_PATH).'work/view.php?id='.$work['iid'].'&action=send_comment&'.api_get_cidreq();
$id = $work->getIid();
$url = api_get_path(WEB_CODE_PATH).'work/view.php?id='.$id.'&action=send_comment&'.api_get_cidreq();
$form = new FormValidator(
'work_comment',
'post',
@ -3815,7 +3816,9 @@ function getWorkCommentForm($work, $workParent)
$allowEdition = false;
if ($isCourseManager) {
$allowEdition = true;
if (!empty($work['qualification']) && api_get_configuration_value('block_student_publication_score_edition')) {
if (!empty($work->getQualification()) &&
api_get_configuration_value('block_student_publication_score_edition')
) {
$allowEdition = false;
}
}
@ -3842,18 +3845,24 @@ function getWorkCommentForm($work, $workParent)
$form,
'qualification',
$qualification,
$work['qualification']
$work->getQualification()
);
}
$form->addFile('file', get_lang('Correction'));
$form->setDefaults(['qualification' => $work['qualification']]);
$form->setDefaults(['qualification' => $work->getQualification()]);
}
}
Skill::addSkillsToUserForm($form, ITEM_TYPE_STUDENT_PUBLICATION, $workParent['iid'], $work['user_id'], $work['iid']);
Skill::addSkillsToUserForm(
$form,
ITEM_TYPE_STUDENT_PUBLICATION,
$workParent['iid'],
$work->getUserId(),
$id
);
$form->addHtmlEditor('comment', get_lang('Comment'), false);
$form->addFile('attachment', get_lang('Attachment'));
$form->addElement('hidden', 'iid', $work['iid']);
$form->addElement('hidden', 'iid', $id);
if (api_is_allowed_to_edit()) {
$form->addCheckBox(

@ -4,9 +4,6 @@
namespace Chamilo\CoreBundle\Tool;
/**
* Class Announcement.
*/
class Settings extends AbstractTool
{
}

@ -21,6 +21,7 @@ use Chamilo\CourseBundle\Repository\CLpCategoryRepository;
use Chamilo\CourseBundle\Repository\CLpRepository;
use Chamilo\CourseBundle\Repository\CQuizQuestionCategoryRepository;
use Chamilo\CourseBundle\Repository\CQuizQuestionRepository;
use Chamilo\CourseBundle\Repository\CStudentPublicationRepository;
use Knp\Menu\FactoryInterface as MenuFactoryInterface;
use Sylius\Bundle\SettingsBundle\Form\Factory\SettingsFormFactory;
use Symfony\Component\HttpFoundation\Request;
@ -43,19 +44,21 @@ trait ControllerTrait
*/
$services[] = ResourceFactory::class;
$services[] = ResourceNodeRepository::class;
$services[] = CAnnouncementRepository::class;
$services[] = CAnnouncementAttachmentRepository::class;
$services[] = CAttendanceRepository::class;
$services[] = CBlogRepository::class;
$services[] = CCalendarEventAttachmentRepository::class;
$services[] = CDocumentRepository::class;
$services[] = CQuizQuestionRepository::class;
$services[] = CQuizQuestionCategoryRepository::class;
$services[] = CForumForumRepository::class;
$services[] = CForumAttachmentRepository::class;
$services[] = CLpRepository::class;
$services[] = CLpCategoryRepository::class;
$services[] = CQuizQuestionRepository::class;
$services[] = CQuizQuestionCategoryRepository::class;
$services[] = CStudentPublicationRepository::class;
$services[] = IllustrationRepository::class;

Loading…
Cancel
Save