diff --git a/lang/en_utf8/glossary.php b/lang/en_utf8/glossary.php index aab631a0ec8..fe05a4b2e2d 100644 --- a/lang/en_utf8/glossary.php +++ b/lang/en_utf8/glossary.php @@ -12,6 +12,7 @@ $string['allowcomments'] = 'Allow comments on entries'; $string['allowduplicatedentries'] = 'Duplicated entries allowed'; $string['allowprintview'] = 'Allow print view'; $string['allowratings'] = 'Allow entries to be rated?'; +$string['andmorenewentries'] = 'and {$a} more new entries.'; $string['answer'] = 'Answer'; $string['approve'] = 'Approve'; $string['areyousuredelete'] = 'Are you sure you want to delete this entry?'; diff --git a/mod/glossary/lib.php b/mod/glossary/lib.php index 9de8f0bda92..4a6095a0f84 100644 --- a/mod/glossary/lib.php +++ b/mod/glossary/lib.php @@ -242,11 +242,14 @@ function glossary_print_recent_activity($course, $viewfullnames, $timestart) { /// Return true if there was output, or false is there was none. global $CFG, $USER; - //TODO: use timestamp in approved field instead of changing timemodified when approving in 2.0 + if (!defined('GLOSSARY_RECENT_ACTIVITY_LIMIT')) { + define('GLOSSARY_RECENT_ACTIVITY_LIMIT', 50); + } $modinfo = get_fast_modinfo($course); $ids = array(); + foreach ($modinfo->cms as $cm) { if ($cm->modname != 'glossary') { continue; @@ -254,58 +257,67 @@ function glossary_print_recent_activity($course, $viewfullnames, $timestart) { if (!$cm->uservisible) { continue; } - $ids[$cm->instance] = $cm->instance; + $ids[$cm->instance] = $cm->id; } if (!$ids) { return false; } - $glist = implode(',', $ids); // there should not be hundreds of glossaries in one course, right? - - if (!$entries = get_records_sql("SELECT ge.id, ge.concept, ge.approved, ge.timemodified, ge.glossaryid, - ge.userid, u.firstname, u.lastname, u.email, u.picture - FROM {$CFG->prefix}glossary_entries ge - JOIN {$CFG->prefix}user u ON u.id = ge.userid - WHERE ge.glossaryid IN ($glist) AND ge.timemodified > $timestart - ORDER BY ge.timemodified ASC")) { - return false; - } - - $editor = array(); - - foreach ($entries as $entryid=>$entry) { - if ($entry->approved) { - continue; - } - - if (!isset($editor[$entry->glossaryid])) { - $editor[$entry->glossaryid] = has_capability('mod/glossary:approve', get_context_instance(CONTEXT_MODULE, $modinfo->instances['glossary'][$entry->glossaryid]->id)); - } - - if (!$editor[$entry->glossaryid]) { - unset($entries[$entryid]); + // generate list of approval capabilities for all glossaries in the course. + $approvals = array(); + foreach ($ids as $glinstanceid => $glcmid) { + $context = get_context_instance(CONTEXT_MODULE, $glcmid); + // get records glossary entries that are approved if user has no capability to approve entries. + if (has_capability('mod/glossary:approve', $context)) { + $approvals[] = ' ge.glossaryid = '.$glinstanceid.' '; + } else { + $approvals[] = ' (ge.approved = 1 AND ge.glossaryid = '.$glinstanceid.') '; } } - if (!$entries) { + $selectsql = "SELECT ge.id, ge.concept, ge.approved, ge.timemodified, ge.glossaryid, + ge.userid, u.firstname, u.lastname, u.email, u.picture "; + $countsql = "SELECT COUNT(*)"; + + $joins = array(" FROM {$CFG->prefix}glossary_entries ge "); + $joins[] = "JOIN {$CFG->prefix}user u ON u.id = ge.userid "; + $fromsql = implode($joins, "\n"); + + $clausesql = ' WHERE ge.timemodified > '.$timestart.' AND ('; + $approvalsql = implode($approvals, ' OR '); + + $ordersql = ') ORDER BY ge.timemodified ASC'; + $entries = get_records_sql($selectsql.$fromsql.$clausesql.$approvalsql.$ordersql, 0, (GLOSSARY_RECENT_ACTIVITY_LIMIT+1)); + $fromsql = implode($joins, "\n"); + if (empty($entries)) { return false; } print_headline(get_string('newentries', 'glossary').':'); $strftimerecent = get_string('strftimerecent'); + $entrycount = 0; foreach ($entries as $entry) { - $link = $CFG->wwwroot.'/mod/glossary/view.php?g='.$entry->glossaryid.'&mode=entry&hook='.$entry->id; - if ($entry->approved) { - $dimmed = ''; + if ($entrycount < GLOSSARY_RECENT_ACTIVITY_LIMIT) { + if ($entry->approved) { + $dimmed = ''; + $urlparams = array('g' => $entry->glossaryid, 'mode' => 'entry', 'hook' => $entry->id); + } else { + $dimmed = ' dimmed_text'; + $urlparams = array('id' => $ids[$entry->glossaryid], 'mode' => 'approval', 'hook' => format_text($entry->concept, true)); + } + $link = new moodle_url($CFG->wwwroot.'/mod/glossary/view.php' , $urlparams); + echo '