Example #1
0
 /**
  * Test the dashboard reset event.
  *
  * We will reset the user dashboard to
  * trigger the event and ensure data is returned as expected.
  */
 public function test_dashboard_reset()
 {
     global $CFG;
     require_once $CFG->dirroot . '/my/lib.php';
     $user = $this->user;
     $sink = $this->redirectEvents();
     // Reset the dashboard.
     my_reset_page($user->id);
     // Trigger and capture the event.
     $events = $sink->get_events();
     $event = reset($events);
     // Check that the event data is valid.
     $this->assertInstanceOf('\\core\\event\\dashboard_reset', $event);
     $this->assertEquals($user->id, $event->userid);
     $this->assertDebuggingNotCalled();
 }
Example #2
0
    if ($node = $PAGE->settingsnav->get('userviewingsettings'.$user->id)) {
        $node->forceopen = true;
    }
} else if ($node = $PAGE->settingsnav->get('dashboard', navigation_node::TYPE_CONTAINER)) {
    $node->forceopen = true;
}
if ($node = $PAGE->settingsnav->get('root')) {
    $node->forceopen = false;
}


// Toggle the editing state and switches.
if ($PAGE->user_allowed_editing()) {
    if ($reset !== null) {
        if (!is_null($userid)) {
            if (!$currentpage = my_reset_page($userid, MY_PAGE_PUBLIC, 'user-profile')) {
                print_error('reseterror', 'my');
            }
            redirect(new moodle_url('/user/profile.php', array('id' => $userid)));
        }
    } else if ($edit !== null) {             // Editing state was specified.
        $USER->editing = $edit;       // Change editing state.
    } else {                          // Editing state is in session.
        if ($currentpage->userid) {   // It's a page we can edit, so load from session.
            if (!empty($USER->editing)) {
                $edit = 1;
            } else {
                $edit = 0;
            }
        } else {
            // For the page to display properly with the user context header the page blocks need to
if (!isguestuser()) {   // Skip default home page for guests
    if (get_home_page() != HOMEPAGE_MY) {
        if (optional_param('setdefaulthome', false, PARAM_BOOL)) {
            set_user_preference('user_home_page_preference', HOMEPAGE_MY);
        } else if (!empty($CFG->defaulthomepage) && $CFG->defaulthomepage == HOMEPAGE_USER) {
            $PAGE->settingsnav->get('usercurrentsettings')->add(get_string('makethismyhome'), new moodle_url('/my/', array('setdefaulthome'=>true)), navigation_node::TYPE_SETTING);
        }
    }
}

// Toggle the editing state and switches
if ($PAGE->user_allowed_editing()) {
    if ($reset !== null) {
        if (!is_null($userid)) {
            require_sesskey();
            if(!$currentpage = my_reset_page($userid, MY_PAGE_PRIVATE)){
                print_error('reseterror', 'my');
            }
            redirect(new moodle_url('/my'));
        }
    } else if ($edit !== null) {             // Editing state was specified
        $USER->editing = $edit;       // Change editing state
        if (!$currentpage->userid && $edit) {
            // If we are viewing a system page as ordinary user, and the user turns
            // editing on, copy the system pages as new user pages, and get the
            // new page record
            if (!$currentpage = my_copy_page($USER->id, MY_PAGE_PRIVATE)) {
                print_error('mymoodlesetup');
            }
            $context = context_user::instance($USER->id);
            $PAGE->set_context($context);
Example #4
0
 /**
  * Test the dashboard reset event.
  *
  * We will reset the user dashboard to
  * trigger the event and ensure data is returned as expected.
  */
 public function test_dashboard_reset()
 {
     global $CFG;
     require_once $CFG->dirroot . '/my/lib.php';
     $user = $this->user;
     $sink = $this->redirectEvents();
     // Reset the dashboard.
     my_reset_page($user->id);
     // Trigger and capture the event.
     $events = $sink->get_events();
     $event = reset($events);
     // Check that the event data is valid.
     $this->assertInstanceOf('\\core\\event\\dashboard_reset', $event);
     $this->assertEquals($user->id, $event->userid);
     $this->assertEquals(MY_PAGE_PRIVATE, $event->other['private']);
     $this->assertEquals('my-index', $event->other['pagetype']);
     $this->assertDebuggingNotCalled();
     // Reset the dashboard with private parameter is set to MY_PAGE_PUBLIC and pagetype set to 'user-profile'.
     $sink = $this->redirectEvents();
     my_reset_page($user->id, MY_PAGE_PUBLIC, 'user-profile');
     // Trigger and capture the event.
     $events = $sink->get_events();
     $event = reset($events);
     $this->assertEquals(MY_PAGE_PUBLIC, $event->other['private']);
     $this->assertEquals('user-profile', $event->other['pagetype']);
 }