Jelajahi Sumber

Merge branch '1.11.x' of github.com:chamilo/chamilo-lms into 1.11.x

Julio 6 tahun lalu
induk
melakukan
62e5c00197

+ 2 - 2
main/course_info/about.php

@@ -21,7 +21,7 @@ $courseId = isset($_GET['course_id']) ? intval($_GET['course_id']) : 0;
 $token = Security::get_existing_token();
 $em = Database::getManager();
 //userID
-$user_id = api_get_user_id();
+$userId = api_get_user_id();
 
 /** @var Course $course */
 $course = $em->find('ChamiloCoreBundle:Course', $courseId);
@@ -124,7 +124,7 @@ $topics = [
     'custom' => array_reverse($courseCustom),
 ];
 
-$subscriptionUser = CourseManager::is_user_subscribed_in_course($user_id, $course->getCode());
+$subscriptionUser = CourseManager::is_user_subscribed_in_course($userId, $course->getCode());
 
 $plugin = BuyCoursesPlugin::create();
 $checker = $plugin->isEnabled();

+ 4 - 0
main/install/configuration.dist.php

@@ -494,6 +494,10 @@ ALTER TABLE c_survey_question ADD is_required TINYINT(1) DEFAULT 0 NOT NULL;
 // Hide survey edition tools for all or some surveys.
 //Set an asterisk to hide for all, otherwise set an array with the survey codes in which the options will be blocked
 //$_configuration['hide_survey_edition'] = ['codes' => []];
+// Allows to set the date and time of availability for surveys. Requires DB changes:
+// ALTER TABLE c_survey CHANGE avail_from avail_from DATETIME DEFAULT NULL, CHANGE avail_till avail_till DATETIME DEFAULT NULL;
+// Requires change the Doctrine type from date to datime in CSurvey::$availFrom and CSurvey::$availTill
+//$_configuration['allow_survey_availability_datetime'] = false;
 // ------
 
 // Allow career diagram, requires a DB change:

+ 27 - 6
main/survey/create_new_survey.php

@@ -18,6 +18,8 @@ require_once __DIR__.'/../inc/global.inc.php';
 
 $this_section = SECTION_COURSES;
 
+$allowSurveyAvailabilityDatetime = api_get_configuration_value('allow_survey_availability_datetime');
+
 // Database table definitions
 $table_survey = Database::get_course_table(TABLE_SURVEY);
 $table_user = Database::get_main_table(TABLE_MAIN_USER);
