Merge branch 'MDL-60579-master' of https://github.com/mihailges/moodle
authorDavid Monllao <davidm@moodle.com>
Wed, 8 Nov 2017 11:16:20 +0000 (12:16 +0100)
committerDavid Monllao <davidm@moodle.com>
Wed, 8 Nov 2017 11:16:20 +0000 (12:16 +0100)
1  2 
lib/db/services.php
user/index.php
user/renderer.php
version.php

Simple merge
diff --cc user/index.php
Simple merge
@@@ -238,7 -251,59 +241,10 @@@ class core_user_renderer extends plugin
              }
          }
  
 -        require_once($CFG->dirroot . '/enrol/locallib.php');
 -        $manager = new course_enrolment_manager($this->page, $course);
 -
 -        $canreviewenrol = has_capability('moodle/course:enrolreview', $context);
 -
 -        // Filter options for enrolment methods.
 -        if ($canreviewenrol && $enrolmentmethods = $manager->get_enrolment_instance_names(true)) {
 -            $criteria = get_string('enrolmentinstances', 'enrol');
 -            $enroloptions = [];
 -            foreach ($enrolmentmethods as $id => $enrolname) {
 -                $enroloptions += $this->format_filter_option(USER_FILTER_ENROLMENT, $criteria, $id, $enrolname);
 -            }
 -            $filteroptions += $enroloptions;
 -        }
 -
 -        // Filter options for groups, if available.
 -        if ($course->groupmode != NOGROUPS) {
 -            if (has_capability('moodle/site:accessallgroups', $context) || $course->groupmode == VISIBLEGROUPS) {
 -                // List all groups if the user can access all groups, or we are in visible group mode.
 -                $groups = $manager->get_all_groups();
 -            } else {
 -                // Otherwise, just list the groups the user belongs to.
 -                $groups = groups_get_all_groups($course->id, $USER->id);
 -            }
 -            $criteria = get_string('group');
 -            $groupoptions = [];
 -            foreach ($groups as $id => $group) {
 -                $groupoptions += $this->format_filter_option(USER_FILTER_GROUP, $criteria, $id, $group->name);
 -            }
 -            $filteroptions += $groupoptions;
 -        }
 -
 -        // Filter options for role.
 -        $roles = role_fix_names(get_profile_roles($context), $context, ROLENAME_ALIAS, true);
 -        $criteria = get_string('role');
 -        $roleoptions = [];
 -        foreach ($roles as $id => $role) {
 -            $roleoptions += $this->format_filter_option(USER_FILTER_ROLE, $criteria, $id, $role);
 -        }
 -        $filteroptions += $roleoptions;
 -
 -        // Filter options for status.
 -        if ($canreviewenrol) {
 -            $criteria = get_string('status');
 -            // Add statuses.
 -            $filteroptions += $this->format_filter_option(USER_FILTER_STATUS, $criteria, ENROL_USER_ACTIVE, get_string('active'));
 -            $filteroptions += $this->format_filter_option(USER_FILTER_STATUS, $criteria, ENROL_USER_SUSPENDED,
 -                get_string('inactive'));
 -        }
  
+         // Add missing applied filters to the filter options.
+         $filteroptions = $this->handle_missing_applied_filters($filtersapplied, $filteroptions);
          $indexpage = new \core_user\output\unified_filter($filteroptions, $filtersapplied);
          $context = $indexpage->export_for_template($this->output);
  
          $optionvalue = "$filtertype:$value";
          return [$optionvalue => $optionlabel];
      }
+     /**
+      * Handles cases when after reloading the applied filters are missing in the filter options.
+      *
+      * @param array $filtersapplied The applied filters.
+      * @param array $filteroptions The filter options.
+      * @return array The formatted options with the ['filtertype:value' => 'criteria: label'] format.
+      */
+     private function handle_missing_applied_filters($filtersapplied, $filteroptions) {
+         global $DB;
+         foreach ($filtersapplied as $filter) {
+             if (!array_key_exists($filter, $filteroptions)) {
+                 $filtervalue = explode(':', $filter);
+                 $key = $filtervalue[0];
+                 $value = $filtervalue[1];
+                 switch($key) {
+                     case USER_FILTER_LAST_ACCESS:
+                         $now = usergetmidnight(time());
+                         $criteria = get_string('usersnoaccesssince');
+                         // Days.
+                         for ($i = 1; $i < 7; $i++) {
+                             $timestamp = strtotime('-' . $i . ' days', $now);
+                             if ($timestamp < $value) {
+                                 break;
+                             }
+                             $val = get_string('numdays', 'moodle', $i);
+                             $filteroptions += $this->format_filter_option(USER_FILTER_LAST_ACCESS, $criteria, $timestamp, $val);
+                         }
+                         // Weeks.
+                         for ($i = 1; $i < 10; $i++) {
+                             $timestamp = strtotime('-'.$i.' weeks', $now);
+                             if ($timestamp < $value) {
+                                 break;
+                             }
+                             $val = get_string('numweeks', 'moodle', $i);
+                             $filteroptions += $this->format_filter_option(USER_FILTER_LAST_ACCESS, $criteria, $timestamp, $val);
+                         }
+                         // Months.
+                         for ($i = 2; $i < 12; $i++) {
+                             $timestamp = strtotime('-'.$i.' months', $now);
+                             if ($timestamp < $value) {
+                                 break;
+                             }
+                             $val = get_string('nummonths', 'moodle', $i);
+                             $filteroptions += $this->format_filter_option(USER_FILTER_LAST_ACCESS, $criteria, $timestamp, $val);
+                         }
+                         // Try a year.
+                         $timestamp = strtotime('-1 year', $now);
+                         if ($timestamp >= $value) {
+                             $val = get_string('numyear', 'moodle', 1);
+                             $filteroptions += $this->format_filter_option(USER_FILTER_LAST_ACCESS, $criteria, $timestamp, $val);
+                         }
+                     case USER_FILTER_ROLE:
+                         $criteria = get_string('role');
+                         if ($role = $DB->get_record('role', array('id' => $value))) {
+                             $role = role_get_name($role);
+                             $filteroptions += $this->format_filter_option(USER_FILTER_ROLE, $criteria, $value, $role);
+                         }
+                 }
+             }
+         }
+         return $filteroptions;
+     }
  }
 -
 -/**
 - * User files tree
 - * @copyright  2010 Dongsheng Cai <dongsheng@moodle.com>
 - * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 - */
 -class user_files_tree implements renderable {
 -
 -    /**
 -     * @var context_user $context
 -     */
 -    public $context;
 -
 -    /**
 -     * @var array $dir
 -     */
 -    public $dir;
 -
 -    /**
 -     * Create user files tree object
 -     */
 -    public function __construct() {
 -        global $USER;
 -        $this->context = context_user::instance($USER->id);
 -        $fs = get_file_storage();
 -        $this->dir = $fs->get_area_tree($this->context->id, 'user', 'private', 0);
 -    }
 -}
diff --cc version.php
@@@ -29,7 -29,7 +29,7 @@@
  
  defined('MOODLE_INTERNAL') || die();
  
- $version  = 2017110800.00;              // YYYYMMDD      = weekly release date of this DEV branch.
 -$version  = 2017110100.01;              // YYYYMMDD      = weekly release date of this DEV branch.
++$version  = 2017110800.01;              // YYYYMMDD      = weekly release date of this DEV branch.
                                          //         RR    = release increments - 00 in DEV branches.
                                          //           .XX = incremental changes.