Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

MDL-34910 blog Remove new entry link when the context doesn't allows …

…to add new entries
  • Loading branch information...
commit 4219ffab434cdccb9fb322cc0ad8b81f7b31fc39 1 parent 7e8ae12
David Monllaó dmonllao authored
Showing with 33 additions and 18 deletions.
  1. +33 −18 blog/locallib.php
51 blog/locallib.php
View
@@ -663,27 +663,42 @@ public function print_entries() {
$userid = optional_param('userid', null, PARAM_INT);
if (empty($userid) || (!empty($userid) && $userid == $USER->id)) {
- $addurl = new moodle_url("$CFG->wwwroot/blog/edit.php");
- $urlparams = array('action' => 'add',
- 'userid' => $userid,
- 'courseid' => optional_param('courseid', null, PARAM_INT),
- 'groupid' => optional_param('groupid', null, PARAM_INT),
- 'modid' => optional_param('modid', null, PARAM_INT),
- 'tagid' => optional_param('tagid', null, PARAM_INT),
- 'tag' => optional_param('tag', null, PARAM_INT),
- 'search' => optional_param('search', null, PARAM_INT));
-
- foreach ($urlparams as $var => $val) {
- if (empty($val)) {
- unset($urlparams[$var]);
+
+ $canaddentries = true;
+ if ($modid = optional_param('modid', null, PARAM_INT)) {
+ if (!has_capability('moodle/blog:associatemodule', context_module::instance($modid))) {
+ $canaddentries = false;
+ }
+ }
+ if ($courseid = optional_param('courseid', null, PARAM_INT)) {
+ if (!has_capability('moodle/blog:associatecourse', context_course::instance($courseid))) {
+ $canaddentries = false;
}
}
- $addurl->params($urlparams);
- $addlink = '<div class="addbloglink">';
- $addlink .= '<a href="'.$addurl->out().'">'. $blogheaders['stradd'].'</a>';
- $addlink .= '</div>';
- echo $addlink;
+ if ($canaddentries) {
+ $addurl = new moodle_url("$CFG->wwwroot/blog/edit.php");
+ $urlparams = array('action' => 'add',
+ 'userid' => $userid,
+ 'courseid' => $courseid,
+ 'groupid' => optional_param('groupid', null, PARAM_INT),
+ 'modid' => $modid,
+ 'tagid' => optional_param('tagid', null, PARAM_INT),
+ 'tag' => optional_param('tag', null, PARAM_INT),
+ 'search' => optional_param('search', null, PARAM_INT));
+
+ foreach ($urlparams as $var => $val) {
+ if (empty($val)) {
+ unset($urlparams[$var]);
+ }
+ }
+ $addurl->params($urlparams);
+
+ $addlink = '<div class="addbloglink">';
+ $addlink .= '<a href="'.$addurl->out().'">'. $blogheaders['stradd'].'</a>';
+ $addlink .= '</div>';
+ echo $addlink;
+ }
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.