Skip to content

Commit

Permalink
mnet: introducing get_my_remotecourses() and get_my_remotehosts() -- …
Browse files Browse the repository at this point in the history
…use them too
  • Loading branch information
martinlanghoff committed Jan 19, 2007
1 parent 0743661 commit db4b12e
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 26 deletions.
47 changes: 21 additions & 26 deletions blocks/course_list/block_course_list.php
Expand Up @@ -110,35 +110,30 @@ function get_remote_courses() {
return false;
}

if ($USER->mnethostid != $CFG->mnet_localhost_id) {
if (!empty($USER->mnet_foreign_host_array) && is_array($USER->mnet_foreign_host_array)) {
$this->content->items[] = get_string('remotemoodles','mnet');
$this->content->icons[] = '';
foreach($USER->mnet_foreign_host_array as $somehost) {
$this->content->items[] = $somehost['count'].get_string('courseson','mnet').'<a title="'.$somehost['name'].'" href="'.$somehost['url'].'">'.$somehost['name'].'</a>';
$this->content->icons[] = $icon;
}
} else {
return false;
if ($courses = get_my_remotecourses()) {
$this->content->items[] = get_string('remotecourses','mnet');
$this->content->icons[] = '';
foreach ($courses as $course) {
$this->content->items[]="<a title=\"$course->shortname\" ".
"href=\"{$CFG->wwwroot}/auth/mnet/jump.php?hostid={$course->hostid}&amp;wantsurl=/course/view.php?id={$course->remoteid}\">$course->fullname</a>";
$this->content->icons[]=$icon;
}
} else {
$sql = "SELECT c.remoteid, c.shortname, c.fullname, c.hostid
FROM {$CFG->prefix}mnet_enrol_course c
JOIN {$CFG->prefix}mnet_enrol_assignments a ON c.id=a.courseid
WHERE a.userid={$USER->id}";
if ($courses = get_records_sql($sql)) {
$this->content->items[] = get_string('remotecourses','mnet');
$this->content->icons[] = '';
foreach ($courses as $course) {
$this->content->items[]="<a title=\"$course->shortname\" ".
"href=\"{$CFG->wwwroot}/auth/mnet/jump.php?hostid={$course->hostid}&amp;wantsurl=/course/view.php?id={$course->remoteid}\">$course->fullname</a>";
$this->content->icons[]=$icon;
}
} else {
return false;
// if we listed courses, we are done
return true;
}

if ($hosts = get_my_remotehosts()) {
$this->content->items[] = get_string('remotemoodles','mnet');
$this->content->icons[] = '';
foreach($USER->mnet_foreign_host_array as $somehost) {
$this->content->items[] = $somehost['count'].get_string('courseson','mnet').'<a title="'.$somehost['name'].'" href="'.$somehost['url'].'">'.$somehost['name'].'</a>';
$this->content->icons[] = $icon;
}
// if we listed hosts, done
return true;
}
return true;

return false;
}

}
Expand Down
40 changes: 40 additions & 0 deletions lib/datalib.php
Expand Up @@ -1002,6 +1002,46 @@ function fix_course_sortorder($categoryid=0, $n=0, $safe=0, $depth=0, $path='')
return $n+1;
}

/**
* List of remote courses that a user has access to via MNET.
* Works only on the IDP
*
* @uses $CFG, $USER
* @return array {@link $COURSE} of course objects
*/
function get_my_remotecourses($userid=0) {
global $CFG, $USER;

if (empty($userid)) {
$userid = $USER->id;
}

$sql = "SELECT c.remoteid, c.shortname, c.fullname, c.hostid
FROM {$CFG->prefix}mnet_enrol_course c
JOIN {$CFG->prefix}mnet_enrol_assignments a ON c.id=a.courseid
WHERE a.userid={$userid}";

return get_records_sql($sql);
}

/**
* List of remote hosts that a user has access to via MNET.
* Works on the SP
*
* @uses $CFG, $USER
* @return array of host objects
*/
function get_my_remotehosts() {
global $CFG, $USER;

if ($USER->mnethostid == $CFG->mnet_localhost_id) {
return false; // Return nothing on the IDP
}
if (!empty($USER->mnet_foreign_host_array) && is_array($USER->mnet_foreign_host_array)) {
return $USER->mnet_foreign_host_array;
}
return false;
}

/**
* This function creates a default separated/connected scale
Expand Down

0 comments on commit db4b12e

Please sign in to comment.