Note: You are currently viewing documentation for Moodle 1.9. Up-to-date documentation for the latest stable version is available here: Make News on Front Page viewable to Teachers only.

Make News on Front Page viewable to Teachers only: Difference between revisions

From MoodleDocs
No edit summary
No edit summary
 
(10 intermediate revisions by 3 users not shown)
Line 2: Line 2:


  case FRONTPAGENEWS:
  case FRONTPAGENEWS:
  ''if (isteacherinanycourse()) {''
  <font color="#cc0000">if (isteacherinanycourse()) {</font>
  if ($SITE->newsitems) { // Print forums only when needed
  if ($SITE->newsitems) { // Print forums only when needed
  require_once($CFG->dirroot .'/mod/forum/lib.php');
  require_once($CFG->dirroot .'/mod/forum/lib.php');
 
  if (! $newsforum = forum_get_course_forum($SITE->id, 'news')) {
  if (! $newsforum = forum_get_course_forum($SITE->id, 'news')) {
  error('Could not find or create a main news forum for the site');
  error('Could not find or create a main news forum for the site');
  }
  }
 
  if (isset($USER->id)) {
  if (isset($USER->id)) {
  $SESSION->fromdiscussion = $CFG->wwwroot;
  $SESSION->fromdiscussion = $CFG->wwwroot;
Line 18: Line 18:
  }
  }
  $headertext = '&lt;table width="100%" border="0" cellspacing="0" cellpadding="0">&lt;tr>'.
  $headertext = '&lt;table width="100%" border="0" cellspacing="0" cellpadding="0">&lt;tr>'.
  '<td><div class="title">'.$newsforum->name.'</div></td>'.
  '&lt;td&gt;&lt;div class="title"&gt;'.$newsforum->name.'&lt;/div&gt;&lt;/td&gt;'.
  '<td><div class="link"><a href="mod/forum/subscribe.php?id='.$newsforum->id.'">'.$subtext.'</a></div></td>'.
  '&lt;td&gt;&lt;div class="link"&gt;&lt;a href="mod/forum/subscribe.php?id='.$newsforum->id.'"&gt;'.$subtext.'&lt;/a&gt;&lt;/div&gt;&lt;/td&gt;'.
  '</tr></table>';
  '&lt;/tr&gt;&lt;/table&gt;';
  } else {
  } else {
  $headertext = $newsforum->name;
  $headertext = $newsforum->name;
  }
  }
 
  print_heading_block($headertext);
  print_heading_block($headertext);
  forum_print_latest_discussions($SITE, $newsforum, $SITE->newsitems);
  forum_print_latest_discussions($SITE, $newsforum, $SITE->newsitems);
  }
  }
  ''}''
  <font color="#cc0000">}</font>
  break;
  break;
The lines in red are the lines you'll need to add.
'''Moodle 2.0'''
It appears that this tip will not work in Moodle 2.0 - you will get an error message saying
  <font color="#cc0000">"Function If (isteacherinanycourse()) is removed, use Capabilities instead"</font>. 
This implies that Moodle 2.0 allows you to set that as a Role Capability in the Front Page. To accomplish this, you will need a good understanding of Capabilities in Moodle 2.0. 
[[Category:Contributed code]]

Latest revision as of 12:40, 2 October 2010

In /index.php, look for case FRONTPAGENEWS:

case FRONTPAGENEWS:
if (isteacherinanycourse()) {
if ($SITE->newsitems) { // Print forums only when needed
require_once($CFG->dirroot .'/mod/forum/lib.php');

if (! $newsforum = forum_get_course_forum($SITE->id, 'news')) {
error('Could not find or create a main news forum for the site');
}

if (isset($USER->id)) {
$SESSION->fromdiscussion = $CFG->wwwroot;
if (forum_is_subscribed($USER->id, $newsforum->id)) {
$subtext = get_string('unsubscribe', 'forum');
} else {
$subtext = get_string('subscribe', 'forum');
}
$headertext = '<table width="100%" border="0" cellspacing="0" cellpadding="0"><tr>'.
'<td><div class="title">'.$newsforum->name.'</div></td>'.
'<td><div class="link"><a href="mod/forum/subscribe.php?id='.$newsforum->id.'">'.$subtext.'</a></div></td>'.
'</tr></table>';
} else {
$headertext = $newsforum->name;
}

print_heading_block($headertext);
forum_print_latest_discussions($SITE, $newsforum, $SITE->newsitems);
}
}
break;

The lines in red are the lines you'll need to add.

Moodle 2.0 It appears that this tip will not work in Moodle 2.0 - you will get an error message saying

 "Function If (isteacherinanycourse()) is removed, use Capabilities instead".  

This implies that Moodle 2.0 allows you to set that as a Role Capability in the Front Page. To accomplish this, you will need a good understanding of Capabilities in Moodle 2.0.