Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Поехали!

  • Loading branch information...
commit 09635141b53f7bb70ea87f12ffd4962fc764958d 0 parents
Dmitry Ketov authored March 29, 2012
58  block_mycourses.php
... ...
@@ -0,0 +1,58 @@
  1
+<?php
  2
+
  3
+include_once($CFG->dirroot . '/course/lib.php');
  4
+include_once($CFG->dirroot . '/lib/accesslib.php');
  5
+
  6
+class block_mycourses extends block_base {
  7
+    function init() {
  8
+        $this->title = get_string('mycourses');
  9
+    }
  10
+
  11
+    function get_content() {
  12
+        global $CFG, $USER, $DB, $OUTPUT;
  13
+
  14
+        if($this->content !== NULL) {
  15
+            return $this->content;
  16
+        }
  17
+
  18
+        $this->content = new stdClass;
  19
+        $this->content->footer = '';
  20
+
  21
+        $icon  = '<img src="' . $OUTPUT->pix_url('i/course') . '" class="icon" alt="" />&nbsp;';
  22
+
  23
+	$coursesbyroles = array();
  24
+        if (isloggedin() && !isguestuser()) {
  25
+          if ($courses = enrol_get_my_courses(NULL, 'fullname ASC')) {
  26
+            foreach ($courses as $course) {
  27
+              $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
  28
+
  29
+	      $roles = get_user_roles($coursecontext, $USER->id);
  30
+	      foreach($roles as $role) {
  31
+		if(empty($coursesbyroles[$role->roleid]))
  32
+	 	{
  33
+		  $coursesbyroles[$role->roleid] = new stdClass;
  34
+		  $coursesbyroles[$role->roleid]->role = $role;
  35
+		}
  36
+		$coursesbyroles[$role->roleid]->courses[] = $course;
  37
+	      }
  38
+            }
  39
+            foreach($coursesbyroles as $r) {
  40
+	      $list = array();
  41
+	      foreach($r->courses as $course) {
  42
+          	$link = new moodle_url('/course/view.php', array('id' => $course->id));
  43
+
  44
+                $list[] = html_writer::link($link, format_string($course->fullname));
  45
+              }
  46
+              $this->content->text .= html_writer::tag('div', 
  47
+			html_writer::tag('h3', $r->role->name) .
  48
+			html_writer::tag('ul', html_writer::alist($list)));
  49
+            }
  50
+	
  51
+            $this->content->footer = html_writer::link(new moodle_url('/course/index.php'), 
  52
+							get_string("fulllistofcourses"));
  53
+          }
  54
+        }
  55
+
  56
+        return $this->content;
  57
+    }
  58
+}
5  lang/en/block_mycourses.php
... ...
@@ -0,0 +1,5 @@
  1
+<?php
  2
+
  3
+$string['pluginname'] = get_string('mycourses');
  4
+
  5
+?>
5  lang/ru/block_mycourses.php
... ...
@@ -0,0 +1,5 @@
  1
+<?php
  2
+
  3
+$string['pluginname'] = get_string('mycourses');
  4
+
  5
+?>
1  styles.css
... ...
@@ -0,0 +1 @@
  1
+.block_course_list .footer {margin-top: 5px;}
8  version.php
... ...
@@ -0,0 +1,8 @@
  1
+<?php
  2
+defined('MOODLE_INTERNAL') || die();
  3
+
  4
+$plugin->version   = 2012032900;        // The current plugin version (Date: YYYYMMDDXX)
  5
+$plugin->requires  = 2011112900;        // Requires this Moodle version
  6
+$plugin->component = 'block_mycourses'; // Full name of the plugin (used for diagnostics)
  7
+
  8
+?>

0 notes on commit 0963514

Please sign in to comment.
Something went wrong with that request. Please try again.