diff --git a/assets/css/app.scss b/assets/css/app.scss index 6c57bf31b4..0219d1506f 100644 --- a/assets/css/app.scss +++ b/assets/css/app.scss @@ -468,7 +468,8 @@ table#skill_holder { padding: 20px 0px; } -#date_fields label, .p-float-label label[for='date_time'] { +#date_fields label, +.p-float-label .datepicker-label { top: 0px; left: 0.5rem; --tw-bg-opacity: 1; diff --git a/public/main/gradebook/lib/be/category.class.php b/public/main/gradebook/lib/be/category.class.php index 5f0efe44d3..4f0d6bfb56 100644 --- a/public/main/gradebook/lib/be/category.class.php +++ b/public/main/gradebook/lib/be/category.class.php @@ -2568,7 +2568,7 @@ class Category implements GradebookItem $cat->set_visible($data['visible']); $cat->set_session_id($data['session_id']); $cat->set_certificate_min_score($data['certif_min_score']); - $cat->set_grade_model_id($data['grade_model_id']); + $cat->set_grade_model_id((int) $data['grade_model_id']); $cat->set_locked($data['locked']); $cat->setGenerateCertificates($data['generate_certificates']); $cat->setIsRequirement($data['is_requirement']); diff --git a/public/main/inc/lib/formvalidator/Element/DatePicker.php b/public/main/inc/lib/formvalidator/Element/DatePicker.php index fa6e332591..73ed7d6a3e 100644 --- a/public/main/inc/lib/formvalidator/Element/DatePicker.php +++ b/public/main/inc/lib/formvalidator/Element/DatePicker.php @@ -113,50 +113,9 @@ class DatePicker extends HTML_QuickForm_text if ($('label[for=\"".$id."\"]').length > 0) { $('label[for=\"".$id."\"]').hide(); } - }); - "; - - return $js; - $js .= ""; return $js; diff --git a/public/main/inc/lib/formvalidator/Element/DateTimePicker.php b/public/main/inc/lib/formvalidator/Element/DateTimePicker.php index 1ac2872f25..55cb011a06 100644 --- a/public/main/inc/lib/formvalidator/Element/DateTimePicker.php +++ b/public/main/inc/lib/formvalidator/Element/DateTimePicker.php @@ -88,6 +88,8 @@ class DateTimePicker extends HTML_QuickForm_text time_24hr: true, wrap: false }); + + document.querySelector('label[for=\"' + '{$id}' + '\"]').classList.add('datepicker-label'); }); "; diff --git a/public/main/survey/survey.lib.php b/public/main/survey/survey.lib.php index 183613f2fa..ac82b06358 100644 --- a/public/main/survey/survey.lib.php +++ b/public/main/survey/survey.lib.php @@ -27,7 +27,7 @@ class SurveyManager * * @return string */ - public static function generate_unique_code($code) + public static function generate_unique_code(string $code, ?int $surveyId = null) { if (empty($code)) { return false; @@ -38,8 +38,15 @@ class SurveyManager $num = 0; $new_code = $code; while (true) { - $sql = "SELECT * FROM $table - WHERE code = '$new_code' AND c_id = $course_id"; + + if (isset($surveyId)) { + $sql = "SELECT * FROM $table + WHERE code = '$new_code' AND iid = $surveyId"; + } else { + $sql = "SELECT * FROM $table + WHERE code = '$new_code'"; + } + $result = Database::query($sql); if (Database::num_rows($result)) { $num++; @@ -492,7 +499,7 @@ class SurveyManager $survey_weight = floatval($_POST['survey_weight']); $max_score = 1; - if (!$gradebook_link_id) { + if (!$gradebook_link_id && isset($values['category_id'])) { GradebookUtils::add_resource_to_course_gradebook( $values['category_id'], $courseCode, @@ -643,7 +650,7 @@ class SurveyManager $new_survey_id = (int) $new_survey_id; } - $sql = "SELECT * FROM $table_survey_question_group + /*$sql = "SELECT * FROM $table_survey_question_group WHERE iid = $survey_id"; $res = Database::query($sql); @@ -662,7 +669,7 @@ class SurveyManager Database::query($sql); $group_id[$row['id']] = $insertId; - } + }*/ // Get questions $sql = "SELECT * FROM $table_survey_question @@ -671,7 +678,6 @@ class SurveyManager $res = Database::query($sql); while ($row = Database::fetch_assoc($res)) { $params = [ - 'c_id' => $targetCourseId, 'survey_id' => $new_survey_id, 'survey_question' => $row['survey_question'], 'survey_question_comment' => $row['survey_question_comment'], @@ -706,7 +712,6 @@ class SurveyManager $res = Database::query($sql); while ($row = Database::fetch_assoc($res)) { $params = [ - 'c_id' => $targetCourseId, 'question_id' => $question_id[$row['question_id']], 'survey_id' => $new_survey_id, 'option_text' => $row['option_text'], @@ -714,11 +719,6 @@ class SurveyManager 'value' => $row['value'], ]; $insertId = Database::insert($table_survey_options, $params); - if ($insertId) { - $sql = "UPDATE $table_survey_options SET question_option_id = $insertId - WHERE iid = $insertId"; - Database::query($sql); - } } return $new_survey_id; @@ -755,16 +755,16 @@ class SurveyManager $sql = 'DELETE FROM '.$table_survey_invitation.' WHERE - c_id = '.$courseId.' AND - survey_code = "'.Database::escape_string($datas['code']).'" '.$session_where.' '; + survey_id = "'.$surveyId.'" '.$session_where.' '; Database::query($sql); $sql = 'DELETE FROM '.$table_survey_answer.' - WHERE c_id = '.$courseId.' AND survey_id='.$surveyId; + WHERE + survey_id = "'.$surveyId.'" '.$session_where.' '; Database::query($sql); $sql = 'UPDATE '.$table_survey.' SET invited=0, answered=0 - WHERE c_id = '.$courseId.' AND iid ='.$surveyId; + WHERE iid ='.$surveyId; Database::query($sql); Event::addEvent( @@ -1027,7 +1027,7 @@ class SurveyManager $survey_data = self::get_survey($surveyId); // Storing a new question - if ('' == $form_content['question_id'] || !is_numeric($form_content['question_id'])) { + if (empty($form_content['question_id']) || !is_numeric($form_content['question_id'])) { // Finding the max sort order of the questions in the given survey $sql = "SELECT max(sort) AS max_sort FROM $tbl_survey_question @@ -1163,59 +1163,41 @@ class SurveyManager } /** - * This functions moves a question of a survey up or down. - * - * @param string $direction - * @param int $survey_question_id - * @param int $survey_id + * Moves a survey question within the ordered list. * - * @author Patrick Cool , Ghent University - * - * @version January 2007 + * @param string $direction The direction to move the question ('moveup' or 'movedown'). + * @param int $surveyQuestionId The ID of the survey question to move. + * @param int $surveyId The ID of the survey to which the question belongs. */ - public static function move_survey_question($direction, $survey_question_id, $survey_id) + public static function moveSurveyQuestion(string $direction, int $surveyQuestionId, int $surveyId): void { - // Table definition - $table_survey_question = Database::get_course_table(TABLE_SURVEY_QUESTION); - $course_id = api_get_course_int_id(); - - if ('moveup' === $direction) { - $sort = 'DESC'; - } - if ('movedown' === $direction) { - $sort = 'ASC'; - } - - $survey_id = (int) $survey_id; + $em = Database::getManager(); + $repo = $em->getRepository(CSurveyQuestion::class); + $sortDirection = $direction === 'moveup' ? 'DESC' : 'ASC'; + $questions = $repo->findBy(['survey' => $surveyId], ['sort' => $sortDirection]); - // Finding the two questions that needs to be swapped - $sql = "SELECT * FROM $table_survey_question - WHERE c_id = $course_id AND survey_id='".$survey_id."' - ORDER BY sort $sort"; - $result = Database::query($sql); $found = false; - while ($row = Database::fetch_assoc($result)) { + foreach ($questions as $question) { if ($found) { - $question_id_two = $row['question_id']; - $question_sort_two = $row['sort']; + $secondQuestion = $question; $found = false; + break; } - if ($row['question_id'] == $survey_question_id) { + if ($question->getIid() == $surveyQuestionId) { $found = true; - $question_id_one = $row['question_id']; - $question_sort_one = $row['sort']; + $firstQuestion = $question; } } - $sql = "UPDATE $table_survey_question - SET sort = '".Database::escape_string($question_sort_two)."' - WHERE c_id = $course_id AND question_id='".intval($question_id_one)."'"; - Database::query($sql); + if (isset($firstQuestion) && isset($secondQuestion)) { + $tempSort = $firstQuestion->getSort(); + $firstQuestion->setSort($secondQuestion->getSort()); + $secondQuestion->setSort($tempSort); - $sql = "UPDATE $table_survey_question - SET sort = '".Database::escape_string($question_sort_one)."' - WHERE c_id = $course_id AND question_id='".intval($question_id_two)."'"; - Database::query($sql); + $em->persist($firstQuestion); + $em->persist($secondQuestion); + $em->flush(); + } } /** diff --git a/public/main/survey/survey.php b/public/main/survey/survey.php index 5849356453..f485bb3917 100644 --- a/public/main/survey/survey.php +++ b/public/main/survey/survey.php @@ -123,7 +123,7 @@ if (!empty($action)) { break; case 'moveup': case 'movedown': - SurveyManager::move_survey_question( + SurveyManager::moveSurveyQuestion( $action, $my_question_id_survey, $my_survey_id_survey diff --git a/public/main/survey/surveyUtil.class.php b/public/main/survey/surveyUtil.class.php index 58d708fde4..b4bb06db3e 100644 --- a/public/main/survey/surveyUtil.class.php +++ b/public/main/survey/surveyUtil.class.php @@ -2425,13 +2425,22 @@ class SurveyUtil ? explode(';', $already_invited['additional_users']) : []; $my_alredy_invited = $already_invited['course_users'] ?? []; - if ((is_numeric($value) && !in_array($value, $my_alredy_invited)) || - (!is_numeric($value) && !in_array($value, $addit_users_array)) - ) { + + $userId = 0; + if (is_string($value) && filter_var($value, FILTER_VALIDATE_EMAIL)) { + $userInfo = api_get_user_info_from_email($value); + if ($userInfo && isset($userInfo['id'])) { + $userId = $userInfo['id']; + } + } elseif (is_numeric($value)) { + $userId = $value; + } + + if ($userId && !in_array($userId, $my_alredy_invited)) { $new_user = true; - if (!array_key_exists($value, $survey_invitations)) { + if (!array_key_exists($userId, $survey_invitations)) { self::saveInvitation( - api_get_user_entity($value), + api_get_user_entity($userId), $invitation_code, api_get_utc_datetime(time(), null, true), $survey, @@ -2820,7 +2829,9 @@ class SurveyUtil public static function display_survey_list() { $parameters = []; - $parameters['cidReq'] = api_get_course_id(); + $parameters['cid'] = api_get_course_int_id(); + $parameters['sid'] = api_get_session_id(); + $parameters['gid'] = api_get_group_id(); if (isset($_GET['do_search']) && $_GET['do_search']) { $message = get_lang('Display search results').'
'; $message .= ''.get_lang('Display all').''; diff --git a/public/main/survey/survey_question.php b/public/main/survey/survey_question.php index df92b167da..99042abaa4 100644 --- a/public/main/survey/survey_question.php +++ b/public/main/survey/survey_question.php @@ -3,6 +3,7 @@ /* For licensing terms, see /license.txt */ use Chamilo\CourseBundle\Entity\CSurvey; +use Chamilo\CourseBundle\Entity\CSurveyQuestion; use ChamiloSession as Session; /** @@ -445,7 +446,7 @@ class survey_question // Adding an answer if (isset($_POST['buttons']) && isset($_POST['buttons']['add_answer'])) { - if (isset($_REQUEST['type']) && 'multiplechoiceother' === $_REQUEST['type']) { + if (isset($_REQUEST['type']) && 'multiplechoiceother' === $_REQUEST['type'] && $counter > 2) { $counter--; } $counter++; @@ -689,22 +690,22 @@ class survey_question * * @return array The questions that have the given question as parent */ - public static function getDependency($question) + public static function getDependency(array $question): ?array { if ('false' === api_get_setting('survey.survey_question_dependency')) { return []; } - $table = Database::get_course_table(TABLE_SURVEY_QUESTION); $questionId = $question['question_id']; - $courseId = api_get_course_int_id(); - // Getting the information of the question - $sql = "SELECT * FROM $table - WHERE c_id = $courseId AND parent_id = $questionId "; - $result = Database::query($sql); - $row = Database::store_result($result, 'ASSOC'); + $em = Database::getManager(); + + $queryBuilder = $em->createQueryBuilder(); + $queryBuilder->select('q') + ->from(CSurveyQuestion::class, 'q') + ->where('q.parent = :parent') + ->setParameter('parent', $questionId); - return $row; + return $queryBuilder->getQuery()->getArrayResult(); } /**