예제 #1
0
 /**
  * Constructs header in editing mode
  *
  * @param int $max maximum number of courses
  * @return string html of header bar.
  */
 public function editing_bar_head($max = 0)
 {
     $output = $this->output->box_start('notice');
     $options = array('0' => get_string('alwaysshowall', 'block_course_overview_lite'));
     for ($i = 1; $i <= $max; $i++) {
         $options[$i] = $i;
     }
     $url = new moodle_url('/my/index.php');
     $select = new single_select($url, 'mynumber', $options, block_course_overview_lite_get_max_user_courses(), array());
     $select->set_label(get_string('numtodisplay', 'block_course_overview_lite'));
     $output .= $this->output->render($select);
     $output .= $this->output->box_end();
     return $output;
 }
예제 #2
0
function block_course_overview_lite_sort_courses($courses)
{
    $limit = block_course_overview_lite_get_max_user_courses();
    // Hard limit the courses to 100 to skip the user pref save error.
    $limit = $limit > 100 ? 100 : $limit;
    $order = array();
    if (!is_null($usersortorder = get_user_preferences('block_course_overview_lite_course_order'))) {
        $order = json_decode($usersortorder, true);
    }
    $sortedcourses = array();
    $remainingcourses = array();
    $counter = 0;
    // Get courses in sort order into list.
    foreach ($order as $key => $cid) {
        if ($counter >= $limit && $limit != 0) {
            break;
        }
        if (isset($courses[$cid])) {
            $sortedcourses[] = $courses[$cid];
            unset($courses[$cid]);
            $counter++;
        }
    }
    // Append unsorted courses if limit allows.
    foreach ($courses as $course) {
        if ($limit != 0 && $counter >= $limit) {
            break;
        }
        if ($course->current) {
            $sortedcourses[] = $course;
        } else {
            $remainingcourses[] = $course;
        }
        $counter++;
    }
    return array_merge($sortedcourses, $remainingcourses);
}