Skip to content
Permalink
Browse files

MDL-52383 Calendar: Allow users to set lookahead to 1 year

  • Loading branch information...
sbourget committed Jan 15, 2016
1 parent e8d5100 commit a7213391939632bcf6622994e3d3101c1e44aa32
Showing with 99 additions and 6 deletions.
  1. +17 −4 calendar/preferences_form.php
  2. +38 −0 calendar/tests/behat/calendar_lookahead.feature
  3. +42 −0 lib/db/upgrade.php
  4. +2 −2 version.php
@@ -70,10 +70,23 @@ function definition() {
$mform->addElement('select', 'maxevents', get_string('pref_maxevents', 'calendar'), $options);
$mform->addHelpButton('maxevents', 'pref_maxevents', 'calendar');
$options = array();
for ($i=1; $i<=99; $i++) {
$options[$i] = $i;
}
$options = array(365 => new lang_string('numyear', '', 1),
270 => get_string('nummonths', '', 9),
180 => get_string('nummonths', '', 6),
150 => get_string('nummonths', '', 5),
120 => get_string('nummonths', '', 4),
90 => get_string('nummonths', '', 3),
60 => get_string('nummonths', '', 2),
30 => get_string('nummonth', '', 1),
21 => get_string('numweeks', '', 3),
14 => get_string('numweeks', '', 2),
7 => get_string('numweek', '', 1),
6 => get_string('numdays', '', 6),
5 => get_string('numdays', '', 5),
4 => get_string('numdays', '', 4),
3 => get_string('numdays', '', 3),
2 => get_string('numdays', '', 2),
1 => get_string('numday', '', 1));
$mform->addElement('select', 'lookahead', get_string('pref_lookahead', 'calendar'), $options);
$mform->addHelpButton('lookahead', 'pref_lookahead', 'calendar');
@@ -0,0 +1,38 @@
@core @core_calendar
Feature: Limit displayed upcoming events
In order to filter what is displayed on the calendar
As a user
I need to interact with the calendar

Background:
Given the following "users" exist:
| username | firstname | lastname | email |
| teacher1 | teacher | 1 | teacher1@example.com |
And the following "courses" exist:
| fullname | shortname | format |
| Course 1 | C1 | topics |
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | C1 | editingteacher |
And I log in as "teacher1"

Scenario: I view calendar details for a future event
Given I follow "C1"
And I turn editing mode on
And I add the "Calendar" block
And I follow "This month"
And I click on "a.next" "css_element"
And I click on "a.next" "css_element"
And I create a calendar event:
| Type of event | course |
| Event title | Two months away event |
When I follow "C1"
Then I should not see "Two months away event"
And I follow "Go to calendar"
And I click on "Preferences" "button"
And I set the following fields to these values:
| Upcoming events look-ahead | 3 months |
And I press "Save changes"
And I wait to be redirected
And I follow "C1"
And I should see "Two months away event"
@@ -4807,5 +4807,47 @@ function xmldb_main_upgrade($oldversion) {
upgrade_main_savepoint(true, 2016011301.00);
}
if ($oldversion < 2016011500.00) {
// Convert calendar_lookahead to nearest new value.
$transaction = $DB->start_delegated_transaction();
// Count all users who curretly have that preference set (for progress bar).
$total = $DB->count_records_select('user_preferences', 'name = \'calendar_lookahead\' AND value > 0');
$pbar = new progress_bar('upgradecalendarlookahead', 500, true);
// Get all these users, one at a time.
$rs = $DB->get_recordset_select('user_preferences', 'name = \'calendar_lookahead\' AND value > 0');
$i = 0;
foreach ($rs as $userpref) {
// Calculate and set new lookahead value.
if ($userpref->value > 90) {
$newvalue = 120;
} else if ($userpref->value > 60 and $userpref->value < 90) {
$newvalue = 90;
} else if ($userpref->value > 30 and $userpref->value < 60) {
$newvalue = 60;
} else if ($userpref->value > 21 and $userpref->value < 30) {
$newvalue = 30;
} else if ($userpref->value > 14 and $userpref->value < 21) {
$newvalue = 21;
} else if ($userpref->value > 7 and $userpref->value < 14) {
$newvalue = 14;
} else {
$newvalue = $userpref->value;
}
$DB->set_field('user_preferences', 'value', $newvalue, array('id' => $userpref->id));
// Update progress.
$i++;
$pbar->update($i, $total, "Upgrading user preference settings - $i/$total.");
}
$rs->close();
$transaction->allow_commit();
upgrade_main_savepoint(true, 2016011500.00);
}
return true;
}
@@ -29,11 +29,11 @@
defined('MOODLE_INTERNAL') || die();
$version = 2016011400.00; // YYYYMMDD = weekly release date of this DEV branch.
$version = 2016011500.00; // YYYYMMDD = weekly release date of this DEV branch.
// RR = release increments - 00 in DEV branches.
// .XX = incremental changes.
$release = '3.1dev (Build: 20160114)'; // Human-friendly version name
$release = '3.1dev (Build: 20160115)'; // Human-friendly version name
$branch = '31'; // This version's branch.
$maturity = MATURITY_ALPHA; // This version's maturity level.

0 comments on commit a721339

Please sign in to comment.
You can’t perform that action at this time.