Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

MDL-30482 - Glossary - Adding capability to other areas using glossary

  • Loading branch information...
commit aa423bd0e6a7b6c1f6cee4f95b46300e412551b4 1 parent d4f2755
Jason Fowler phalacee authored nebgor committed
4 blocks/glossary_random/block_glossary_random.php
@@ -118,6 +118,10 @@ function instance_allow_multiple() {
118 118 function get_content() {
119 119 global $USER, $CFG, $DB;
120 120
  121 + if (!has_capability('mod/glossary:view', $this->context)) {
  122 + return "";
  123 + }
  124 +
121 125 if (empty($this->config->glossary)) {
122 126 $this->content->text = get_string('notyetconfigured','block_glossary_random');
123 127 $this->content->footer = '';
2  filter/glossary/filter.php
@@ -57,7 +57,7 @@ public function filter($text, array $options = array()) {
57 57 $nothingtodo = false;
58 58 }
59 59
60   - if ($nothingtodo === true) {
  60 + if (($nothingtodo === true) || (!has_capability('mod/glossary:view', $this->context))) {
61 61 return $text;
62 62 }
63 63
4 mod/glossary/db/access.php
@@ -30,7 +30,7 @@
30 30
31 31 $capabilities = array(
32 32
33   - 'mod/glossary:read' => array(
  33 + 'mod/glossary:view' => array(
34 34
35 35 'captype' => 'read',
36 36 'contextlevel' => CONTEXT_MODULE,
@@ -41,7 +41,7 @@
41 41 'editingteacher' => CAP_ALLOW,
42 42 'manager' => CAP_ALLOW
43 43 )
44   - ),
  44 + ),
45 45
46 46
47 47 'mod/glossary:write' => array(
2  mod/glossary/lang/en/glossary.php
@@ -178,7 +178,7 @@
178 178 $string['glossary:managecomments'] = 'Manage comments';
179 179 $string['glossary:manageentries'] = 'Manage entries';
180 180 $string['glossary:rate'] = 'Rate entries';
181   -$string['glossary:read'] = 'Read entries';
  181 +$string['glossary:view'] = 'View entries';
182 182 $string['glossarytype'] = 'Glossary type';
183 183 $string['glossarytype_help'] = 'A main glossary is a glossary in which entries from secondary glossaries can be imported. There can only be one main glossary in a course. if glossary entry import is not required, all glossaries in the course can be secondary glossaries.';
184 184 $string['glossary:view'] = 'View glossary';
17 mod/glossary/lib.php
@@ -323,7 +323,7 @@ function glossary_user_complete($course, $user, $mod, $glossary) {
323 323 * @return bool
324 324 */
325 325 function glossary_print_recent_activity($course, $viewfullnames, $timestart) {
326   - global $CFG, $USER, $DB, $OUTPUT;
  326 + global $CFG, $USER, $DB, $OUTPUT, $PAGE;
327 327
328 328 //TODO: use timestamp in approved field instead of changing timemodified when approving in 2.0
329 329 if (!defined('GLOSSARY_RECENT_ACTIVITY_LIMIT')) {
@@ -351,6 +351,9 @@ function glossary_print_recent_activity($course, $viewfullnames, $timestart) {
351 351 $approvals = array();
352 352 foreach ($ids as $glinstanceid => $glcmid) {
353 353 $context = get_context_instance(CONTEXT_MODULE, $glcmid);
  354 + if (!has_capability('mod/glossary:view', $context)) {
  355 + continue;
  356 + }
354 357 // get records glossary entries that are approved if user has no capability to approve entries.
355 358 if (has_capability('mod/glossary:approve', $context)) {
356 359 $approvals[] = ' ge.glossaryid = :glsid'.$glinstanceid.' ';
@@ -358,6 +361,7 @@ function glossary_print_recent_activity($course, $viewfullnames, $timestart) {
358 361 $approvals[] = ' (ge.approved = 1 AND ge.glossaryid = :glsid'.$glinstanceid.') ';
359 362 }
360 363 $params['glsid'.$glinstanceid] = $glinstanceid;
  364 +
361 365 }
362 366
363 367 $selectsql = 'SELECT ge.id, ge.concept, ge.approved, ge.timemodified, ge.glossaryid,
@@ -369,11 +373,12 @@ function glossary_print_recent_activity($course, $viewfullnames, $timestart) {
369 373 $fromsql = implode($joins, "\n");
370 374
371 375 $params['timestart'] = $timestart;
372   - $clausesql = ' WHERE ge.timemodified > :timestart AND (';
373   - $approvalsql = implode($approvals, ' OR ');
374   -
375   - $ordersql = ') ORDER BY ge.timemodified ASC';
  376 + $clausesql = ' WHERE ge.timemodified > :timestart ';
376 377
  378 + if (count($approval) > 0) {
  379 + $approvalsql = 'AND ('. implode($approvals, ' OR ') .') ';
  380 + }
  381 + $ordersql = 'ORDER BY ge.timemodified ASC';
377 382 $entries = $DB->get_records_sql($selectsql.$fromsql.$clausesql.$approvalsql.$ordersql, $params, 0, (GLOSSARY_RECENT_ACTIVITY_LIMIT+1));
378 383
379 384 if (empty($entries)) {
@@ -2771,7 +2776,7 @@ function glossary_extend_settings_navigation(settings_navigation $settings, navi
2771 2776
2772 2777 $glossary = $DB->get_record('glossary', array("id" => $PAGE->cm->instance));
2773 2778
2774   - if (!empty($CFG->enablerssfeeds) && !empty($CFG->glossary_enablerssfeeds) && $glossary->rsstype && $glossary->rssarticles && can_access_course($PAGE->course, $USER)) {
  2779 + if (!empty($CFG->enablerssfeeds) && !empty($CFG->glossary_enablerssfeeds) && $glossary->rsstype && $glossary->rssarticles && has_capability('mod/glossary:view', $PAGE->cm->context)) {
2775 2780 require_once("$CFG->libdir/rsslib.php");
2776 2781
2777 2782 $string = get_string('rsstype','forum');
2  mod/glossary/rsslib.php
@@ -23,7 +23,7 @@ function glossary_rss_get_feed($context, $args) {
23 23 $course = $DB->get_record('course', array('id'=>$cm->course), '*', MUST_EXIST);
24 24 }
25 25 //context id from db should match the submitted one
26   - if ($context->id != $modcontext->id || !has_capability('mod/glossary:read', $modcontext)) {
  26 + if ($context->id != $modcontext->id || !has_capability('mod/glossary:view', $modcontext)) {
27 27 return null;
28 28 }
29 29 }
2  mod/glossary/version.php
@@ -25,7 +25,7 @@
25 25
26 26 defined('MOODLE_INTERNAL') || die();
27 27
28   -$module->version = 2011112900; // The current module version (Date: YYYYMMDDXX)
  28 +$module->version = 2011121400; // The current module version (Date: YYYYMMDDXX)
29 29 $module->requires = 2011112900; // Requires this Moodle version
30 30 $module->component = 'mod_glossary'; // Full name of the plugin (used for diagnostics)
31 31 $module->cron = 0;
2  mod/glossary/view.php
@@ -49,7 +49,7 @@
49 49
50 50 require_course_login($course->id, true, $cm);
51 51 $context = get_context_instance(CONTEXT_MODULE, $cm->id);
52   -require_capability('mod/glossary:read', $context);
  52 +require_capability('mod/glossary:view', $context);
53 53
54 54 // Prepare format_string/text options
55 55 $fmtoptions = array(

0 comments on commit aa423bd

Please sign in to comment.
Something went wrong with that request. Please try again.