Skip to content
This repository has been archived by the owner. It is now read-only.

Commit 4b2326f

Browse files
committed
Merge branch 'MDL-52383'
2 parents 6f85e72 + d3220ca commit 4b2326f

4 files changed

Lines changed: 98 additions & 5 deletions

File tree

calendar/preferences_form.php

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,23 @@ function definition() {
7070
$mform->addElement('select', 'maxevents', get_string('pref_maxevents', 'calendar'), $options);
7171
$mform->addHelpButton('maxevents', 'pref_maxevents', 'calendar');
7272

73-
$options = array();
74-
for ($i=1; $i<=99; $i++) {
75-
$options[$i] = $i;
76-
}
73+
$options = array(365 => new lang_string('numyear', '', 1),
74+
270 => get_string('nummonths', '', 9),
75+
180 => get_string('nummonths', '', 6),
76+
150 => get_string('nummonths', '', 5),
77+
120 => get_string('nummonths', '', 4),
78+
90 => get_string('nummonths', '', 3),
79+
60 => get_string('nummonths', '', 2),
80+
30 => get_string('nummonth', '', 1),
81+
21 => get_string('numweeks', '', 3),
82+
14 => get_string('numweeks', '', 2),
83+
7 => get_string('numweek', '', 1),
84+
6 => get_string('numdays', '', 6),
85+
5 => get_string('numdays', '', 5),
86+
4 => get_string('numdays', '', 4),
87+
3 => get_string('numdays', '', 3),
88+
2 => get_string('numdays', '', 2),
89+
1 => get_string('numday', '', 1));
7790
$mform->addElement('select', 'lookahead', get_string('pref_lookahead', 'calendar'), $options);
7891
$mform->addHelpButton('lookahead', 'pref_lookahead', 'calendar');
7992

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
@core @core_calendar
2+
Feature: Limit displayed upcoming events
3+
In order to filter what is displayed on the calendar
4+
As a user
5+
I need to interact with the calendar
6+
7+
Background:
8+
Given the following "users" exist:
9+
| username | firstname | lastname | email |
10+
| teacher1 | teacher | 1 | teacher1@example.com |
11+
And the following "courses" exist:
12+
| fullname | shortname | format |
13+
| Course 1 | C1 | topics |
14+
And the following "course enrolments" exist:
15+
| user | course | role |
16+
| teacher1 | C1 | editingteacher |
17+
And I log in as "teacher1"
18+
19+
Scenario: I view calendar details for a future event
20+
Given I follow "C1"
21+
And I turn editing mode on
22+
And I add the "Calendar" block
23+
And I follow "This month"
24+
And I click on "a.next" "css_element"
25+
And I click on "a.next" "css_element"
26+
And I create a calendar event:
27+
| Type of event | course |
28+
| Event title | Two months away event |
29+
When I follow "C1"
30+
Then I should not see "Two months away event"
31+
And I follow "Go to calendar"
32+
And I click on "Preferences" "button"
33+
And I set the following fields to these values:
34+
| Upcoming events look-ahead | 3 months |
35+
And I press "Save changes"
36+
And I wait to be redirected
37+
And I follow "C1"
38+
And I should see "Two months away event"

lib/db/upgrade.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4807,5 +4807,47 @@ function xmldb_main_upgrade($oldversion) {
48074807
upgrade_main_savepoint(true, 2016011301.00);
48084808
}
48094809

4810+
if ($oldversion < 2016011901.00) {
4811+
4812+
// Convert calendar_lookahead to nearest new value.
4813+
$transaction = $DB->start_delegated_transaction();
4814+
4815+
// Count all users who curretly have that preference set (for progress bar).
4816+
$total = $DB->count_records_select('user_preferences', 'name = \'calendar_lookahead\' AND value > 0');
4817+
$pbar = new progress_bar('upgradecalendarlookahead', 500, true);
4818+
4819+
// Get all these users, one at a time.
4820+
$rs = $DB->get_recordset_select('user_preferences', 'name = \'calendar_lookahead\' AND value > 0');
4821+
$i = 0;
4822+
foreach ($rs as $userpref) {
4823+
4824+
// Calculate and set new lookahead value.
4825+
if ($userpref->value > 90) {
4826+
$newvalue = 120;
4827+
} else if ($userpref->value > 60 and $userpref->value < 90) {
4828+
$newvalue = 90;
4829+
} else if ($userpref->value > 30 and $userpref->value < 60) {
4830+
$newvalue = 60;
4831+
} else if ($userpref->value > 21 and $userpref->value < 30) {
4832+
$newvalue = 30;
4833+
} else if ($userpref->value > 14 and $userpref->value < 21) {
4834+
$newvalue = 21;
4835+
} else if ($userpref->value > 7 and $userpref->value < 14) {
4836+
$newvalue = 14;
4837+
} else {
4838+
$newvalue = $userpref->value;
4839+
}
4840+
4841+
$DB->set_field('user_preferences', 'value', $newvalue, array('id' => $userpref->id));
4842+
4843+
// Update progress.
4844+
$i++;
4845+
$pbar->update($i, $total, "Upgrading user preference settings - $i/$total.");
4846+
}
4847+
$rs->close();
4848+
$transaction->allow_commit();
4849+
4850+
upgrade_main_savepoint(true, 2016011901.00);
4851+
}
48104852
return true;
48114853
}

version.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
defined('MOODLE_INTERNAL') || die();
3131

32-
$version = 2016011900.00; // YYYYMMDD = weekly release date of this DEV branch.
32+
$version = 2016011901.00; // YYYYMMDD = weekly release date of this DEV branch.
3333
// RR = release increments - 00 in DEV branches.
3434
// .XX = incremental changes.
3535

0 commit comments

Comments
 (0)