@@ -72,6 +74,13 @@ if ($_GET['action'] == 'edit' && isset($survey_id) && is_numeric($survey_id)) {
     $defaults['survey_id'] = $survey_id;
     $defaults['anonymous'] = $survey_data['anonymous'];
 
+    if ($allowSurveyAvailabilityDatetime) {
+        $defaults['avail_from'] = api_get_local_time($defaults['avail_from'], null, 'UTC');
+        $defaults['avail_till'] = api_get_local_time($defaults['avail_till'], null, 'UTC');
+        $defaults['start_date'] = $defaults['avail_from'];
+        $defaults['end_date'] = $defaults['avail_till'];
+    }
+
     $link_info = GradebookUtils::isResourceInCourseGradebook(
         $course_id,
         $gradebook_link_type,
@@ -93,9 +102,15 @@ if ($_GET['action'] == 'edit' && isset($survey_id) && is_numeric($survey_id)) {
     }
 } else {
     $defaults['survey_language'] = $_course['language'];
-    $defaults['start_date'] = date('Y-m-d', api_strtotime(api_get_local_time()));
+    $defaults['start_date'] = date(
+        $allowSurveyAvailabilityDatetime ? 'Y-m-d 00:00:00' : 'Y-m-d',
+        api_strtotime(api_get_local_time())
+    );
     $startdateandxdays = time() + 864000; // today + 10 days
-    $defaults['end_date'] = date('Y-m-d', $startdateandxdays);
+    $defaults['end_date'] = date(
+        $allowSurveyAvailabilityDatetime ? 'Y-m-d 23:59:59' : 'Y-m-d',
+        $startdateandxdays
+    );
     //$defaults['survey_share']['survey_share'] = 0;
     //$form_share_value = 1;
     $defaults['anonymous'] = 0;
@@ -149,8 +164,14 @@ $form->addElement(
 
 // Pass the language of the survey in the form
 $form->addElement('hidden', 'survey_language');
-$form->addElement('date_picker', 'start_date', get_lang('StartDate'));
-$form->addElement('date_picker', 'end_date', get_lang('EndDate'));
+
+if ($allowSurveyAvailabilityDatetime) {
+    $form->addDateTimePicker('start_date', get_lang('StartDate'));
+    $form->addDateTimePicker('end_date', get_lang('EndDate'));
+} else {
+    $form->addElement('date_picker', 'start_date', get_lang('StartDate'));
+    $form->addElement('date_picker', 'end_date', get_lang('EndDate'));
+}
 
 $form->addElement('checkbox', 'anonymous', null, get_lang('Anonymous'));
 $visibleResults = [
@@ -298,8 +319,8 @@ if ($_GET['action'] == 'add') {
     $form->addRule('survey_code', '', 'maxlength', 20);
 }
 $form->addRule('survey_title', get_lang('ThisFieldIsRequired'), 'required');
-$form->addRule('start_date', get_lang('InvalidDate'), 'date');
-$form->addRule('end_date', get_lang('InvalidDate'), 'date');
+$form->addRule('start_date', get_lang('InvalidDate'), $allowSurveyAvailabilityDatetime ? 'datetime': 'date');
+$form->addRule('end_date', get_lang('InvalidDate'), $allowSurveyAvailabilityDatetime ? 'datetime': 'date');
 $form->addRule(
     ['start_date', 'end_date'],
     get_lang('StartDateShouldBeBeforeEndDate'),

+ 4 - 1
main/survey/fillsurvey.php

@@ -1364,11 +1364,14 @@ Display::display_footer();
  */
 function check_time_availability($surveyData)
 {
+    $allowSurveyAvailabilityDatetime = api_get_configuration_value('allow_survey_availability_datetime');
     $utcZone = new DateTimeZone('UTC');
     $startDate = new DateTime($surveyData['start_date'], $utcZone);
     $endDate = new DateTime($surveyData['end_date'], $utcZone);
     $currentDate = new DateTime('now', $utcZone);
-    $currentDate->modify('today');
+    if (!$allowSurveyAvailabilityDatetime) {
+        $currentDate->modify('today');
+    }
     if ($currentDate < $startDate) {
         api_not_allowed(
             true,

+ 13 - 4
main/survey/survey.lib.php

@@ -218,6 +218,7 @@ class SurveyManager
      */
     public static function store_survey($values)
     {
+        $allowSurveyAvailabilityDatetime = api_get_configuration_value('allow_survey_availability_datetime');
         $_user = api_get_user_info();
         $course_id = api_get_course_int_id();
         $session_id = api_get_session_id();
@@ -338,8 +339,12 @@ class SurveyManager
                 'subtitle' => $values['survey_subtitle'],
                 'author' => $_user['user_id'],
                 'lang' => $values['survey_language'],
-                'avail_from' => $values['start_date'],
-                'avail_till' => $values['end_date'],
+                'avail_from' => $allowSurveyAvailabilityDatetime
+                    ? api_get_utc_datetime($values['start_date'])
+                    : $values['start_date'],
+                'avail_till' => $allowSurveyAvailabilityDatetime
+                    ? api_get_utc_datetime($values['end_date'])
+                    : $values['end_date'],
                 'is_shared' => $shared_survey_id,
                 'template' => 'template',
                 'intro' => $values['survey_introduction'],
@@ -444,8 +449,12 @@ class SurveyManager
                 'subtitle' => $values['survey_subtitle'],
                 'author' => $_user['user_id'],
                 'lang' => $values['survey_language'],
-                'avail_from' => $values['start_date'],
-                'avail_till' => $values['end_date'],
+                'avail_from' => $allowSurveyAvailabilityDatetime
+                    ? api_get_utc_datetime($values['start_date'])
+                    : $values['start_date'],
+                'avail_till' => $allowSurveyAvailabilityDatetime
+                    ? api_get_utc_datetime($values['end_date'])
+                    : $values['end_date'],
                 'is_shared' => $shared_survey_id,
                 'template' => 'template',
                 'intro' => $values['survey_introduction'],

+ 24 - 4
main/survey/surveyUtil.class.php

@@ -3075,6 +3075,8 @@ class SurveyUtil
         $mandatoryAllowed = api_get_configuration_value('allow_mandatory_survey');
         $_user = api_get_user_info();
 
+        $allowSurveyAvailabilityDatetime = api_get_configuration_value('allow_survey_availability_datetime');
+
         // Searching
         $search_restriction = self::survey_search_restriction();
         if ($search_restriction) {
@@ -3145,8 +3147,14 @@ class SurveyUtil
             $array[2] = $survey[2].$session_img;
             $array[3] = $survey[3];
             $array[4] = $survey[4];
-            $array[5] = $survey[5];
-            $array[6] = $survey[6];
+            $array[5] = api_convert_and_format_date(
+                $survey[5],
+                $allowSurveyAvailabilityDatetime ? DATE_TIME_FORMAT_LONG : DATE_FORMAT_LONG
+            );
+            $array[6] = api_convert_and_format_date(
+                $survey[6],
+                $allowSurveyAvailabilityDatetime ? DATE_TIME_FORMAT_LONG : DATE_FORMAT_LONG
+            );
             $array[7] =
                 Display::url(
                     $survey['answered'],
@@ -3196,6 +3204,7 @@ class SurveyUtil
     public static function get_survey_data_for_coach($from, $number_of_items, $column, $direction)
     {
         $mandatoryAllowed = api_get_configuration_value('allow_mandatory_survey');
+        $allowSurveyAvailabilityDatetime = api_get_configuration_value('allow_survey_availability_datetime');
         $survey_tree = new SurveyTree();
         //$last_version_surveys = $survey_tree->get_last_children_from_branch($survey_tree->surveylist);
         $last_version_surveys = $survey_tree->surveylist;
@@ -3251,6 +3260,15 @@ class SurveyUtil
         $res = Database::query($sql);
         $surveys = [];
         while ($survey = Database::fetch_array($res)) {
+            $survey['col5'] = api_convert_and_format_date(
+                $survey['col5'],
+                $allowSurveyAvailabilityDatetime ? DATE_TIME_FORMAT_LONG : DATE_FORMAT_LONG
+            );
+            $survey['col6'] = api_convert_and_format_date(
+                $survey['col6'],
+                $allowSurveyAvailabilityDatetime ? DATE_TIME_FORMAT_LONG : DATE_FORMAT_LONG
+            );
+
             if ($mandatoryAllowed) {
                 $survey['col10'] = $survey['col9'];
                 $efvMandatory = $efv->get_values_by_handler_and_field_variable(
@@ -3281,6 +3299,7 @@ class SurveyUtil
         $user_id = intval($user_id);
         $sessionId = api_get_session_id();
         $mandatoryAllowed = api_get_configuration_value('allow_mandatory_survey');
+        $allowSurveyAvailabilityDatetime = api_get_configuration_value('allow_survey_availability_datetime');
 
         // Database table definitions
         $table_survey_question = Database::get_course_table(TABLE_SURVEY_QUESTION);
@@ -3311,6 +3330,7 @@ class SurveyUtil
 
         /** @var \DateTime $now */
         $now = api_get_utc_datetime(null, false, true);
+        $filterDate = $allowSurveyAvailabilityDatetime ? $now->format('Y-m-d H:i') : $now->format('Y-m-d');
 
         $sql = "SELECT *
                 FROM $table_survey survey 
@@ -3323,8 +3343,8 @@ class SurveyUtil
                 )
 				WHERE
                     survey_invitation.user = $user_id AND                    
-                    survey.avail_from <= '".$now->format('Y-m-d')."' AND
-                    survey.avail_till >= '".$now->format('Y-m-d')."' AND
+                    survey.avail_from <= '$filterDate' AND
+                    survey.avail_till >= '$filterDate' AND
                     survey.c_id = $course_id AND
                     survey.session_id = $sessionId AND
                     survey_invitation.c_id = $course_id