2009-09-24 07:29:14 +00:00
< ? php
2003-09-16 03:07:21 +00:00
/// This page lists all the instances of glossary in a particular course
/// Replace glossary with the name of your module
2009-09-24 07:29:14 +00:00
require_once ( " ../../config.php " );
require_once ( " lib.php " );
require_once ( " $CFG->libdir /rsslib.php " );
require_once ( " $CFG->dirroot /course/lib.php " );
2003-09-16 03:07:21 +00:00
2009-09-24 07:29:14 +00:00
$id = required_param ( 'id' , PARAM_INT ); // course
2003-09-16 03:07:21 +00:00
2010-01-16 15:39:56 +00:00
$PAGE -> set_url ( '/mod/glossary/index.php' , array ( 'id' => $id ));
2009-09-24 07:29:14 +00:00
if ( ! $course = $DB -> get_record ( 'course' , array ( 'id' => $id ))) {
print_error ( 'invalidcourseid' );
}
2003-09-16 03:07:21 +00:00
2009-09-24 07:29:14 +00:00
require_course_login ( $course );
2009-12-27 12:02:04 +00:00
$PAGE -> set_pagelayout ( 'incourse' );
2009-09-24 07:29:14 +00:00
$context = get_context_instance ( CONTEXT_COURSE , $course -> id );
2003-09-16 03:07:21 +00:00
2009-09-24 07:29:14 +00:00
add_to_log ( $course -> id , " glossary " , " view all " , " index.php?id= $course->id " , " " );
2003-09-16 03:07:21 +00:00
/// Get all required strings
2009-09-24 07:29:14 +00:00
$strglossarys = get_string ( " modulenameplural " , " glossary " );
$strglossary = get_string ( " modulename " , " glossary " );
$strrss = get_string ( " rss " );
2003-09-16 03:07:21 +00:00
/// Print the header
2009-09-24 07:29:14 +00:00
$PAGE -> navbar -> add ( $strglossarys , " index.php?id= $course->id " );
$PAGE -> set_title ( $strglossarys );
2010-05-28 06:38:17 +00:00
$PAGE -> set_heading ( $course -> fullname );
2009-09-24 07:29:14 +00:00
echo $OUTPUT -> header ();
2003-09-16 03:07:21 +00:00
/// Get all the appropriate data
2009-09-24 07:29:14 +00:00
if ( ! $glossarys = get_all_instances_in_course ( " glossary " , $course )) {
notice ( get_string ( 'thereareno' , 'moodle' , $strglossarys ), " ../../course/view.php?id= $course->id " );
die ;
}
2003-09-16 03:07:21 +00:00
2010-06-08 06:21:25 +00:00
$usesections = course_format_uses_sections ( $course -> format );
if ( $usesections ) {
$sections = get_all_sections ( $course -> id );
}
2003-09-16 03:07:21 +00:00
/// Print the list of instances (your module will probably extend this)
2009-09-24 07:29:14 +00:00
$timenow = time ();
2010-06-08 06:21:25 +00:00
$strsectionname = get_string ( 'sectionname' , 'format_' . $course -> format );
2009-09-24 07:29:14 +00:00
$strname = get_string ( " name " );
$strentries = get_string ( " entries " , " glossary " );
$table = new html_table ();
2010-06-08 06:21:25 +00:00
if ( $usesections ) {
2010-07-14 09:44:19 +00:00
$table -> head = array ( $strsectionname , $strname , $strentries );
2009-09-24 07:29:14 +00:00
$table -> align = array ( " CENTER " , " LEFT " , " CENTER " );
} else {
2010-07-14 09:44:19 +00:00
$table -> head = array ( $strname , $strentries );
2009-09-24 07:29:14 +00:00
$table -> align = array ( " LEFT " , " CENTER " );
}
if ( $show_rss = ( isset ( $CFG -> enablerssfeeds ) && isset ( $CFG -> glossary_enablerssfeeds ) &&
$CFG -> enablerssfeeds && $CFG -> glossary_enablerssfeeds )) {
$table -> head [] = $strrss ;
$table -> align [] = " CENTER " ;
}
$currentsection = " " ;
foreach ( $glossarys as $glossary ) {
if ( ! $glossary -> visible && has_capability ( 'moodle/course:viewhiddenactivities' , $context )) {
// Show dimmed if the mod is hidden.
$link = " <a class= \" dimmed \" href= \" view.php?id= $glossary->coursemodule\ " > " .format_string( $glossary->name ,true). " </ a > " ;
} else if ( $glossary -> visible ) {
// Show normal if the mod is visible.
$link = " <a href= \" view.php?id= $glossary->coursemodule\ " > " .format_string( $glossary->name ,true). " </ a > " ;
2003-09-16 03:07:21 +00:00
} else {
2009-09-24 07:29:14 +00:00
// Don't show the glossary.
continue ;
2003-09-16 03:07:21 +00:00
}
2009-09-24 07:29:14 +00:00
$printsection = " " ;
2010-06-08 06:21:25 +00:00
if ( $usesections ) {
if ( $glossary -> section !== $currentsection ) {
if ( $glossary -> section ) {
$printsection = get_section_name ( $course , $sections [ $glossary -> section ]);
}
if ( $currentsection !== " " ) {
$table -> data [] = 'hr' ;
}
$currentsection = $glossary -> section ;
2004-01-26 12:21:44 +00:00
}
2009-09-24 07:29:14 +00:00
}
2003-09-16 03:07:21 +00:00
2009-09-24 07:29:14 +00:00
// TODO: count only approved if not allowed to see them
2004-08-08 18:44:45 +00:00
2009-09-24 07:29:14 +00:00
$count = $DB -> count_records_sql ( " SELECT COUNT(*) FROM { glossary_entries} WHERE (glossaryid = ? OR sourceglossaryid = ?) " , array ( $glossary -> id , $glossary -> id ));
2004-08-08 18:44:45 +00:00
2009-09-24 07:29:14 +00:00
//If this glossary has RSS activated, calculate it
if ( $show_rss ) {
$rsslink = '' ;
if ( $glossary -> rsstype and $glossary -> rssarticles ) {
//Calculate the tolltip text
$tooltiptext = get_string ( " rsssubscriberss " , " glossary " , format_string ( $glossary -> name ));
2010-03-31 07:41:31 +00:00
if ( ! isloggedin ()) {
2009-09-24 07:29:14 +00:00
$userid = 0 ;
} else {
$userid = $USER -> id ;
}
//Get html code for RSS link
2010-07-19 10:57:52 +00:00
$rsslink = rss_get_link ( $context -> id , $userid , 'mod_glossary' , $glossary -> id , $tooltiptext );
2003-09-16 03:07:21 +00:00
}
2009-09-24 07:29:14 +00:00
}
2004-08-08 18:44:45 +00:00
2010-06-08 06:21:25 +00:00
if ( $usesections ) {
2009-09-24 07:29:14 +00:00
$linedata = array ( $printsection , $link , $count );
} else {
$linedata = array ( $link , $count );
2003-09-16 03:07:21 +00:00
}
2009-09-24 07:29:14 +00:00
if ( $show_rss ) {
$linedata [] = $rsslink ;
}
$table -> data [] = $linedata ;
}
echo " <br /> " ;
2003-09-16 03:07:21 +00:00
2010-03-20 22:15:54 +00:00
echo html_writer :: table ( $table );
2003-09-16 03:07:21 +00:00
/// Finish the page
2009-09-24 07:29:14 +00:00
echo $OUTPUT -> footer ();
2003-09-16 03:07:21 +00:00