MDL-13397 Implemented the requiredentries parameter (previously not implemented). This includes a warning message and an SQL restriction on entries fetched for view.php

This commit is contained in:
nicolasconnault
2008-02-12 15:54:20 +00:00
parent 3211d8b265
commit 1e51f8fa07
2 changed files with 24 additions and 0 deletions
+1
View File
@@ -71,6 +71,7 @@ $string['editordisable'] = 'Disable editor';
$string['emptyadd'] = 'The Add template is empty, generating a default form...';
$string['emptyaddform'] = 'You did not fill out any fields!';
$string['entries'] = 'Entries';
$string['entrieslefttoadd'] = 'You must add $a more entry/entries before you can view other participants\' entries.';
$string['entry'] = 'Entry';
$string['entrysaved'] = 'Your entry has been saved';
$string['errormustbeteacher'] = 'You need to be a teacher to use this page!';
+23
View File
@@ -266,6 +266,16 @@
}
}
// Check the number of entries required against the number of entries already made (doesn't apply to teachers)
$requiredentries_allowed = true;
$numentries = data_numentries($data);
if ($data->requiredentries > 0 && $numentries < $data->requiredentries && !has_capability('mod/data:manageentries', $context)) {
$entriesleft = $data->requiredentries - $numentries;
$strentrieslefttoadd = get_string('entrieslefttoadd', 'data', $entriesleft);
notify($strentrieslefttoadd);
$requiredentries_allowed = false;
}
// If not teacher, check whether user has sufficient records to view
if (!has_capability('mod/data:managetemplates', $context) and data_numentries($data) < $data->requiredentriestoview){
notify (($data->requiredentriestoview - data_numentries($data)).'&nbsp;'.get_string('insufficiententries','data'));
@@ -308,6 +318,10 @@
AND r.userid = u.id
AND c1.recordid = r.id ';
$sortorder = ' ORDER BY _order '.$order.' , r.id ASC ';
// If requiredentries is not reached, only show current user's entries
if (!$requiredentries_allowed) {
$where .= ' AND u.id = ' . $USER->id;
}
if ($search) {
$searchselect = ' AND (c1.content ' . sql_ilike() . " '%$search%') "; //Be case-insensitive
} else {
@@ -322,6 +336,10 @@
AND r.userid = u.id
AND r.dataid = '.$data->id;
$sortorder = ' ORDER BY r.id ASC ';
// If requiredentries is not reached, only show current user's entries
if (!$requiredentries_allowed) {
$where .= ' AND u.id = ' . $USER->id;
}
$searchselect = ' AND (c.content ' . sql_ilike() . " '%$search%') "; //Be case-insensitive
} else {
@@ -331,6 +349,11 @@
$where = 'WHERE r.dataid = '.$data->id. ' AND r.userid = u.id ';
$sortorder = ' ORDER BY r.timecreated '.$order. ' ';
$searchselect = ' ';
// If requiredentries is not reached, only show current user's entries
if (!$requiredentries_allowed) {
$where .= ' AND u.id = ' . $USER->id;
}
}