Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-39727

Course request approve page improvements

XMLWordPrintable

    • Icon: Improvement Improvement
    • Resolution: Won't Do
    • Icon: Minor Minor
    • None
    • 2.4, 2.5, 3.8
    • Course
    • MOODLE_24_STABLE, MOODLE_25_STABLE, MOODLE_38_STABLE

      We need to have little improvements in "Courses pending approval" page (/course/pending.php):

      1. "Requested by" user name as link to user profile (otherwise admin needs to go to user search...)
      2. "Category" should be full category path – we have a lot of categories and the name without the path is not sufficient.

      I also have code for these changes:

      Moodle 2.4

      /course/lib.php file changes

      diff --git a/course/lib.php b/course/lib.php
      index 18576c8..8633443 100644
      --- a/course/lib.php
      +++ b/course/lib.php
      @@ -2248,6 +2248,24 @@ function make_categories_options() {
       }
       
       /**
      + * This function will make category path with ID-s (like "/123/789") to readable path string (like "Main Category ► Sub Category").
      + *
      + * @param string $path Path containing category ID-s instead of names
      + * @param string $separator Separator to use between category names
      + * @return string full category path with cateory names
      + */
      +function get_category_readable_path($path, $separator = ' ► ') {
      +    global $DB;
      +    $categories = explode('/', $path);
      +    $readablepath = '';
      +    foreach ($categories as $categoryid) {
      +        $category = $DB->get_record('course_categories', array('id' => $categoryid));
      +        $readablepath .= ($readablepath == '' ? '' : $separator) . $category->name;
      +    }
      +    return $readablepath;
      +}
      +
      +/**
        * Prints the category info in indented fashion
        * This function is only used by print_whole_category_list() above
        */
      

      /course/pending.php file changes

      diff --git a/course/pending.php b/course/pending.php
      index 3d6cb18..50583ca 100644
      --- a/course/pending.php
      +++ b/course/pending.php
      @@ -124,9 +124,13 @@ if (empty($pending)) {
               $row = array();
               $row[] = format_string($course->shortname);
               $row[] = format_string($course->fullname);
      -        $row[] = fullname($course->get_requester());
      +
      +        $requester = $course->get_requester();
      +        $userurl = new moodle_url('/user/profile.php', array('id' => $requester->id));
      +        $row[] = html_writer::link($userurl, fullname($requester), array('target' => '_blank'));
      +
               $row[] = $course->summary;
      -        $row[] = format_string($category->name);
      +        $row[] = format_string(get_category_readable_path($category->path));
               $row[] = format_string($course->reason);
               $row[] = $OUTPUT->single_button(new moodle_url($baseurl, array('approve' => $course->id, 'sesskey' => sesskey())), get_string('approve'), 'get') .
                        $OUTPUT->single_button(new moodle_url($baseurl, array('reject' => $course->id)), get_string('rejectdots'), 'get');
      
      

      Moodle 2.5 (not tested)

      /lib/coursecatlib.php file changes

      diff --git a/lib/coursecatlib.php b/lib/coursecatlib.php
      index 6cf2ea1..7a8f5ab 100644
      --- a/lib/coursecatlib.php
      +++ b/lib/coursecatlib.php
      @@ -1806,6 +1806,24 @@ class coursecat implements renderable, cacheable_object, IteratorAggregate {
           }
       
           /**
      +     * Returns nice readable cateogry path string wiht cetegory names (example: "Main Category ► Sub Category").
      +     *
      +     * @param string $separator separator to use between category names
      +     * @return string full category path with cateory names
      +     */
      +    function get_path_with_names($separator = ' ► ') {
      +        global $DB;
      +        $categories = explode('/', $this->path);
      +        $readablepath = '';
      +        foreach ($categories as $categoryid) {
      +            $category = $DB->get_record('course_categories', array('id' => $categoryid));
      +            $coursecat = new coursecat($category);
      +            $readablepath .= ($readablepath == '' ? '' : $separator) . $coursecat->get_formatted_name();
      +        }
      +        return $readablepath;
      +    }
      +
      +    /**
            * Returns ids of all parents of the category. Last element in the return array is the direct parent
            *
            * For example, if you have a tree of categories like:
      

      /course/pending.php file changes

      diff --git a/course/pending.php b/course/pending.php
      index eaf4c28..f8b8f62 100644
      --- a/course/pending.php
      +++ b/course/pending.php
      @@ -115,9 +115,13 @@ if (empty($pending)) {
               $row = array();
               $row[] = format_string($course->shortname);
               $row[] = format_string($course->fullname);
      -        $row[] = fullname($course->get_requester());
      +
      +        $requester = $course->get_requester();
      +        $userurl = new moodle_url('/user/profile.php', array('id' => $requester->id));
      +        $row[] = html_writer::link($userurl, fullname($requester), array('target' => '_blank'));
      +
               $row[] = $course->summary;
      -        $row[] = $category->get_formatted_name();
      +        $row[] = $category->get_path_with_names();
               $row[] = format_string($course->reason);
               $row[] = $OUTPUT->single_button(new moodle_url($baseurl, array('approve' => $course->id, 'sesskey' => sesskey())), get_string('approve'), 'get') .
                        $OUTPUT->single_button(new moodle_url($baseurl, array('reject' => $course->id)), get_string('rejectdots'), 'get');
      
      

            Unassigned Unassigned
            mangus Mart Mangus
            Votes:
            2 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved:

                Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.