MDL-26464: remove 'add entry' link on setting block when it reachs the max number of records. Link removal does not apply to user who has data:manageentries capability (eg: teacher).
This commit is contained in:
+2
-2
@@ -190,7 +190,7 @@ if ($datarecord = data_submitted() and confirm_sesskey()) {
|
||||
|
||||
} 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 @@ echo '<div class="mdl-align"><input type="submit" name="saveandview" value="'.ge
|
||||
if ($rid) {
|
||||
echo ' <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 ' <input type="submit" value="'.get_string('saveandadd','data').'" />';
|
||||
}
|
||||
}
|
||||
|
||||
+16
-6
@@ -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);
|
||||
}
|
||||
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
||||
|
||||
if (!has_capability('mod/data:writeentry', $context) and !has_capability('mod/data:manageentries',$context)) {
|
||||
$haswritecapability = has_capability('mod/data:writeentry', $context);
|
||||
$hasmanagecapability = has_capability('mod/data:manageentries', $context);
|
||||
|
||||
if (!$haswritecapability && !$hasmanagecapability) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//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 {
|
||||
|
||||
+1
-1
@@ -49,7 +49,7 @@
|
||||
$row[] = new tabobject('asearch', $CFG->wwwroot.'/mod/data/view.php?d='.$data->id.'&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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user