From: sam_marshall Date: Fri, 17 Apr 2009 16:06:29 +0000 (+0000) Subject: MDL-18297: Changed date conditions so that the text and behaviour is more natural. X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=e7c6bf0eab7afc1253a7219da9a5faf6688c8bc0;p=moodle.git MDL-18297: Changed date conditions so that the text and behaviour is more natural. --- diff --git a/course/modedit.php b/course/modedit.php index e12e7d639a..304d66bd6d 100644 --- a/course/modedit.php +++ b/course/modedit.php @@ -294,6 +294,12 @@ if(!empty($CFG->enableavailability)) { $cm->availablefrom = $fromform->availablefrom; $cm->availableuntil = $fromform->availableuntil; + // The form time is midnight, but because we want it to be + // inclusive, set it to 23:59:59 on that day. + if ($cm->availableuntil) { + $cm->availableuntil = strtotime('23:59:59', + $cm->availableuntil); + } $cm->showavailability = $fromform->showavailability; condition_info::update_cm_from_form($cm,$fromform,true); } @@ -348,6 +354,12 @@ if(!empty($CFG->enableavailability)) { $newcm->availablefrom = $fromform->availablefrom; $newcm->availableuntil = $fromform->availableuntil; + // The form time is midnight, but because we want it to be + // inclusive, set it to 23:59:59 on that day. + if ($newcm->availableuntil) { + $newcm->availableuntil = strtotime('23:59:59', + $newcm->availableuntil); + } $newcm->showavailability = $fromform->showavailability; } diff --git a/lang/en_utf8/condition.php b/lang/en_utf8/condition.php index f10decf23e..f1511e3e3f 100644 --- a/lang/en_utf8/condition.php +++ b/lang/en_utf8/condition.php @@ -3,7 +3,7 @@ $string['addgrades']='Add {no} grade conditions to form'; $string['addcompletions']='Add {no} activity conditions to form'; $string['availabilityconditions']='Restrict availability'; $string['availablefrom']='Only available from'; -$string['availableuntil']='Only available until'; +$string['availableuntil']='Only available until end'; $string['badavailabledates']='Invalid dates. If you set both dates, the \'available from\' date should be before the \'until\' date.'; $string['completion_complete']=' must be marked complete'; $string['completion_incomplete']=' must not be marked complete'; @@ -23,8 +23,9 @@ $string['requires_completion_0']='Not available unless the activity $a$a is marked complete.'; $string['requires_completion_2']='Not available until the activity $a is complete and passed.'; $string['requires_completion_3']='Not available unless the activity $a is complete and failed.'; -$string['requires_date']='Not available until $a.'; -$string['requires_date_before']='Not available from $a.'; +$string['requires_date']='Available from $a.'; +$string['requires_date_before']='Available until $a.'; +$string['requires_date_both']='Available from $a->from to $a->until.'; $string['requires_grade_any']='Not available until you have a grade in $a.'; $string['requires_grade_min']='Not available until you achieve a required score in $a.'; $string['requires_grade_max']='Not available unless you get an appropriate score in $a.'; diff --git a/lang/en_utf8/help/condition/conditiondates.html b/lang/en_utf8/help/condition/conditiondates.html index d26bf49fce..ba23b77c06 100644 --- a/lang/en_utf8/help/condition/conditiondates.html +++ b/lang/en_utf8/help/condition/conditiondates.html @@ -1,9 +1,9 @@

Available dates

-Using the 'Only available from' and 'Only available until' dates, you can make +Using the 'Only available from' and 'Only available until end' dates, you can make an activity appear or disappear. The activity is only shown to students from the -'available from' date, and it disappears on the 'available until' date. Students +'available from' date, and it disappears after the 'available until end' date. Students cannot access it outside those times, even if they guess the URL.

@@ -16,7 +16,7 @@ any time (as long as the student can access the course).
  • If you choose to show information about an activity that is unavailable, then before the 'available from' date, students will see the activity greyed-out, with informational text about the date that it appears.
  • -
  • The activity completely vanishes on the 'available to' date, even if +
  • The activity completely vanishes at midnight on the 'available to end' date, even if you've chosen to show information.
  • Setting 'Visible' to 'Hide' overrides these settings. If you set 'Visible' to 'Hide', the activity is never available regardless of date.
  • diff --git a/lib/conditionlib.php b/lib/conditionlib.php index 240334e1a0..b7ebb1f660 100644 --- a/lib/conditionlib.php +++ b/lib/conditionlib.php @@ -269,14 +269,17 @@ WHERE } // Dates - if ($this->cm->availablefrom) { - $information .= get_string('requires_date', 'condition', userdate( - $this->cm->availablefrom, get_string('strftimedate', 'langconfig'))); - } - - if ($this->cm->availableuntil) { - $information .= get_string('requires_date_before', 'condition', userdate( - $this->cm->availableuntil, get_string('strftimedate', 'langconfig'))); + if ($this->cm->availablefrom && $this->cm->availableuntil) { + $information .= get_string('requires_date_both', 'condition', + (object)array( + 'from' => self::show_time($this->cm->availablefrom, false), + 'until' => self::show_time($this->cm->availableuntil, true))); + } else if ($this->cm->availablefrom) { + $information .= get_string('requires_date', 'condition', + self::show_time($this->cm->availablefrom, false)); + } else if ($this->cm->availableuntil) { + $information .= get_string('requires_date_before', 'condition', + self::show_time($this->cm->availableuntil, true)); } $information = trim($information); @@ -385,8 +388,9 @@ WHERE if ($this->cm->availablefrom) { if (time() < $this->cm->availablefrom) { $available = false; - $information .= get_string('requires_date', 'condition', userdate( - $this->cm->availablefrom, get_string('strftimedate','langconfig'))); + + $information .= get_string('requires_date', 'condition', + self::show_time($this->cm->availablefrom, false)); } } @@ -409,6 +413,32 @@ WHERE return $available; } + /** + * Shows a time either as a date (if it falls exactly on the day) or + * a full date and time, according to user's timezone. + * @param int $time Time + * @param bool $until True if this date should be treated as the second of + * an inclusive pair - if so the time will be shown unless date is 23:59:59. + * Without this the date shows for 0:00:00. + * @return string Date + */ + private function show_time($time, $until) { + // Break down the time into fields + $userdate = usergetdate($time); + + // Handle the 'inclusive' second date + if($until) { + $dateonly = $userdate['hours']==23 && $userdate['minutes']==59 && + $userdate['seconds']==59; + } else { + $dateonly = $userdate['hours']==0 && $userdate['minutes']==0 && + $userdate['seconds']==0; + } + + return userdate($time, get_string( + $dateonly ? 'strftimedate' : 'strftimedatetime', 'langconfig')); + } + /** * @return bool True if information about availability should be shown to * normal users diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index a9bd56ddeb..e6d753e320 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -1640,6 +1640,16 @@ WHERE gradeitemid IS NOT NULL AND grademax IS NOT NULL"); upgrade_main_savepoint($result, 2009040600); } + if ($result && $oldversion < 2009041700) { + /// To ensure the UI remains consistent with no behaviour change, any + /// 'until' date in an activity condition should have 1 second subtracted + /// (to go from 0:00 on the following day to 23:59 on the previous one). + $DB->execute('UPDATE {course_modules} SET availableuntil = availableuntil - 1 WHERE availableuntil <> 0'); + + /// Main savepoint reached + upgrade_main_savepoint($result, 2009041700); + } + return $result; } diff --git a/version.php b/version.php index cbd7b46887..c4b5110b2f 100644 --- a/version.php +++ b/version.php @@ -6,7 +6,7 @@ // This is compared against the values stored in the database to determine // whether upgrades should be performed (see lib/db/*.php) - $version = 2009040601; // YYYYMMDD = date of the last version bump + $version = 2009041700; // YYYYMMDD = date of the last version bump // XX = daily increments $release = '2.0 dev (Build: 20090417)'; // Human-friendly version name