Permalink
Browse files

MDL-27814 blogs: Refactoring code to use proper context and such

Based on the decisions made in the issue, most places in blog should use site context.
There are also minor other refactoring to support all changes made in the issue.
  • Loading branch information...
1 parent 4ef0829 commit f42d2a22bc396673f6fca7b9671af7f44e3fd8d3 @ankitagarwal ankitagarwal committed Apr 4, 2013
Showing with 4 additions and 21 deletions.
  1. +1 −5 blog/edit_form.php
  2. +3 −5 blog/index.php
  3. +0 −11 blog/rsslib.php
View
6 blog/edit_form.php
@@ -139,9 +139,7 @@ function validation($data, $files) {
if (!empty($data['courseassoc'])) {
$coursecontext = context::instance_by_id($data['courseassoc']);
- if ($coursecontext->contextlevel == CONTEXT_COURSE) {
- $errors['courseassoc'] = get_string('studentnotallowed', '', fullname($USER, true));
- } else {
+ if ($coursecontext->contextlevel != CONTEXT_COURSE) {
$errors['courseassoc'] = get_string('error');
}
}
@@ -163,8 +161,6 @@ function validation($data, $files) {
} else {
$data['courseassoc'] = $coursecontext->id;
}
-
- $errors['modassoc'] = get_string('studentnotallowed', '', fullname($USER, true));
} else {
$errors['modassoc'] = get_string('error');
}
View
8 blog/index.php
@@ -124,11 +124,9 @@
}
$courseid = $course->id;
- $coursecontext = context_course::instance($course->id);
-
require_login($course);
- if (!has_capability('moodle/blog:view', $coursecontext)) {
+ if (!has_capability('moodle/blog:view', $sitecontext)) {
print_error('cannotviewcourseblog', 'blog');
}
} else {
@@ -152,7 +150,7 @@
$courseid = $course->id;
require_login($course);
- if (!has_capability('moodle/blog:view', $coursecontext)) {
+ if (!has_capability('moodle/blog:view', $sitecontext)) {
print_error(get_string('cannotviewcourseorgroupblog', 'blog'));
}
@@ -210,7 +208,7 @@
$thingid = null;
list($thingid, $rsscontext, $filtertype) = blog_rss_get_params($blogheaders['filters']);
if (empty($rsscontext)) {
- $rsscontext = get_system_context();
+ $rsscontext = context_system::instance();
}
$rsstitle = $blogheaders['heading'];
View
11 blog/rsslib.php
@@ -123,26 +123,15 @@ function blog_rss_get_params($filters) {
if (!$filters) {
$thingid = SITEID;
- $rsscontext = $sitecontext;
$filtertype = 'site';
} else if (array_key_exists('course', $filters)) {
$thingid = $filters['course'];
-
- $coursecontext = context_course::instance($thingid);
- $rsscontext = $coursecontext;
-
$filtertype = 'course';
} else if (array_key_exists('user', $filters)) {
$thingid = $filters['user'];
-
- $usercontext = context_user::instance($thingid);
- $rsscontext = $usercontext;
-
$filtertype = 'user';
} else if (array_key_exists('group', $filters)) {
$thingid = $filters['group'];
-
- $rsscontext = $sitecontext; //is this the context we should be using for group blogs?
$filtertype = 'group';
}

0 comments on commit f42d2a2

Please sign in to comment.