From 72d23099d7596f4a091363a742af7d782f737001 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Wed, 16 Sep 2020 09:55:16 +0200 Subject: [PATCH] Internal - Add travis behat, fix course creation, add psalm checks --- .travis.yml | 3 +- public/main/admin/course_add.php | 5 -- public/main/admin/course_category.php | 4 +- public/main/admin/course_edit.php | 16 ++++--- public/main/admin/course_list.php | 16 +++---- public/main/admin/course_request_edit.php | 12 +++-- public/main/admin/extra_field_workflow.php | 10 ++-- public/main/admin/gradebook_dependency.php | 2 +- public/main/admin/gradebook_list.php | 4 +- public/main/admin/index.php | 4 +- public/main/admin/legal_list.php | 3 +- public/main/admin/questions.php | 10 ++-- public/main/admin/resource_sequence.php | 2 +- public/main/admin/skill.php | 9 ++-- public/main/admin/skill_badge_create.php | 9 +++- public/main/admin/skill_level.php | 11 +++-- public/main/admin/skill_list.php | 18 +++++--- public/main/admin/skill_profile.php | 10 ++-- public/main/admin/skill_rel_course.php | 2 +- public/main/admin/skill_translate.php | 5 +- public/main/admin/system_announcements.php | 3 +- .../admin/teachers_time_by_session_report.php | 2 +- public/main/admin/user_add.php | 13 ------ public/main/admin/user_export.php | 8 ++-- public/main/admin/user_linking_requests.php | 6 +-- public/main/admin/user_list_consent.php | 14 +++--- public/main/inc/lib/add_course.lib.inc.php | 14 ++---- public/main/inc/lib/course.lib.php | 2 - public/main/inc/lib/display.lib.php | 1 - .../lib/formvalidator/FormValidator.class.php | 4 +- public/main/inc/lib/template.lib.php | 2 +- src/CoreBundle/Entity/Course.php | 10 +--- src/CoreBundle/Entity/CourseRelUser.php | 8 ---- src/CoreBundle/Entity/CourseRequest.php | 46 ++++--------------- src/CoreBundle/Entity/CourseType.php | 18 ++++---- 35 files changed, 127 insertions(+), 179 deletions(-) diff --git a/.travis.yml b/.travis.yml index ee98fa4706..a145ffffa5 100755 --- a/.travis.yml +++ b/.travis.yml @@ -102,6 +102,7 @@ script: - sed -i "s/APP_ENV='dev'/APP_ENV='test'/g" .env.local - cd tests/behat - ../../vendor/behat/behat/bin/behat features/adminFillUsers.feature -vvv + - ../../vendor/behat/behat/bin/behat features/actionUserLogin.feature -vvv - ../../vendor/behat/behat/bin/behat features/adminSettings.feature -vvv - ../../vendor/behat/behat/bin/behat features/career.feature -vvv - ../../vendor/behat/behat/bin/behat features/class.feature -vvv @@ -114,7 +115,7 @@ script: # - ../../vendor/behat/behat/bin/behat features/profile.feature -v # - ../../vendor/behat/behat/bin/behat features/promotion.feature -v # - ../../vendor/behat/behat/bin/behat features/registration.feature -v -# - ../../vendor/behat/behat/bin/behat features/sessionAccess.feature -v + - ../../vendor/behat/behat/bin/behat features/sessionAccess.feature -v # - ../../vendor/behat/behat/bin/behat features/sessionManagement.feature -v # - ../../vendor/behat/behat/bin/behat features/socialGroup.feature -v # - ../../vendor/behat/behat/bin/behat features/systemAnnouncements.feature -v diff --git a/public/main/admin/course_add.php b/public/main/admin/course_add.php index f6fcbb1df8..9ff5ca53a2 100644 --- a/public/main/admin/course_add.php +++ b/public/main/admin/course_add.php @@ -2,9 +2,6 @@ /* For licensing terms, see /license.txt */ -use Chamilo\CoreBundle\Entity\CourseCategory; -use Chamilo\CoreBundle\Repository\CourseCategoryRepository; - $cidReset = true; require_once __DIR__.'/../inc/global.inc.php'; $this_section = SECTION_PLATFORM_ADMIN; @@ -16,8 +13,6 @@ $interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('Administration') $interbreadcrumb[] = ['url' => 'course_list.php', 'name' => get_lang('Course list')]; $em = Database::getManager(); -/** @var CourseCategoryRepository $courseCategoriesRepo */ -$courseCategoriesRepo = $em->getRepository('ChamiloCoreBundle:CourseCategory'); // Get all possible teachers. $accessUrlId = api_get_current_access_url_id(); diff --git a/public/main/admin/course_category.php b/public/main/admin/course_category.php index ea0dec54e9..d1ac931e50 100644 --- a/public/main/admin/course_category.php +++ b/public/main/admin/course_category.php @@ -49,10 +49,10 @@ if (!empty($action)) { $ret = $categoryInfo['id']; //Delete Picture Category - $deletePicture = isset($_POST['delete_picture']) ? $_POST['delete_picture'] : ''; + /*$deletePicture = isset($_POST['delete_picture']) ? $_POST['delete_picture'] : ''; if ($deletePicture) { CourseCategory::deletePictureCategory($ret); - } + }*/ $errorMsg = Display::return_message(get_lang('Update successful')); } diff --git a/public/main/admin/course_edit.php b/public/main/admin/course_edit.php index 333b2ee040..01b9685565 100644 --- a/public/main/admin/course_edit.php +++ b/public/main/admin/course_edit.php @@ -2,10 +2,7 @@ /* For licensing terms, see /license.txt */ -use Chamilo\CoreBundle\Entity\CourseCategory; use Chamilo\CoreBundle\Entity\User; -use Chamilo\CoreBundle\Repository\CourseCategoryRepository; -use Chamilo\CoreBundle\Repository\CourseRepository; use Chamilo\CoreBundle\Framework\Container; $cidReset = true; @@ -164,7 +161,7 @@ $form->addSelectAjax( $courseCategoryNames, [ 'url' => api_get_path(WEB_AJAX_PATH).'course.ajax.php?a=search_category', - 'multiple' => 'multiple' + 'multiple' => 'multiple', ] ); $courseInfo['course_categories'] = $courseCategoryIds; @@ -297,7 +294,8 @@ if ($form->validate()) { $course = $form->getSubmitValues(); $visibility = $course['visibility']; - global $_configuration; + // @todo should be check in the CourseListener + /*global $_configuration; if (isset($_configuration[$urlId]) && isset($_configuration[$urlId]['hosting_limit_active_courses']) && @@ -312,14 +310,18 @@ if ($form->validate()) { api_warn_hosting_contact('hosting_limit_active_courses'); Display::addFlash( - Display::return_message(get_lang('Sorry, this installation has an active courses limit, which has now been reached. You can still create new courses, but only if you hide/disable at least one existing active course. To do this, edit a course from the administration courses list, and change the visibility to \'hidden\', then try creating this course again. To increase the maximum number of active courses allowed on this Chamilo installation, please contact your hosting provider or, if available, upgrade to a superior hosting plan.')) + Display::return_message( + get_lang( + 'Sorry, this installation has an active courses limit, which has now been reached. You can still create new courses, but only if you hide/disable at least one existing active course. To do this, edit a course from the administration courses list, and change the visibility to \'hidden\', then try creating this course again. To increase the maximum number of active courses allowed on this Chamilo installation, please contact your hosting provider or, if available, upgrade to a superior hosting plan.' + ) + ) ); header('Location: course_list.php'); exit; } } - } + }*/ $visual_code = $course['visual_code']; $visual_code = CourseManager::generate_course_code($visual_code); diff --git a/public/main/admin/course_list.php b/public/main/admin/course_list.php index 2e53652efd..c49897ee2b 100644 --- a/public/main/admin/course_list.php +++ b/public/main/admin/course_list.php @@ -103,7 +103,7 @@ function get_course_data($from, $number_of_items, $column, $direction, $dataFunc unsubscribe LIKE '".$keyword_unsubscribe."'"; if (!empty($keyword_category)) { - $sql .= " AND category.id = ".$keyword_category . " "; + $sql .= " AND category.id = ".$keyword_category." "; } } @@ -141,7 +141,7 @@ function get_course_data($from, $number_of_items, $column, $direction, $dataFunc // get categories $sqlCategoriesByCourseId = "SELECT category.name FROM $tblCourseCategory category INNER JOIN $tblCourseRelCategory course_rel_category ON category.id = course_rel_category.course_category_id - WHERE course_rel_category.course_id = " . $course['id']; + WHERE course_rel_category.course_id = ".$course['id']; $resultCategories = Database::query($sqlCategoriesByCourseId); $categories = []; @@ -151,7 +151,7 @@ function get_course_data($from, $number_of_items, $column, $direction, $dataFunc // Place colour icons in front of courses. $show_visual_code = $course['visual_code'] != $course[2] ? Display::label($course['visual_code'], 'info') : null; - $course[1] = get_course_visibility_icon($course[8]).PHP_EOL + $course[1] = get_course_visibility_icon($courseInfo['visibility']).PHP_EOL .Display::url(Security::remove_XSS($course[1]), $courseInfo['course_public_url']).PHP_EOL .$show_visual_code; $course[5] = SUBSCRIBE_ALLOWED == $course[5] ? get_lang('Yes') : get_lang('No'); @@ -260,7 +260,7 @@ function get_course_data_by_session($from, $number_of_items, $column, $direction while ($course = Database::fetch_array($res)) { // Place colour icons in front of courses. $showVisualCode = $course['visual_code'] != $course[2] ? Display::label($course['visual_code'], 'info') : null; - $course[1] = get_course_visibility_icon($course[8]). + $course[1] = get_course_visibility_icon($course['col8']). ''. $course[1]. ' '. @@ -286,12 +286,14 @@ function get_course_data_by_session($from, $number_of_items, $column, $direction /** * Return an icon representing the visibility of the course. * - * @param string $visibility + * @param int $visibility * * @return string */ function get_course_visibility_icon($visibility) { + $visibility = (int) $visibility; + $style = 'margin-bottom:0;margin-right:5px;'; switch ($visibility) { case 0: @@ -453,8 +455,7 @@ if (isset($_GET['search']) && 'advanced' === $_GET['search']) { FormValidator::LAYOUT_INLINE ); $url = api_get_path(WEB_AJAX_PATH).'session.ajax.php?a=search_session'; - $sessionSelect = $sessionFilter->addElement( - 'select_ajax', + $sessionSelect = $sessionFilter->addSelectAjax( 'session_name', get_lang('Search course by session'), null, @@ -504,7 +505,6 @@ if (isset($_GET['search']) && 'advanced' === $_GET['search']) { if (!sessionId) { return; } - window.location = "'.$courseListUrl.'?session_id="+sessionId; }); }); diff --git a/public/main/admin/course_request_edit.php b/public/main/admin/course_request_edit.php index 06521521d0..10ac7755e6 100644 --- a/public/main/admin/course_request_edit.php +++ b/public/main/admin/course_request_edit.php @@ -15,7 +15,7 @@ $tool_name = get_lang('Edit a course request'); api_protect_admin_script(); // A check whether the course validation feature is enabled. -$course_validation_feature = 'true' == api_get_setting('course_validation'); +$course_validation_feature = 'true' === api_get_setting('course_validation'); // Filtering passed to this page parameters. $id = (int) ($_GET['id']); @@ -55,8 +55,7 @@ if ($course_validation_feature) { // Course category. $url = api_get_path(WEB_AJAX_PATH).'course.ajax.php?a=search_category'; - $courseSelect = $form->addElement( - 'select_ajax', + $courseSelect = $form->addSelectAjax( 'category_code', get_lang('Category'), null, @@ -69,7 +68,12 @@ if ($course_validation_feature) { } // Course code. - $form->addText('wanted_code', get_lang('Course code'), false, ['size' => '$maxlength', 'maxlength' => $maxlength]); + $form->addText( + 'wanted_code', + get_lang('Course code'), + false, + ['size' => '$maxlength', 'maxlength' => $maxlength] + ); $form->applyFilter('wanted_code', 'html_filter'); $form->addRule('wanted_code', get_lang('max. 20 characters, e.g. INNOV21'), 'maxlength', $maxlength); $form->addRule('wanted_code', get_lang('Required field'), 'required'); diff --git a/public/main/admin/extra_field_workflow.php b/public/main/admin/extra_field_workflow.php index 467a696206..834029da0c 100644 --- a/public/main/admin/extra_field_workflow.php +++ b/public/main/admin/extra_field_workflow.php @@ -93,20 +93,20 @@ $htmlHeadXtra[] = '