]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-18297: Changed date conditions so that the text and behaviour is more natural.
authorsam_marshall <sam_marshall>
Fri, 17 Apr 2009 16:06:29 +0000 (16:06 +0000)
committersam_marshall <sam_marshall>
Fri, 17 Apr 2009 16:06:29 +0000 (16:06 +0000)
course/modedit.php
lang/en_utf8/condition.php
lang/en_utf8/help/condition/conditiondates.html
lib/conditionlib.php
lib/db/upgrade.php
version.php

index e12e7d639a0192c373453e1c7314c216ee37011c..304d66bd6dcf477160083a84c2809b8ae267c167 100644 (file)
             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);
             }
             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;
             }
 
index f10decf23e8a63615edf0a8c54b77625e7178f8c..f1511e3e3fff086b0715639c8d850e0f8fcf7122 100644 (file)
@@ -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 <strong>$a</
 $string['requires_completion_1']='Not available until the activity <strong>$a</strong> is marked complete.';
 $string['requires_completion_2']='Not available until the activity <strong>$a</strong> is complete and passed.';
 $string['requires_completion_3']='Not available unless the activity <strong>$a</strong> 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 <strong>$a</strong>.';
 $string['requires_grade_min']='Not available until you achieve a required score in <strong>$a</strong>.';
 $string['requires_grade_max']='Not available unless you get an appropriate score in <strong>$a</strong>.';
index d26bf49fce5283bcf5a639fcad3cc346d1ce4160..ba23b77c065d0023e35cbd39a721873efa3591ce 100644 (file)
@@ -1,9 +1,9 @@
 <h1>Available dates</h1>
 
 <p>
-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.
 </p>
 
@@ -16,7 +16,7 @@ any time (as long as the student can access the course).
 <li> 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.</li>
-<li> The activity completely vanishes on the 'available to' date, even if 
+<li> The activity completely vanishes at midnight on the 'available to end' date, even if 
   you've chosen to show information.</li>
 <li> Setting 'Visible' to 'Hide' overrides these settings. If you set 'Visible'
   to 'Hide', the activity is never available regardless of date.</li>
index 240334e1a00f3b91ec7d1bbcc6e644cd938da3cf..b7ebb1f660d47570d8ea4a304c541f20b9687558 100644 (file)
@@ -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
index a9bd56ddebbcc1128d571be1210e834b3fa4bfb0..e6d753e3201aef0aa2e5103e69b2d88daadf5dbf 100644 (file)
@@ -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;
 }
 
index cbd7b4688769a03be0bc6d36d4cd0b4a22c7e470..c4b5110b2f841378582bcaaf46c0b13aa802fef4 100644 (file)
@@ -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