Moodle
  1. Moodle
  2. MDL-19981

new front page component list only "my courses" (divided by roles)

    Details

    • Difficulty:
      Easy
    • Affected Branches:
      MOODLE_19_STABLE

      Description

      a new Front Page component that adds the ability to show a list of only "my courses"
      divided into roles i take in each course.

      Admin (menu) >> FrontPage >> FrontPage Settings >> frontpage (listbox) >> My Courses

      patch instructions follows as comments.

        Gliffy Diagrams

          Activity

          Hide
          Nadav Kavalerchik added a comment -

          open moodle/index.php

          add the following code after the "break;" of "case FRONTPAGECOURSELIST:"

            // after authentication to the system, displays my courses
          	    case FRONTPAGEMYCOURSESLIST:
           
                         if (isloggedin() and !has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM)) and !isguest() and empty($CFG->disablemycourses)) {
                              print_heading_block(get_string('mycourses'));
                              print_my_courses();
                          } else if ((!has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM)) and !isguest()) or (count_records('course') <= FRONTPAGECOURSELIMIT)) {
                              // admin should not see list of courses when there are too many of them
                              print_heading_block(get_string('availablecourses'));
                              print_my_courses();
                          }
                      break;
          

          open moodel/course/lib/php
          after (line 16~) :

          define('FRONTPAGECATEGORYCOMBO',  '4');
          

          add:

          define('FRONTPAGEMYCOURSESLIST',  '5');
          

          add two functions (over-write current functions if necessary)

          // special custom display settings
          function print_my_courses() {
          /// Prints custom user information on the home page.
          /// Over time this can include all sorts of information
           
              global $USER, $CFG;
           
              if (empty($USER->id)) {
                  error("It shouldn't be possible to see My Moodle without being logged in.");
              }
           
              $courses  = get_my_courses($USER->id, 'visible DESC,fullname ASC', array('summary'));
              $rhosts   = array();
              $rcourses = array();
              if (!empty($CFG->mnet_dispatcher_mode) && $CFG->mnet_dispatcher_mode==='strict') {
                  $rcourses = get_my_remotecourses($USER->id);
                  $rhosts   = get_my_remotehosts();
              }
           
              if (!empty($courses) || !empty($rcourses) || !empty($rhosts)) {
           
                  if (!empty($courses)) {
                      echo '<ul class="unlist">';
          	    $studentlist = '';
          	    $assistentteacherlist = '';
          	    $teacherlist = '';
                      foreach ($courses as $course) {
                          if ($course->id == SITEID) {
                              continue;
                          }
          		$context = get_context_instance(CONTEXT_COURSE,$course->id);
          		if (has_capability('moodle/legacy:student', $context, $USER->id, false) ) {
          		  $studentlist .= '<li>';
          		  $studentlist .= print_course_custom($course);
          		  $studentlist .= "</li>\n";
          		  continue;
          		}
          		if (has_capability('moodle/legacy:teacher', $context, $USER->id, false) ) {
          		  $assistentteacherlist .= '<li>';
          		  $assistentteacherlist .= print_course_custom($course);
          		  $assistentteacherlist .= "</li>\n";
          		  continue;
          		}
          		if (has_capability('moodle/legacy:editingteacher', $context, $USER->id, false)) {
          		  $teacherlist .= '<li>';
          		  $teacherlist .= print_course_custom($course);
          		  $teacherlist .= "</li>\n";
          		  continue;
          		}
          		//if (has_capability('moodle/legacy:admin', $context, $userid, false)) {echo "is GOD<br/>";}
                      }
          	    echo "<h2>courses in which i am student</h2><br/>$studentlist<hr>";
          	    echo "<h2>courses in which i am assistant teacher</h2><br/>$assistentteacherlist<hr>";
          	    echo "<h2>courses in which i am teacher</h2><br/>$teacherlist<hr>";
                      echo "</ul>\n";
                  }
           
                  // MNET
                  if (!empty($rcourses)) {
                      // at the IDP, we know of all the remote courses
                      foreach ($rcourses as $course) {
                          print_remote_course($course, "100%");
                      }
                  } elseif (!empty($rhosts)) {
                      // non-IDP, we know of all the remote servers, but not courses
                      foreach ($rhosts as $host) {
                          print_remote_host($host, "100%");
                      }
                  }
                  unset($course);
                  unset($host);
           
                  if (count_records("course") > (count($courses) + 1) ) {  // Some courses not being displayed
                      echo "<table width=\"100%\"><tr><td align=\"center\">";
                      print_course_search("", false, "short");
                      echo "</td><td align=\"center\">";
                      print_single_button("$CFG->wwwroot/course/index.php", NULL, get_string("fulllistofcourses"), "get");
                      echo "</td></tr></table>\n";
                  }
           
              } else {
                  if (count_records("course_categories") > 1) {
                      print_simple_box_start("center", "100%", "#FFFFFF", 5, "categorybox");
                      print_whole_category_list();
                      print_simple_box_end();
                  } else {
                      print_courses(0);
                  }
              }
          }
           
          /**
           * Print a description of a course, suitable for browsing in a list.
           *
           * @param object $course the course object.
           * @param string $highlightterms (optional) some search terms that should be highlighted in the display.
           * @param string $displayoutput (true OR false) should we display output on page or return a string with the data ?
           */
          function print_course_custom($course, $highlightterms = '',$displayoutput = false) {
           
            global $CFG, $USER;
           
              if (isset($course->context)) {
                  $context = $course->context;
              } else {
                  $context = get_context_instance(CONTEXT_COURSE, $course->id);
              }
           
              $linkcss = $course->visible ? '' : ' class="dimmed" ';
           
              $output = '<div class="coursebox clearfix">';
              $output .= '<div class="info">';
                $output .= '<div class="name"><a title="'.get_string('entercourse').'"'.
          	$linkcss.' href="'.$CFG->wwwroot.'/course/view.php?id='.$course->id.'">'.
          	highlight($highlightterms, format_string($course->fullname)).'</a></div>';
          		    
          //       require_once("$CFG->dirroot/enrol/enrol.class.php");
          //       $enrol = enrolment_factory::factory($course->enrol);
          //       echo $enrol->get_access_icons($course);
           
                $output .= '</div>';
              $output .= '<div class="summary">';
                $options = NULL;
                $options->noclean = true;
                $options->para = false;
                $output .= highlight($highlightterms, format_text($course->summary, FORMAT_MOODLE, $options,  $course->id));
              $output .= '</div>';
              $output .= '</div>';
           
            if ($displayoutput) {
              echo $output;
            } else {
              return $output;
            }
          	
          }
          

          open moodle/lib/adminlib.php
          just after line 2672 :

          FRONTPAGECATEGORYCOMBO => get_string('frontpagecategorycombo'),
          

          add:

          FRONTPAGEMYCOURSESLIST => get_string('frontpagemycourseslist'),
          

          add the following string to your local language translation files (moodle.php)
          $string['frontpagemycourseslist'] = 'My Courses list';

          Show
          Nadav Kavalerchik added a comment - open moodle/index.php add the following code after the "break;" of "case FRONTPAGECOURSELIST:" // after authentication to the system, displays my courses case FRONTPAGEMYCOURSESLIST:   if (isloggedin() and !has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM)) and !isguest() and empty($CFG->disablemycourses)) { print_heading_block(get_string('mycourses')); print_my_courses(); } else if ((!has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM)) and !isguest()) or (count_records('course') <= FRONTPAGECOURSELIMIT)) { // admin should not see list of courses when there are too many of them print_heading_block(get_string('availablecourses')); print_my_courses(); } break; open moodel/course/lib/php after (line 16~) : define('FRONTPAGECATEGORYCOMBO', '4'); add: define('FRONTPAGEMYCOURSESLIST', '5'); add two functions (over-write current functions if necessary) // special custom display settings function print_my_courses() { /// Prints custom user information on the home page. /// Over time this can include all sorts of information   global $USER, $CFG;   if (empty($USER->id)) { error("It shouldn't be possible to see My Moodle without being logged in."); }   $courses = get_my_courses($USER->id, 'visible DESC,fullname ASC', array('summary')); $rhosts = array(); $rcourses = array(); if (!empty($CFG->mnet_dispatcher_mode) && $CFG->mnet_dispatcher_mode==='strict') { $rcourses = get_my_remotecourses($USER->id); $rhosts = get_my_remotehosts(); }   if (!empty($courses) || !empty($rcourses) || !empty($rhosts)) {   if (!empty($courses)) { echo '<ul class="unlist">'; $studentlist = ''; $assistentteacherlist = ''; $teacherlist = ''; foreach ($courses as $course) { if ($course->id == SITEID) { continue; } $context = get_context_instance(CONTEXT_COURSE,$course->id); if (has_capability('moodle/legacy:student', $context, $USER->id, false) ) { $studentlist .= '<li>'; $studentlist .= print_course_custom($course); $studentlist .= "</li>\n"; continue; } if (has_capability('moodle/legacy:teacher', $context, $USER->id, false) ) { $assistentteacherlist .= '<li>'; $assistentteacherlist .= print_course_custom($course); $assistentteacherlist .= "</li>\n"; continue; } if (has_capability('moodle/legacy:editingteacher', $context, $USER->id, false)) { $teacherlist .= '<li>'; $teacherlist .= print_course_custom($course); $teacherlist .= "</li>\n"; continue; } //if (has_capability('moodle/legacy:admin', $context, $userid, false)) {echo "is GOD<br/>";} } echo "<h2>courses in which i am student</h2><br/>$studentlist<hr>"; echo "<h2>courses in which i am assistant teacher</h2><br/>$assistentteacherlist<hr>"; echo "<h2>courses in which i am teacher</h2><br/>$teacherlist<hr>"; echo "</ul>\n"; }   // MNET if (!empty($rcourses)) { // at the IDP, we know of all the remote courses foreach ($rcourses as $course) { print_remote_course($course, "100%"); } } elseif (!empty($rhosts)) { // non-IDP, we know of all the remote servers, but not courses foreach ($rhosts as $host) { print_remote_host($host, "100%"); } } unset($course); unset($host);   if (count_records("course") > (count($courses) + 1) ) { // Some courses not being displayed echo "<table width=\"100%\"><tr><td align=\"center\">"; print_course_search("", false, "short"); echo "</td><td align=\"center\">"; print_single_button("$CFG->wwwroot/course/index.php", NULL, get_string("fulllistofcourses"), "get"); echo "</td></tr></table>\n"; }   } else { if (count_records("course_categories") > 1) { print_simple_box_start("center", "100%", "#FFFFFF", 5, "categorybox"); print_whole_category_list(); print_simple_box_end(); } else { print_courses(0); } } }   /** * Print a description of a course, suitable for browsing in a list. * * @param object $course the course object. * @param string $highlightterms (optional) some search terms that should be highlighted in the display. * @param string $displayoutput (true OR false) should we display output on page or return a string with the data ? */ function print_course_custom($course, $highlightterms = '',$displayoutput = false) {   global $CFG, $USER;   if (isset($course->context)) { $context = $course->context; } else { $context = get_context_instance(CONTEXT_COURSE, $course->id); }   $linkcss = $course->visible ? '' : ' class="dimmed" ';   $output = '<div class="coursebox clearfix">'; $output .= '<div class="info">'; $output .= '<div class="name"><a title="'.get_string('entercourse').'"'. $linkcss.' href="'.$CFG->wwwroot.'/course/view.php?id='.$course->id.'">'. highlight($highlightterms, format_string($course->fullname)).'</a></div>'; // require_once("$CFG->dirroot/enrol/enrol.class.php"); // $enrol = enrolment_factory::factory($course->enrol); // echo $enrol->get_access_icons($course);   $output .= '</div>'; $output .= '<div class="summary">'; $options = NULL; $options->noclean = true; $options->para = false; $output .= highlight($highlightterms, format_text($course->summary, FORMAT_MOODLE, $options, $course->id)); $output .= '</div>'; $output .= '</div>';   if ($displayoutput) { echo $output; } else { return $output; } } open moodle/lib/adminlib.php just after line 2672 : FRONTPAGECATEGORYCOMBO => get_string('frontpagecategorycombo'), add: FRONTPAGEMYCOURSESLIST => get_string('frontpagemycourseslist'), add the following string to your local language translation files (moodle.php) $string ['frontpagemycourseslist'] = 'My Courses list';
          Hide
          Nadav Kavalerchik added a comment -

          multilingual support:

          change function print_my_course()

            if (!empty($studentlist)) echo "<h2>".get_string('mycoursesrolestudent')."</h2><br/>$studentlist<hr>";
            if (!empty($assistentteacherlist)) echo "<h2>".get_string('mycoursesroleteacher')."</h2><br/>$assistentteacherlist<hr>";
            if (!empty($teacherlist)) echo "<h2>".get_string('mycoursesroleeditingteacher')."</h2><br/>$teacherlist<hr>";
          

          and add these strings to your local language file (moodle.php)

          $string['mycoursesrolestudent'] = 'courses in which i am a Student';
          $string['mycoursesroleteacher'] = 'courses in which i am an Assistant Teacher';
          $string['mycoursesroleeditingteacher'] = 'courses in which i am a Teacher';
          

          Show
          Nadav Kavalerchik added a comment - multilingual support: change function print_my_course() if (!empty($studentlist)) echo "<h2>".get_string('mycoursesrolestudent')."</h2><br/>$studentlist<hr>"; if (!empty($assistentteacherlist)) echo "<h2>".get_string('mycoursesroleteacher')."</h2><br/>$assistentteacherlist<hr>"; if (!empty($teacherlist)) echo "<h2>".get_string('mycoursesroleeditingteacher')."</h2><br/>$teacherlist<hr>"; and add these strings to your local language file (moodle.php) $string['mycoursesrolestudent'] = 'courses in which i am a Student'; $string['mycoursesroleteacher'] = 'courses in which i am an Assistant Teacher'; $string['mycoursesroleeditingteacher'] = 'courses in which i am a Teacher';
          Hide
          Marina Glancy added a comment -

          We have detected that this issue has been inactive for over two years and also did not collect many votes. It is possible that it has been already implemented in a more recent version of Moodle, or it is not highly demanded. There are unlimited number of ways Moodle functinality can be expanded and improved but we would like to concentrate on the features that will benefit majority of users, and which can not be implemented as plugins. If you have a suggestion for improving Moodle core, and there is no open issue for it in the tracker, please start a new forum discussion to see how many other users agree with you, and then create a new issue providing as many details as possible.

          ==BLK2YIMP20141121==

          Show
          Marina Glancy added a comment - We have detected that this issue has been inactive for over two years and also did not collect many votes. It is possible that it has been already implemented in a more recent version of Moodle, or it is not highly demanded. There are unlimited number of ways Moodle functinality can be expanded and improved but we would like to concentrate on the features that will benefit majority of users, and which can not be implemented as plugins. If you have a suggestion for improving Moodle core, and there is no open issue for it in the tracker, please start a new forum discussion to see how many other users agree with you, and then create a new issue providing as many details as possible. ==BLK2YIMP20141121==
          Hide
          Nadav Kavalerchik added a comment -

          Eventually, after renderers were introduced, we solved it on the theme's level using renderers.

          Show
          Nadav Kavalerchik added a comment - Eventually, after renderers were introduced, we solved it on the theme's level using renderers.

            People

            • Votes:
              2 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: