### Eclipse Workspace Patch 1.0 #P moodle_MAIN_CVS_CORE_19 Index: mod/glossary/lib.php =================================================================== RCS file: /cvsroot/moodle/moodle/mod/glossary/lib.php,v retrieving revision 1.193.2.6 diff -u -r1.193.2.6 lib.php --- mod/glossary/lib.php 24 Jan 2008 20:29:35 -0000 1.193.2.6 +++ mod/glossary/lib.php 1 Feb 2008 10:25:46 -0000 @@ -2328,4 +2328,99 @@ return $status; } +/** + * This function prints the recent activity (since current user's last access + * to course) for specified courses. + * @param array $courses Array of courses to print activity for. + * @param string by reference $htmlarray Array of html snippets for display some + * -where, which this function adds its new html to. + */ +function glossary_print_overview($courses,&$htmlarray) { + global $USER, $CFG; + + $LIKE = sql_ilike(); + + if (empty($courses) || !is_array($courses) || count($courses) == 0) { + return array(); + } + + if (!$glossaries = get_all_instances_in_courses('glossary',$courses)) { + return; + } + + // get all glossary logs in ONE query (much better!) + $sql = "SELECT instance,cmid,l.course,COUNT(l.id) as count FROM {$CFG->prefix}log l " + ." JOIN {$CFG->prefix}course_modules cm ON cm.id = cmid " + ." WHERE ("; + foreach ($courses as $course) { + $sql .= '(l.course = '.$course->id.' AND l.time > '.$course->lastaccess.') OR '; + } + $sql = substr($sql,0,-3); // take off the last OR + + //Ignore comment actions for now, only entries. + $sql .= ") AND l.module = 'glossary' AND action in('add entry','update entry') " + ." AND userid != ".$USER->id." GROUP BY cmid,l.course,instance"; + + if (!$new = get_records_sql($sql)) { + $new = array(); // avoid warnings + } + + $strglossarys = get_string('modulename','glossary'); + + $site = get_site(); + if( count( $courses ) == 1 && isset( $courses[$site->id] ) ){ + + $strnumrespsince1 = get_string('overviewnumentrylog1','glossary'); + $strnumrespsince = get_string('overviewnumentrylog','glossary'); + + }else{ + + $strnumrespsince1 = get_string('overviewnumentryvw1','glossary'); + $strnumrespsince = get_string('overviewnumentryvw','glossary'); + + } + + //Go through the list of all glossarys build previously, and check whether + //they have had any activity. + foreach ($glossaries as $glossary) { + + if (array_key_exists($glossary->id, $new) && !empty($new[$glossary->id])) { + $count = $new[$glossary->id]->count; + + if( $count > 0 ){ + + if( $count == 1 ){ + + $strresp = $strnumrespsince1; + + }else{ + + $strresp = $strnumrespsince; + + } + + $str = '
'. + $strglossarys.': '. + $glossary->name.'
'; + $str .= '
'; + $str .= $count.' '.$strresp; + $str .= '
'; + + if (!array_key_exists($glossary->course,$htmlarray)) { + $htmlarray[$glossary->course] = array(); + } + if (!array_key_exists('glossary',$htmlarray[$glossary->course])) { + $htmlarray[$glossary->course]['glossary'] = ''; // initialize, avoid warnings + } + $htmlarray[$glossary->course]['glossary'] .= $str; + + } + + } + + } + +} + ?>