mirror of
https://github.com/moodle/moodle.git
synced 2025-07-12 18:06:41 +02:00
MDL-30482 - Glossary - Adding capability to other areas using glossary
This commit is contained in:
@ -118,6 +118,10 @@ class block_glossary_random extends block_base {
|
|||||||
function get_content() {
|
function get_content() {
|
||||||
global $USER, $CFG, $DB;
|
global $USER, $CFG, $DB;
|
||||||
|
|
||||||
|
if (!has_capability('mod/glossary:view', $this->context)) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
if (empty($this->config->glossary)) {
|
if (empty($this->config->glossary)) {
|
||||||
$this->content = new stdClass();
|
$this->content = new stdClass();
|
||||||
$this->content->text = get_string('notyetconfigured','block_glossary_random');
|
$this->content->text = get_string('notyetconfigured','block_glossary_random');
|
||||||
|
@ -57,7 +57,7 @@ class filter_glossary extends moodle_text_filter {
|
|||||||
$nothingtodo = false;
|
$nothingtodo = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($nothingtodo === true) {
|
if (($nothingtodo === true) || (!has_capability('mod/glossary:view', $this->context))) {
|
||||||
return $text;
|
return $text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,6 +26,21 @@ defined('MOODLE_INTERNAL') || die();
|
|||||||
|
|
||||||
$capabilities = array(
|
$capabilities = array(
|
||||||
|
|
||||||
|
'mod/glossary:view' => array(
|
||||||
|
|
||||||
|
'captype' => 'read',
|
||||||
|
'contextlevel' => CONTEXT_MODULE,
|
||||||
|
'archetypes' => array(
|
||||||
|
'frontpage' => CAP_ALLOW,
|
||||||
|
'guest' => CAP_ALLOW,
|
||||||
|
'student' => CAP_ALLOW,
|
||||||
|
'teacher' => CAP_ALLOW,
|
||||||
|
'editingteacher' => CAP_ALLOW,
|
||||||
|
'manager' => CAP_ALLOW
|
||||||
|
)
|
||||||
|
),
|
||||||
|
|
||||||
|
|
||||||
'mod/glossary:write' => array(
|
'mod/glossary:write' => array(
|
||||||
|
|
||||||
'riskbitmask' => RISK_SPAM,
|
'riskbitmask' => RISK_SPAM,
|
||||||
|
@ -181,6 +181,7 @@ $string['glossary:managecategories'] = 'Manage categories';
|
|||||||
$string['glossary:managecomments'] = 'Manage comments';
|
$string['glossary:managecomments'] = 'Manage comments';
|
||||||
$string['glossary:manageentries'] = 'Manage entries';
|
$string['glossary:manageentries'] = 'Manage entries';
|
||||||
$string['glossary:rate'] = 'Rate entries';
|
$string['glossary:rate'] = 'Rate entries';
|
||||||
|
$string['glossary:view'] = 'View entries';
|
||||||
$string['glossarytype'] = 'Glossary type';
|
$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['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';
|
$string['glossary:view'] = 'View glossary';
|
||||||
|
@ -323,7 +323,7 @@ function glossary_user_complete($course, $user, $mod, $glossary) {
|
|||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
function glossary_print_recent_activity($course, $viewfullnames, $timestart) {
|
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
|
//TODO: use timestamp in approved field instead of changing timemodified when approving in 2.0
|
||||||
if (!defined('GLOSSARY_RECENT_ACTIVITY_LIMIT')) {
|
if (!defined('GLOSSARY_RECENT_ACTIVITY_LIMIT')) {
|
||||||
@ -351,6 +351,9 @@ function glossary_print_recent_activity($course, $viewfullnames, $timestart) {
|
|||||||
$approvals = array();
|
$approvals = array();
|
||||||
foreach ($ids as $glinstanceid => $glcmid) {
|
foreach ($ids as $glinstanceid => $glcmid) {
|
||||||
$context = get_context_instance(CONTEXT_MODULE, $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.
|
// get records glossary entries that are approved if user has no capability to approve entries.
|
||||||
if (has_capability('mod/glossary:approve', $context)) {
|
if (has_capability('mod/glossary:approve', $context)) {
|
||||||
$approvals[] = ' ge.glossaryid = :glsid'.$glinstanceid.' ';
|
$approvals[] = ' ge.glossaryid = :glsid'.$glinstanceid.' ';
|
||||||
@ -369,11 +372,14 @@ function glossary_print_recent_activity($course, $viewfullnames, $timestart) {
|
|||||||
$fromsql = implode($joins, "\n");
|
$fromsql = implode($joins, "\n");
|
||||||
|
|
||||||
$params['timestart'] = $timestart;
|
$params['timestart'] = $timestart;
|
||||||
$clausesql = ' WHERE ge.timemodified > :timestart AND (';
|
$clausesql = ' WHERE ge.timemodified > :timestart ';
|
||||||
$approvalsql = implode($approvals, ' OR ');
|
|
||||||
|
|
||||||
$ordersql = ') ORDER BY ge.timemodified ASC';
|
|
||||||
|
|
||||||
|
if (count($approvals) > 0) {
|
||||||
|
$approvalsql = 'AND ('. implode($approvals, ' OR ') .') ';
|
||||||
|
} else {
|
||||||
|
$approvalsql = '';
|
||||||
|
}
|
||||||
|
$ordersql = 'ORDER BY ge.timemodified ASC';
|
||||||
$entries = $DB->get_records_sql($selectsql.$fromsql.$clausesql.$approvalsql.$ordersql, $params, 0, (GLOSSARY_RECENT_ACTIVITY_LIMIT+1));
|
$entries = $DB->get_records_sql($selectsql.$fromsql.$clausesql.$approvalsql.$ordersql, $params, 0, (GLOSSARY_RECENT_ACTIVITY_LIMIT+1));
|
||||||
|
|
||||||
if (empty($entries)) {
|
if (empty($entries)) {
|
||||||
@ -2832,7 +2838,7 @@ function glossary_extend_settings_navigation(settings_navigation $settings, navi
|
|||||||
|
|
||||||
$glossary = $DB->get_record('glossary', array("id" => $PAGE->cm->instance));
|
$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");
|
require_once("$CFG->libdir/rsslib.php");
|
||||||
|
|
||||||
$string = get_string('rsstype','forum');
|
$string = get_string('rsstype','forum');
|
||||||
|
@ -52,8 +52,7 @@
|
|||||||
$course = $DB->get_record('course', array('id'=>$cm->course), '*', MUST_EXIST);
|
$course = $DB->get_record('course', array('id'=>$cm->course), '*', MUST_EXIST);
|
||||||
}
|
}
|
||||||
//context id from db should match the submitted one
|
//context id from db should match the submitted one
|
||||||
//no specific capability required to view glossary entries so just check user is enrolled
|
if ($context->id != $modcontext->id || !has_capability('mod/glossary:view', $modcontext)) {
|
||||||
if ($context->id != $modcontext->id || !can_access_course($course, $USER)) {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
|
|
||||||
defined('MOODLE_INTERNAL') || die();
|
defined('MOODLE_INTERNAL') || die();
|
||||||
|
|
||||||
$module->version = 2012022000; // The current module version (Date: YYYYMMDDXX)
|
$module->version = 2012031200; // The current module version (Date: YYYYMMDDXX)
|
||||||
$module->requires = 2011112900; // Requires this Moodle version
|
$module->requires = 2011112900; // Requires this Moodle version
|
||||||
$module->component = 'mod_glossary'; // Full name of the plugin (used for diagnostics)
|
$module->component = 'mod_glossary'; // Full name of the plugin (used for diagnostics)
|
||||||
$module->cron = 0;
|
$module->cron = 0;
|
||||||
|
@ -48,7 +48,8 @@ if (!empty($id)) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
require_course_login($course->id, true, $cm);
|
require_course_login($course->id, true, $cm);
|
||||||
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
$context = context_module::instance($cm->id);
|
||||||
|
require_capability('mod/glossary:view', $context);
|
||||||
|
|
||||||
// Prepare format_string/text options
|
// Prepare format_string/text options
|
||||||
$fmtoptions = array(
|
$fmtoptions = array(
|
||||||
|
Reference in New Issue
Block a user