Permalink
Browse files

Merge branch 'MDL-26464_m20_v2' of github.com:skodak/moodle

  • Loading branch information...
skodak committed Mar 14, 2011
2 parents cd3d282 + 0393a8b commit b0b4ab1aff3224c27d9b23438b45b9821beff98a
Showing with 18 additions and 10 deletions.
  1. +2 −2 mod/data/edit.php
  2. +15 −7 mod/data/lib.php
  3. +1 −1 mod/data/tabs.php
View
@@ -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
@@ -1927,21 +1927,29 @@ function data_print_header($course, $cm, $data, $currenttab='') {
}
/**
- * @global object
+ * Can user add more entries?
+ *
* @param object $data
* @param mixed $currentgroup
* @param int $groupmode
+ * @param stdClass $context
* @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)) {
+ $cm = get_coursemodule_from_instance('data', $data->id, 0, false, MUST_EXIST);
+ $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)) {
+ if (has_capability('mod/data:manageentries', $context)) {
+ // no entry limits apply if user can manage
+
+ } else if (!has_capability('mod/data:writeentry', $context)) {
+ return false;
+
+ } else if (data_atmaxentries($data)) {
return false;
}
@@ -2836,7 +2844,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
@@ -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 b0b4ab1

Please sign in to comment.