Skip to content

Commit

Permalink
minor fix for recommended courses out of enrolled
Browse files Browse the repository at this point in the history
  • Loading branch information
dketov committed Sep 7, 2012
1 parent 8eaaf97 commit a940b4a
Showing 1 changed file with 45 additions and 46 deletions.
91 changes: 45 additions & 46 deletions block_mycourses.php
Expand Up @@ -49,64 +49,63 @@ function get_content() {
$mycourses[$id]->courses[$course->id] = $course;
}
}
}

if($idnumber = trim($DB->get_field('user', 'idnumber', array('id' => $USER->id))))
{
if($groups = block_mycourses_get_groups_by_name($idnumber)) {
$r = new stdClass;
$r->enrolledas = get_string('recommended', 'block_mycourses', $idnumber);
if($idnumber = trim($DB->get_field('user', 'idnumber', array('id' => $USER->id))))
{
if($groups = block_mycourses_get_groups_by_name($idnumber)) {
$r = new stdClass;
$r->enrolledas = get_string('recommended', 'block_mycourses', $idnumber);

foreach($groups as $group) {
$coursecontext = get_context_instance(CONTEXT_COURSE, $group->courseid);
if(!is_enrolled($coursecontext, $USER)) {
$r->courses[] = block_mycourses_get_course_by_id($group->courseid);
}
}
if(!empty($r->courses)) {
$mycourses['recommended'] = $r;
foreach($groups as $group) {
$coursecontext = get_context_instance(CONTEXT_COURSE, $group->courseid);
if(!is_enrolled($coursecontext, $USER)) {
$r->courses[] = block_mycourses_get_course_by_id($group->courseid);
}
}
if(!empty($r->courses)) {
$mycourses['recommended'] = $r;
}
}
}

$uicon = html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('t/user'),
'class' => 'smallicon'));
$cicon = html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('i/course'),
'class' => 'icon'));

foreach($mycourses as $k => $r) {
$list = array();
foreach($r->courses as $course) {
$link = new moodle_url('/course/view.php', array('id' => $course->id));

if($k === 'recommended') {
$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
$coursecontactroles = explode(',', $CFG->coursecontact);

$teachers = array();
foreach ($coursecontactroles as $roleid) {
$users = get_role_users($roleid, $coursecontext);
foreach ($users as $user) {
$teachers[] = $uicon . html_writer::link(new moodle_url($CFG->wwwroot.'/message/',
array('id' => $user->id)), fullname($user));
}
$uicon = html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('t/user'),
'class' => 'smallicon'));
$cicon = html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('i/course'),
'class' => 'icon'));

foreach($mycourses as $k => $r) {
$list = array();
foreach($r->courses as $course) {
$link = new moodle_url('/course/view.php', array('id' => $course->id));

if($k === 'recommended') {
$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
$coursecontactroles = explode(',', $CFG->coursecontact);

$teachers = array();
foreach ($coursecontactroles as $roleid) {
$users = get_role_users($roleid, $coursecontext);
foreach ($users as $user) {
$teachers[] = $uicon . html_writer::link(new moodle_url($CFG->wwwroot.'/message/',
array('id' => $user->id)), fullname($user));
}
$teachers = html_writer::alist($teachers);
}

$list[] = $cicon . html_writer::link($link, format_string($course->fullname)) . $teachers;
$teachers = html_writer::alist($teachers);
}
$this->content->text .= html_writer::tag('div',
html_writer::tag('h3', $r->enrolledas) .
html_writer::alist($list,
array('class' => 'unlist')),
array('class' => $k));
}

$this->content->footer = html_writer::link(new moodle_url('/course/index.php'),
get_string("fulllistofcourses")) . " …";

$list[] = $cicon . html_writer::link($link, format_string($course->fullname)) . $teachers;
}
$this->content->text .= html_writer::tag('div',
html_writer::tag('h3', $r->enrolledas) .
html_writer::alist($list,
array('class' => 'unlist')),
array('class' => $k));
}

$this->content->footer = html_writer::link(new moodle_url('/course/index.php'),
get_string("fulllistofcourses")) . " …";

return $this->content;
}
}

0 comments on commit a940b4a

Please sign in to comment.