original_string: private function handle_missing_applied_filters($filtersapplied, $filteroptions) {
          global $DB;
  
          foreach ($filtersapplied as $filter) {
              if (!array_key_exists($filter, $filteroptions)) {
                  $filtervalue = explode(':', $filter);
                  if (count($filtervalue) !== 2) {
                      continue;
                  }
                  $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);
                          }
                          break;
                      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);
                          }
                          break;
                  }
              }
          }
          return $filteroptions;
      }
code: private function handle_missing_applied_filters($filtersapplied, $filteroptions) {
          global $DB;
  
          foreach ($filtersapplied as $filter) {
              if (!array_key_exists($filter, $filteroptions)) {
                  $filtervalue = explode(':', $filter);
                  if (count($filtervalue) !== 2) {
                      continue;
                  }
                  $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);
                          }
                          break;
                      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);
                          }
                          break;
                  }
              }
          }
          return $filteroptions;
      }
code_tokens: private function handle_missing_applied_filters ( $ filtersapplied , $ filteroptions ) { global $ DB ; foreach ( $ filtersapplied as $ filter ) { if ( ! array_key_exists ( $ filter , $ filteroptions ) ) { $ filtervalue = explode ( ':' , $ filter ) ; if ( count ( $ filtervalue ) !== 2 ) { continue ; } $ 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 ) ; } break ; 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 ) ; } break ; } } } return $ filteroptions ; }
docstring: 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.
docstring_tokens: Handles cases when after reloading the applied filters are missing in the filter options .