Skip to content

Commit

Permalink
MDL-30482 - Glossary - Adding capability to other areas using glossary
Browse files Browse the repository at this point in the history
  • Loading branch information
jsnfwlr authored and Aparup Banerjee committed Dec 14, 2011
1 parent d4f2755 commit aa423bd
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 13 deletions.
4 changes: 4 additions & 0 deletions blocks/glossary_random/block_glossary_random.php
Expand Up @@ -118,6 +118,10 @@ function instance_allow_multiple() {
function get_content() {
global $USER, $CFG, $DB;

if (!has_capability('mod/glossary:view', $this->context)) {
return "";
}

if (empty($this->config->glossary)) {
$this->content->text = get_string('notyetconfigured','block_glossary_random');
$this->content->footer = '';
Expand Down
2 changes: 1 addition & 1 deletion filter/glossary/filter.php
Expand Up @@ -57,7 +57,7 @@ public function filter($text, array $options = array()) {
$nothingtodo = false;
}

if ($nothingtodo === true) {
if (($nothingtodo === true) || (!has_capability('mod/glossary:view', $this->context))) {
return $text;
}

Expand Down
4 changes: 2 additions & 2 deletions mod/glossary/db/access.php
Expand Up @@ -30,7 +30,7 @@

$capabilities = array(

'mod/glossary:read' => array(
'mod/glossary:view' => array(

'captype' => 'read',
'contextlevel' => CONTEXT_MODULE,
Expand All @@ -41,7 +41,7 @@
'editingteacher' => CAP_ALLOW,
'manager' => CAP_ALLOW
)
),
),


'mod/glossary:write' => array(
Expand Down
2 changes: 1 addition & 1 deletion mod/glossary/lang/en/glossary.php
Expand Up @@ -178,7 +178,7 @@
$string['glossary:managecomments'] = 'Manage comments';
$string['glossary:manageentries'] = 'Manage entries';
$string['glossary:rate'] = 'Rate entries';
$string['glossary:read'] = 'Read entries';
$string['glossary:view'] = 'View entries';
$string['glossarytype'] = 'Glossary type';
$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.';
$string['glossary:view'] = 'View glossary';
Expand Down
17 changes: 11 additions & 6 deletions mod/glossary/lib.php
Expand Up @@ -323,7 +323,7 @@ function glossary_user_complete($course, $user, $mod, $glossary) {
* @return bool
*/
function glossary_print_recent_activity($course, $viewfullnames, $timestart) {
global $CFG, $USER, $DB, $OUTPUT;
global $CFG, $USER, $DB, $OUTPUT, $PAGE;

//TODO: use timestamp in approved field instead of changing timemodified when approving in 2.0
if (!defined('GLOSSARY_RECENT_ACTIVITY_LIMIT')) {
Expand Down Expand Up @@ -351,13 +351,17 @@ function glossary_print_recent_activity($course, $viewfullnames, $timestart) {
$approvals = array();
foreach ($ids as $glinstanceid => $glcmid) {
$context = get_context_instance(CONTEXT_MODULE, $glcmid);
if (!has_capability('mod/glossary:view', $context)) {
continue;
}
// 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 = :glsid'.$glinstanceid.' ';
} else {
$approvals[] = ' (ge.approved = 1 AND ge.glossaryid = :glsid'.$glinstanceid.') ';
}
$params['glsid'.$glinstanceid] = $glinstanceid;

}

$selectsql = 'SELECT ge.id, ge.concept, ge.approved, ge.timemodified, ge.glossaryid,
Expand All @@ -369,11 +373,12 @@ function glossary_print_recent_activity($course, $viewfullnames, $timestart) {
$fromsql = implode($joins, "\n");

$params['timestart'] = $timestart;
$clausesql = ' WHERE ge.timemodified > :timestart AND (';
$approvalsql = implode($approvals, ' OR ');

$ordersql = ') ORDER BY ge.timemodified ASC';
$clausesql = ' WHERE ge.timemodified > :timestart ';

if (count($approval) > 0) {
$approvalsql = 'AND ('. implode($approvals, ' OR ') .') ';
}
$ordersql = 'ORDER BY ge.timemodified ASC';
$entries = $DB->get_records_sql($selectsql.$fromsql.$clausesql.$approvalsql.$ordersql, $params, 0, (GLOSSARY_RECENT_ACTIVITY_LIMIT+1));

if (empty($entries)) {
Expand Down Expand Up @@ -2771,7 +2776,7 @@ function glossary_extend_settings_navigation(settings_navigation $settings, navi

$glossary = $DB->get_record('glossary', array("id" => $PAGE->cm->instance));

if (!empty($CFG->enablerssfeeds) && !empty($CFG->glossary_enablerssfeeds) && $glossary->rsstype && $glossary->rssarticles && can_access_course($PAGE->course, $USER)) {
if (!empty($CFG->enablerssfeeds) && !empty($CFG->glossary_enablerssfeeds) && $glossary->rsstype && $glossary->rssarticles && has_capability('mod/glossary:view', $PAGE->cm->context)) {
require_once("$CFG->libdir/rsslib.php");

$string = get_string('rsstype','forum');
Expand Down
2 changes: 1 addition & 1 deletion mod/glossary/rsslib.php
Expand Up @@ -23,7 +23,7 @@ function glossary_rss_get_feed($context, $args) {
$course = $DB->get_record('course', array('id'=>$cm->course), '*', MUST_EXIST);
}
//context id from db should match the submitted one
if ($context->id != $modcontext->id || !has_capability('mod/glossary:read', $modcontext)) {
if ($context->id != $modcontext->id || !has_capability('mod/glossary:view', $modcontext)) {
return null;
}
}
Expand Down
2 changes: 1 addition & 1 deletion mod/glossary/version.php
Expand Up @@ -25,7 +25,7 @@

defined('MOODLE_INTERNAL') || die();

$module->version = 2011112900; // The current module version (Date: YYYYMMDDXX)
$module->version = 2011121400; // The current module version (Date: YYYYMMDDXX)
$module->requires = 2011112900; // Requires this Moodle version
$module->component = 'mod_glossary'; // Full name of the plugin (used for diagnostics)
$module->cron = 0;
2 changes: 1 addition & 1 deletion mod/glossary/view.php
Expand Up @@ -49,7 +49,7 @@

require_course_login($course->id, true, $cm);
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
require_capability('mod/glossary:read', $context);
require_capability('mod/glossary:view', $context);

// Prepare format_string/text options
$fmtoptions = array(
Expand Down

0 comments on commit aa423bd

Please sign in to comment.