original_string: public function available_courses() {
          global $CFG, $DB;
          require_once($CFG->libdir.'/filelib.php');
  
          if (!$client = get_mnet_remote_client()) {
              die('Callable via XML-RPC only');
          }
  
          // we call our id as 'remoteid' because it will be sent to the peer
          // the column aliases are required by MNet protocol API for clients 1.x and 2.0
          $sql = "SELECT c.id AS remoteid, c.fullname, c.shortname, c.idnumber, c.summary, c.summaryformat,
                         c.sortorder, c.startdate, cat.id AS cat_id, cat.name AS cat_name,
                         cat.description AS cat_description, cat.descriptionformat AS cat_descriptionformat,
                         e.cost, e.currency, e.roleid AS defaultroleid, r.name AS defaultrolename,
                         e.customint1
                    FROM {enrol} e
              INNER JOIN {course} c ON c.id = e.courseid
              INNER JOIN {course_categories} cat ON cat.id = c.category
              INNER JOIN {role} r ON r.id = e.roleid
                   WHERE e.enrol = 'mnet'
                         AND (e.customint1 = 0 OR e.customint1 = ?)
                         AND c.visible = 1
                ORDER BY cat.sortorder, c.sortorder, c.shortname";
  
          $rs = $DB->get_recordset_sql($sql, array($client->id));
  
          $courses = array();
          foreach ($rs as $course) {
              // use the record if it does not exist yet or is host-specific
              if (empty($courses[$course->remoteid]) or ($course->customint1 > 0)) {
                  unset($course->customint1); // the client does not need to know this
                  $context = context_course::instance($course->remoteid);
                  // Rewrite file URLs so that they are correct
                  $course->summary = file_rewrite_pluginfile_urls($course->summary, 'pluginfile.php', $context->id, 'course', 'summary', false);
                  $courses[$course->remoteid] = $course;
              }
          }
          $rs->close();
  
          return array_values($courses); // can not use keys for backward compatibility
      }
code: public function available_courses() {
          global $CFG, $DB;
          require_once($CFG->libdir.'/filelib.php');
  
          if (!$client = get_mnet_remote_client()) {
              die('Callable via XML-RPC only');
          }
  
          // we call our id as 'remoteid' because it will be sent to the peer
          // the column aliases are required by MNet protocol API for clients 1.x and 2.0
          $sql = "SELECT c.id AS remoteid, c.fullname, c.shortname, c.idnumber, c.summary, c.summaryformat,
                         c.sortorder, c.startdate, cat.id AS cat_id, cat.name AS cat_name,
                         cat.description AS cat_description, cat.descriptionformat AS cat_descriptionformat,
                         e.cost, e.currency, e.roleid AS defaultroleid, r.name AS defaultrolename,
                         e.customint1
                    FROM {enrol} e
              INNER JOIN {course} c ON c.id = e.courseid
              INNER JOIN {course_categories} cat ON cat.id = c.category
              INNER JOIN {role} r ON r.id = e.roleid
                   WHERE e.enrol = 'mnet'
                         AND (e.customint1 = 0 OR e.customint1 = ?)
                         AND c.visible = 1
                ORDER BY cat.sortorder, c.sortorder, c.shortname";
  
          $rs = $DB->get_recordset_sql($sql, array($client->id));
  
          $courses = array();
          foreach ($rs as $course) {
              // use the record if it does not exist yet or is host-specific
              if (empty($courses[$course->remoteid]) or ($course->customint1 > 0)) {
                  unset($course->customint1); // the client does not need to know this
                  $context = context_course::instance($course->remoteid);
                  // Rewrite file URLs so that they are correct
                  $course->summary = file_rewrite_pluginfile_urls($course->summary, 'pluginfile.php', $context->id, 'course', 'summary', false);
                  $courses[$course->remoteid] = $course;
              }
          }
          $rs->close();
  
          return array_values($courses); // can not use keys for backward compatibility
      }
code_tokens: public function available_courses ( ) { global $ CFG , $ DB ; require_once ( $ CFG -> libdir . '/filelib.php' ) ; if ( ! $ client = get_mnet_remote_client ( ) ) { die ( 'Callable via XML-RPC only' ) ; } // we call our id as 'remoteid' because it will be sent to the peer // the column aliases are required by MNet protocol API for clients 1.x and 2.0 $ sql = "SELECT c.id AS remoteid, c.fullname, c.shortname, c.idnumber, c.summary, c.summaryformat,
                         c.sortorder, c.startdate, cat.id AS cat_id, cat.name AS cat_name,
                         cat.description AS cat_description, cat.descriptionformat AS cat_descriptionformat,
                         e.cost, e.currency, e.roleid AS defaultroleid, r.name AS defaultrolename,
                         e.customint1
                    FROM {enrol} e
              INNER JOIN {course} c ON c.id = e.courseid
              INNER JOIN {course_categories} cat ON cat.id = c.category
              INNER JOIN {role} r ON r.id = e.roleid
                   WHERE e.enrol = 'mnet'
                         AND (e.customint1 = 0 OR e.customint1 = ?)
                         AND c.visible = 1
                ORDER BY cat.sortorder, c.sortorder, c.shortname" ; $ rs = $ DB -> get_recordset_sql ( $ sql , array ( $ client -> id ) ) ; $ courses = array ( ) ; foreach ( $ rs as $ course ) { // use the record if it does not exist yet or is host-specific if ( empty ( $ courses [ $ course -> remoteid ] ) or ( $ course -> customint1 > 0 ) ) { unset ( $ course -> customint1 ) ; // the client does not need to know this $ context = context_course :: instance ( $ course -> remoteid ) ; // Rewrite file URLs so that they are correct $ course -> summary = file_rewrite_pluginfile_urls ( $ course -> summary , 'pluginfile.php' , $ context -> id , 'course' , 'summary' , false ) ; $ courses [ $ course -> remoteid ] = $ course ; } } $ rs -> close ( ) ; return array_values ( $ courses ) ; // can not use keys for backward compatibility }
docstring: Returns list of courses that we offer to the caller for remote enrolment of their users
  
  Since Moodle 2.0, courses are made available for MNet peers by creating an instance
  of enrol_mnet plugin for the course. Hidden courses are not returned. If there are two
  instances - one specific for the host and one for 'All hosts', the setting of the specific
  one is used. The id of the peer is kept in customint1, no other custom fields are used.
  
  @uses mnet_remote_client Callable via XML-RPC only
  @return array
docstring_tokens: Returns list of courses that we offer to the caller for remote enrolment of their users