Skip to content
Browse files

MDL-26464: remove 'add entry' link on setting block when it reachs th…

…e max number of records. Link removal does not apply to user who has data:manageentries capability (eg: teacher).
  • Loading branch information...
1 parent c096042 commit e4e96115702bb6bc43f6cbb5e306cafdb54f2efe @rwijaya rwijaya committed Mar 11, 2011
Showing with 19 additions and 9 deletions.
  1. +2 −2 mod/data/edit.php
  2. +16 −6 mod/data/lib.php
  3. +1 −1 mod/data/tabs.php
View
4 mod/data/edit.php
@@ -190,7 +190,7 @@
} else { /// Add some new records
- if (!data_user_can_add_entry($data, $currentgroup, $groupmode)) {
+ if (!data_user_can_add_entry($data, $currentgroup, $groupmode, $context)) {
print_error('cannotadd', 'data');
}
@@ -317,7 +317,7 @@
if ($rid) {
echo '&nbsp;<input type="submit" name="cancel" value="'.get_string('cancel').'" onclick="javascript:history.go(-1)" />';
} else {
- if ( (!$data->maxentries) || (data_numentries($data)<($data->maxentries-1)) ) {
+ if ((!$data->maxentries) || has_capability('mod/data:manageentries', $context) || (data_numentries($data) < ($data->maxentries - 1))) {
echo '&nbsp;<input type="submit" value="'.get_string('saveandadd','data').'" />';
}
}
View
22 mod/data/lib.php
@@ -1933,15 +1933,25 @@ function data_print_header($course, $cm, $data, $currenttab='') {
* @param int $groupmode
* @return bool
*/
-function data_user_can_add_entry($data, $currentgroup, $groupmode) {
+function data_user_can_add_entry($data, $currentgroup, $groupmode, $context = null) {
global $USER;
- if (!$cm = get_coursemodule_from_instance('data', $data->id)) {
- print_error('invalidcoursemodule');
+ if (empty($context)) {
+ if (!$cm = get_coursemodule_from_instance('data', $data->id)) {
+ print_error('invalidcoursemodule');
+ }
+ $context = get_context_instance(CONTEXT_MODULE, $cm->id);
+ }
+
+ $haswritecapability = has_capability('mod/data:writeentry', $context);
+ $hasmanagecapability = has_capability('mod/data:manageentries', $context);
+
+ if (!$haswritecapability && !$hasmanagecapability) {
+ return false;
}
- $context = get_context_instance(CONTEXT_MODULE, $cm->id);
- if (!has_capability('mod/data:writeentry', $context) and !has_capability('mod/data:manageentries',$context)) {
+ //check for maximum number of entries
+ if ($haswritecapability && !$hasmanagecapability && data_atmaxentries($data)) {
return false;
}
@@ -2836,7 +2846,7 @@ function data_extend_settings_navigation(settings_navigation $settings, navigati
$currentgroup = groups_get_activity_group($PAGE->cm);
$groupmode = groups_get_activity_groupmode($PAGE->cm);
- if (data_user_can_add_entry($data, $currentgroup, $groupmode)) { // took out participation list here!
+ if (data_user_can_add_entry($data, $currentgroup, $groupmode, $PAGE->cm->context)) { // took out participation list here!
if (empty($editentry)) { //TODO: undefined
$addstring = get_string('add', 'data');
} else {
View
2 mod/data/tabs.php
@@ -49,7 +49,7 @@
$row[] = new tabobject('asearch', $CFG->wwwroot.'/mod/data/view.php?d='.$data->id.'&amp;mode=asearch', get_string('search', 'data'));
if (isloggedin()) { // just a perf shortcut
- if (data_user_can_add_entry($data, $currentgroup, $groupmode) && !data_atmaxentries($data)) { // took out participation list here!
+ if (data_user_can_add_entry($data, $currentgroup, $groupmode, $context)) { // took out participation list here!
$addstring = empty($editentry) ? get_string('add', 'data') : get_string('editentry', 'data');
$row[] = new tabobject('add', $CFG->wwwroot.'/mod/data/edit.php?d='.$data->id, $addstring);
}

0 comments on commit e4e9611

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