Skip to content

Commit

Permalink
MDL-72834 Calendar: Move the calendar into the user menu
Browse files Browse the repository at this point in the history
  • Loading branch information
HuongNV13 committed Nov 30, 2021
1 parent 18b2af6 commit 7de559f
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 47 deletions.
1 change: 1 addition & 0 deletions admin/settings/appearance.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
new lang_string('customusermenuitems', 'admin'),
new lang_string('configcustomusermenuitems', 'admin'),
'grades,grades|/grade/report/mygrades.php|t/grades
calendar,core_calendar|/calendar/view.php?view=month|i/calendar
messages,message|/message/index.php|t/message
preferences,moodle|/user/preferences.php|t/preferences',
PARAM_RAW,
Expand Down
4 changes: 2 additions & 2 deletions admin/tool/uploaduser/tests/behat/upload_users.feature
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,12 @@ Feature: Upload users
# Boost check.
And I log in as "jonest"
And I am on "Maths" course homepage
And "Calendar" "link" should be visible
And "Private files" "link" should be visible
And I log out
# Classic check.
And I log in as "reznor"
And I am on "Maths" course homepage
And "Calendar" "link" should not be visible
And "Private files" "link" should not be visible

@javascript
Scenario: Upload users setting their user theme when allowuserthemes is false
Expand Down
18 changes: 3 additions & 15 deletions calendar/tests/behat/category_events.feature
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,7 @@ Feature: Course Category Events
@javascript
Scenario: Manager of a Category can see all child and parent events in their category
Given I log in as "managera"
And I turn editing mode on
# TODO MDL-57120 site "Tags" link not accessible without navigation block.
When I add the "Navigation" block if not present
And I click on "Site pages" "list_item" in the "Navigation" "block"
And I click on "Calendar" "link" in the "Navigation" "block"
When I follow "Calendar" in the user menu
Then I should see "FA event"
And I should see "DA1 event"
And I should see "DA2 event"
Expand All @@ -80,11 +76,7 @@ Feature: Course Category Events
And I should not see "DB2 event"
And I log out
Given I log in as "managerb"
And I turn editing mode on
# TODO MDL-57120 site "Tags" link not accessible without navigation block.
When I add the "Navigation" block if not present
And I click on "Site pages" "list_item" in the "Navigation" "block"
And I click on "Calendar" "link" in the "Navigation" "block"
And I follow "Calendar" in the user menu
Then I should see "FB event"
And I should see "DB1 event"
And I should see "DB2 event"
Expand All @@ -95,11 +87,7 @@ Feature: Course Category Events
@javascript
Scenario: Users enrolled in a course can see all child and parent events in their category
Given I log in as "student1"
And I turn editing mode on
# TODO MDL-57120 site "Tags" link not accessible without navigation block.
When I add the "Navigation" block if not present
And I click on "Site pages" "list_item" in the "Navigation" "block"
And I click on "Calendar" "link" in the "Navigation" "block"
When I follow "Calendar" in the user menu
Then I should see "FA event"
And I should see "DA1 event"
And I should see "DA2 event"
Expand Down
2 changes: 0 additions & 2 deletions course/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -4049,7 +4049,6 @@ function course_get_user_navigation_options($context, $course = null) {
$options = (object) [
'badges' => false,
'blogs' => false,
'calendar' => false,
'competencies' => false,
'grades' => false,
'notes' => false,
Expand All @@ -4072,7 +4071,6 @@ function course_get_user_navigation_options($context, $course = null) {
$options->badges = !empty($CFG->enablebadges) && has_capability('moodle/badges:viewbadges', $sitecontext);
$options->tags = !empty($CFG->usetags) && $isloggedin;
$options->search = !empty($CFG->enableglobalsearch) && has_capability('moodle/search:query', $sitecontext);
$options->calendar = $isloggedin;
} else {
// We are in a course, so make sure we use the proper capability (course:viewparticipants).
$options->participants = course_can_view_participants($context);
Expand Down
2 changes: 0 additions & 2 deletions course/tests/courselib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -3191,7 +3191,6 @@ public function test_course_get_user_navigation_options_for_frontpage() {
$this->assertTrue($navoptions->badges);
$this->assertTrue($navoptions->tags);
$this->assertFalse($navoptions->search);
$this->assertTrue($navoptions->calendar);
$this->assertTrue($navoptions->competencies);

// Enable global search now.
Expand All @@ -3216,7 +3215,6 @@ public function test_course_get_user_navigation_options_for_frontpage() {
$this->assertTrue($navoptions->badges);
$this->assertTrue($navoptions->tags);
$this->assertTrue($navoptions->search);
$this->assertTrue($navoptions->calendar);
}

/**
Expand Down
4 changes: 1 addition & 3 deletions course/tests/externallib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -2538,7 +2538,7 @@ public function test_get_user_navigation_options() {
foreach ($course['options'] as $option) {
$navoptions->{$option['name']} = $option['available'];
}
$this->assertCount(9, $course['options']);
$this->assertCount(8, $course['options']);
if ($course['id'] == SITEID) {
$this->assertTrue($navoptions->blogs);
$this->assertFalse($navoptions->notes);
Expand All @@ -2547,7 +2547,6 @@ public function test_get_user_navigation_options() {
$this->assertTrue($navoptions->tags);
$this->assertFalse($navoptions->grades);
$this->assertFalse($navoptions->search);
$this->assertTrue($navoptions->calendar);
$this->assertTrue($navoptions->competencies);
} else {
$this->assertTrue($navoptions->blogs);
Expand All @@ -2557,7 +2556,6 @@ public function test_get_user_navigation_options() {
$this->assertFalse($navoptions->tags);
$this->assertTrue($navoptions->grades);
$this->assertFalse($navoptions->search);
$this->assertFalse($navoptions->calendar);
$this->assertTrue($navoptions->competencies);
}
}
Expand Down
3 changes: 3 additions & 0 deletions course/upgrade.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ course formats don't have their own renderer.
* New course_get_enrolled_courses_for_logged_in_user_from_search which hooks in with external\get_enrolled_courses_by_timeline_classification
given COURSE_TIMELINE_SEARCH is set then get_enrolled_courses_by_timeline_classification will deviate to use a string search of enrolled courses.
* Class core_course\output\course_module_name is deprecated. Now core_courseformat\output\local\cm\cmname controls inline edit.
* Calendar menu entry is now moved to User menu items, so the following methods will not return the calendar item anymore:
- course_get_user_navigation_options
- core_course_externalcore_course_external::get_user_navigation_options

=== 3.11 ===
* A new callback xxx_coursemodule_definition_after_data that allows plugins to extend activity forms after the data is set.
Expand Down
18 changes: 18 additions & 0 deletions lib/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -3171,5 +3171,23 @@ function xmldb_main_upgrade($oldversion) {
upgrade_main_savepoint(true, 2021111700.01);
}

if ($oldversion < 2021112600.01) {

// Get current configuration data.
$currentcustomusermenuitems = str_replace(["\r\n", "\r"], "\n", $CFG->customusermenuitems);
$lines = explode("\n", $currentcustomusermenuitems);
$lines = array_map('trim', $lines);
$calendarcustomusermenu = 'calendar,core_calendar|/calendar/view.php?view=month|i/calendar';

if (!in_array($calendarcustomusermenu, $lines)) {
// Add Calendar item to the menu.
array_splice($lines, 1, 0, [$calendarcustomusermenu]);
set_config('customusermenuitems', implode("\n", $lines));
}

// Main savepoint reached.
upgrade_main_savepoint(true, 2021112600.01);
}

return true;
}
14 changes: 0 additions & 14 deletions lib/navigationlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -2927,20 +2927,6 @@ public function add_front_page_course_essentials(navigation_node $coursenode, st
self::TYPE_SETTING, null, 'search');
}

if ($navoptions->calendar) {
$courseid = $COURSE->id;
$params = array('view' => 'month');
if ($courseid != $SITE->id) {
$params['course'] = $courseid;
}

// Calendar
$calendarurl = new moodle_url('/calendar/view.php', $params);
$node = $coursenode->add(get_string('calendar', 'calendar'), $calendarurl,
self::TYPE_CUSTOM, null, 'calendar', new pix_icon('i/calendar', ''));
$node->showinflatnavigation = true;
}

if (isloggedin()) {
$usercontext = context_user::instance($USER->id);
if (has_capability('moodle/user:manageownfiles', $usercontext)) {
Expand Down
10 changes: 2 additions & 8 deletions mod/chat/tests/behat/chat_calendar_events.feature
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,13 @@ Feature: Chat calendar entries
| activity | name | intro | course | idnumber | schedule |
| chat | Test chat name | Test chat description | C1 | chat1 | 0 |
And I log in as "teacher1"
And I am on "Course 1" course homepage with editing mode on
# TODO MDL-57120 site "Calendar" link not accessible without navigation block.
And I add the "Navigation" block if not present
Given I click on "Calendar" "link" in the "Navigation" "block"
When I follow "Calendar" in the user menu
Then I should not see "Test chat name"

Scenario: Create a chat activity and publish the start date to the calendar
Given the following "activities" exist:
| activity | name | intro | course | idnumber | schedule |
| chat | Test chat name | Test chat description | C1 | chat1 | 1 |
And I log in as "teacher1"
And I am on "Course 1" course homepage with editing mode on
# TODO MDL-57120 site "Calendar" link not accessible without navigation block.
And I add the "Navigation" block if not present
Given I click on "Calendar" "link" in the "Navigation" "block"
When I follow "Calendar" in the user menu
Then I should see "Test chat name"
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

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

$version = 2021112600.00; // YYYYMMDD = weekly release date of this DEV branch.
$version = 2021112600.01; // YYYYMMDD = weekly release date of this DEV branch.
// RR = release increments - 00 in DEV branches.
// .XX = incremental changes.
$release = '4.0dev+ (Build: 20211126)'; // Human-friendly version name
Expand Down

0 comments on commit 7de559f

Please sign in to comment.