}
$jumpurl = new moodle_url($jumpurl, array('page' => $page, 'sesskey' => sesskey()));
- // Check whether this activity is read-only at present
- $readonly = data_in_readonly_period($data);
-
foreach ($records as $record) { // Might be just one for the single template
// Replacing tags
// Replacing special tags (##Edit##, ##Delete##, ##More##)
$patterns[]='##edit##';
$patterns[]='##delete##';
- if ($canmanageentries || (!$readonly && data_isowner($record->id))) {
+ if (data_user_can_manage_entry($record, $data, $context)) {
$replacement[] = '<a href="'.$CFG->wwwroot.'/mod/data/edit.php?d='
.$data->id.'&rid='.$record->id.'&sesskey='.sesskey().'"><img src="'.$OUTPUT->pix_url('t/edit') . '" class="iconsmall" alt="'.get_string('edit').'" title="'.get_string('edit').'" /></a>';
$replacement[] = '<a href="'.$CFG->wwwroot.'/mod/data/view.php?d='
}
}
+/**
+ * Check whether the current user is allowed to manage the given record considering manageentries capability,
+ * data_in_readonly_period() result, ownership (determined by data_isowner()) and manageapproved setting.
+ * @param mixed $record record object or id
+ * @param object $data data object
+ * @param object $context context object
+ * @return bool returns true if the user is allowd to edit the entry, false otherwise
+ */
+function data_user_can_manage_entry($record, $data, $context) {
+ global $DB;
+
+ if (has_capability('mod/data:manageentries', $context)) {
+ return true;
+ }
+
+ // Check whether this activity is read-only at present.
+ $readonly = data_in_readonly_period($data);
+
+ if (!$readonly) {
+ // Get record object from db if just id given like in data_isowner.
+ // ...done before calling data_isowner() to avoid querying db twice.
+ if (!is_object($record)) {
+ if (!$record = $DB->get_record('data_records', array('id' => $record))) {
+ return false;
+ }
+ }
+ if (data_isowner($record)) {
+ if ($data->approval && $record->approved) {
+ return $data->manageapproved == 1;
+ } else {
+ return true;
+ }
+ }
+ }
+
+ return false;
+}
+
/**
* Check whether the specified database activity is currently in a read-only period
*
'maxentries',
'rssarticles',
'approval',
+ 'manageapproved',
'defaultsortdir'
);